Jeroen De Dauw has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/383789 )

Change subject: Automawtically mawk boxes when a comma is input
......................................................................

Automawtically mawk boxes when a comma is input

https://phabricator.wikimedia.org/T173563

Change-Id: I010110c6788b577824cdf27d41a8a033a97016e7
---
M modules/ui/ext.advancedSearch.ArbitraryWordInput.js
1 file changed, 56 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/AdvancedSearch 
refs/changes/89/383789/1

diff --git a/modules/ui/ext.advancedSearch.ArbitraryWordInput.js 
b/modules/ui/ext.advancedSearch.ArbitraryWordInput.js
index 5bcf076..abba980 100644
--- a/modules/ui/ext.advancedSearch.ArbitraryWordInput.js
+++ b/modules/ui/ext.advancedSearch.ArbitraryWordInput.js
@@ -16,6 +16,7 @@
        mw.libs.advancedSearch.ui.ArbitraryWordInput = function ( store, config 
) {
                this.store = store;
                this.optionId = config.optionId;
+               this.placeholderText = config.placeholder || '';
 
                this.store.connect( this, { update: 'onStoreUpdate' } );
 
@@ -24,26 +25,29 @@
                        $.extend( { allowArbitrary: true }, config || {} )
                );
 
+               this.input.$input.on( 'input', this.onInput.bind( this ) );
+               this.on( 'change', this.updatePlaceholder.bind( this ) );
+
                this.populateFromStore();
        };
 
        OO.inheritClass( mw.libs.advancedSearch.ui.ArbitraryWordInput, 
OO.ui.TagMultiselectWidget );
 
-       // TODO move to util module
-       function arrayEquals( a1, a2 ) {
-               var i = a1.length;
-               if ( a1.length !== a2.length ) {
-                       return false;
-               }
-               while ( i-- ) {
-                       if ( a1[ i ] !== a2[ i ] ) {
+       
mw.libs.advancedSearch.ui.ArbitraryWordInput.prototype.populateFromStore = 
function () {
+               // TODO move to util module
+               function arrayEquals( a1, a2 ) {
+                       var i = a1.length;
+                       if ( a1.length !== a2.length ) {
                                return false;
                        }
+                       while ( i-- ) {
+                               if ( a1[ i ] !== a2[ i ] ) {
+                                       return false;
+                               }
+                       }
+                       return true;
                }
-               return true;
-       }
 
-       
mw.libs.advancedSearch.ui.ArbitraryWordInput.prototype.populateFromStore = 
function () {
                var val = this.store.getOption( this.optionId ) || [];
                if ( arrayEquals( this.getValue(), val ) ) {
                        return;
@@ -55,6 +59,46 @@
                this.populateFromStore();
        };
 
+       mw.libs.advancedSearch.ui.ArbitraryWordInput.prototype.onInput = 
function () {
+               var segments = this.input.getValue().split( ',' );
+
+               if ( segments.length > 1 ) {
+                       var self = this;
+
+                       segments.map( function ( segment ) {
+                               if ( self.isAllowedData( segment ) ) {
+                                       self.addTag( segment );
+                               }
+                       } );
+
+                       this.clearInput();
+                       this.focus();
+               }
+       };
+
+       /**
+        * @inheritdoc
+        */
+       mw.libs.advancedSearch.ui.ArbitraryWordInput.prototype.isAllowedData = 
function ( data ) {
+               if ( data.trim() === '' ) {
+                       return false;
+               }
+
+               return 
mw.libs.advancedSearch.ui.ArbitraryWordInput.parent.prototype.isAllowedData.call(
 this, data );
+       };
+
+       
mw.libs.advancedSearch.ui.ArbitraryWordInput.prototype.updatePlaceholder = 
function () {
+               this.input.$input.attr( 'placeholder', 
this.getTextForPlaceholder() );
+       };
+
+       
mw.libs.advancedSearch.ui.ArbitraryWordInput.prototype.getTextForPlaceholder = 
function () {
+               if ( this.input.getValue() !== '' || this.getValue().length > 0 
) {
+                       return '';
+               }
+
+               return this.placeholderText;
+       };
+
        /**
         * @inheritdoc
         */
@@ -62,6 +106,7 @@
                if ( !this.input.getValue() ) {
                        return true;
                }
+
                return 
mw.libs.advancedSearch.ui.ArbitraryWordInput.parent.prototype.doInputEnter.call(
 this );
        };
 

-- 
To view, visit https://gerrit.wikimedia.org/r/383789
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I010110c6788b577824cdf27d41a8a033a97016e7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/AdvancedSearch
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <jeroended...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to