@xenknight/framework7 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/app/app.less +1 -1
- package/components/icon/icon-ios.less +9 -0
- package/components/icon/icon-md.less +9 -0
- package/components/icon/icon.less +2 -1
- package/components/list/list-vars.less +1 -1
- package/components/messagebar/messagebar-rtl.css +1 -1
- package/components/messagebar/messagebar-vars.less +1 -1
- package/components/messagebar/messagebar.css +1 -1
- package/components/messages/messages-rtl.css +1 -1
- package/components/messages/messages-vars.less +7 -7
- package/components/messages/messages.css +1 -1
- package/components/navbar-new/navbar-ios.less +135 -0
- package/components/navbar-new/navbar-md.less +105 -0
- package/components/navbar-new/navbar-vars.less +78 -0
- package/components/navbar-new/navbar.d.ts +77 -0
- package/components/navbar-new/navbar.js +568 -0
- package/components/navbar-new/navbar.less +268 -0
- package/components/searchbar-new/remove-diacritics.js +271 -0
- package/components/searchbar-new/searchbar-ios.less +131 -0
- package/components/searchbar-new/searchbar-md.less +153 -0
- package/components/searchbar-new/searchbar-new-class.js +592 -0
- package/components/searchbar-new/searchbar-vars.less +75 -0
- package/components/searchbar-new/searchbar.js +122 -0
- package/components/searchbar-new/searchbar.less +331 -0
- package/components/swipeout/swipeout.js +8 -9
- package/components/tabs/tabs.js +5 -0
- package/components/toolbar-new/tabbar-highlight.js +134 -0
- package/components/toolbar-new/toolbar-ios.less +193 -0
- package/components/toolbar-new/toolbar-md.less +152 -0
- package/components/toolbar-new/toolbar-vars.less +77 -0
- package/components/toolbar-new/toolbar.js +223 -0
- package/components/toolbar-new/toolbar.less +261 -0
- package/framework7-bundle-rtl.css +2198 -387
- package/framework7-bundle-rtl.min.css +12 -6
- package/framework7-bundle.css +2194 -383
- package/framework7-bundle.esm.js +11 -4
- package/framework7-bundle.js +2368 -467
- package/framework7-bundle.js.map +1 -1
- package/framework7-bundle.less +6 -3
- package/framework7-bundle.min.css +12 -6
- package/framework7-bundle.min.js +4 -4
- package/framework7-bundle.min.js.map +1 -1
- package/framework7-lite-bundle.esm.js +11 -4
- package/framework7-lite.esm.js +11 -4
- package/framework7-lite.js +8 -1
- package/framework7-rtl.css +2191 -380
- package/framework7-rtl.min.css +11 -5
- package/framework7.css +2189 -378
- package/framework7.esm.js +11 -4
- package/framework7.js +8 -1
- package/framework7.less +6 -3
- package/framework7.min.css +11 -5
- package/package.json +1 -1
|
@@ -0,0 +1,592 @@
|
|
|
1
|
+
import { getDocument } from 'ssr-window';
|
|
2
|
+
import $ from '../../shared/dom7.js';
|
|
3
|
+
import { extend, nextTick, deleteProps } from '../../shared/utils.js';
|
|
4
|
+
import FrameworkClass from '../../shared/class.js';
|
|
5
|
+
import { getDevice } from '../../shared/get-device.js';
|
|
6
|
+
import removeDiacritics from './remove-diacritics.js';
|
|
7
|
+
class SearchbarNew extends FrameworkClass {
|
|
8
|
+
constructor(app, params) {
|
|
9
|
+
if (params === void 0) {
|
|
10
|
+
params = {};
|
|
11
|
+
}
|
|
12
|
+
super(params, [app]);
|
|
13
|
+
const sb = this;
|
|
14
|
+
const defaults = {
|
|
15
|
+
el: undefined,
|
|
16
|
+
inputEl: undefined,
|
|
17
|
+
inputEvents: 'change input compositionend',
|
|
18
|
+
disableButton: true,
|
|
19
|
+
disableButtonEl: undefined,
|
|
20
|
+
backdropEl: undefined,
|
|
21
|
+
searchContainer: undefined,
|
|
22
|
+
// container to search, HTMLElement or CSS selector
|
|
23
|
+
searchItem: 'li',
|
|
24
|
+
// single item selector, CSS selector
|
|
25
|
+
searchIn: undefined,
|
|
26
|
+
// where to search in item, CSS selector
|
|
27
|
+
searchGroup: '.list-group',
|
|
28
|
+
searchGroupTitle: '.list-group-title',
|
|
29
|
+
ignore: '.searchbar-new-ignore',
|
|
30
|
+
foundEl: '.searchbar-new-found',
|
|
31
|
+
notFoundEl: '.searchbar-new-not-found',
|
|
32
|
+
hideOnEnableEl: '.searchbar-new-hide-on-enable',
|
|
33
|
+
hideOnSearchEl: '.searchbar-new-hide-on-search',
|
|
34
|
+
backdrop: true,
|
|
35
|
+
removeDiacritics: true,
|
|
36
|
+
customSearch: false,
|
|
37
|
+
hideGroupTitles: true,
|
|
38
|
+
hideGroups: true,
|
|
39
|
+
disableOnBackdropClick: true,
|
|
40
|
+
expandable: false,
|
|
41
|
+
inline: false
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// Extend defaults with modules params
|
|
45
|
+
sb.useModulesParams(defaults);
|
|
46
|
+
sb.params = extend(defaults, params);
|
|
47
|
+
const $el = $(sb.params.el);
|
|
48
|
+
if ($el.length === 0) return sb;
|
|
49
|
+
if ($el[0].f7SearchbarNew) return $el[0].f7SearchbarNew;
|
|
50
|
+
$el[0].f7SearchbarNew = sb;
|
|
51
|
+
let $pageEl;
|
|
52
|
+
const $navbarEl = $el.parents('.navbar-new');
|
|
53
|
+
if ($el.parents('.page').length > 0) {
|
|
54
|
+
$pageEl = $el.parents('.page');
|
|
55
|
+
} else if ($navbarEl.length > 0) {
|
|
56
|
+
$pageEl = $(app.navbarNew.getPageByEl($navbarEl[0]));
|
|
57
|
+
if (!$pageEl.length) {
|
|
58
|
+
const $currentPageEl = $el.parents('.view').find('.page-current');
|
|
59
|
+
if ($currentPageEl[0] && $currentPageEl[0].f7Page && $currentPageEl[0].f7Page.navbarNewEl === $navbarEl[0]) {
|
|
60
|
+
$pageEl = $currentPageEl;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
let $foundEl;
|
|
65
|
+
if (params.foundEl) {
|
|
66
|
+
$foundEl = $(params.foundEl);
|
|
67
|
+
} else if (typeof sb.params.foundEl === 'string' && $pageEl) {
|
|
68
|
+
$foundEl = $pageEl.find(sb.params.foundEl);
|
|
69
|
+
}
|
|
70
|
+
let $notFoundEl;
|
|
71
|
+
if (params.notFoundEl) {
|
|
72
|
+
$notFoundEl = $(params.notFoundEl);
|
|
73
|
+
} else if (typeof sb.params.notFoundEl === 'string' && $pageEl) {
|
|
74
|
+
$notFoundEl = $pageEl.find(sb.params.notFoundEl);
|
|
75
|
+
}
|
|
76
|
+
let $hideOnEnableEl;
|
|
77
|
+
if (params.hideOnEnableEl) {
|
|
78
|
+
$hideOnEnableEl = $(params.hideOnEnableEl);
|
|
79
|
+
} else if (typeof sb.params.hideOnEnableEl === 'string' && $pageEl) {
|
|
80
|
+
$hideOnEnableEl = $pageEl.find(sb.params.hideOnEnableEl);
|
|
81
|
+
}
|
|
82
|
+
let $hideOnSearchEl;
|
|
83
|
+
if (params.hideOnSearchEl) {
|
|
84
|
+
$hideOnSearchEl = $(params.hideOnSearchEl);
|
|
85
|
+
} else if (typeof sb.params.hideOnSearchEl === 'string' && $pageEl) {
|
|
86
|
+
$hideOnSearchEl = $pageEl.find(sb.params.hideOnSearchEl);
|
|
87
|
+
}
|
|
88
|
+
const expandable = sb.params.expandable || $el.hasClass('searchbar-new-expandable');
|
|
89
|
+
const inline = sb.params.inline || $el.hasClass('searchbar-new-inline');
|
|
90
|
+
if (typeof sb.params.backdrop === 'undefined') {
|
|
91
|
+
sb.params.backdrop = !inline;
|
|
92
|
+
}
|
|
93
|
+
let $backdropEl;
|
|
94
|
+
if (sb.params.backdrop) {
|
|
95
|
+
if (sb.params.backdropEl) {
|
|
96
|
+
$backdropEl = $(sb.params.backdropEl);
|
|
97
|
+
} else if ($pageEl && $pageEl.length > 0) {
|
|
98
|
+
$backdropEl = $pageEl.find('.searchbar-new-backdrop');
|
|
99
|
+
} else {
|
|
100
|
+
$backdropEl = $el.siblings('.searchbar-new-backdrop');
|
|
101
|
+
}
|
|
102
|
+
if ($backdropEl.length === 0) {
|
|
103
|
+
$backdropEl = $('<div class="searchbar-new-backdrop"></div>');
|
|
104
|
+
if ($pageEl && $pageEl.length) {
|
|
105
|
+
if ($el.parents($pageEl).length > 0 && $navbarEl && $el.parents($navbarEl).length === 0) {
|
|
106
|
+
$backdropEl.insertBefore($el);
|
|
107
|
+
} else {
|
|
108
|
+
$backdropEl.insertBefore($pageEl.find('.page-content').eq(0));
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
$backdropEl.insertBefore($el);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
let $searchContainer;
|
|
116
|
+
if (sb.params.searchContainer) {
|
|
117
|
+
$searchContainer = $(sb.params.searchContainer);
|
|
118
|
+
}
|
|
119
|
+
let $inputEl;
|
|
120
|
+
if (sb.params.inputEl) {
|
|
121
|
+
$inputEl = $(sb.params.inputEl);
|
|
122
|
+
} else {
|
|
123
|
+
$inputEl = $el.find('input[type="search"]').eq(0);
|
|
124
|
+
}
|
|
125
|
+
let $disableButtonEl;
|
|
126
|
+
if (sb.params.disableButton) {
|
|
127
|
+
if (sb.params.disableButtonEl) {
|
|
128
|
+
$disableButtonEl = $(sb.params.disableButtonEl);
|
|
129
|
+
} else {
|
|
130
|
+
$disableButtonEl = $el.find('.searchbar-new-disable-button');
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
extend(sb, {
|
|
134
|
+
app,
|
|
135
|
+
view: app.views.get($el.parents('.view')),
|
|
136
|
+
$el,
|
|
137
|
+
el: $el[0],
|
|
138
|
+
$backdropEl,
|
|
139
|
+
backdropEl: $backdropEl && $backdropEl[0],
|
|
140
|
+
$searchContainer,
|
|
141
|
+
searchContainer: $searchContainer && $searchContainer[0],
|
|
142
|
+
$inputEl,
|
|
143
|
+
inputEl: $inputEl[0],
|
|
144
|
+
$disableButtonEl,
|
|
145
|
+
disableButtonEl: $disableButtonEl && $disableButtonEl[0],
|
|
146
|
+
disableButtonHasMargin: false,
|
|
147
|
+
$pageEl,
|
|
148
|
+
pageEl: $pageEl && $pageEl[0],
|
|
149
|
+
$navbarEl,
|
|
150
|
+
navbarEl: $navbarEl && $navbarEl[0],
|
|
151
|
+
$foundEl,
|
|
152
|
+
foundEl: $foundEl && $foundEl[0],
|
|
153
|
+
$notFoundEl,
|
|
154
|
+
notFoundEl: $notFoundEl && $notFoundEl[0],
|
|
155
|
+
$hideOnEnableEl,
|
|
156
|
+
hideOnEnableEl: $hideOnEnableEl && $hideOnEnableEl[0],
|
|
157
|
+
$hideOnSearchEl,
|
|
158
|
+
hideOnSearchEl: $hideOnSearchEl && $hideOnSearchEl[0],
|
|
159
|
+
previousQuery: '',
|
|
160
|
+
query: '',
|
|
161
|
+
isVirtualList: $searchContainer && $searchContainer.hasClass('virtual-list'),
|
|
162
|
+
virtualList: undefined,
|
|
163
|
+
enabled: false,
|
|
164
|
+
expandable,
|
|
165
|
+
inline
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
// Events
|
|
169
|
+
function preventSubmit(e) {
|
|
170
|
+
e.preventDefault();
|
|
171
|
+
}
|
|
172
|
+
function onInputFocus(e) {
|
|
173
|
+
sb.enable(e);
|
|
174
|
+
sb.$el.addClass('searchbar-new-focused');
|
|
175
|
+
}
|
|
176
|
+
function onInputBlur() {
|
|
177
|
+
sb.$el.removeClass('searchbar-new-focused');
|
|
178
|
+
}
|
|
179
|
+
function onInputChange() {
|
|
180
|
+
const value = sb.$inputEl.val().trim();
|
|
181
|
+
if (sb.$searchContainer && sb.$searchContainer.length > 0 && (sb.params.searchIn || sb.isVirtualList || sb.params.searchIn === sb.params.searchItem) || sb.params.customSearch) {
|
|
182
|
+
sb.search(value, true);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function onInputClear(e, previousValue) {
|
|
186
|
+
sb.$el.trigger('searchbar-new:clear', previousValue);
|
|
187
|
+
sb.emit('local::clear searchbarNewClear', sb, previousValue);
|
|
188
|
+
}
|
|
189
|
+
function disableOnClick(e) {
|
|
190
|
+
sb.disable(e);
|
|
191
|
+
}
|
|
192
|
+
function onPageBeforeOut() {
|
|
193
|
+
if (!sb || sb && !sb.$el) return;
|
|
194
|
+
if (sb.enabled) {
|
|
195
|
+
sb.$el.removeClass('searchbar-new-enabled');
|
|
196
|
+
if (sb.expandable) {
|
|
197
|
+
sb.$el.parents('.navbar-new').removeClass('with-searchbar-new-expandable-enabled with-searchbar-new-expandable-enabled-no-transition');
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
function onPageBeforeIn() {
|
|
202
|
+
if (!sb || sb && !sb.$el) return;
|
|
203
|
+
if (sb.enabled) {
|
|
204
|
+
sb.$el.addClass('searchbar-new-enabled');
|
|
205
|
+
if (sb.expandable) {
|
|
206
|
+
sb.$el.parents('.navbar-new').addClass('with-searchbar-new-expandable-enabled-no-transition');
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
sb.attachEvents = function attachEvents() {
|
|
211
|
+
$el.on('submit', preventSubmit);
|
|
212
|
+
if (sb.params.disableButton) {
|
|
213
|
+
sb.$disableButtonEl.on('click', disableOnClick);
|
|
214
|
+
}
|
|
215
|
+
if (sb.params.disableOnBackdropClick && sb.$backdropEl) {
|
|
216
|
+
sb.$backdropEl.on('click', disableOnClick);
|
|
217
|
+
}
|
|
218
|
+
if (sb.expandable && app.theme === 'ios' && sb.view && $navbarEl.length && sb.$pageEl) {
|
|
219
|
+
sb.$pageEl.on('page:beforeout', onPageBeforeOut);
|
|
220
|
+
sb.$pageEl.on('page:beforein', onPageBeforeIn);
|
|
221
|
+
}
|
|
222
|
+
sb.$inputEl.on('focus', onInputFocus);
|
|
223
|
+
sb.$inputEl.on('blur', onInputBlur);
|
|
224
|
+
sb.$inputEl.on(sb.params.inputEvents, onInputChange);
|
|
225
|
+
sb.$inputEl.on('input:clear', onInputClear);
|
|
226
|
+
};
|
|
227
|
+
sb.detachEvents = function detachEvents() {
|
|
228
|
+
$el.off('submit', preventSubmit);
|
|
229
|
+
if (sb.params.disableButton) {
|
|
230
|
+
sb.$disableButtonEl.off('click', disableOnClick);
|
|
231
|
+
}
|
|
232
|
+
if (sb.params.disableOnBackdropClick && sb.$backdropEl) {
|
|
233
|
+
sb.$backdropEl.off('click', disableOnClick);
|
|
234
|
+
}
|
|
235
|
+
if (sb.expandable && app.theme === 'ios' && sb.view && $navbarEl.length && sb.$pageEl) {
|
|
236
|
+
sb.$pageEl.off('page:beforeout', onPageBeforeOut);
|
|
237
|
+
sb.$pageEl.off('page:beforein', onPageBeforeIn);
|
|
238
|
+
}
|
|
239
|
+
sb.$inputEl.off('focus', onInputFocus);
|
|
240
|
+
sb.$inputEl.off('blur', onInputBlur);
|
|
241
|
+
sb.$inputEl.off(sb.params.inputEvents, onInputChange);
|
|
242
|
+
sb.$inputEl.off('input:clear', onInputClear);
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
// Install Modules
|
|
246
|
+
sb.useModules();
|
|
247
|
+
|
|
248
|
+
// Init
|
|
249
|
+
sb.init();
|
|
250
|
+
return sb;
|
|
251
|
+
}
|
|
252
|
+
clear(e) {
|
|
253
|
+
const sb = this;
|
|
254
|
+
if (!sb.query && e && $(e.target).hasClass('searchbar-new-clear')) {
|
|
255
|
+
sb.disable();
|
|
256
|
+
return sb;
|
|
257
|
+
}
|
|
258
|
+
const previousQuery = sb.value;
|
|
259
|
+
sb.$inputEl.val('').trigger('change').focus();
|
|
260
|
+
sb.$el.trigger('searchbar-new:clear', previousQuery);
|
|
261
|
+
sb.emit('local::clear searchbarNewClear', sb, previousQuery);
|
|
262
|
+
return sb;
|
|
263
|
+
}
|
|
264
|
+
setDisableButtonMargin() {
|
|
265
|
+
const sb = this;
|
|
266
|
+
if (sb.expandable) return;
|
|
267
|
+
const app = sb.app;
|
|
268
|
+
sb.$disableButtonEl.transition(0).show();
|
|
269
|
+
sb.$disableButtonEl.css(`margin-${app.rtl ? 'left' : 'right'}`, `${-sb.disableButtonEl.offsetWidth}px`);
|
|
270
|
+
/* eslint no-underscore-dangle: ["error", { "allow": ["_clientLeft"] }] */
|
|
271
|
+
sb._clientLeft = sb.$disableButtonEl[0].clientLeft;
|
|
272
|
+
sb.$disableButtonEl.transition('');
|
|
273
|
+
sb.disableButtonHasMargin = true;
|
|
274
|
+
}
|
|
275
|
+
enable(setFocus) {
|
|
276
|
+
const sb = this;
|
|
277
|
+
if (sb.enabled) return sb;
|
|
278
|
+
const app = sb.app;
|
|
279
|
+
const document = getDocument();
|
|
280
|
+
const device = getDevice();
|
|
281
|
+
sb.enabled = true;
|
|
282
|
+
function enable() {
|
|
283
|
+
if (sb.$backdropEl && (sb.$searchContainer && sb.$searchContainer.length || sb.params.customSearch) && !sb.$el.hasClass('searchbar-new-enabled') && !sb.query) {
|
|
284
|
+
sb.backdropShow();
|
|
285
|
+
}
|
|
286
|
+
sb.$el.addClass('searchbar-new-enabled');
|
|
287
|
+
if (!sb.$disableButtonEl || sb.$disableButtonEl && sb.$disableButtonEl.length === 0) {
|
|
288
|
+
sb.$el.addClass('searchbar-new-enabled-no-disable-button');
|
|
289
|
+
}
|
|
290
|
+
if (!sb.expandable && sb.$disableButtonEl && sb.$disableButtonEl.length > 0 && app.theme !== 'md') {
|
|
291
|
+
if (!sb.disableButtonHasMargin) {
|
|
292
|
+
sb.setDisableButtonMargin();
|
|
293
|
+
}
|
|
294
|
+
sb.$disableButtonEl.css(`margin-${app.rtl ? 'left' : 'right'}`, '0px');
|
|
295
|
+
}
|
|
296
|
+
if (sb.expandable) {
|
|
297
|
+
const $navbarEl = sb.$el.parents('.navbar-new');
|
|
298
|
+
if ($navbarEl.hasClass('navbar-new-large') && sb.$pageEl) {
|
|
299
|
+
const $pageContentEl = sb.$pageEl.find('.page-content');
|
|
300
|
+
const $titleLargeEl = $navbarEl.find('.title-large');
|
|
301
|
+
$pageContentEl.addClass('with-searchbar-new-expandable-enabled');
|
|
302
|
+
if ($navbarEl.hasClass('navbar-new-large') && $navbarEl.hasClass('navbar-new-large-collapsed') && $titleLargeEl.length && $pageContentEl.length) {
|
|
303
|
+
$pageContentEl.transition(0);
|
|
304
|
+
$pageContentEl[0].scrollTop -= $titleLargeEl[0].offsetHeight;
|
|
305
|
+
setTimeout(() => {
|
|
306
|
+
$pageContentEl.transition('');
|
|
307
|
+
}, 200);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if (app.theme === 'md' && $navbarEl.length) {
|
|
311
|
+
$navbarEl.addClass('with-searchbar-new-expandable-enabled');
|
|
312
|
+
} else {
|
|
313
|
+
$navbarEl.addClass('with-searchbar-new-expandable-enabled');
|
|
314
|
+
if ($navbarEl.hasClass('navbar-new-large')) {
|
|
315
|
+
$navbarEl.addClass('navbar-new-large-collapsed');
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
if (sb.$hideOnEnableEl) sb.$hideOnEnableEl.addClass('hidden-by-searchbar-new');
|
|
320
|
+
sb.$el.trigger('searchbar-new:enable');
|
|
321
|
+
sb.emit('local::enable searchbarNewEnable', sb);
|
|
322
|
+
}
|
|
323
|
+
let needsFocus = false;
|
|
324
|
+
if (setFocus === true) {
|
|
325
|
+
if (document.activeElement !== sb.inputEl) {
|
|
326
|
+
needsFocus = true;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
const isIos = device.ios && app.theme === 'ios';
|
|
330
|
+
if (isIos) {
|
|
331
|
+
if (sb.expandable) {
|
|
332
|
+
if (needsFocus) sb.$inputEl.focus();
|
|
333
|
+
enable();
|
|
334
|
+
} else {
|
|
335
|
+
if (needsFocus) sb.$inputEl.focus();
|
|
336
|
+
if (setFocus && (setFocus.type === 'focus' || setFocus === true)) {
|
|
337
|
+
nextTick(() => {
|
|
338
|
+
enable();
|
|
339
|
+
}, 400);
|
|
340
|
+
} else {
|
|
341
|
+
enable();
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
} else {
|
|
345
|
+
if (needsFocus) sb.$inputEl.focus();
|
|
346
|
+
if (app.theme === 'md' && sb.expandable) {
|
|
347
|
+
sb.$el.parents('.page, .view, .navbar-new-inner, .navbar-new').scrollLeft(app.rtl ? 100 : 0);
|
|
348
|
+
}
|
|
349
|
+
enable();
|
|
350
|
+
}
|
|
351
|
+
return sb;
|
|
352
|
+
}
|
|
353
|
+
disable() {
|
|
354
|
+
const sb = this;
|
|
355
|
+
if (!sb.enabled) return sb;
|
|
356
|
+
const app = sb.app;
|
|
357
|
+
sb.$inputEl.val('').trigger('change');
|
|
358
|
+
sb.$el.removeClass('searchbar-new-enabled searchbar-new-focused searchbar-new-enabled-no-disable-button');
|
|
359
|
+
if (sb.expandable) {
|
|
360
|
+
const $navbarEl = sb.$el.parents('.navbar-new');
|
|
361
|
+
const $pageContentEl = sb.$pageEl && sb.$pageEl.find('.page-content');
|
|
362
|
+
if ($navbarEl.hasClass('navbar-new-large') && $pageContentEl.length) {
|
|
363
|
+
const $titleLargeEl = $navbarEl.find('.title-large');
|
|
364
|
+
sb.$el.transitionEnd(() => {
|
|
365
|
+
$pageContentEl.removeClass('with-searchbar-new-expandable-closing');
|
|
366
|
+
});
|
|
367
|
+
if ($navbarEl.hasClass('navbar-new-large') && $navbarEl.hasClass('navbar-new-large-collapsed') && $titleLargeEl.length) {
|
|
368
|
+
const scrollTop = $pageContentEl[0].scrollTop;
|
|
369
|
+
const titleLargeHeight = $titleLargeEl[0].offsetHeight;
|
|
370
|
+
if (scrollTop > titleLargeHeight) {
|
|
371
|
+
$pageContentEl.transition(0);
|
|
372
|
+
$pageContentEl[0].scrollTop = scrollTop + titleLargeHeight;
|
|
373
|
+
setTimeout(() => {
|
|
374
|
+
$pageContentEl.transition('');
|
|
375
|
+
}, 200);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
$pageContentEl.removeClass('with-searchbar-new-expandable-enabled').addClass('with-searchbar-new-expandable-closing');
|
|
379
|
+
}
|
|
380
|
+
if (app.theme === 'md' && $navbarEl.length) {
|
|
381
|
+
$navbarEl.removeClass('with-searchbar-new-expandable-enabled with-searchbar-new-expandable-enabled-no-transition').addClass('with-searchbar-new-expandable-closing');
|
|
382
|
+
sb.$el.transitionEnd(() => {
|
|
383
|
+
$navbarEl.removeClass('with-searchbar-new-expandable-closing');
|
|
384
|
+
});
|
|
385
|
+
} else {
|
|
386
|
+
$navbarEl.removeClass('with-searchbar-new-expandable-enabled with-searchbar-new-expandable-enabled-no-transition').addClass('with-searchbar-new-expandable-closing');
|
|
387
|
+
sb.$el.transitionEnd(() => {
|
|
388
|
+
$navbarEl.removeClass('with-searchbar-new-expandable-closing');
|
|
389
|
+
});
|
|
390
|
+
if (sb.$pageEl) {
|
|
391
|
+
sb.$pageEl.find('.page-content').trigger('scroll');
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
if (!sb.expandable && sb.$disableButtonEl && sb.$disableButtonEl.length > 0 && app.theme !== 'md') {
|
|
396
|
+
sb.$disableButtonEl.css(`margin-${app.rtl ? 'left' : 'right'}`, `${-sb.disableButtonEl.offsetWidth}px`);
|
|
397
|
+
}
|
|
398
|
+
if (sb.$backdropEl && (sb.$searchContainer && sb.$searchContainer.length || sb.params.customSearch)) {
|
|
399
|
+
sb.backdropHide();
|
|
400
|
+
}
|
|
401
|
+
sb.enabled = false;
|
|
402
|
+
sb.$inputEl.blur();
|
|
403
|
+
if (sb.$hideOnEnableEl) sb.$hideOnEnableEl.removeClass('hidden-by-searchbar-new');
|
|
404
|
+
sb.$el.trigger('searchbar-new:disable');
|
|
405
|
+
sb.emit('local::disable searchbarNewDisable', sb);
|
|
406
|
+
return sb;
|
|
407
|
+
}
|
|
408
|
+
toggle() {
|
|
409
|
+
const sb = this;
|
|
410
|
+
if (sb.enabled) sb.disable();else sb.enable(true);
|
|
411
|
+
return sb;
|
|
412
|
+
}
|
|
413
|
+
backdropShow() {
|
|
414
|
+
const sb = this;
|
|
415
|
+
if (sb.$backdropEl) {
|
|
416
|
+
sb.$backdropEl.addClass('searchbar-new-backdrop-in');
|
|
417
|
+
}
|
|
418
|
+
return sb;
|
|
419
|
+
}
|
|
420
|
+
backdropHide() {
|
|
421
|
+
const sb = this;
|
|
422
|
+
if (sb.$backdropEl) {
|
|
423
|
+
sb.$backdropEl.removeClass('searchbar-new-backdrop-in');
|
|
424
|
+
}
|
|
425
|
+
return sb;
|
|
426
|
+
}
|
|
427
|
+
search(query, internal) {
|
|
428
|
+
const sb = this;
|
|
429
|
+
sb.previousQuery = sb.query || '';
|
|
430
|
+
if (query === sb.previousQuery) return sb;
|
|
431
|
+
if (!internal) {
|
|
432
|
+
if (!sb.enabled) {
|
|
433
|
+
sb.enable();
|
|
434
|
+
}
|
|
435
|
+
sb.$inputEl.val(query);
|
|
436
|
+
sb.$inputEl.trigger('input');
|
|
437
|
+
}
|
|
438
|
+
sb.query = query;
|
|
439
|
+
sb.value = query;
|
|
440
|
+
const {
|
|
441
|
+
$searchContainer,
|
|
442
|
+
$el,
|
|
443
|
+
$foundEl,
|
|
444
|
+
$notFoundEl,
|
|
445
|
+
$hideOnSearchEl,
|
|
446
|
+
isVirtualList
|
|
447
|
+
} = sb;
|
|
448
|
+
|
|
449
|
+
// Hide on search element
|
|
450
|
+
if (query.length > 0 && $hideOnSearchEl) {
|
|
451
|
+
$hideOnSearchEl.addClass('hidden-by-searchbar-new');
|
|
452
|
+
} else if ($hideOnSearchEl) {
|
|
453
|
+
$hideOnSearchEl.removeClass('hidden-by-searchbar-new');
|
|
454
|
+
}
|
|
455
|
+
// Add active/inactive classes on overlay
|
|
456
|
+
if ($searchContainer && $searchContainer.length && $el.hasClass('searchbar-new-enabled') || sb.params.customSearch && $el.hasClass('searchbar-new-enabled')) {
|
|
457
|
+
if (query.length === 0) {
|
|
458
|
+
sb.backdropShow();
|
|
459
|
+
} else {
|
|
460
|
+
sb.backdropHide();
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
if (sb.params.customSearch) {
|
|
464
|
+
$el.trigger('searchbar-new:search', {
|
|
465
|
+
query,
|
|
466
|
+
previousQuery: sb.previousQuery
|
|
467
|
+
});
|
|
468
|
+
sb.emit('local::search searchbarNewSearch', sb, query, sb.previousQuery);
|
|
469
|
+
return sb;
|
|
470
|
+
}
|
|
471
|
+
let foundItems = [];
|
|
472
|
+
let vlQuery;
|
|
473
|
+
if (isVirtualList) {
|
|
474
|
+
sb.virtualList = $searchContainer[0].f7VirtualList;
|
|
475
|
+
if (query.trim() === '') {
|
|
476
|
+
sb.virtualList.resetFilter();
|
|
477
|
+
if ($notFoundEl) $notFoundEl.hide();
|
|
478
|
+
if ($foundEl) $foundEl.show();
|
|
479
|
+
$el.trigger('searchbar-new:search', {
|
|
480
|
+
query,
|
|
481
|
+
previousQuery: sb.previousQuery
|
|
482
|
+
});
|
|
483
|
+
sb.emit('local::search searchbarNewSearch', sb, query, sb.previousQuery);
|
|
484
|
+
return sb;
|
|
485
|
+
}
|
|
486
|
+
vlQuery = sb.params.removeDiacritics ? removeDiacritics(query) : query;
|
|
487
|
+
if (sb.virtualList.params.searchAll) {
|
|
488
|
+
foundItems = sb.virtualList.params.searchAll(vlQuery, sb.virtualList.items) || [];
|
|
489
|
+
} else if (sb.virtualList.params.searchByItem) {
|
|
490
|
+
for (let i = 0; i < sb.virtualList.items.length; i += 1) {
|
|
491
|
+
if (sb.virtualList.params.searchByItem(vlQuery, sb.virtualList.items[i], i)) {
|
|
492
|
+
foundItems.push(i);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
} else {
|
|
497
|
+
let values;
|
|
498
|
+
if (sb.params.removeDiacritics) values = removeDiacritics(query.trim().toLowerCase()).split(' ');else {
|
|
499
|
+
values = query.trim().toLowerCase().split(' ');
|
|
500
|
+
}
|
|
501
|
+
$searchContainer.find(sb.params.searchItem).removeClass('hidden-by-searchbar-new').each(itemEl => {
|
|
502
|
+
const $itemEl = $(itemEl);
|
|
503
|
+
let compareWithText = [];
|
|
504
|
+
let $searchIn = sb.params.searchIn ? $itemEl.find(sb.params.searchIn) : $itemEl;
|
|
505
|
+
if (sb.params.searchIn === sb.params.searchItem) {
|
|
506
|
+
$searchIn = $itemEl;
|
|
507
|
+
}
|
|
508
|
+
$searchIn.each(searchInEl => {
|
|
509
|
+
let itemText = $(searchInEl).text().trim().toLowerCase();
|
|
510
|
+
if (sb.params.removeDiacritics) itemText = removeDiacritics(itemText);
|
|
511
|
+
compareWithText.push(itemText);
|
|
512
|
+
});
|
|
513
|
+
compareWithText = compareWithText.join(' ');
|
|
514
|
+
let wordsMatch = 0;
|
|
515
|
+
for (let i = 0; i < values.length; i += 1) {
|
|
516
|
+
if (compareWithText.indexOf(values[i]) >= 0) wordsMatch += 1;
|
|
517
|
+
}
|
|
518
|
+
if (wordsMatch !== values.length && !(sb.params.ignore && $itemEl.is(sb.params.ignore))) {
|
|
519
|
+
$itemEl.addClass('hidden-by-searchbar-new');
|
|
520
|
+
} else {
|
|
521
|
+
foundItems.push($itemEl[0]);
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
if (sb.params.hideGroupTitles) {
|
|
525
|
+
$searchContainer.find(sb.params.searchGroupTitle).each(titleEl => {
|
|
526
|
+
const $titleEl = $(titleEl);
|
|
527
|
+
const $nextElements = $titleEl.nextAll(sb.params.searchItem);
|
|
528
|
+
let hide = true;
|
|
529
|
+
for (let i = 0; i < $nextElements.length; i += 1) {
|
|
530
|
+
const $nextEl = $nextElements.eq(i);
|
|
531
|
+
if ($nextEl.is(sb.params.searchGroupTitle)) break;
|
|
532
|
+
if (!$nextEl.hasClass('hidden-by-searchbar-new')) {
|
|
533
|
+
hide = false;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
const ignore = sb.params.ignore && $titleEl.is(sb.params.ignore);
|
|
537
|
+
if (hide && !ignore) $titleEl.addClass('hidden-by-searchbar-new');else $titleEl.removeClass('hidden-by-searchbar-new');
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
if (sb.params.hideGroups) {
|
|
541
|
+
$searchContainer.find(sb.params.searchGroup).each(groupEl => {
|
|
542
|
+
const $groupEl = $(groupEl);
|
|
543
|
+
const ignore = sb.params.ignore && $groupEl.is(sb.params.ignore);
|
|
544
|
+
// eslint-disable-next-line
|
|
545
|
+
const notHidden = $groupEl.find(sb.params.searchItem).filter(el => {
|
|
546
|
+
return !$(el).hasClass('hidden-by-searchbar-new');
|
|
547
|
+
});
|
|
548
|
+
if (notHidden.length === 0 && !ignore) {
|
|
549
|
+
$groupEl.addClass('hidden-by-searchbar-new');
|
|
550
|
+
} else {
|
|
551
|
+
$groupEl.removeClass('hidden-by-searchbar-new');
|
|
552
|
+
}
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
if (foundItems.length === 0) {
|
|
557
|
+
if ($notFoundEl) $notFoundEl.show();
|
|
558
|
+
if ($foundEl) $foundEl.hide();
|
|
559
|
+
} else {
|
|
560
|
+
if ($notFoundEl) $notFoundEl.hide();
|
|
561
|
+
if ($foundEl) $foundEl.show();
|
|
562
|
+
}
|
|
563
|
+
if (isVirtualList && sb.virtualList) {
|
|
564
|
+
sb.virtualList.filterItems(foundItems);
|
|
565
|
+
}
|
|
566
|
+
$el.trigger('searchbar-new:search', {
|
|
567
|
+
query,
|
|
568
|
+
previousQuery: sb.previousQuery,
|
|
569
|
+
foundItems
|
|
570
|
+
});
|
|
571
|
+
sb.emit('local::search searchbarNewSearch', sb, query, sb.previousQuery, foundItems);
|
|
572
|
+
return sb;
|
|
573
|
+
}
|
|
574
|
+
init() {
|
|
575
|
+
const sb = this;
|
|
576
|
+
if (sb.expandable && sb.$el) sb.$el.addClass('searchbar-new-expandable');
|
|
577
|
+
if (sb.inline && sb.$el) sb.$el.addClass('searchbar-new-inline');
|
|
578
|
+
sb.attachEvents();
|
|
579
|
+
}
|
|
580
|
+
destroy() {
|
|
581
|
+
const sb = this;
|
|
582
|
+
sb.emit('local::beforeDestroy searchbarNewBeforeDestroy', sb);
|
|
583
|
+
sb.$el.trigger('searchbar-new:beforedestroy');
|
|
584
|
+
sb.detachEvents();
|
|
585
|
+
if (sb.$el[0]) {
|
|
586
|
+
sb.$el[0].f7SearchbarNew = null;
|
|
587
|
+
delete sb.$el[0].f7SearchbarNew;
|
|
588
|
+
}
|
|
589
|
+
deleteProps(sb);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
export default SearchbarNew;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
/*
|
|
3
|
+
--f7-searchbar-new-link-color: var(--f7-bars-link-color);
|
|
4
|
+
--f7-searchbar-new-inline-input-font-size: var(--f7-searchbar-new-input-font-size);
|
|
5
|
+
*/
|
|
6
|
+
--f7-searchbar-new-input-border-width: 0px;
|
|
7
|
+
--f7-searchbar-new-input-border-color: transparent;
|
|
8
|
+
}
|
|
9
|
+
.ios-vars({
|
|
10
|
+
/*
|
|
11
|
+
--f7-searchbar-new-border-color: var(--f7-bars-border-color);
|
|
12
|
+
*/
|
|
13
|
+
--f7-searchbar-new-bg-color: transparent;
|
|
14
|
+
--f7-searchbar-new-height: 44px;
|
|
15
|
+
--f7-searchbar-new-inner-padding-left: 0px;
|
|
16
|
+
--f7-searchbar-new-inner-padding-right: 0px;
|
|
17
|
+
--f7-searchbar-new-link-color: var(--f7-bars-text-color);
|
|
18
|
+
--f7-searchbar-new-input-font-size: 17px;
|
|
19
|
+
--f7-searchbar-new-input-border-radius: 44px;
|
|
20
|
+
--f7-searchbar-new-input-height: 44px;
|
|
21
|
+
--f7-searchbar-new-inline-input-height: 44px;
|
|
22
|
+
/*
|
|
23
|
+
--f7-searchbar-new-inline-input-border-radius: var(--f7-searchbar-new-input-border-radius);
|
|
24
|
+
*/
|
|
25
|
+
--f7-searchbar-new-input-padding-horizontal: 44px;
|
|
26
|
+
/*
|
|
27
|
+
--f7-searchbar-new-inline-input-padding-horizontal: var(--f7-searchbar-new-input-padding-horizontal);
|
|
28
|
+
--f7-searchbar-new-input-clear-button-color: var(--f7-input-clear-button-color);
|
|
29
|
+
*/
|
|
30
|
+
--f7-searchbar-new-backdrop-bg-color: rgba(0,0,0,0.4);
|
|
31
|
+
--f7-searchbar-new-in-page-content-margin: 16px;
|
|
32
|
+
--f7-searchbar-new-in-page-content-box-shadow: none;
|
|
33
|
+
--f7-searchbar-new-in-page-content-border-radius: 44px;
|
|
34
|
+
--f7-searchbar-new-in-page-content-input-border-radius: 44px;
|
|
35
|
+
--f7-searchbar-new-input-bg-color: var(--f7-glass-bg-color);
|
|
36
|
+
.light-vars({
|
|
37
|
+
--f7-searchbar-new-placeholder-color: rgba(0, 0, 0, 0.4);
|
|
38
|
+
--f7-searchbar-new-input-text-color: #000;
|
|
39
|
+
--f7-searchbar-new-search-icon-color: rgba(0, 0, 0, 0.4);
|
|
40
|
+
--f7-searchbar-new-bars-bg-color: #efeff4;
|
|
41
|
+
});
|
|
42
|
+
.dark-vars({
|
|
43
|
+
--f7-searchbar-new-placeholder-color: rgba(255, 255, 255, 0.4);
|
|
44
|
+
--f7-searchbar-new-input-text-color: #fff;
|
|
45
|
+
--f7-searchbar-new-search-icon-color: rgba(255, 255, 255, 0.4);
|
|
46
|
+
--f7-searchbar-new-bars-bg-color: rgba(0, 0, 0, 0.5);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
.md-vars({
|
|
50
|
+
--f7-searchbar-new-border-color: transparent;
|
|
51
|
+
--f7-searchbar-new-height: 48px;
|
|
52
|
+
--f7-searchbar-new-inner-padding-left: 8px;
|
|
53
|
+
--f7-searchbar-new-inner-padding-right: 8px;
|
|
54
|
+
--f7-searchbar-new-input-font-size: 16px;
|
|
55
|
+
--f7-searchbar-new-input-border-radius: 24px;
|
|
56
|
+
--f7-searchbar-new-input-height: 48px;
|
|
57
|
+
--f7-searchbar-new-inline-input-height: 48px;
|
|
58
|
+
--f7-searchbar-new-inline-input-border-radius: 24px;
|
|
59
|
+
--f7-searchbar-new-input-padding-horizontal: 16px;
|
|
60
|
+
--f7-searchbar-new-inline-input-padding-horizontal: 16px;
|
|
61
|
+
--f7-searchbar-new-backdrop-bg-color: rgba(0,0,0,0.25);
|
|
62
|
+
--f7-searchbar-new-in-page-content-margin: 16px 0;
|
|
63
|
+
--f7-searchbar-new-in-page-content-box-shadow: none;
|
|
64
|
+
--f7-searchbar-new-in-page-content-border-radius: 24px;
|
|
65
|
+
--f7-searchbar-new-in-page-content-input-border-radius: 24px;
|
|
66
|
+
--f7-searchbar-new-bg-color: transparent;
|
|
67
|
+
});
|
|
68
|
+
.md-color-vars({
|
|
69
|
+
--f7-searchbar-new-link-color: var(--f7-md-on-surface);
|
|
70
|
+
--f7-searchbar-new-search-icon-color: var(--f7-md-on-surface);
|
|
71
|
+
--f7-searchbar-new-input-clear-button-color: var(--f7-md-on-surface);
|
|
72
|
+
--f7-searchbar-new-placeholder-color: var(--f7-md-on-surface-variant);
|
|
73
|
+
--f7-searchbar-new-input-bg-color: var(--f7-md-secondary-container);
|
|
74
|
+
--f7-searchbar-new-input-text-color: var(--f7-md-on-surface);
|
|
75
|
+
});
|