Migration of searchfields, searchresults and searchpage to ES6 modules
This commit is contained in:
parent
fd853a180a
commit
89fcda5f05
4 changed files with 109 additions and 83 deletions
|
@ -1,10 +1,20 @@
|
|||
define(['layoutManager', 'globalize', 'require', 'events', 'browser', 'alphaPicker', 'emby-input', 'flexStyles', 'material-icons', 'css!./searchfields'], function (layoutManager, globalize, require, events, browser, AlphaPicker) {
|
||||
'use strict';
|
||||
import layoutManager from 'layoutManager';
|
||||
import globalize from 'globalize';
|
||||
import require from 'require';
|
||||
import events from 'events';
|
||||
import browser from 'browser';
|
||||
import AlphaPicker from 'alphaPicker';
|
||||
import 'emby-input';
|
||||
import 'flexStyles';
|
||||
import 'material-icons';
|
||||
import 'css!./searchfields';
|
||||
|
||||
/* eslint-disable indent*/
|
||||
|
||||
function onSearchTimeout() {
|
||||
|
||||
var instance = this;
|
||||
var value = instance.nextSearchValue;
|
||||
const instance = this;
|
||||
let value = instance.nextSearchValue;
|
||||
|
||||
value = (value || '').trim();
|
||||
events.trigger(instance, 'search', [value]);
|
||||
|
@ -22,14 +32,14 @@ define(['layoutManager', 'globalize', 'require', 'events', 'browser', 'alphaPick
|
|||
|
||||
function onAlphaValueClicked(e) {
|
||||
|
||||
var value = e.detail.value;
|
||||
var searchFieldsInstance = this;
|
||||
const value = e.detail.value;
|
||||
const searchFieldsInstance = this;
|
||||
|
||||
var txtSearch = searchFieldsInstance.options.element.querySelector('.searchfields-txtSearch');
|
||||
const txtSearch = searchFieldsInstance.options.element.querySelector('.searchfields-txtSearch');
|
||||
|
||||
if (value === 'backspace') {
|
||||
|
||||
var val = txtSearch.value;
|
||||
const val = txtSearch.value;
|
||||
txtSearch.value = val.length ? val.substring(0, val.length - 1) : '';
|
||||
|
||||
} else {
|
||||
|
@ -53,8 +63,8 @@ define(['layoutManager', 'globalize', 'require', 'events', 'browser', 'alphaPick
|
|||
|
||||
function onSearchInput(e) {
|
||||
|
||||
var value = e.target.value;
|
||||
var searchFieldsInstance = this;
|
||||
const value = e.target.value;
|
||||
const searchFieldsInstance = this;
|
||||
triggerSearch(searchFieldsInstance, value);
|
||||
}
|
||||
|
||||
|
@ -62,7 +72,7 @@ define(['layoutManager', 'globalize', 'require', 'events', 'browser', 'alphaPick
|
|||
|
||||
require(['text!./searchfields.template.html'], function (template) {
|
||||
|
||||
var html = globalize.translateDocument(template, 'core');
|
||||
let html = globalize.translateDocument(template, 'core');
|
||||
|
||||
if (browser.tizen || browser.orsay) {
|
||||
html = html.replace('<input ', '<input readonly ');
|
||||
|
@ -72,10 +82,10 @@ define(['layoutManager', 'globalize', 'require', 'events', 'browser', 'alphaPick
|
|||
|
||||
elem.classList.add('searchFields');
|
||||
|
||||
var txtSearch = elem.querySelector('.searchfields-txtSearch');
|
||||
const txtSearch = elem.querySelector('.searchfields-txtSearch');
|
||||
|
||||
if (layoutManager.tv) {
|
||||
var alphaPickerElement = elem.querySelector('.alphaPicker');
|
||||
const alphaPickerElement = elem.querySelector('.alphaPicker');
|
||||
|
||||
elem.querySelector('.alphaPicker').classList.remove('hide');
|
||||
initAlphaPicker(alphaPickerElement, instance);
|
||||
|
@ -87,38 +97,39 @@ define(['layoutManager', 'globalize', 'require', 'events', 'browser', 'alphaPick
|
|||
});
|
||||
}
|
||||
|
||||
function SearchFields(options) {
|
||||
class SearchFields {
|
||||
constructor(options) {
|
||||
|
||||
this.options = options;
|
||||
embed(options.element, this, options);
|
||||
}
|
||||
|
||||
SearchFields.prototype.focus = function () {
|
||||
focus() {
|
||||
|
||||
this.options.element.querySelector('.searchfields-txtSearch').focus();
|
||||
};
|
||||
}
|
||||
destroy() {
|
||||
|
||||
SearchFields.prototype.destroy = function () {
|
||||
|
||||
var options = this.options;
|
||||
const options = this.options;
|
||||
if (options) {
|
||||
options.element.classList.remove('searchFields');
|
||||
}
|
||||
this.options = null;
|
||||
|
||||
var alphaPicker = this.alphaPicker;
|
||||
const alphaPicker = this.alphaPicker;
|
||||
if (alphaPicker) {
|
||||
alphaPicker.destroy();
|
||||
}
|
||||
this.alphaPicker = null;
|
||||
|
||||
var searchTimeout = this.searchTimeout;
|
||||
const searchTimeout = this.searchTimeout;
|
||||
if (searchTimeout) {
|
||||
clearTimeout(searchTimeout);
|
||||
}
|
||||
this.searchTimeout = null;
|
||||
this.nextSearchValue = null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return SearchFields;
|
||||
});
|
||||
export default SearchFields;
|
||||
|
||||
/* eslint-enable indent */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue