Skip to content
Extraits de code Groupes Projets
Valider a44eaf25 rédigé par renato's avatar renato
Parcourir les fichiers

onAjaxLoad now works on private and public space, for both jQuery and SPIP ajax requests

parent cd01997c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -2124,3 +2124,61 @@ $.fn.serialize = function() { ...@@ -2124,3 +2124,61 @@ $.fn.serialize = function() {
this.vars = a; this.vars = a;
return this; return this;
}; };
// A plugin that wraps all ajax calls introducing a fixed callback function on ajax complete
var load_handlers = new Array();
//
// Add a function to the list of those to be executed on ajax load complete
//
function onAjaxLoad(f) {
load_handlers.push(f);
};
//
// Call the functions that have been added to onAjaxLoad
//
function triggerAjaxLoad(root) {
for ( var i = 0; i < load_handlers.length; i++ )
load_handlers[i].apply( root );
};
jQuery.fn._load = jQuery.fn.load;
jQuery.fn.load = function( url, params, callback, ifModified ) {
callback = callback || function(){};
// If the second parameter was provided
if ( params ) {
// If it's a function
if ( params.constructor == Function ) {
// We assume that it's the callback
callback = params;
params = null;
}
}
var callback2 = function(res,status) {triggerAjaxLoad(this);callback(res,status);};
return this._load( url, params, callback2, ifModified );
};
jQuery._ajax = jQuery.ajax;
jQuery.ajax = function( type, url, data, ret, ifModified ) {
//If called by _load exit now because the callback has already been set
if (jQuery.ajax.caller==jQuery.fn._load) return jQuery._ajax( type, url, data, ret, ifModified );
// If only a single argument was passed in,
// assume that it is a object of key/value pairs
if ( !url ) {
var orig_complete = type.complete || function() {};
type.complete = function(res,status) {triggerAjaxLoad(document);orig_complete(res,status);};
} else {
var orig_ret = ret || function() {};
ret = function(res,status) {triggerAjaxLoad(document);orig_ret(res,status);};
}
jQuery._ajax( type, url, data, ret, ifModified );
};
Ce diff est replié.
var memo_obj = new Array(); var memo_obj = new Array();
var url_chargee = new Array(); var url_chargee = new Array();
var xhr_actifs = new Array(); var xhr_actifs = new Array();
var load_handlers = new Array();
function findObj_test_forcer(n, forcer) { function findObj_test_forcer(n, forcer) {
var p,i,x; var p,i,x;
...@@ -205,21 +204,6 @@ function verifForm(racine) { ...@@ -205,21 +204,6 @@ function verifForm(racine) {
}); });
} }
//
// Add a function to the list of those to be executed on ajax load complete
//
function onAjaxLoad(f) {
load_handlers.push(f);
}
//
// Call the functions that have been added to onAjaxLoad
//
function triggerAjaxLoad(root) {
for ( var i = 0; i < load_handlers.length; i++ )
load_handlers[i].apply( root );
}
// Alloue un gestionnaire Ajax, et le lance sur les parametres donnes // Alloue un gestionnaire Ajax, et le lance sur les parametres donnes
// Retourne False si l'allocation est impossible, // Retourne False si l'allocation est impossible,
// le gestionnaire lui-meme autrement (utile pour memoriser ceux alloues). // le gestionnaire lui-meme autrement (utile pour memoriser ceux alloues).
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter