X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki.rcfilters%2Fui%2Fmw.rcfilters.ui.SavedLinksListItemWidget.js;h=b6b20eeb1aed32e2e412e3f7b018ba30d2a955bd;hb=68e16c26dd58afdf58a97f18f3cc76ed3b0ad9ee;hp=acda29e12a83d042d09e65504462ce695dd52690;hpb=b4440a0f2ff822c1e82b809032413a0ddca2a35b;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.SavedLinksListItemWidget.js b/resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.SavedLinksListItemWidget.js index acda29e12a..b6b20eeb1a 100644 --- a/resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.SavedLinksListItemWidget.js +++ b/resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.SavedLinksListItemWidget.js @@ -41,12 +41,12 @@ icon: 'ellipsis', framed: false } ); - this.menu = new OO.ui.FloatingMenuSelectWidget( { + this.menu = new OO.ui.MenuSelectWidget( { classes: [ 'mw-rcfilters-ui-savedLinksListItemWidget-menu' ], widget: this.popupButton, width: 200, horizontalPosition: 'end', - $container: this.popupButton.$element, + $floatableContainer: this.popupButton.$element, items: [ new OO.ui.MenuOptionWidget( { data: 'edit', @@ -81,8 +81,11 @@ this.menu.connect( this, { choose: 'onMenuChoose' } ); - this.saveButton.connect( this, { click: 'onSaveButtonClick' } ); - this.editInput.connect( this, { enter: 'onEditInputEnter' } ); + this.saveButton.connect( this, { click: 'save' } ); + this.editInput.connect( this, { + change: 'onInputChange', + enter: 'save' + } ); this.editInput.$input.on( { blur: this.onInputBlur.bind( this ), keyup: this.onInputKeyup.bind( this ) @@ -204,22 +207,6 @@ this.menu.toggle( false ); }; - /** - * Respond to save button click - */ - mw.rcfilters.ui.SavedLinksListItemWidget.prototype.onSaveButtonClick = function () { - this.emit( 'edit', this.editInput.getValue() ); - this.toggleEdit( false ); - }; - - /** - * Respond to input enter event - */ - mw.rcfilters.ui.SavedLinksListItemWidget.prototype.onEditInputEnter = function () { - this.emit( 'edit', this.editInput.getValue() ); - this.toggleEdit( false ); - }; - /** * Respond to input keyup event, this is the way to intercept 'escape' key * @@ -239,10 +226,39 @@ * Respond to blur event on the input */ mw.rcfilters.ui.SavedLinksListItemWidget.prototype.onInputBlur = function () { - this.emit( 'edit', this.editInput.getValue() ); + this.save(); + + // Whether the save succeeded or not, the input-blur event + // means we need to cancel editing mode this.toggleEdit( false ); }; + /** + * Respond to input change event + * + * @param {string} value Input value + */ + mw.rcfilters.ui.SavedLinksListItemWidget.prototype.onInputChange = function ( value ) { + value = value.trim(); + + this.saveButton.setDisabled( !value ); + }; + + /** + * Save the name of the query + * + * @param {string} [value] The value to save + * @fires edit + */ + mw.rcfilters.ui.SavedLinksListItemWidget.prototype.save = function () { + var value = this.editInput.getValue().trim(); + + if ( value ) { + this.emit( 'edit', value ); + this.toggleEdit( false ); + } + }; + /** * Toggle edit mode on this widget *