Use jquery.debounce instead of custom code to speed up navigation scroll and resize handlers
This commit is contained in:
parent
437c2ef012
commit
9db53f4c02
71
js/jquery/jquery.debounce-1.0.5.js
Normal file
71
js/jquery/jquery.debounce-1.0.5.js
Normal file
@ -0,0 +1,71 @@
|
||||
/**
|
||||
* Debounce and throttle function's decorator plugin 1.0.5
|
||||
*
|
||||
* Copyright (c) 2009 Filatov Dmitry (alpha@zforms.ru)
|
||||
* Dual licensed under the MIT and GPL licenses:
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
*/
|
||||
|
||||
(function($) {
|
||||
|
||||
$.extend({
|
||||
|
||||
debounce : function(fn, timeout, invokeAsap, ctx) {
|
||||
|
||||
if(arguments.length == 3 && typeof invokeAsap != 'boolean') {
|
||||
ctx = invokeAsap;
|
||||
invokeAsap = false;
|
||||
}
|
||||
|
||||
var timer;
|
||||
|
||||
return function() {
|
||||
|
||||
var args = arguments;
|
||||
ctx = ctx || this;
|
||||
|
||||
invokeAsap && !timer && fn.apply(ctx, args);
|
||||
|
||||
clearTimeout(timer);
|
||||
|
||||
timer = setTimeout(function() {
|
||||
!invokeAsap && fn.apply(ctx, args);
|
||||
timer = null;
|
||||
}, timeout);
|
||||
|
||||
};
|
||||
|
||||
},
|
||||
|
||||
throttle : function(fn, timeout, ctx) {
|
||||
|
||||
var timer, args, needInvoke;
|
||||
|
||||
return function() {
|
||||
|
||||
args = arguments;
|
||||
needInvoke = true;
|
||||
ctx = ctx || this;
|
||||
|
||||
if(!timer) {
|
||||
(function() {
|
||||
if(needInvoke) {
|
||||
fn.apply(ctx, args);
|
||||
needInvoke = false;
|
||||
timer = setTimeout(arguments.callee, timeout);
|
||||
}
|
||||
else {
|
||||
timer = null;
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
@ -432,15 +432,18 @@ var ScrollHandler = {
|
||||
};
|
||||
this.displayScrollbar();
|
||||
$(window).bind('resize', this.displayScrollbar);
|
||||
this.elms.$handle.live('drag', function (event, drag) {
|
||||
var elms = ScrollHandler.elms;
|
||||
var scrollbarOffset = elms.$scrollbar.offset().top;
|
||||
var pos = drag.offsetY - scrollbarOffset;
|
||||
var height = $(window).height() - scrollbarOffset - elms.$handle.height();
|
||||
value = ScrollHandler.sanitize(pos / height);
|
||||
ScrollHandler.setScrollbar(value);
|
||||
ScrollHandler.setContent(value);
|
||||
});
|
||||
this.elms.$handle.live(
|
||||
'drag',
|
||||
$.throttle(function (event, drag) {
|
||||
var elms = ScrollHandler.elms;
|
||||
var scrollbarOffset = elms.$scrollbar.offset().top;
|
||||
var pos = drag.offsetY - scrollbarOffset;
|
||||
var height = $(window).height() - scrollbarOffset - elms.$handle.height();
|
||||
value = ScrollHandler.sanitize(pos / height);
|
||||
ScrollHandler.setScrollbar(value);
|
||||
ScrollHandler.setContent(value);
|
||||
}, 4)
|
||||
);
|
||||
this.elms.$scrollbar.live('click', function (event) {
|
||||
if($(event.target).attr('id') === $(this).attr('id')) {
|
||||
var $scrollbar = ScrollHandler.elms.$scrollbar;
|
||||
@ -642,7 +645,7 @@ var ResizeHandler = function () {
|
||||
.live('mousedown', {'resize_handler':this}, this.mousedown);
|
||||
$(document)
|
||||
.bind('mouseup', {'resize_handler':this}, this.mouseup)
|
||||
.bind('mousemove', {'resize_handler':this}, this.mousemove);
|
||||
.bind('mousemove', {'resize_handler':this}, $.throttle(this.mousemove, 4));
|
||||
var $collapser = $('#pma_navigation_collapser');
|
||||
$collapser.live('click', {'resize_handler':this}, this.collapse);
|
||||
// Add the correct arrow symbol to the collapser
|
||||
|
||||
@ -153,6 +153,7 @@ class PMA_Header
|
||||
$this->_scripts->addFile('jquery/jquery.event.drag-2.0.js');
|
||||
$this->_scripts->addFile('jquery/timepicker.js');
|
||||
$this->_scripts->addFile('jquery/jquery.ba-hashchange-1.3.js');
|
||||
$this->_scripts->addFile('jquery/jquery.debounce-1.0.5.js');
|
||||
|
||||
$this->_scripts->addFile('jquery/jquery.qtip-1.0.0-rc3.js');
|
||||
if ($GLOBALS['cfg']['CodemirrorEnable']) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user