Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Commit

Permalink
Merge pull request #174 from Wikia/XW-4026-release-74-fix-search
Browse files Browse the repository at this point in the history
Xw 4026 release 74 fix search
  • Loading branch information
JamesHawking authored Sep 26, 2017
2 parents 7c3b29f + ae5ad2d commit 06178f7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 35 deletions.
24 changes: 8 additions & 16 deletions app/components/wikia-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export default Component.extend(
inputFocused: false,
// Whether or not to display the loading search suggestion results message (en: 'Loading...')
isLoadingResultsSuggestions: false,
phrase: '',
phraseMinimalLength: 3,
query: '',
/**
Expand All @@ -60,30 +59,23 @@ export default Component.extend(
i18n: inject.service(),
logger: inject.service(),
wikiVariables: inject.service(),

inputSearchSelector: '.side-search__input',
emptyPhraseInput: computed.not('phrase'),
hasSuggestions: computed.notEmpty('suggestions'),
noScroll: computed.oneWay('hasSuggestions'),
queryObserver: observer('query', function () {
// ensures that phrase is changed according to external change
this.set('phrase', this.get('query'));
}),
phrase: Ember.computed.oneWay('query'),

searchPlaceholderLabel: computed(function () {
return this.get('i18n').t('search:main.search-input-label');
}),

didInsertElement() {
this._super(...arguments);

run.scheduleOnce('afterRender', this, () => {
// initialize with query
this.set('phrase', this.get('query'));
this.set('inputField', $('.side-search__input'));
if (this.get('focusInput')) {
this.$(this.get('inputSearchSelector')).focus();
}

if (this.get('focusInput')) {
this.get('inputField').focus();
}
});
},

actions: {
Expand All @@ -94,7 +86,7 @@ export default Component.extend(
label: 'search-open-special-search'
});

this.get('inputField').blur();
this.$(this.get('inputSearchSelector')).blur();
this.set('searchRequestInProgress', true);
this.setSearchSuggestionItems();
this.get('onEnterHandler')(value);
Expand All @@ -103,7 +95,7 @@ export default Component.extend(

clearSearch() {
this.set('phrase', '');
this.get('inputField').focus();
this.$(this.get('inputSearchSelector')).focus();
},

searchSuggestionClick() {
Expand Down
21 changes: 2 additions & 19 deletions app/controllers/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const {
computed,
inject,
$,
run
} = Ember;

export default Controller.extend({
Expand All @@ -14,23 +13,7 @@ export default Controller.extend({
// TODO: to be removed as we'll be supporting more errors on search page,
// see: https://wikia-inc.atlassian.net/browse/DAT-4324
notFoundError: computed.equal('model.error', 'search-error-not-found'),

init() {
/*
yes, we have the same function in two places (here and in wikia-search component).
This was the best solution, as wikia-search component had to have implemented this function
as well (because is used also in other contexts). We cannot pass actions from controllers
to components (DDAU). Observing for certain property passed from controller to component
wouldn't be clean solution as well.
*/
run.scheduleOnce('afterRender', this, () => {
this.set('inputPhrase', this.get('query'));

if (!this.get('fastboot.isFastBoot')) {
this.set('inputField', $('.side-search__input'));
}
});
},
inputPhrase: computed.alias('query'),

actions: {
onSearchEnter(query) {
Expand All @@ -40,7 +23,7 @@ export default Controller.extend({

onErrorPageClick() {
this.set('inputPhrase', '');
this.get('inputField').focus();
$('.side-search__input').focus();
},

onLoadMore() {
Expand Down

0 comments on commit 06178f7

Please sign in to comment.