mage-eventpress/js/form-field-dependency.min.js

1 line
8.8 KiB
JavaScript
Executable File

"use strict";(function(a){a.fn.formFieldDependency=function(o){var d=a.extend({attribute:"data-depends",rules:{}},o);var e=function(q,s,p){if(typeof p=="undefined"){p=false}if(q==null){q=[]}if(p==true){if((q.sort().join(",").toLowerCase())==(s.sort().join(",").toLowerCase())){return true}return false}else{for(var r=0;r<q.length;r++){if(s.indexOf(q[r])>=0){return true}}return false}};var l=function(p,q){if((a.inArray(p,q)>=0)&&a.isArray(q)){return true}else{return false}};var h=function(q){if(typeof q=="null"||typeof q=="undefined"){return true}if(typeof q=="string"){return(a.trim(q)=="")?true:false}if(typeof q=="string"){return(a.trim(q)=="")?true:false}if(typeof q=="object"){if(a.isArray(q)){var p=a.map(q,function(s,r){return(a.trim(s)=="")?null:s});return a.isEmptyObject(p)}else{return a.isEmptyObject(q)}}};var k=function(s,t,x,q){if(typeof q=="undefined"){q=false}if(typeof a(x).prop("tagName")=="undefined"){return false}var y=a(x).prop("tagName").toLowerCase();var v=a(x).prop("type").toLowerCase();var p=y+":"+v;var w=a.trim(a(x).val());switch(p){case"input:text":case"input:password":case"input:number":case"input:date":case"input:email":case"input:url":case"input:tel":case"textarea:textarea":var r=(typeof t.modifier=="undefined")?"":t.modifier;var u=new RegExp(t.pattern,r);if(u.test(w)){a(s).show()}else{a(s).hide()}break}if(q){a(document.body).on("keyup",a(x),function(z){z.stopPropagation();k(s,t,x,false)})}};var f=function(s,r,u,v){if(typeof v=="undefined"){v=false}if(typeof a(u).prop("tagName")=="undefined"){return false}var p=a(u).prop("tagName").toLowerCase();var t=a(u).prop("type").toLowerCase();var q=p+":"+t;var w=a(u).val();switch(q){case"input:text":case"input:password":case"input:number":case"input:date":case"input:email":case"input:url":case"input:tel":case"textarea:textarea":case"select:select-one":if(a.trim(w)==""){a(s).show()}else{a(s).hide()}break;case"input:checkbox":if(a(u).is(":checked")&&a.trim(w)!=""){a(s).hide()}else{a(s).show()}break;case"select:select-multiple":if(h(w)){a(s).show()}else{a(s).hide()}break}if(v){a(document.body).on("keyup change",a(u),function(x){x.stopPropagation();f(s,r,u,false)})}};var i=function(s,r,u,v){if(typeof v=="undefined"){v=false}if(typeof a(u).prop("tagName")=="undefined"){return false}var p=a(u).prop("tagName").toLowerCase();var t=a(u).prop("type").toLowerCase();var q=p+":"+t;var w=a(u).val();switch(q){case"input:text":case"input:password":case"input:number":case"input:date":case"input:email":case"input:url":case"input:tel":case"textarea:textarea":case"select:select-one":if(a.trim(w)!=""){a(s).show()}else{a(s).hide()}break;case"input:checkbox":if(a(u).is(":checked")&&a.trim(w)!=""){a(s).show()}else{a(s).hide()}break;case"select:select-multiple":if(h(w)){a(s).hide()}else{a(s).show()}break}if(v){a(document.body).on("keyup change",a(u),function(x){x.stopPropagation();i(s,r,u,false)})}};var b=function(s,t,y,q){console.log(q);if(typeof q=="undefined"){q=false}if(typeof a(y).prop("tagName")=="undefined"){return false}var A=a(y).prop("tagName").toLowerCase();var v=a(y).prop("type").toLowerCase();var p=A+":"+v;var x=a(y).val();var u=(typeof t.like=="undefined")?false:true;t.empty=(typeof t.empty=="undefined")?false:t.empty;t.strict=(typeof t.strict=="undefined")?false:t.strict;if(u){var w=a(t.like).prop("tagName").toLowerCase();var z=a(t.like).prop("type").toLowerCase();var r=w+":"+z;if(r=="input:checkbox"||r=="input:radio"){t.value=a(t.like+":checked").map(function(){return this.value}).get()}else{t.value=a(t.like).val();if(!showOnEmptyValue){t.value=(a.trim(a(t.like).val())=="")?null:a(t.like).val()}}}switch(p){case"input:text":case"input:password":case"input:number":case"input:date":case"input:email":case"input:url":case"input:tel":case"textarea:textarea":case"select:select-one":if(a.trim(x)==t.value){a(s).show()}else{if(l(x,t.value)){a(s).show()}else{if(a.trim(x)==""&&t.empty){a(s).show()}else{a(s).hide()}}}break;case"input:checkbox":case"input:radio":var x=a(y+":checked").map(function(){return this.value}).get();if(x==t.value){a(s).show()}else{if(l(x,t.value)){a(s).show()}else{if(e(x,t.value,t.strict)){a(s).show()}else{if(h(x)&&t.empty){a(s).show()}else{a(s).hide()}}}}break;case"select:select-multiple":if(e(x,t.value,t.strict)){a(s).show()}else{if(x==null&&t.empty){a(s).show()}else{a(s).hide()}}break}if(q){a(document.body).on("keyup change",a(y),function(B){B.stopPropagation();b(s,t,y,false)})}};var c=function(s,t,y,q){if(typeof q=="undefined"){q=false}if(typeof a(y).prop("tagName")=="undefined"){return false}var A=a(y).prop("tagName").toLowerCase();var v=a(y).prop("type").toLowerCase();var p=A+":"+v;var x=a(y).val();var u=(typeof t.like=="undefined")?false:true;t.strict=(typeof t.strict=="undefined")?false:t.strict;t.empty=(typeof t.empty=="undefined")?true:t.empty;if(u){var w=a(t.like).prop("tagName").toLowerCase();var z=a(t.like).prop("type").toLowerCase();var r=w+":"+z;if(r=="input:checkbox"||r=="input:radio"){t.value=a(t.like+":checked").map(function(){return this.value}).get()}else{t.value=a(t.like).val();if(!showOnEmptyValue){t.value=(a.trim(a(t.like).val())=="")?null:a(t.like).val()}}}switch(p){case"input:text":case"input:password":case"input:number":case"input:date":case"input:email":case"input:url":case"input:tel":case"textarea:textarea":case"select:select-one":if(x==t.value){a(s).hide()}else{if(l(x,t.value)){a(s).hide()}else{if(a.trim(x)==""&&!t.empty){a(s).hide()}else{a(s).show()}}}break;case"input:checkbox":case"input:radio":x=a(y+":checked").map(function(){return this.value}).get();if(typeof t.strict=="undefined"){t.strict=false}if(x==t.value){a(s).hide()}else{if(l(x,t.value)){a(s).hide()}else{if(e(x,t.value,t.strict)){a(s).hide()}else{if(h(x)&&!t.empty){a(s).hide()}else{a(s).show()}}}}break;case"select:select-multiple":if(e(x,t.value,t.strict)){a(s).hide()}else{if(x==null&&!t.empty){a(s).hide()}else{a(s).show()}}break}if(q){a(document.body).on("keyup change",a(y),function(B){B.stopPropagation();c(s,t,y,false)})}};var n=function(s,r,u,v){if(typeof v=="undefined"){v=false}if(typeof a(u).prop("tagName")=="undefined"){return false}var p=a(u).prop("tagName").toLowerCase();var t=a(u).prop("type").toLowerCase();var q=p+":"+t;var w=parseInt(a(u).val());r.value=parseInt(r.value);switch(r.sign){case"<":case"lt":case"lessthen":case"less-then":case"LessThen":if(w<r.value){a(s).show()}else{a(s).hide()}break;case"<=":case"lteq":case"lessthenequal":case"less-then-equal":case"LessThenEqual":case"eqlt":if(w<=r.value){a(s).show()}else{a(s).hide()}break;case">=":case"gteq":case"greaterthenequal":case"greater-then-equal":case"GreaterThenEqual":case"eqgt":if(w>=r.value){a(s).show()}else{a(s).hide()}break;case">":case"gt":case"greaterthen":case"greater-then":case"GreaterThen":if(w>r.value){a(s).show()}else{a(s).hide()}break}if(v){a(document.body).on("keyup change",a(u),function(x){x.stopPropagation();n(s,r,u,false)})}};var g=function(s,t,x,q){if(typeof q=="undefined"){q=false}if(typeof a(x).prop("tagName")=="undefined"){return false}var y=a(x).prop("tagName").toLowerCase();var u=a(x).prop("type").toLowerCase();var p=y+":"+u;var w=parseInt(a(x).val());var r,v;if(a.isArray(t.value)){r=parseInt(t.value[0]);v=parseInt(t.value[1])}if(typeof t.value=="undefined"){r=parseInt(t.min);v=parseInt(t.max)}if(r<w&&w<v){a(s).show()}else{a(s).hide()}if(q){a(document.body).on("keyup change",a(x),function(z){z.stopPropagation();g(s,t,x,false)})}};var m=function(s,r,u,v){if(typeof v=="undefined"){v=false}if(typeof a(u).prop("tagName")=="undefined"){return false}var p=a(u).prop("tagName").toLowerCase();var t=a(u).prop("type").toLowerCase();var q=p+":"+t;var w=a(u).val().length;r.value=parseInt(r.value);switch(r.sign){case"<":case"lt":case"lessthen":case"less-then":case"LessThen":if(w<r.value){a(s).show()}else{a(s).hide()}break;case"<=":case"lteq":case"lessthenequal":case"less-then-equal":case"LessThenEqual":case"eqlt":if(w<=r.value){a(s).show()}else{a(s).hide()}break;case">=":case"gteq":case"greaterthenequal":case"greater-then-equal":case"GreaterThenEqual":case"eqgt":if(w>=r.value){a(s).show()}else{a(s).hide()}break;case">":case"gt":case"greaterthen":case"greater-then":case"GreaterThen":if(w>r.value){a(s).show()}else{a(s).hide()}break}if(v){a(document.body).on("keyup change",a(u),function(x){x.stopPropagation();m(s,r,u,false)})}};var j=function(q,p){a.each(p,function(r,s){switch(s.type){case"empty":f(q,s,r,true);break;case"notempty":case"not-empty":case"notEmpty":case"!empty":i(q,s,r,true);break;case"equal":case"==":case"=":b(q,s,r,true);break;case"!equal":case"notequal":case"!=":case"not-equal":case"notEqual":c(q,s,r,true);break;case"regexp":case"expression":case"reg":case"exp":k(q,s,r,true);break;case"compare":case"comp":n(q,s,r,true);break;case"length":case"lng":m(q,s,r,true);break;case"range":g(q,s,r,true);break}})};(function(p){a.each(p,function(r,q){j(a(r),q)})})(d.rules);return this.each(function(){var p=JSON.parse(a(this).attr(d.attribute).replace(/'/g,'"'));var q=a(this);a.each(p,function(r,s){j(q,s)})})}})(jQuery);