Gabriel Birke has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/358562 )
Change subject: Connect search preview to ArbitraryWordInput ...................................................................... Connect search preview to ArbitraryWordInput Closing a pill now removes the elements. Change-Id: I64b8f0692d3c7c29924e2ae3b19eb51407d00558 --- M modules/ext.advancedSearch.init.js M modules/ui/ext.advancedSearch.ArbitraryWordInput.js M modules/ui/ext.advancedSearch.MenuedInput.js 3 files changed, 34 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/AdvancedSearch refs/changes/62/358562/1 diff --git a/modules/ext.advancedSearch.init.js b/modules/ext.advancedSearch.init.js index f102b31..c375d1e 100644 --- a/modules/ext.advancedSearch.init.js +++ b/modules/ext.advancedSearch.init.js @@ -152,10 +152,6 @@ state, { optionId: 'phrase' } ); - // TODO Move widget initialization to store, make widget listen to store. - $.each( state.getOption( 'phrase' ), function () { - widget.addTag( this ); - } ); return widget; } }, @@ -182,10 +178,6 @@ state, { optionId: 'or' } ); - // TODO Move widget initialization to store, make widget listen to store. - $.each( state.getOption( 'or' ), function () { - widget.addTag( this ); - } ); return widget; } }, diff --git a/modules/ui/ext.advancedSearch.ArbitraryWordInput.js b/modules/ui/ext.advancedSearch.ArbitraryWordInput.js index 3b0d118..bb4be46 100644 --- a/modules/ui/ext.advancedSearch.ArbitraryWordInput.js +++ b/modules/ui/ext.advancedSearch.ArbitraryWordInput.js @@ -18,7 +18,11 @@ this.store = store; this.optionId = config.optionId; + this.store.connect( this, { update: 'onStoreUpdate' } ); + mw.libs.advancedSearch.ui.ArbitraryWordInput.parent.call( this, myConfig ); + + this.populateFromStore(); }; OO.inheritClass( mw.libs.advancedSearch.ui.ArbitraryWordInput, OO.ui.TagMultiselectWidget ); @@ -43,4 +47,30 @@ return mw.libs.advancedSearch.ui.ArbitraryWordInput.parent.prototype.onInputBlur.call( this ); }; + // 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; + } + + mw.libs.advancedSearch.ui.ArbitraryWordInput.prototype.onStoreUpdate = function () { + this.populateFromStore(); + }; + + mw.libs.advancedSearch.ui.ArbitraryWordInput.prototype.populateFromStore = function () { + var val = this.store.getOption( this.optionId ) || []; + if ( arrayEquals( this.getValue(), val ) ) { + return; + } + this.setValue( val ); + }; + } )( mediaWiki ); diff --git a/modules/ui/ext.advancedSearch.MenuedInput.js b/modules/ui/ext.advancedSearch.MenuedInput.js index ae86b8c..cbf7382 100644 --- a/modules/ui/ext.advancedSearch.MenuedInput.js +++ b/modules/ui/ext.advancedSearch.MenuedInput.js @@ -51,8 +51,12 @@ menu.addItems( items ); }; + // 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; -- To view, visit https://gerrit.wikimedia.org/r/358562 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I64b8f0692d3c7c29924e2ae3b19eb51407d00558 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/AdvancedSearch Gerrit-Branch: master Gerrit-Owner: Gabriel Birke <gabriel.bi...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits