From 90d02f455eabdd6c55420e9ff33a37b434daade8 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Sat, 26 Sep 2015 11:01:15 +0200 Subject: [PATCH] revert jquery.resize update (better performances with older version) --- app/browser/js/jquery/jquery.ba-resize.js | 108 ++++++---------------- 1 file changed, 29 insertions(+), 79 deletions(-) diff --git a/app/browser/js/jquery/jquery.ba-resize.js b/app/browser/js/jquery/jquery.ba-resize.js index 110ac96e..0c1116ab 100644 --- a/app/browser/js/jquery/jquery.ba-resize.js +++ b/app/browser/js/jquery/jquery.ba-resize.js @@ -49,9 +49,9 @@ (function($){ '$:nomunge'; // Used by YUI compressor. - // Array containing all non-window elements to which the resize + // A jQuery object containing all non-window elements to which the resize // event is bound. - var elems = [], + var elems = $([]), // Extend $.resize if it already exists, otherwise create it. jq_resize = $.resize = $.extend( $.resize, {} ), @@ -63,8 +63,6 @@ str_resize = 'resize', str_data = str_resize + '-special-event', str_delay = 'delay', - str_pendingDelay = 'pendingDelay', - str_activeDelay = 'activeDelay', str_throttle = 'throttleWindow'; // Property: jQuery.resize.delay @@ -72,9 +70,7 @@ // The numeric interval (in milliseconds) at which the resize event polling // loop executes. Defaults to 250. - jq_resize[ str_pendingDelay ] = 250; - jq_resize[ str_activeDelay ] = 20; - jq_resize[ str_delay ] = jq_resize[ str_pendingDelay ]; + jq_resize[ str_delay ] = 250; // Property: jQuery.resize.throttleWindow // @@ -91,7 +87,7 @@ // event throttling, please note that this property must be changed before any // window object resize event callbacks are bound. - jq_resize[ str_throttle ] = false; + jq_resize[ str_throttle ] = true; // Event: resize event // @@ -143,17 +139,13 @@ var elem = $(this); // Add this element to the list of internal elements to monitor. - elems.push( this ); + elems = elems.add( elem ); // Initialize data store on the element. - elem.data( str_data, { w: elem.width(), h: elem.height() } ); + $.data( this, str_data, { w: elem.width(), h: elem.height() } ); // If this is the first element added, start the polling loop. if ( elems.length === 1 ) { - //set the timeout_id to undefined. - timeout_id = undefined; - - //start the loop loopy(); } }, @@ -169,22 +161,14 @@ var elem = $(this); // Remove this element from the list of internal elements to monitor. - for (var i = elems.length - 1; i >= 0; i--) { - if(elems[i] == this){ - elems.splice(i, 1); - break; - } - }; + elems = elems.not( elem ); // Remove any data stored on the element. elem.removeData( str_data ); // If this is the last element removed, stop the polling loop. if ( !elems.length ) { - cancelAnimationFrame( timeout_id ); - - //set the timeout_id to null, to make sure the loop is stopped - timeout_id = null; + clearTimeout( timeout_id ); } }, @@ -206,7 +190,7 @@ function new_handler( e, w, h ) { var elem = $(this), - data = elem.data( str_data ) || {}; + data = $.data( this, str_data ); // If called from the polling loop, w and h will be passed in as // arguments. If called manually, via .trigger( 'resize' ) or .resize(), @@ -233,64 +217,30 @@ }; function loopy() { + + // Start the polling loop, asynchronously. + timeout_id = window[ str_setTimeout ](function(){ + // Iterate over all elements to which the 'resize' event is bound. - for (var i = elems.length - 1; i >= 0; i--) { - var elem = $(elems[i]); - if (elem[0] == window || elem.is(':visible')) { + elems.each(function(){ + var elem = $(this), + width = elem.width(), + height = elem.height(), + data = $.data( this, str_data ); - var width = elem.width(), - height = elem.height(), - data = elem.data( str_data ); - - // If element size has changed since the last time, update the element - // data store and trigger the 'resize' event. - if ( data && ( width !== data.w || height !== data.h ) ) { - jq_resize[ str_delay ] = jq_resize[ str_activeDelay ]; - elem.trigger( str_resize, [ data.w = width, data.h = height ] ); - } else { - jq_resize[ str_delay ] = jq_resize[ str_pendingDelay ]; - } + // If element size has changed since the last time, update the element + // data store and trigger the 'resize' event. + if ( width !== data.w || height !== data.h ) { + elem.trigger( str_resize, [ data.w = width, data.h = height ] ); } - else { - // resetting stored width and height so that resize event is triggered next time - data = elem.data(str_data); - data.w = 0; - data.h = 0; - } - }; - //request another animationFrame to poll the elements - if(timeout_id !== null) - timeout_id = window.requestAnimationFrame(loopy); + }); + + // Loop. + loopy(); + + }, jq_resize[ str_delay ] ); + }; - /** - * Provides requestAnimationFrame in a cross browser way. - * http://paulirish.com/2011/requestanimationframe-for-smart-animating/ - */ - if ( !window.requestAnimationFrame ) { - window.requestAnimationFrame = (function(){ - return window.webkitRequestAnimationFrame || - window.mozRequestAnimationFrame || - window.oRequestAnimationFrame || - window.msRequestAnimationFrame || - function( /* function FrameRequestCallback */ callback, /* DOMElement Element */ element ) { - return window.setTimeout( callback, jq_resize[ str_delay ] ); - }; - })(); - } - /** - * Provides cancelAnimationFrame in a cross browser way. - */ - if( !window.cancelAnimationFrame ){ - window.cancelAnimationFrame = ( function() { - return window.webkitCancelRequestAnimationFrame || - window.mozCancelRequestAnimationFrame || - window.oCancelRequestAnimationFrame || - window.msCancelRequestAnimationFrame || - clearTimeout - })(); - } - - })(jQuery,this);