-
Notifications
You must be signed in to change notification settings - Fork 3
/
ngModelOptions.min.js
1 lines (1 loc) · 1.82 KB
/
ngModelOptions.min.js
1
!function(a,b){"undefined"!=typeof module&&module.exports?module.exports=b(require("angular")):"function"==typeof define&&define.amd?define(["angular"],b):b(a.angular)}(window,function(a){a.module("modelOptions",[]).directive("ngModelOptions",function(){return{priority:1,restrict:"A",require:["ngModel"],link:function(b,c,d,e){function f(){var a;switch(j){case"inputradio":a=d.ngValue?b.$eval(d.ngValue):c.val();break;case"inputcheckbox":a=c.prop("checked");break;case"select":a=g();break;default:a=c.val(),d.ngTrim&&"false"===d.ngTrim.toLowerCase()||(a=a.replace(/^\s+|\s+$/g,""))}b.$apply(function(){e[0].$setViewValue(a)})}function g(){if(!d.ngOptions)throw"Must have ng-options";var e,f=d.ngOptions.match(i),g=f[8],h=f[7],j=b.$eval(h),k=c.val();return g?a.forEach(j,function(a,b){a[g.replace(/^.*?\./,"")]==k&&(e=b)}):e=k,/.*\..*/.test(f[1])?b.$eval(f[1].replace(/^.*?\./,h+"["+e+"].")):j[e]}var h,i=/^\s*([\s\S]+?)(?:\s+as\s+([\s\S]+?))?(?:\s+group\s+by\s+([\s\S]+?))?\s+for\s+(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?$/,j=c[0].nodeName.toLowerCase()+(d.type||""),k=[],l={debounce:0,updateOn:"default"},m=a.extend(l,b.$eval(d.ngModelOptions)),n="object"==typeof m.debounce,o=m.updateOn.split(" ");k="inputtext"===j||"textarea"===j?["keydown","input","change"]:"inputradio"===j||"inputcheckbox"===j?["click"]:"select"===j?["change"]:["keydown","input","change"],a.forEach(k,function(a){try{c.off(a)}catch(b){}}),m.updateOn.match(/default/i)&&c.on(k.join(" "),function(){var a=m.debounce["default"]||m.debounce||0;clearTimeout(h),h=setTimeout(function(){f()},a)}),a.forEach(o,function(a){if("default"!==a){var b;b=n?m.debounce[a]:m.debounce;var d=b;"undefined"==typeof d&&(d=m.debounce["default"]||0),c.on(a,function(){clearTimeout(h),h=setTimeout(function(){f()},d)})}})}}})});