Skip to content

Instantly share code, notes, and snippets.

@lc-nyovchev
Created April 26, 2015 09:31
Show Gist options
  • Save lc-nyovchev/ddbca622f7ede73ac346 to your computer and use it in GitHub Desktop.
Save lc-nyovchev/ddbca622f7ede73ac346 to your computer and use it in GitHub Desktop.
.config(['$provide', function($provide){
$provide.decorator('$modal', function($delegate){
var original = $delegate.open;
var wrapFunction = function wrapFunction (obj, functionName, callback){
var originalFunction = obj[functionName];
obj[functionName] = function(){
var result = originalFunction.apply(this, arguments);
callback.apply(this, arguments);
return result;
};
};
var getRandom = function getRandom(){
return Math.floor((Math.random() * 10000000000));
};
var openedModals = {};
$delegate.open = function open (config){
var modal = original.apply(this, arguments);
var idx = getRandom();
openedModals[idx] = {
modal: modal,
config: config
};
modal.result['finally'](function(){
delete openedModals[idx];
});
wrapFunction(modal, 'close', function(){
delete openedModals[idx];
});
wrapFunction(modal, 'dismiss', function(){
delete openedModals[idx];
});
return modal;
};
$delegate.getOpenedModals = function(){
var mods = [];
_.forOwn(openedModals, function(modal){
mods.push(modal);
});
return mods;
}
return $delegate;
});
}])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment