diff --git a/app/scripts/app.js b/app/scripts/app.js index 2fb1e90..0a2e840 100644 --- a/app/scripts/app.js +++ b/app/scripts/app.js @@ -12,7 +12,9 @@ angular.module('jsbb.angularTicker', []) .run(function($rootScope, TickerSrv) { // add the register task to the rootScope. This will allow for autoUnregister when the // scope is destroyed to prevent tasks from leaking. - $rootScope.registerTickerTask = function(id, tickHandler, interval, delay, isLinear) { + + var ScopeProt = Object.getPrototypeOf($rootScope); + ScopeProt.registerTickerTask = function(id, tickHandler, interval, delay, isLinear) { TickerSrv.register(id, tickHandler, interval, delay, isLinear); this.$on('$destroy', function() { @@ -20,30 +22,5 @@ angular.module('jsbb.angularTicker', []) }); }; - $rootScope.unregisterTickerTask = TickerSrv.unregister; - - // since isolated scopes do not inherit prototypically from rootScope, we need to override $new - // and add the functionality manually. - function applyScopeApi (targetScope) { - if (!targetScope.$origNew) { - targetScope.$origNew = targetScope.$new; - } - - return function(isolate, parent) { - var newScope = targetScope.$origNew(isolate, parent); - - if (isolate) { - newScope.unregisterTickerTask = $rootScope.unregisterTickerTask; - newScope.registerTickerTask = $rootScope.registerTickerTask; - } - - newScope.$new = applyScopeApi(newScope); - - return newScope; - }; - - } - - $rootScope.$new = applyScopeApi($rootScope); - + ScopeProt.unregisterTickerTask = TickerSrv.unregister; }); diff --git a/release/angular-ticker.js b/release/angular-ticker.js index fe4c459..c5a030c 100644 --- a/release/angular-ticker.js +++ b/release/angular-ticker.js @@ -12,7 +12,9 @@ angular.module('jsbb.angularTicker', []) .run(["$rootScope", "TickerSrv", function($rootScope, TickerSrv) { // add the register task to the rootScope. This will allow for autoUnregister when the // scope is destroyed to prevent tasks from leaking. - $rootScope.registerTickerTask = function(id, tickHandler, interval, delay, isLinear) { + + var ScopeProt = Object.getPrototypeOf($rootScope); + ScopeProt.registerTickerTask = function(id, tickHandler, interval, delay, isLinear) { TickerSrv.register(id, tickHandler, interval, delay, isLinear); this.$on('$destroy', function() { @@ -20,32 +22,7 @@ angular.module('jsbb.angularTicker', []) }); }; - $rootScope.unregisterTickerTask = TickerSrv.unregister; - - // since isolated scopes do not inherit prototypically from rootScope, we need to override $new - // and add the functionality manually. - function applyScopeApi (targetScope) { - if (!targetScope.$origNew) { - targetScope.$origNew = targetScope.$new; - } - - return function(isolate, parent) { - var newScope = targetScope.$origNew(isolate, parent); - - if (isolate) { - newScope.unregisterTickerTask = $rootScope.unregisterTickerTask; - newScope.registerTickerTask = $rootScope.registerTickerTask; - } - - newScope.$new = applyScopeApi(newScope); - - return newScope; - }; - - } - - $rootScope.$new = applyScopeApi($rootScope); - + ScopeProt.unregisterTickerTask = TickerSrv.unregister; }]); ;/** * Created by sefi on 5/13/14. diff --git a/release/angular-ticker.min.js b/release/angular-ticker.min.js index f95c8a5..9a13632 100644 --- a/release/angular-ticker.min.js +++ b/release/angular-ticker.min.js @@ -1 +1 @@ -"use strict";angular.module("jsbb.angularTicker",[]).run(["$rootScope","TickerSrv",function(a,b){function c(b){return b.$origNew||(b.$origNew=b.$new),function(d,e){var f=b.$origNew(d,e);return d&&(f.unregisterTickerTask=a.unregisterTickerTask,f.registerTickerTask=a.registerTickerTask),f.$new=c(f),f}}a.registerTickerTask=function(a,c,d,e,f){b.register(a,c,d,e,f),this.$on("$destroy",function(){b.unregister(a)})},a.unregisterTickerTask=b.unregister,a.$new=c(a)}]),angular.module("jsbb.angularTicker").provider("TickerSrv",function(){function a(a){var d=function(a){a.delay=a.interval,a.isPending=!1},e=function(a){a.isPending||(a.isPending=!0,a.tick().then(function(){d(a)},function(){d(a)}))},f=function(a){a.tick(),d(a)},g=function(){angular.forEach(b,function(a){if(a.delay-=c,a.delay<=0)try{a.isLinear?e(a):f(a)}catch(b){throw d(a),b}})},h=function(){a(g,c),g()};this.register=function(a,c,d,e,f){void 0===d&&(d=1e3),void 0===e&&(e=0),void 0===f&&(f=!0),b[a]={id:a,tick:c,interval:d,delay:e,isLinear:f,isPending:!1}},this.unregister=function(a){delete b[a]},this.unregisterAll=function(){b={}},h()}var b={},c=1e3;this.setInterval=function(a){if(!angular.isNumber(a))throw new Error("TickerSrv: expected interval to be numeric, got "+a);c=a},this.getInterval=function(){return c},this.$get=["$interval",function(b){return new a(b)}]}); \ No newline at end of file +"use strict";angular.module("jsbb.angularTicker",[]).run(["$rootScope","TickerSrv",function(a,b){var c=Object.getPrototypeOf(a);c.registerTickerTask=function(a,c,d,e,f){b.register(a,c,d,e,f),this.$on("$destroy",function(){b.unregister(a)})},c.unregisterTickerTask=b.unregister}]),angular.module("jsbb.angularTicker").provider("TickerSrv",function(){function a(a){var d=function(a){a.delay=a.interval,a.isPending=!1},e=function(a){a.isPending||(a.isPending=!0,a.tick().then(function(){d(a)},function(){d(a)}))},f=function(a){a.tick(),d(a)},g=function(){angular.forEach(b,function(a){if(a.delay-=c,a.delay<=0)try{a.isLinear?e(a):f(a)}catch(b){throw d(a),b}})},h=function(){a(g,c),g()};this.register=function(a,c,d,e,f){void 0===d&&(d=1e3),void 0===e&&(e=0),void 0===f&&(f=!0),b[a]={id:a,tick:c,interval:d,delay:e,isLinear:f,isPending:!1}},this.unregister=function(a){delete b[a]},this.unregisterAll=function(){b={}},h()}var b={},c=1e3;this.setInterval=function(a){if(!angular.isNumber(a))throw new Error("TickerSrv: expected interval to be numeric, got "+a);c=a},this.getInterval=function(){return c},this.$get=["$interval",function(b){return new a(b)}]}); \ No newline at end of file