Built motion from commit 54a160d.|0.0.140
[motion.git] / public / bower_components / angular-spinner / angular-spinner.js
1 /**
2  * angular-spinner version 0.8.1
3  * License: MIT.
4  * Copyright (C) 2013, 2014, 2015, 2016, Uri Shaked and contributors.
5  */
6
7 'format amd';
8
9 (function (root) {
10         'use strict';
11
12         function factory(angular, Spinner) {
13
14                 return angular
15                         .module('angularSpinner', [])
16
17                         .constant('SpinJSSpinner', Spinner)
18
19                         .provider('usSpinnerConfig', function () {
20                                 var _config = {}, _themes = {};
21
22                                 return {
23                                         setDefaults: function (config) {
24                                                 _config = config || _config;
25                                         },
26                                         setTheme: function(name, config) {
27                                                 _themes[name] = config;
28                                         },
29                                         $get: function () {
30                                                 return {
31                                                         config: _config,
32                                                         themes: _themes
33                                                 };
34                                         }
35                                 };
36                         })
37
38                         .factory('usSpinnerService', ['$rootScope', function ($rootScope) {
39                                 var config = {};
40
41                                 config.spin = function (key) {
42                                         $rootScope.$broadcast('us-spinner:spin', key);
43                                 };
44
45                                 config.stop = function (key) {
46                                         $rootScope.$broadcast('us-spinner:stop', key);
47                                 };
48
49                                 return config;
50                         }])
51
52                         .directive('usSpinner', ['SpinJSSpinner', 'usSpinnerConfig', function (SpinJSSpinner, usSpinnerConfig) {
53                                 return {
54                                         scope: true,
55                                         link: function (scope, element, attr) {
56                                                 scope.spinner = null;
57
58                                                 scope.key = angular.isDefined(attr.spinnerKey) ? attr.spinnerKey : false;
59
60                                                 scope.startActive = angular.isDefined(attr.spinnerStartActive) ?
61                                                         scope.$eval(attr.spinnerStartActive) : scope.key ?
62                                                         false : true;
63
64                                                 function stopSpinner() {
65                                                         if (scope.spinner) {
66                                                                 scope.spinner.stop();
67                                                         }
68                                                 }
69
70                                                 scope.spin = function () {
71                                                         if (scope.spinner) {
72                                                                 scope.spinner.spin(element[0]);
73                                                         }
74                                                 };
75
76                                                 scope.stop = function () {
77                                                         scope.startActive = false;
78                                                         stopSpinner();
79                                                 };
80
81                                                 scope.$watch(attr.usSpinner, function (options) {
82                                                         stopSpinner();
83
84                                                         // order of precedence: element options, theme, defaults.
85                                                         options = angular.extend(
86                                                                 {},
87                                                                 usSpinnerConfig.config,
88                                                                 usSpinnerConfig.themes[attr.spinnerTheme],
89                                                                 options);
90
91                                                         scope.spinner = new SpinJSSpinner(options);
92                                                         if ((!scope.key || scope.startActive) && !attr.spinnerOn) {
93                                                                 scope.spinner.spin(element[0]);
94                                                         }
95                                                 }, true);
96
97                                                 if (attr.spinnerOn) {
98                                                         scope.$watch(attr.spinnerOn, function (spin) {
99                                                                 if (spin) {
100                                                                         scope.spin();
101                                                                 } else {
102                                                                         scope.stop();
103                                                                 }
104                                                         });
105                                                 }
106
107                                                 scope.$on('us-spinner:spin', function (event, key) {
108                                                         if (key === scope.key) {
109                                                                 scope.spin();
110                                                         }
111                                                 });
112
113                                                 scope.$on('us-spinner:stop', function (event, key) {
114                                                         if (key === scope.key) {
115                                                                 scope.stop();
116                                                         }
117                                                 });
118
119                                                 scope.$on('$destroy', function () {
120                                                         scope.stop();
121                                                         scope.spinner = null;
122                                                 });
123                                         }
124                                 };
125                         }]);
126         }
127
128     if ((typeof module === 'object') && module.exports) {
129                 /* CommonJS module */
130                 module.exports = factory(require('angular'), require('spin.js'));
131         } else if (typeof define === 'function' && define.amd) {
132                 /* AMD module */
133                 define(['angular', 'spin'], factory);
134         } else {
135                 /* Browser global */
136                 factory(root.angular, root.Spinner);
137         }
138 }(this));