Code coverage report for ./angular-spinner.js

Statements: 100% (14 / 14)      Branches: 100% (2 / 2)      Functions: 100% (5 / 5)      Lines: 100% (14 / 14)     

All files » .\ » angular-spinner.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34          1   1   6     7   1 9 2 2       7 8 8 8     7 1          
/* angular-spinner version 0.2.1
 * License: MIT.
 * Copyright (C) 2013, Uri Shaked.
 */
 
'use strict';
 
angular.module('angularSpinner', [])
	.directive('usSpinner', ['$window', function ($window) {
		return {
			scope: true,
			link: function (scope, element, attr) {
				scope.spinner = null;
				
				function stopSpinner() {
					if (scope.spinner) {
						scope.spinner.stop();
						scope.spinner = null;
					}
				}
				
				scope.$watch(attr.usSpinner, function (options) {
					stopSpinner();
					scope.spinner = new $window.Spinner(options);
					scope.spinner.spin(element[0]);
				}, true);
				
				scope.$on('$destroy', function () {
					stopSpinner();
				});
			}
		};
	}]);