Bartosz Dziewoński has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/349133 )
Change subject: Element: New method #getElementId ...................................................................... Element: New method #getElementId The method ensures that the element has an 'id' attribute, setting it to an unique value if it's missing, and returns its value. Use it to simplify some code in Dialog. Further usages: * I2d27bdbba408c31001e4db088148a3b454eb6e3a * Ie993345e44ddb43dfbe2bebe0e12fd2bd9f5812e Change-Id: Ica44cb523efab239b44dc1080460147c54bdba36 --- M src/Dialog.js M src/Element.js 2 files changed, 17 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/oojs/ui refs/changes/33/349133/1 diff --git a/src/Dialog.js b/src/Dialog.js index d6eead5..445f372 100644 --- a/src/Dialog.js +++ b/src/Dialog.js @@ -248,21 +248,15 @@ * @inheritdoc */ OO.ui.Dialog.prototype.initialize = function () { - var titleId; - // Parent method OO.ui.Dialog.parent.prototype.initialize.call( this ); - titleId = OO.ui.generateElementId(); - // Properties - this.title = new OO.ui.LabelWidget( { - id: titleId - } ); + this.title = new OO.ui.LabelWidget(); // Initialization this.$content.addClass( 'oo-ui-dialog-content' ); - this.$element.attr( 'aria-labelledby', titleId ); + this.$element.attr( 'aria-labelledby', this.title.getElementId() ); this.setPendingElement( this.$head ); }; diff --git a/src/Element.js b/src/Element.js index fd597e9..562ede9 100644 --- a/src/Element.js +++ b/src/Element.js @@ -820,6 +820,21 @@ }; /** + * Ensure that the element has an 'id' attribute, setting it to an unique value if it's missing, + * and return its value. + * + * @return {string} + */ +OO.ui.Element.prototype.getElementId = function () { + var id = this.$element.attr( 'id' ); + if ( id === undefined ) { + id = OO.ui.generateElementId(); + this.$element.attr( 'id', id ); + } + return id; +}; + +/** * Check if element supports one or more methods. * * @param {string|string[]} methods Method or list of methods to check -- To view, visit https://gerrit.wikimedia.org/r/349133 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ica44cb523efab239b44dc1080460147c54bdba36 Gerrit-PatchSet: 1 Gerrit-Project: oojs/ui Gerrit-Branch: master Gerrit-Owner: Bartosz Dziewoński <matma....@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits