Created
April 26, 2015 09:31
-
-
Save lc-nyovchev/ddbca622f7ede73ac346 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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