jenkins-bot has submitted this change and it was merged. Change subject: Removed toolbarlabel's get/setContent method ......................................................................
Removed toolbarlabel's get/setContent method There is no need to have dedicated get/setContent methods. After converting to a jQuery widget, instead of using dedicated methods, jQuery's native contents() method can be used. Change-Id: I21c279ccacfb27d2f47ef98fffc02a6d022630de --- M lib/resources/jquery.wikibase/toolbar/toolbareditgroup.js M lib/resources/jquery.wikibase/toolbar/toolbarlabel.js M lib/tests/qunit/jquery.wikibase/toolbar/toolbar.tests.js M lib/tests/qunit/jquery.wikibase/toolbar/toolbarbutton.tests.js M lib/tests/qunit/jquery.wikibase/toolbar/toolbarlabel.tests.js M lib/tests/qunit/wikibase.ui.Tooltip.tests.js 6 files changed, 24 insertions(+), 74 deletions(-) Approvals: Tobias Gritschacher: Looks good to me, approved Daniel Werner: Looks good to me, approved diff --git a/lib/resources/jquery.wikibase/toolbar/toolbareditgroup.js b/lib/resources/jquery.wikibase/toolbar/toolbareditgroup.js index 108d67f..1b0a7ec 100644 --- a/lib/resources/jquery.wikibase/toolbar/toolbareditgroup.js +++ b/lib/resources/jquery.wikibase/toolbar/toolbareditgroup.js @@ -164,16 +164,18 @@ this.innerGroup = $innerGroup.data( 'toolbar' ); this.addElement( $innerGroup ); - this.$tooltipAnchor = $( '<span/>' ).toolbarlabel( { - content: $( '<span/>', { + this.$tooltipAnchor = $( '<span/>' ); + + this.$tooltipAnchor + .append( $( '<span/>', { 'class': 'mw-help-field-hint', style: 'display:inline;text-decoration:none;', // TODO: Get rid of inline styles. html: ' ' // TODO find nicer way to hack Webkit browsers to display tooltip image (see also css) - } ), - stateChangeable: false // Tooltip anchor has no disabled/enabled behavior. - } ); + } ) ) + // Tooltip anchor has no disabled/enabled behavior. + .toolbarlabel( { stateChangeable: false } ) // Initialize the tooltip just to be able to change render variables like gravity: - this.$tooltipAnchor.data( 'toolbarlabel' ).setTooltip( '' ); + .data( 'toolbarlabel' ).setTooltip( '' ); // Now, create the buttons we need for basic editing: var self = this; diff --git a/lib/resources/jquery.wikibase/toolbar/toolbarlabel.js b/lib/resources/jquery.wikibase/toolbar/toolbarlabel.js index 2d9d6ae..95ba14d 100644 --- a/lib/resources/jquery.wikibase/toolbar/toolbarlabel.js +++ b/lib/resources/jquery.wikibase/toolbar/toolbarlabel.js @@ -19,12 +19,7 @@ * @extends wb.utilities.ui.StatableObject * @since 0.4 * - * @option {string|jQuery} The label's content. - * * @option {boolean} isStateChangeable Whether object's state is changeable (enabled, disabled). - * - * TODO: Use widget method scheme (e.g.: content() instead of setContent() and getContent()). - * Probably, get rid of content option completely. */ $.widget( 'wikibase.toolbarlabel', PARENT, { /** @@ -32,7 +27,6 @@ * @type {Object} */ options: { - content: null, stateChangeable: true }, @@ -42,17 +36,9 @@ _create: function() { PARENT.prototype._create.call( this ); - if ( typeof this.options.content === 'string' ) { - this.options.content = $.trim( this.options.content ); - } - this.element .addClass( this.widgetBaseClass ) .data( 'wikibase-toolbaritem', this ); - - if( this.options.content ) { - this.element.empty().append( this.options.content ); - } }, /** @@ -71,36 +57,6 @@ }, /** - * Sets the label's content - * - * @param {string|jQuery} content - */ - setContent: function( content ) { - this.element.empty(); - if ( typeof content === 'string' ) { - content = $.trim( content ); - } - this.element.append( content ); - }, - - /** - * Returns the labels content. If only text was set as content, a string will be returned, if - * HTML nodes were set, this will return a jQuery object. - * - * @return {jQuery|string} - */ - getContent: function() { - var contents = this.element.contents(); - - if( contents.length === 1 && contents[0].nodeType === 3 ) { - // return the text - return contents.text(); - } - // return jQuery object - return contents; - }, - - /** * Determines whether state change (enabling, disabling) is possible for this object. * * @return {boolean} Whether changing the state is possible. @@ -111,6 +67,8 @@ /** * Sets focus on this label. + * TODO: Convert setFocus() and removeFocus() to combined focus() method or remove if not needed + * anymore. */ setFocus: function() { this._makeFocusable(); @@ -126,6 +84,8 @@ /** * Applies tab index since regular HTML elements cannot be focused. + * TODO: Evaluate if still needed since buttons/links are no more replaced with <span> when + * disabling. */ _makeFocusable: function() { var self = this; diff --git a/lib/tests/qunit/jquery.wikibase/toolbar/toolbar.tests.js b/lib/tests/qunit/jquery.wikibase/toolbar/toolbar.tests.js index 024b0d6..0cc1949 100644 --- a/lib/tests/qunit/jquery.wikibase/toolbar/toolbar.tests.js +++ b/lib/tests/qunit/jquery.wikibase/toolbar/toolbar.tests.js @@ -42,7 +42,7 @@ QUnit.test( 'Fill and remove', function( assert ) { var $toolbar = $( '<span/>' ).toolbar(), toolbar = $toolbar.data( 'toolbar' ), - $label = $( '<span/>' ).toolbarlabel( { content: 'label text' } ); + $label = $( '<span/>' ).text( 'label text' ).toolbarlabel(); toolbar.addElement( $label ); @@ -91,7 +91,7 @@ 'Confirmed toolbar length.' ); - var $secondLabel = $( '<span/>' ).toolbarlabel( { content: 'second label text' } ); + var $secondLabel = $( '<span/>' ).text( 'second label text' ).toolbarlabel(); toolbar.addElement( $secondLabel, 1 ); @@ -159,7 +159,7 @@ QUnit.test( 'Dis- and enabling', function( assert ) { var $toolbar = $( '<span/>' ).toolbar(), toolbar = $toolbar.data( 'toolbar' ), - $label = $( '<span/>' ).toolbarlabel( { content: 'label text', stateChangeable: false } ); + $label = $( '<span/>' ).text( 'label text' ).toolbarlabel( { stateChangeable: false } ); toolbar.addElement( $label ); diff --git a/lib/tests/qunit/jquery.wikibase/toolbar/toolbarbutton.tests.js b/lib/tests/qunit/jquery.wikibase/toolbar/toolbarbutton.tests.js index 54fdd1d..6f1862f 100644 --- a/lib/tests/qunit/jquery.wikibase/toolbar/toolbarbutton.tests.js +++ b/lib/tests/qunit/jquery.wikibase/toolbar/toolbarbutton.tests.js @@ -43,7 +43,7 @@ button = $node.data( 'toolbarbutton' ); assert.ok( - button.getContent() === 'Label', + button.element.text() === 'Label', 'Button was initialised properly.' ); } ); diff --git a/lib/tests/qunit/jquery.wikibase/toolbar/toolbarlabel.tests.js b/lib/tests/qunit/jquery.wikibase/toolbar/toolbarlabel.tests.js index abc022d..c6cc9d0 100644 --- a/lib/tests/qunit/jquery.wikibase/toolbar/toolbarlabel.tests.js +++ b/lib/tests/qunit/jquery.wikibase/toolbar/toolbarlabel.tests.js @@ -17,11 +17,10 @@ * @return {jQuery} */ var newTestLabel = function( options ) { - options = $.extend( { - content: 'Text' - }, options ); + options = options || {}; return $( '<span/>' ) + .text( 'Text' ) .addClass( 'test_label' ) .toolbarlabel( options ); }; @@ -40,30 +39,19 @@ } } ) ); - QUnit.test( 'Set and get content.', function( assert ) { + QUnit.test( 'Init and destroy.', function( assert ) { var $node = newTestLabel(), label = $node.data( 'toolbarlabel' ); assert.ok( - label.getContent() === 'Text', + $node.data( 'toolbarlabel' ) instanceof $.wikibase.toolbarlabel, 'Initialized label.' ); - label.setContent( 'Foo' ); - assert.equal( - label.getContent(), - 'Foo', - 'Set new text content.' - ); - - var jQueryObj = $( '<span/>' ); - label.setContent( jQueryObj ); - - assert.equal( - label.getContent()[0], - jQueryObj[0], // compare with containing node - 'Set jQuery object as content.' + $node.text(), + 'Text', + 'Verified node text.' ); label.destroy(); diff --git a/lib/tests/qunit/wikibase.ui.Tooltip.tests.js b/lib/tests/qunit/wikibase.ui.Tooltip.tests.js index 1e2ec61..714e6f2 100644 --- a/lib/tests/qunit/wikibase.ui.Tooltip.tests.js +++ b/lib/tests/qunit/wikibase.ui.Tooltip.tests.js @@ -15,7 +15,7 @@ module( 'wikibase.ui.Tooltip', window.QUnit.newWbEnvironment( { setup: function() { this.node = $( '<div/>' ); - this.label = $( '<span/>' ).toolbarlabel( { content: 'Text' } ); + this.label = $( '<span/>' ).text( 'Text' ).toolbarlabel(); }, teardown: function() { $( window ).off( 'click' ); -- To view, visit https://gerrit.wikimedia.org/r/72692 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I21c279ccacfb27d2f47ef98fffc02a6d022630de Gerrit-PatchSet: 8 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Henning Snater <henning.sna...@wikimedia.de> Gerrit-Reviewer: Daniel Werner <daniel.wer...@wikimedia.de> Gerrit-Reviewer: Tobias Gritschacher <tobias.gritschac...@wikimedia.de> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits