Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 4 additions & 27 deletions app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,15 @@ 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() {
TickerSrv.unregister(id);
});
};

$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;
});
31 changes: 4 additions & 27 deletions release/angular-ticker.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,17 @@ 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() {
TickerSrv.unregister(id);
});
};

$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.
Expand Down
2 changes: 1 addition & 1 deletion release/angular-ticker.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.