Last active
August 29, 2015 14:19
-
-
Save fredericksilva/37794a6e90c346e49e5d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/** | |
* ui-ladda | |
* | |
* To use, simply use normal Ladda classes and attributes and pass a model to ui-ladda. You can | |
* use truthy or falsey values, or pass decimals from 0 to 1 to show the progress bar animation. | |
* | |
* | |
* @param uiLadda (mixed): Sets wether or not to show the ladda loading | |
* truthy - show loading animation | |
* falsey (non-zero) - stop loading animation | |
* number (decimal from 0 to 1) - show loading and progress animation | |
* @example: | |
* <button ui-ladda="loading" class="ladda-button" data-style="expand-right" ng-click="loading=true"> | |
* <span class="ladda-label">Submit</span> | |
* </button> | |
*/ | |
angular.module('ui.ladda', []).directive('uiLadda', [function () { | |
return { | |
link: function postLink(scope, element, attrs) { | |
var ladda = Ladda.create(element[0]); | |
scope.$watch(attrs.uiLadda, function(newVal, oldVal){ | |
if (angular.isNumber(oldVal)) { | |
if (angular.isNumber(newVal)) { | |
ladda.setProgress(newVal); | |
} else { | |
newVal && ladda.setProgress(0) || ladda.stop(); | |
} | |
} else { | |
newVal && ladda.start() || ladda.stop(); | |
} | |
}); | |
} | |
}; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment