SHARE
TWEET

Untitled

a guest Jul 21st, 2014 200 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. triggered with
  2.  
  3. <element loading data-action="callThisFunction($event)">
  4.  
  5. angular.module('loadingOverlay').directive('loading', ['$rootScope', '$timeout', '$q', function($rootScope, $timeout, $q) {
  6.         return {
  7.                 restrict: 'A',
  8.                 priority: 100,
  9.                 terminal: false,
  10.                 controller: function() {
  11.  
  12.                 },
  13.                 link: function (scope, element, attrs) {
  14.                         var clickAction = attrs.action;
  15.  
  16.                         scope.$tapHandler = function(event) {
  17.                                 element.unbind('click');
  18.                                 event.stopPropagation();
  19.                                 event.stopImmediatePropagation();
  20.  
  21.                                 scope.$apply(function() {
  22.                                         $rootScope.AILoading = true;
  23.                                         $timeout(function() {
  24.                                                 scope.$eval(clickAction);
  25.                                         }, 0);
  26.                                 });
  27.  
  28.                                 var unbindWatcher = $rootScope.$watch('AILoading', function(newVal) {
  29.                                         if(newVal == false) {
  30.                                                 element.bind('click', scope.$tapHandler);
  31.                                                 unbindWatcher();
  32.                                         }
  33.                                 });
  34.                         };
  35.                         element.bind('click', scope.$tapHandler);
  36.                 }
  37.         }
  38. }]);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top