[MediaWiki-commits] [Gerrit] mediawiki...Vector[master]: collapsibleTabs: Clean up and simplify code
jenkins-bot has submitted this change and it was merged. Change subject: collapsibleTabs: Clean up and simplify code .. collapsibleTabs: Clean up and simplify code * Rename 'rtl' to 'isRTL' and use DOM to compute its value. * Document code with JSDuck similar to other extensions. * Remove unused 'prevElement' property. Not used in Vector nor anywhere else in Wikimedia Git. * Make 'boundEvent' property private. Not used anywhere in Wikimedia Git outside this file. * Simplify 'instances' tracking. The jQuery object stored in this property wasn't used beyond calling each(). Convert to a plain array. Preserve and re-use the jQuery object first created by collapsibleTabs(). * Simplify calculateTabDistance() by using getElementById() and getBoundingClientRect(). Its support includes IE 5. The "new" version (since Firefox 3.5 and IE 9) also includes 'height' and 'width' properties and is supported in all browsers supported by the MediaWiki 1.28 startup feature test. This helps avoid code in offset() and width(), which is fairly expensive in jQuery 1.x. * moveToCollapsed() - Remove redundant jQuery object creation (only caller passes a jQuery object already). - Remove redundant re-receiving of expContainerSettings inside the animate() callback. Already in the main scope. Relates to a bunch of patches that work around a problem caused by use of remove() instead of detach() in an earlier version of the code. Which was only a problem because the other settings object was also not used from the main scope. (See pre-Gerrit commits 1f93310e and e7900807.) Change-Id: I48d542580d767df2d17ce4c6668e9e233a0f7902 --- M .gitignore M collapsibleTabs.js A jsduck.json M package.json 4 files changed, 74 insertions(+), 57 deletions(-) Approvals: Catrope: Looks good to me, approved Jforrester: Looks good to me, but someone else must approve VolkerE: Looks good to me, but someone else must approve jenkins-bot: Verified diff --git a/.gitignore b/.gitignore index 53bbca6..7c9e72a 100644 --- a/.gitignore +++ b/.gitignore @@ -18,11 +18,10 @@ sftp-config.json # Building & testing -node_modules/ - -# Composer -/vendor /composer.lock +/docs +/node_modules +/vendor # Operating systems ## Mac OS X diff --git a/collapsibleTabs.js b/collapsibleTabs.js index 1c8891f..c37d76b 100644 --- a/collapsibleTabs.js +++ b/collapsibleTabs.js @@ -1,10 +1,31 @@ /** - * Collapsible tabs jQuery Plugin + * Collapsible Tabs for the Vector skin. + * + * @class jQuery.plugin.collapsibleTabs */ ( function ( $ ) { - var rtl = $( 'html' ).attr( 'dir' ) === 'rtl', + var isRTL = document.documentElement.dir === 'rtl', + boundEvent = false, rAF = window.requestAnimationFrame || setTimeout; + /** +* @event beforeTabCollapse +*/ + + /** +* @event afterTabCollapse +*/ + + /** +* @param {Object} [options] +* @param {string} [options.expandedContainer="#p-views ul"] List of tabs +* @param {string} [options.collapsedContainer="#p-cactions ul"] List of menu items +* @param {string} [options.collapsible="li.collapsible"] Match tabs that are collapsible +* @param {Function} [options.expandCondition] +* @param {Function} [options.collapseCondition] +* @return {jQuery} +* @chainable +*/ $.fn.collapsibleTabs = function ( options ) { // Merge options into the defaults var settings = $.extend( {}, $.collapsibleTabs.defaults, options ); @@ -17,7 +38,7 @@ this.each( function () { var $el = $( this ); // add the element to our array of collapsible managers - $.collapsibleTabs.instances = $.collapsibleTabs.instances.add( $el ); + $.collapsibleTabs.instances.push( $el ); // attach the settings to the elements $el.data( 'collapsibleTabsSettings', settings ); // attach data to our collapsible elements @@ -27,11 +48,11 @@ } ); // if we haven't already bound our resize handler, bind it now - if ( !$.collapsibleTabs.boundEvent ) { + if ( !boundEvent ) { + boundEvent = true; $( window ).on( 'resize', $.debounce( 100, function () { rAF( $.collapsibleTabs.handleResize ); } ) ); - $.collapsibleTabs.boundEvent = true; } // call our resize handler to setup the page @@ -39,8 +60,7 @@ return this; }; $.collapsibleTabs = { - instances: $( [] ), - boundEvent: null, +
[MediaWiki-commits] [Gerrit] mediawiki...Vector[master]: collapsibleTabs: Clean up and simplify code
Krinkle has uploaded a new change for review. https://gerrit.wikimedia.org/r/324010 Change subject: collapsibleTabs: Clean up and simplify code .. collapsibleTabs: Clean up and simplify code * Rename 'rtl' to 'isRTL' and use DOM to compute its value. * Document rAF. * Document code with JSDuck similar to other extensions. * Remove unused 'prevElement' property. Not used in Vector nor anywhere else in Wikimedia Git. * Make 'boundEvent' property private. Not used anywhere in Wikimedia Git outside this file. * Simplify 'instances' tracking. The jQuery object stored in this property wasn't used beyond calling each(). Convert to a plain array. Preserve and re-use the jQuery object first created by collapsibleTabs(). * Simplify calculateTabDistance() by using getElementById() and getBoundingClientRect(). Its support includes IE 5. The "new" version (since Firefox 3.5 and IE 9) also includes 'height' and 'width' properties and is supported in all browsers supported by the MediaWiki 1.28 startup feature test. This helps avoid code in offset() and width(), which is fairly expensive in jQuery 1.x. * moveToCollapsed() - Remove redundant jQuery object creation (only caller passes a jQuery object already). - Remove redundant re-receiving of expContainerSettings inside the animate() callback. Already in the main scope. Relates to a bunch of patches that work around a problem caused by use of remove() instead of detach() in an earlier version of the code. Which was only a problem because the other settings object was also not used from the main scope. (See pre-Gerrit commits 1f93310e and e7900807.) Change-Id: I48d542580d767df2d17ce4c6668e9e233a0f7902 --- M .gitignore M collapsibleTabs.js A jsduck.json M package.json 4 files changed, 74 insertions(+), 57 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/skins/Vector refs/changes/10/324010/1 diff --git a/.gitignore b/.gitignore index 53bbca6..7c9e72a 100644 --- a/.gitignore +++ b/.gitignore @@ -18,11 +18,10 @@ sftp-config.json # Building & testing -node_modules/ - -# Composer -/vendor /composer.lock +/docs +/node_modules +/vendor # Operating systems ## Mac OS X diff --git a/collapsibleTabs.js b/collapsibleTabs.js index 1c8891f..c37d76b 100644 --- a/collapsibleTabs.js +++ b/collapsibleTabs.js @@ -1,10 +1,31 @@ /** - * Collapsible tabs jQuery Plugin + * Collapsible Tabs for the Vector skin. + * + * @class jQuery.plugin.collapsibleTabs */ ( function ( $ ) { - var rtl = $( 'html' ).attr( 'dir' ) === 'rtl', + var isRTL = document.documentElement.dir === 'rtl', + boundEvent = false, rAF = window.requestAnimationFrame || setTimeout; + /** +* @event beforeTabCollapse +*/ + + /** +* @event afterTabCollapse +*/ + + /** +* @param {Object} [options] +* @param {string} [options.expandedContainer="#p-views ul"] List of tabs +* @param {string} [options.collapsedContainer="#p-cactions ul"] List of menu items +* @param {string} [options.collapsible="li.collapsible"] Match tabs that are collapsible +* @param {Function} [options.expandCondition] +* @param {Function} [options.collapseCondition] +* @return {jQuery} +* @chainable +*/ $.fn.collapsibleTabs = function ( options ) { // Merge options into the defaults var settings = $.extend( {}, $.collapsibleTabs.defaults, options ); @@ -17,7 +38,7 @@ this.each( function () { var $el = $( this ); // add the element to our array of collapsible managers - $.collapsibleTabs.instances = $.collapsibleTabs.instances.add( $el ); + $.collapsibleTabs.instances.push( $el ); // attach the settings to the elements $el.data( 'collapsibleTabsSettings', settings ); // attach data to our collapsible elements @@ -27,11 +48,11 @@ } ); // if we haven't already bound our resize handler, bind it now - if ( !$.collapsibleTabs.boundEvent ) { + if ( !boundEvent ) { + boundEvent = true; $( window ).on( 'resize', $.debounce( 100, function () { rAF( $.collapsibleTabs.handleResize ); } ) ); - $.collapsibleTabs.boundEvent = true; } // call our resize handler to setup the page @@ -39,8 +60,7 @@ return this; }; $.collapsibleTabs = { - instances: $( [] ), - boundEvent: null, + instances: [], defaults: {