Skip to content

Commit

Permalink
Added cutDownAlarm and and restoreAlarm to override alert confirm and…
Browse files Browse the repository at this point in the history
… prompt during unleash and restoring them at the end.
  • Loading branch information
ThieryMichel committed Oct 27, 2013
1 parent 33e577d commit 8e4f5ec
Showing 1 changed file with 45 additions and 12 deletions.
57 changes: 45 additions & 12 deletions src/gremlins.js
Expand Up @@ -95,20 +95,53 @@ var Gremlins = (function() {
return this;
};

GremlinsHorde.prototype.unleash = function(nb, done) {
var i;
var self = this;

callCallbacks(this._beforeCallbacks, [], function () {
runUnleashers(self._unleashers, self._gremlins, nb, function() {
callCallbacks(self._afterCallbacks, [], function () {
if (typeof done === 'function') {
done();
}
GremlinsHorde.prototype.unleash = (function(){
var alert;
var confirm;
var prompt;

var cutDownAlarm = function cutDownAlarm() {
alert = window.alert;
confirm = window.confirm;
prompt = window.prompt;
window.alert = function () {

}
window.confirm = function () {
// Random OK or cancel
return Math.random() >= 0.5;
}

window.prompt = function () {
// Return a random string
return Math.random().toString(36).slice(2);
}
}

var restoreAlarm = function restoreAlarm() {
window.alert = alert;
window.confirm = confirm;
window.prompt = prompt;
}

return function(nb, done) {
var i;
var self = this;

cutDownAlarm();

callCallbacks(this._beforeCallbacks, [], function () {
runUnleashers(self._unleashers, self._gremlins, nb, function() {
callCallbacks(self._afterCallbacks, [], function () {
restoreAlarm();
if (typeof done === 'function') {
done();
}
});
});
});
});
};
};
})()

Gremlins.createHorde = function() {
return new GremlinsHorde();
Expand Down

0 comments on commit 8e4f5ec

Please sign in to comment.