SHARE
TWEET

Untitled

a guest Jul 21st, 2014 191 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. triggered with:
  2. <element loading data-action="callThisFunction($event)">
  3.  
  4. watcher:
  5. <div ng-show="AILoading" class="loading-spinner">
  6.   <div>
  7.     <i class="fa fa-spin fa-spinner"></i>
  8.   </div>
  9. </div>
  10.  
  11. angular.module('loadingOverlay').directive('loading', ['$rootScope', '$timeout', '$q', function($rootScope, $timeout, $q) {
  12.         return {
  13.                 restrict: 'A',
  14.                 priority: 100,
  15.                 terminal: false,
  16.                 controller: function() {
  17.  
  18.                 },
  19.                 link: function (scope, element, attrs) {
  20.                         var clickAction = attrs.action;
  21.                         scope.isClicked = false;
  22.  
  23.                         scope.$tapHandler = function(event) {
  24.                                 console.log('click, isClicked: ' + scope.isClicked);
  25.                                 if(scope.isClicked == true) {
  26.                                         return;
  27.                                 }
  28.                                 //element.unbind('click');
  29.                                 scope.isClicked = true;
  30.                                 event.stopPropagation();
  31.                                 event.stopImmediatePropagation();
  32.  
  33.                                 scope.$apply(function() {
  34.                                         $rootScope.AILoading = true;
  35.                                         $timeout(function() {
  36.                                                 scope.$eval(clickAction);
  37.                                         }, 0);
  38.                                 });
  39.  
  40.                                 //scope.$eval(clickAction);
  41.  
  42.                                 var unbindWatcher = $rootScope.$watch('AILoading', function(newVal) {
  43.                                         if(newVal == false) {
  44.                                                 //element.bind('click', scope.$tapHandler);
  45.                                                 scope.isClicked = false;
  46.                                                 unbindWatcher();
  47.                                         }
  48.                                 });
  49.                         };
  50.                         element.bind('click', scope.$tapHandler);
  51.                 }
  52.         }
  53. }]);
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