diff --git a/js/jquery/jquery.debounce-1.0.5.js b/js/jquery/jquery.debounce-1.0.5.js new file mode 100644 index 0000000000..020128cb03 --- /dev/null +++ b/js/jquery/jquery.debounce-1.0.5.js @@ -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); \ No newline at end of file diff --git a/js/navigation.js b/js/navigation.js index 8eec2ceef7..f8370c7e5c 100644 --- a/js/navigation.js +++ b/js/navigation.js @@ -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 diff --git a/libraries/Header.class.php b/libraries/Header.class.php index 6781cae458..17618d05bb 100644 --- a/libraries/Header.class.php +++ b/libraries/Header.class.php @@ -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']) {