[ Index ] |
|
Code source de SPIP 1.9.2c |
1 // A plugin that wraps all ajax calls introducing a fixed callback function on ajax complete 2 if(!jQuery.load_handlers) { 3 jQuery.load_handlers = new Array(); 4 // 5 // Add a function to the list of those to be executed on ajax load complete 6 // 7 function onAjaxLoad(f) { 8 jQuery.load_handlers.push(f); 9 }; 10 11 // 12 // Call the functions that have been added to onAjaxLoad 13 // 14 function triggerAjaxLoad(root) { 15 for ( var i = 0; i < jQuery.load_handlers.length; i++ ) 16 jQuery.load_handlers[i].apply( root ); 17 }; 18 19 jQuery.fn._load = jQuery.fn.load; 20 21 jQuery.fn.load = function( url, params, callback, ifModified ) { 22 23 callback = callback || function(){}; 24 25 // If the second parameter was provided 26 if ( params ) { 27 // If it's a function 28 if ( params.constructor == Function ) { 29 // We assume that it's the callback 30 callback = params; 31 params = null; 32 } 33 } 34 var callback2 = function(res,status) {triggerAjaxLoad(this);callback(res,status);}; 35 36 return this._load( url, params, callback2, ifModified ); 37 }; 38 39 40 jQuery._ajax = jQuery.ajax; 41 42 jQuery.ajax = function( type, url, data, ret, ifModified ) { 43 44 //If called by _load exit now because the callback has already been set 45 if (jQuery.ajax.caller==jQuery.fn._load) return jQuery._ajax( type, url, data, ret, ifModified ); 46 // If only a single argument was passed in, 47 // assume that it is a object of key/value pairs 48 if ( !url ) { 49 var orig_complete = type.complete || function() {}; 50 type.complete = function(res,status) {triggerAjaxLoad(document);orig_complete(res,status);}; 51 } else { 52 var orig_ret = ret || function() {}; 53 ret = function(res,status) {triggerAjaxLoad(document);orig_ret(res,status);}; 54 } 55 56 return jQuery._ajax( type, url, data, ret, ifModified ); 57 58 }; 59 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Wed Nov 21 10:20:27 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |