//
// Author: J. Odeyer
// Date: 2011/09/05
// Last modif date:
// version: 1.0.0
//
// This script add csp_message function and replace the alert() native javascript function with it .
//
// Dependencies:
// This class relies on jQuery core library and jQuery ui dialog
function csp_message(settings) {
//default settings
this.defaultSettings = {
modal: true,
resizable: true,
title: '',
text: '',
html: '',
zIndex: 1000,
buttons: {
"OK": function() {
$(this)
.dialog("close")
.dialog("destroy")
.remove();
}
}
}
//merge passed settings with default settings
settings = $.extend({}, this.defaultSettings, settings);
//create helper (message box)
var helper = $('
')
.appendTo(document.body);
//check if html is provided
if(settings.html != '') {
//add html to the dialog box content
helper.html(settings.html);
} else {
//no html, use text
helper.append($(''));
}
//add dialog jQuery UI widget
helper.dialog(settings);
}
/*
function csp_confirm(text, title, okCallbackFunction, okButtonCaption, cancelButtonCaption) {
//if title is null, define a default title value
if(title == null) {
title = 'Confirm';
}
if(okButtonCaption == null) {
okButtonCaption = "OK";
}
if(cancelButtonCaption == null) {
cancelButtonCaption = "Cancel";
}
//show csp_message
csp_message({
text: text,
title: title,
buttons: {
okButtonCaption: function() {
eval(okCallbackFunction + '()' );
$(this)
.dialog("close")
.dialog("destroy")
.remove();
},
cancelButtonCaption: function() {
$(this)
.dialog("close")
.dialog("destroy")
.remove();
}
}
});
//return false to cancel eventual current event
return false;
}
*/
//take window as object and replace the alert() native javascript function with csp_message()
(function(obj) {
//add window variable to activate/deactivate this replacement
obj.csp_message_replace_alert_active = true;
var proxied = obj.alert;
//alert(text, [title], [closeCallbackFn function() {}])
obj.alert = function(text, title, closeCallbackFn) {
if(!obj.csp_message_replace_alert_active) {
//if window.csp_message_replace_alert_active = false, keep the normal behaviour
return proxied.apply(this, arguments);
}
//if title is null, define a default title value
if(title == null) {
title = 'Alert';
}
//show csp_message
csp_message({ text: text, title: title, close: closeCallbackFn});
};
})(window);
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();