wpmind/vendors/assets/conditionize/conditionize.min.js
2023-06-02 17:29:56 +03:00

7 lines
7.7 KiB
JavaScript

/*!
* Name : Conditionize - jQuery conditions for forms
* Version : 1.0.5
* Author : nK <https://nkdev.info>
* GitHub : https://github.com/nk-o/conditionize
*/!function(n){var o={};function r(t){if(o[t])return o[t].exports;var e=o[t]={i:t,l:!1,exports:{}};return n[t].call(e.exports,e,e.exports,r),e.l=!0,e.exports}r.m=n,r.c=o,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,n){t.exports=n(1)},function(t,e,n){"use strict";n.r(e);var r=n(2),o=n(3);function u(t){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function c(e,t){var n,o=Object.keys(e);return Object.getOwnPropertySymbols&&(n=Object.getOwnPropertySymbols(e),t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),o.push.apply(o,n)),o}function i(r){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?c(Object(i),!0).forEach(function(t){var e,n,o;e=r,o=i[n=t],n in e?Object.defineProperty(e,n,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[n]=o}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(i)):c(Object(i)).forEach(function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(i,t))})}return r}function a(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}var f=o.window.jQuery,s=0;function l(t){this.table=t}l.prototype.parse=function(t){for(var e,n=t.length,o=this.table,r=[],i=[],c=0;c<n;){switch(e=t[c++]){case"(":i.unshift(e);break;case")":for(;i.length;){if("("===(e=i.shift()))break;r.push(e)}if("("!==e)throw new Error("Mismatched parentheses.");break;default:if(o.hasOwnProperty(e)){for(;i.length;){var u=i[0];if("("===u)break;var a=o[e],f=a.precedence,s=o[u].precedence;if(s<f||f===s&&"right"===a.associativity)break;r.push(i.shift())}i.unshift(e)}else r.push(e)}}for(;i.length;){if("("===(e=i.shift()))throw new Error("Mismatched parentheses.");r.push(e)}return r};function p(t,e){("object"===("undefined"==typeof HTMLElement?"undefined":u(HTMLElement))?t instanceof HTMLElement:t&&"object"===u(t)&&null!==t&&1===t.nodeType&&"string"==typeof t.nodeName)&&(t=[t]);for(var n,o=e,r=Array.prototype.slice.call(arguments,2),i=t.length,c=0;c<i;c++)if("object"===u(o)||void 0===o?t[c].Conditionize||(t[c].Conditionize=new v(t[c],o)):t[c].Conditionize&&(n=t[c].Conditionize[o].apply(t[c].Conditionize,r)),void 0!==n)return n;return t}var d={precedence:3,associativity:"left"},y={precedence:2,associativity:"left"},h={"==":{eval:function(t,e){return t==e},sort:y},"!=":{eval:function(t,e){return t!=e},sort:y},"===":{eval:function(t,e){return t===e},sort:y},"!==":{eval:function(t,e){return t!==e},sort:y},"*=":{eval:function(t,e){return-1!==t.indexOf(e)},sort:y},"<=":{eval:function(t,e){return t<=e},sort:d},">=":{eval:function(t,e){return e<=t},sort:d},"<":{eval:function(t,e){return t<e},sort:d},">":{eval:function(t,e){return e<t},sort:d},"&&":{eval:function(t,e){return t&&e},sort:{precedence:1,associativity:"right"}},"||":{eval:function(t,e){return t||e},sort:{precedence:0,associativity:"right"}}},v=function(){function o(t,e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,o);var n=this;n.instanceID=s++,n.$container=f(t),n.defaults={selector:"[data-cond]",conditionAttr:"data-cond",checkDebounce:150,customToggle:null,onInit:null,onDestroy:null,onCheck:null},n.options=i(i({},n.defaults),e),n.runCheck=Object(r.debounce)(n.options.checkDebounce,n.runCheck),n.init()}var t,e,n;return t=o,(e=[{key:"init",value:function(){var t=this;t.options.customToggle?t.options.customToggle.call(t,t.$container.find(t.options.selector),!1):t.$container.find(t.options.selector).hide(),t.$container.on("change.conditionize","input, select, textarea",function(){t.runCheck(t.$container.find(t.options.selector))}),t.runCheck(t.$container.find(t.options.selector)),t.options.onInit&&t.options.onInit.call(t)}},{key:"runCheck",value:function(t){var o=this;t.each(function(){var t=f(this),e=t.attr(o.options.conditionAttr).toString(),n=o.checkCondition(e);o.options.customToggle?o.options.customToggle.call(o,t,n):t[n?"show":"hide"](),o.options.onCheck&&o.options.onCheck(t,n)})}},{key:"checkCondition",value:function(t){var e=t.match(/[^\s]+/g),n={};Object.keys(h).forEach(function(t){n[t]=h[t].sort});for(var o,r,i,e=new l(n).parse(e),c=[],u=0;u<e.length;){(i=e[u++])in h?(o=c.pop(),r=c.pop(),c.push([r,i,o])):c.push(i)}return this.compare(c.length&&c[0])}},{key:"isValidSelector",value:function(t){if("string"!=typeof t||f.isNumeric(t)||"false"===t||"true"===t||0==t||1==t)return!1;try{f(t)}catch(t){return!1}return!0}},{key:"condition",value:function(t,e,n){return e in h&&("false"===t?t=!1:"true"===t&&(t=!0),"false"===n?n=!1:"true"===n&&(n=!0),h[e].eval(t,n))}},{key:"compare",value:function(t){var e=this;if(t instanceof Array)return 3===t.length?(t[0]=e.compare(t[0]),t[2]instanceof Array&&(t[2]=e.compare(t[2])),e.condition(t[0],t[1],t[2])):1===t.length&&e.compare(t[0]);if(e.isValidSelector(t)){var n=f(t),o=!1;return n.is("[type=checkbox]")?o=n.is(":checked"):n.is("[type=radio]")?o=n.filter(":checked").val():n.is("textarea, select, input")&&(o=n.val()),o}return t}},{key:"destroy",value:function(){var t=this;t.options.onDestroy&&t.options.onDestroy.call(t),t.$container.off("change.conditionize"),t.options.customToggle?t.options.customToggle.call(t,t.$container.find(t.options.selector),!0):t.$container.find(t.options.selector).show(),delete t.$container.Conditionize}}])&&a(t.prototype,e),n&&a(t,n),o}();p.constructor=v,o.window.Conditionize=v;function b(){var t=arguments||[];Array.prototype.unshift.call(t,this);var e=p.apply(o.window,t);return"object"!==u(e)?e:this}b.constructor=p.constructor;var g=f.fn.conditionize;f.fn.conditionize=b,f.fn.conditionize.noConflict=function(){return f.fn.conditionize=g,this}},function(t,e,n){"use strict";function o(r,i,c,u){var a,f=!1,s=0;function l(){a&&clearTimeout(a)}function t(){var t=this,e=Date.now()-s,n=arguments;function o(){s=Date.now(),c.apply(t,n)}f||(u&&!a&&o(),l(),void 0===u&&r<e?o():!0!==i&&(a=setTimeout(u?function(){a=void 0}:o,void 0===u?r-e:r)))}return"boolean"!=typeof i&&(u=c,c=i,i=void 0),t.cancel=function(){l(),f=!0},t}function r(t,e,n){return void 0===n?o(t,e,!1):o(t,n,!1!==e)}n.r(e),n.d(e,"throttle",function(){return o}),n.d(e,"debounce",function(){return r})},function(n,t,e){(function(t){var e="undefined"!=typeof window?window:void 0!==t?t:"undefined"!=typeof self?self:{};n.exports=e}).call(this,e(4))},function(t,e){function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var o=function(){return this}();try{o=o||new Function("return this")()}catch(t){"object"===("undefined"==typeof window?"undefined":n(window))&&(o=window)}t.exports=o}]);
//# sourceMappingURL=conditionize.min.js.map