forked from kirstein/angular-autodisable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular-autodisable.min.js
7 lines (7 loc) · 1.25 KB
/
angular-autodisable.min.js
1
2
3
4
5
6
7
/*
* angular-autodisable 0.1.1
* http://github.com/kirstein/angular-autodisable
*
* Licensed under the MIT license
*/
!function(a){"use strict";return a.module("ngAutodisable",[]).directive("ngAutodisable",["$parse",function(b){function c(b){return b&&a.isFunction(b.then)&&a.isFunction(b["finally"])}function d(a,b,d){var e=d(b,{$event:a.eventName});c(e)&&a.handlePromise(e)}function e(a,b,c){c.unbind(a.eventName).bind(a.eventName,function(){b.$apply(function(){a.callbacks.forEach(d.bind(null,a,b))})})}function f(a){return a.split(";").map(function(a){return b(a,null,!0)})}function g(a){return a.hasOwnProperty(n)?a[n]:!1}function h(a,b,c,d){function e(){j--,0===j&&g()}function f(){a.attr(i,!0),c&&a.addClass(c)}function g(){a.attr(i,!1),c&&a.removeClass(c)}var h={},j=0;return h.eventName=b,h.callbacks=d,h.handlePromise=function(a){0===j&&f(),j++,a["finally"](function(){e()})},h}var i="disabled",j="click",k="ngClick",l="submit",m="ngSubmit",n="ngAutodisableClass";return{restrict:"A",compile:function(a,b){var c;if(b.hasOwnProperty(k))c=h(a,j,g(b),f(b[k]));else{if(!b.hasOwnProperty(m))throw new Error("ngAutodisable requires ngClick or ngSubmit attribute in order to work");c=h(a.find("button[type=submit]"),l,g(b),f(b[m]))}return e.bind(null,c)}}}])}(angular);