jQuery.ajaxSettings.traditional = true;
var jQueryLoad = jQuery.fn.load;
jQuery.fn.load = function(url, params, callback) {
if ( !jQuery.isFunction( url ) )
{
$('*', this).unbind();
$(this).ajaxError(ajaxLoadError).empty().append('
');
var newCallback = function() {
$(this).unbind("ajaxError");
if(testAjaxResponse($(this).html(), this) && callback != null) {
callback();
}
}
}
jQueryLoad.call($(this), url, params, newCallback);
};
function ajaxLoadError(xml, a, t) {
$(this).unbind("ajaxError");
$(this).html('- An error occurred while contacting the server
');
// If the content is being loaded into a modal dialog, add a close button as well
if($(this).is('.jqmWindow')) {
$(this).append('');
}
}
var jQueryGet = jQuery.get;
jQuery.get = function(url, params, callback, type, ifModified) {
var newCallback = function(data)
{
if(testAjaxResponse(data) && callback != null) {
callback(data);
}
}
jQueryGet.call(this, url, params, newCallback, type, ifModified);
}
var jQueryPost = jQuery.post;
jQuery.post = function(url, params, callback, type, ifModified) {
var newCallback = function(data)
{
if(testAjaxResponse(data) && callback != null) {
callback(data);
}
}
jQueryPost.call(this, url, params, newCallback, type, ifModified);
}
function testAjaxResponse(data, element) {
if (! _.isString(data)){
return true;
}
// Check for an error page response
if (data.indexOf('isErrorPage') != -1) {
$('*', document.body).unbind();
if(element == undefined) {
element = $("").html(data);
}
$(document.body).html($('#isErrorPage', element).html());
window.location='#';
return false;
}
// Check for a login page response
if (data.indexOf('divLogin') != -1) {
location.href='/';
return false;
}
// Check for a message bar response
if (data.indexOf('messageBarAlertBox') != -1) {
if($(data).filter('div.messageBarAlertBox').size() > 0) {
$('#messageBar').empty().append($(data).filter('div.messageBarAlertBox'));
}
}
return true;
}