mirror of
https://github.com/e107inc/e107.git
synced 2025-04-19 20:21:51 +02:00
commit
b840189b5a
@ -146,7 +146,9 @@ var e107 = e107 || {'settings': {}, 'behaviors': {}};
|
||||
// If this is a navigation controller, e.g. pager.
|
||||
nav: $element.attr('data-nav-inc'),
|
||||
// Old way - href='myscript.php#id-to-target.
|
||||
href: $element.attr("href")
|
||||
href: $element.attr("href"),
|
||||
// Wait for final event. Useful for keyUp, keyDown... etc.
|
||||
wait: $element.attr('data-event-wait')
|
||||
};
|
||||
|
||||
// If this is a navigation controller, e.g. pager.
|
||||
@ -160,7 +162,16 @@ var e107 = e107 || {'settings': {}, 'behaviors': {}};
|
||||
ajaxOptions.type = 'GET';
|
||||
}
|
||||
|
||||
e107.callbacks.ajaxRequestHandler($element, ajaxOptions);
|
||||
if(ajaxOptions.wait != null)
|
||||
{
|
||||
e107.callbacks.waitForFinalEvent(function(){
|
||||
e107.callbacks.ajaxRequestHandler($element, ajaxOptions);
|
||||
}, parseInt(ajaxOptions.wait), event);
|
||||
}
|
||||
else
|
||||
{
|
||||
e107.callbacks.ajaxRequestHandler($element, ajaxOptions);
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
@ -622,6 +633,39 @@ var e107 = e107 || {'settings': {}, 'behaviors': {}};
|
||||
e107.attachBehaviors();
|
||||
};
|
||||
|
||||
/**
|
||||
* Wait for final event. Useful when you need to call an event callback
|
||||
* only once, but event is fired multiple times. For example:
|
||||
* - resizing window manually
|
||||
* - wait for User to stop typing
|
||||
*
|
||||
* Example usage:
|
||||
* @code
|
||||
* $(window).resize(function () {
|
||||
* waitForFinalEvent(function(){
|
||||
* alert('Resize...');
|
||||
* //...
|
||||
* }, 500, "some unique string");
|
||||
* });
|
||||
* @endcode
|
||||
*/
|
||||
e107.callbacks.waitForFinalEvent = (function ()
|
||||
{
|
||||
var timers = {};
|
||||
return function (callback, ms, uniqueId)
|
||||
{
|
||||
if(!uniqueId)
|
||||
{
|
||||
uniqueId = "Don't call this twice without a uniqueId";
|
||||
}
|
||||
if(timers[uniqueId])
|
||||
{
|
||||
clearTimeout(timers[uniqueId]);
|
||||
}
|
||||
timers[uniqueId] = setTimeout(callback, ms);
|
||||
};
|
||||
})();
|
||||
|
||||
})(jQuery);
|
||||
|
||||
$.ajaxSetup({
|
||||
|
Loading…
x
Reference in New Issue
Block a user