From 8a53b2cd07ec7819c6c22800ea1d24664a3a5ecc Mon Sep 17 00:00:00 2001 From: Moriel Schottlender Date: Thu, 29 Jan 2015 15:09:47 -0800 Subject: [PATCH] Use css class instead of jquery show/hide Replace instances of .show() and .hide() with ooui 'hidden' class to make performance better. Related ooui change: Ibf7c99aa4aad Bug: T87420 Bug: T88736 Change-Id: I3af8a322e88b7ba3364f350819d6dbcdc8b13270 --- modules/ve-mw/ce/nodes/ve.ce.MWBlockImageNode.js | 3 +-- modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js | 10 +++++----- modules/ve-mw/ui/dialogs/ve.ui.MWReferenceDialog.js | 4 ++-- modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js | 10 ++++++---- .../ve-mw/ui/widgets/ve.ui.MWCategoryPopupWidget.js | 4 +++- modules/ve-mw/ui/widgets/ve.ui.MWMediaResultWidget.js | 2 +- modules/ve-mw/ui/widgets/ve.ui.MWMediaSearchWidget.js | 10 +++++----- modules/ve-mw/ui/widgets/ve.ui.MWTocWidget.js | 7 ++----- 8 files changed, 25 insertions(+), 25 deletions(-) diff --git a/modules/ve-mw/ce/nodes/ve.ce.MWBlockImageNode.js b/modules/ve-mw/ce/nodes/ve.ce.MWBlockImageNode.js index 3211b12c1b..f0476ef5c1 100644 --- a/modules/ve-mw/ce/nodes/ve.ce.MWBlockImageNode.js +++ b/modules/ve-mw/ce/nodes/ve.ce.MWBlockImageNode.js @@ -143,8 +143,7 @@ ve.ce.MWBlockImageNode.prototype.updateCaption = function () { } } if ( this.$caption ) { - // Don't use show() as it sets display to block, overriding the stylesheet. - this.$caption.css( 'display', this.captionVisible ? '' : 'none' ); + this.$caption.toggleClass( 'oo-ui-element-hidden', !this.captionVisible ); } }; diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js index adf98e4e76..697c138ab6 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js @@ -1098,17 +1098,17 @@ ve.ui.MWMediaDialog.prototype.switchPanels = function ( panel, stopSearchRequery // The filerepo promise will be sent to the API // only once per session so this will be resolved // every time the search panel reloads - this.$spinner.show(); - this.search.$element.hide(); + this.$spinner.removeClass( 'oo-ui-element-hidden' ); + this.search.toggle( false ); // Get the repos from the API first // The ajax request will only be done once per session dialog.getFileRepos().done( function ( repos ) { dialog.search.setSources( repos ); // Done, hide the spinner - dialog.$spinner.hide(); + dialog.$spinner.addClass( 'oo-ui-element-hidden' ); // Show the search and query the media sources - dialog.search.$element.show(); + dialog.search.toggle( true ); dialog.search.query.setValue( dialog.pageTitle ); dialog.search.queryMediaSources(); // Initialization @@ -1168,7 +1168,7 @@ ve.ui.MWMediaDialog.prototype.attachImageModel = function () { ); // Size widget - this.sizeErrorLabel.$element.hide(); + this.sizeErrorLabel.toggle( false ); this.sizeWidget.setScalable( this.imageModel.getScalable() ); this.sizeWidget.connect( this, { changeSizeType: 'checkChanged', diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWReferenceDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWReferenceDialog.js index 63bfc225d4..81e8f38a59 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWReferenceDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWReferenceDialog.js @@ -267,13 +267,13 @@ ve.ui.MWReferenceDialog.prototype.useReference = function ( ref ) { group = this.getFragment().getDocument().getInternalList() .getNodeGroup( this.referenceModel.getListGroup() ); if ( group && group.keyedNodes[this.referenceModel.getListKey()].length > 1 ) { - this.$reuseWarning.show(); + this.$reuseWarning.removeClass( 'oo-ui-element-hidden' ); this.$reuseWarningText.text( mw.msg( 'visualeditor-dialog-reference-editing-reused', group.keyedNodes[this.referenceModel.getListKey()].length ) ); } else { - this.$reuseWarning.hide(); + this.$reuseWarning.addClass( 'oo-ui-element-hidden' ); } return this; diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js index 1f1e9a08be..551813b619 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js @@ -203,20 +203,22 @@ ve.ui.MWSaveDialog.prototype.swapPanel = function ( panel ) { if ( !currentEditSummaryWikitext || currentEditSummaryWikitext.trim() === '' ) { // Don't bother with an API request for an empty summary - this.$reviewEditSummary.parent().hide(); + this.$reviewEditSummary.parent().addClass( 'oo-ui-element-hidden' ); } else { - this.$reviewEditSummary.parent().show().addClass( 'mw-ajax-loader' ); + this.$reviewEditSummary.parent() + .removeClass( 'oo-ui-element-hidden' ) + .addClass( 'mw-ajax-loader' ); this.editSummaryXhr = new mw.Api().post( { action: 'parse', summary: currentEditSummaryWikitext } ).done( function ( result ) { if ( result.parse.parsedsummary['*'] === '' ) { - dialog.$reviewEditSummary.parent().hide(); + dialog.$reviewEditSummary.parent().addClass( 'oo-ui-element-hidden' ); } else { dialog.$reviewEditSummary.html( ve.msg( 'parentheses', result.parse.parsedsummary['*'] ) ); } } ).fail( function () { - dialog.$reviewEditSummary.parent().hide(); + dialog.$reviewEditSummary.parent().addClass( 'oo-ui-element-hidden' ); } ).always( function () { dialog.$reviewEditSummary.parent().removeClass( 'mw-ajax-loader' ); } ); diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWCategoryPopupWidget.js b/modules/ve-mw/ui/widgets/ve.ui.MWCategoryPopupWidget.js index 74c2c269cf..7ab676cdf4 100644 --- a/modules/ve-mw/ui/widgets/ve.ui.MWCategoryPopupWidget.js +++ b/modules/ve-mw/ui/widgets/ve.ui.MWCategoryPopupWidget.js @@ -48,7 +48,9 @@ ve.ui.MWCategoryPopupWidget = function VeUiMWCategoryPopupWidget( config ) { this.$sortKeyForm.on( 'submit', this.onSortKeySubmit.bind( this ) ); // Initialization - this.$element.addClass( 've-ui-mwCategoryPopupWidget' ).hide(); + this.$element + .addClass( 've-ui-mwCategoryPopupWidget' ); + this.toggle( false ); this.$title .addClass( 've-ui-mwCategoryPopupWidget-title oo-ui-icon-tag' ) .text( ve.msg( 'visualeditor-dialog-meta-categories-category' ) ); diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWMediaResultWidget.js b/modules/ve-mw/ui/widgets/ve.ui.MWMediaResultWidget.js index f555503c6c..62d0421c5f 100644 --- a/modules/ve-mw/ui/widgets/ve.ui.MWMediaResultWidget.js +++ b/modules/ve-mw/ui/widgets/ve.ui.MWMediaResultWidget.js @@ -55,7 +55,7 @@ ve.ui.MWMediaResultWidget = function VeUiMWMediaResultWidget( config ) { label: ve.msg( 'visualeditor-dialog-media-searchselect' ), icon: 'check' } ); - this.selectButton.$element.hide(); + this.selectButton.toggle( false ); this.$element.prepend( this.selectButton.$element ); }; diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWMediaSearchWidget.js b/modules/ve-mw/ui/widgets/ve.ui.MWMediaSearchWidget.js index 90f540d122..94a5744ccf 100644 --- a/modules/ve-mw/ui/widgets/ve.ui.MWMediaSearchWidget.js +++ b/modules/ve-mw/ui/widgets/ve.ui.MWMediaSearchWidget.js @@ -42,9 +42,8 @@ ve.ui.MWMediaSearchWidget = function VeUiMWMediaSearchWidget( config ) { this.rows = []; this.$noItemsMessage = this.$( '
' ) - .addClass( 've-ui-mwMediaSearchWidget-noresults' ) + .addClass( 've-ui-mwMediaSearchWidget-noresults oo-ui-element-hidden' ) .text( ve.msg( 'visualeditor-dialog-media-noresults' ) ) - .hide() .appendTo( this.$query ); // Events @@ -168,7 +167,8 @@ ve.ui.MWMediaSearchWidget.prototype.queryMediaSources = function () { } // Reset message - this.$noItemsMessage.hide(); + this.$noItemsMessage.addClass( 'oo-ui-element-hidden' ); + // Abort previous promises if they are pending this.resetPromises(); @@ -270,9 +270,9 @@ ve.ui.MWMediaSearchWidget.prototype.onAllMediaQueriesDone = function () { this.query.popPending(); if ( this.results.getItems().length === 0 ) { - this.$noItemsMessage.show(); + this.$noItemsMessage.removeClass( 'oo-ui-element-hidden' ); } else { - this.$noItemsMessage.hide(); + this.$noItemsMessage.addClass( 'oo-ui-element-hidden' ); this.lazyLoadResults(); } }; diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWTocWidget.js b/modules/ve-mw/ui/widgets/ve.ui.MWTocWidget.js index 115200eafb..39794978f1 100644 --- a/modules/ve-mw/ui/widgets/ve.ui.MWTocWidget.js +++ b/modules/ve-mw/ui/widgets/ve.ui.MWTocWidget.js @@ -62,6 +62,7 @@ ve.ui.MWTocWidget = function VeUiMWTocWidget( surface, config ) { widget.toggle.$link.text( widget.toggle.hideMsg ); widget.toggle.open = true; } + // FIXME: We should really use CSS here widget.topics.$group.add( widget.$tempTopics ).slideToggle(); } ); @@ -136,11 +137,7 @@ ve.ui.MWTocWidget.prototype.initFromMetaList = function () { ve.ui.MWTocWidget.prototype.hideOrShow = function () { // In MediaWiki if __FORCETOC__ is anywhere TOC is always displayed // ... Even if there is a __NOTOC__ in the article - if ( !this.mwTOCDisable && ( this.mwTOCForce || this.topics.items.length >= 3 ) ) { - this.$element.show(); - } else { - this.$element.hide(); - } + this.toggle( !this.mwTOCDisable && ( this.mwTOCForce || this.topics.items.length >= 3 ) ); }; /**