collapsibleTabs: Defer DOM changes via requestAnimiationFrame

Widely supported, unprefixed (over 85%)
http://caniuse.com/#feat=requestanimationframe

Change-Id: I13a73e3ba4f68af86ca77ca8242107ee449b255e
This commit is contained in:
Timo Tijhof 2015-11-19 23:53:05 +00:00
parent 020956d070
commit f354aafebc

View file

@ -2,7 +2,9 @@
* Collapsible tabs jQuery Plugin
*/
( function ( $ ) {
var rtl = $( 'html' ).attr( 'dir' ) === 'rtl';
var rtl = $( 'html' ).attr( 'dir' ) === 'rtl',
rAF = window.requestAnimationFrame || setTimeout;
$.fn.collapsibleTabs = function ( options ) {
// Merge options into the defaults
var settings = $.extend( {}, $.collapsibleTabs.defaults, options );
@ -27,13 +29,13 @@
// if we haven't already bound our resize handler, bind it now
if ( !$.collapsibleTabs.boundEvent ) {
$( window ).on( 'resize', $.debounce( 100, function () {
$.collapsibleTabs.handleResize();
rAF( $.collapsibleTabs.handleResize );
} ) );
$.collapsibleTabs.boundEvent = true;
}
// call our resize handler to setup the page
$.collapsibleTabs.handleResize();
rAF( $.collapsibleTabs.handleResize );
return this;
};
$.collapsibleTabs = {
@ -132,7 +134,7 @@
expContainerSettings = $.collapsibleTabs.getSettings( $( data.expandedContainer ) );
if ( expContainerSettings ) {
expContainerSettings.shifting = false;
$.collapsibleTabs.handleResize();
rAF( $.collapsibleTabs.handleResize );
}
}
} );
@ -168,7 +170,7 @@
expContainerSettings = $.collapsibleTabs.getSettings( $( data.expandedContainer ) );
if ( expContainerSettings ) {
expContainerSettings.shifting = false;
$.collapsibleTabs.handleResize();
rAF( $.collapsibleTabs.handleResize );
}
}
} )