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

1 line
8.8 KiB
JavaScript
Raw Normal View History

2020-04-28 06:37:33 -04:00
"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(