Created
November 14, 2012 14:41
-
-
Save thehungrycoder/4072503 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
myCustomConfirmBox = function(message, callback) { | |
var options; | |
options = [ | |
{ | |
'label': 'Yes, Definitely', | |
'class': 'btn-danger', | |
'callback': function() { | |
if (typeof callback === 'function') { | |
return callback(); | |
} | |
} | |
}, { | |
'label': 'Opss! No', | |
'class': 'btn-success' | |
} | |
]; | |
return bootbox.dialog(message, options); | |
}; | |
$.rails.allowAction = function(element) { | |
var answer, callback, message; | |
message = element.data("confirm"); | |
if (!message) { | |
return true; | |
} | |
answer = false; | |
callback = void 0; | |
if ($.rails.fire(element, "confirm")) { | |
myCustomConfirmBox(message, function() { | |
var oldAllowAction; | |
callback = $.rails.fire(element, "confirm:complete", [answer]); | |
if (callback) { | |
oldAllowAction = $.rails.allowAction; | |
$.rails.allowAction = function() { | |
return true; | |
}; | |
element.trigger("click"); | |
return $.rails.allowAction = oldAllowAction; | |
} | |
}); | |
} | |
return false; | |
}; |
This file contains hidden or 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
window.myCustomConfirmBox = (message, callback) -> | |
options = [ | |
{ | |
'label': 'Yes, Definitely' | |
'class': 'btn-danger' | |
'callback': -> | |
if typeof callback == 'function' | |
callback() | |
} | |
{ | |
'label': 'Opss! No' | |
'class': 'btn-success' | |
} | |
] | |
bootbox.dialog message, options | |
$.rails.allowAction = (element) -> | |
message = element.data("confirm") | |
return true unless message | |
answer = false | |
callback = undefined | |
if $.rails.fire(element, "confirm") | |
myCustomConfirmBox message, -> | |
callback = $.rails.fire(element, "confirm:complete", [answer]) | |
if callback | |
oldAllowAction = $.rails.allowAction | |
$.rails.allowAction = -> | |
true | |
element.trigger "click" | |
$.rails.allowAction = oldAllowAction | |
false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment