@xwadex/fesd 0.0.2 → 0.0.5

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.
Files changed (43) hide show
  1. package/package.json +5 -11
  2. package/20240328-video4-setting.png +0 -0
  3. package/CHANGELOG.md +0 -41
  4. package/index.html +0 -25
  5. package/prepros.config +0 -883
  6. package/src/fesd/anchor4/anchor4.js +0 -179
  7. package/src/fesd/aost4/_aost4.sass +0 -64
  8. package/src/fesd/aost4/aost4.js +0 -138
  9. package/src/fesd/article4/article4.js +0 -280
  10. package/src/fesd/article4/article4.md +0 -1
  11. package/src/fesd/category-slider/_category-slider.sass +0 -33
  12. package/src/fesd/category-slider/category-slider.js +0 -332
  13. package/src/fesd/collapse4/collapse4.js +0 -159
  14. package/src/fesd/detect4/detect4.js +0 -70
  15. package/src/fesd/dropdown4/_dropdown4.sass +0 -185
  16. package/src/fesd/dropdown4/cityData.js +0 -830
  17. package/src/fesd/dropdown4/dropdown4.js +0 -647
  18. package/src/fesd/image-preview/_image-preview.sass +0 -26
  19. package/src/fesd/image-preview/image-preview.js +0 -209
  20. package/src/fesd/image-validate/_image-validate.sass +0 -21
  21. package/src/fesd/image-validate/image-validate.js +0 -84
  22. package/src/fesd/marquee4/_marquee4.sass +0 -45
  23. package/src/fesd/marquee4/marquee4.js +0 -371
  24. package/src/fesd/modal4/_modal4.sass +0 -134
  25. package/src/fesd/modal4/modal4.js +0 -236
  26. package/src/fesd/modal4/modernModal.js +0 -182
  27. package/src/fesd/multipurpose4/_multipurpose4.sass +0 -282
  28. package/src/fesd/multipurpose4/multipurpose4.js +0 -562
  29. package/src/fesd/ripple4/_ripple4.sass +0 -44
  30. package/src/fesd/ripple4/ripple4.js +0 -138
  31. package/src/fesd/share4/share4.js +0 -191
  32. package/src/fesd/shared/shared.js +0 -59
  33. package/src/fesd/shared/utils.js +0 -98
  34. package/src/fesd/tab4/_tab4.sass +0 -25
  35. package/src/fesd/tab4/tab4.js +0 -473
  36. package/src/fesd/video4/README.md +0 -3
  37. package/src/fesd/video4/_video4.sass +0 -117
  38. package/src/fesd/video4/video4.js +0 -237
  39. package/src/fesd/video4/videoPlayer.js +0 -195
  40. package/src/fesd.js +0 -53
  41. package/src/fesd.sass +0 -29
  42. package/src/fesdDB.js +0 -282
  43. package/vite.config.js +0 -37
@@ -1,647 +0,0 @@
1
- import SHARED from '../shared/shared';
2
- import { isElementExist, getElement, getAllElements, insert, warn } from '../shared/utils.js';
3
- import { OverlayScrollbars } from 'overlayscrollbars';
4
- // 縣市資料
5
- import { cityData } from './cityData.js';
6
-
7
- ('use strict');
8
-
9
- // create template method
10
- const createTemplate = d4 => {
11
- const { TEMPLATE } = fesdDB.dropdown4;
12
- const { childDom } = d4.s;
13
- const container = document.createElement('div');
14
- const filter = d4.classList.contains('filter');
15
- const filterPlaceholder = d4.getAttribute('filter-placeholder');
16
- container.innerHTML = TEMPLATE(filter, filterPlaceholder);
17
- const content = container.querySelector('.dropdown-list');
18
- [...childDom].forEach(child => {
19
- if (child.tagName === 'LI') {
20
- if (child.classList.contains('has-sublayer')) {
21
- const subOptions = child.querySelectorAll('li');
22
- [...subOptions].forEach(subOption => {
23
- if (!subOption.hasAttribute('data-option') || subOption.getAttribute('data-option').trim() === '') {
24
- subOption.setAttribute('data-option', subOption.textContent.trim());
25
- }
26
- });
27
- } else {
28
- if (!child.hasAttribute('data-option') || child.getAttribute('data-option').trim() === '') {
29
- child.setAttribute('data-option', child.textContent.trim());
30
- }
31
- }
32
- }
33
- content.append(child);
34
- });
35
-
36
- return container.children[0];
37
- };
38
-
39
- /**
40
- * 判斷是否有設定連動
41
- * @param {object} d4 d4 Element
42
- */
43
- const detectSync = d4 => {
44
- const controlElements = d4.getAttribute('control-elements')?.split(',');
45
- if (controlElements) {
46
- controlElements.forEach(el => {
47
- const disabledEl = document.querySelector(el);
48
- if (!disabledEl) {
49
- warn('dropdown', `Can't not find control element(${el})`);
50
- }
51
- if (disabledEl && disabledEl.classList.contains('disabled')) {
52
- disabledEl.classList.remove('disabled');
53
- if (disabledEl.tagName === 'DROPDOWN-EL' && disabledEl.s.activeLi) {
54
- setSelectDisplay(disabledEl, [...disabledEl.s.allLi].indexOf(disabledEl.s.activeLi));
55
- }
56
- }
57
- });
58
- }
59
- };
60
-
61
- /**
62
- * 顯示選擇的選項
63
- * @param {object} d4 d4 Element
64
- * @param {number} valueIndex 被選擇的選項索引值
65
- * @returns
66
- */
67
- const setSelectDisplay = (d4, valueIndex) => {
68
- const placeholder = d4.getAttribute('d4-placeholder');
69
- const allLi = d4.querySelectorAll('.dropdown-list li');
70
- if (valueIndex < 0 || valueIndex.length === 0) {
71
- // 恢復空值狀態
72
- allLi.forEach(el => {
73
- el.classList.remove('active');
74
- });
75
- d4.s.activeLi = undefined;
76
- // 判斷單選或複選
77
- switch (d4.s.selectType) {
78
- case 'single':
79
- d4.s.value = {
80
- index: -1,
81
- id: undefined,
82
- el: undefined,
83
- };
84
- break;
85
- case 'multiple':
86
- d4.s.value = [];
87
- break;
88
- }
89
-
90
- d4.s.selectDisplayEl.textContent = placeholder.trim();
91
- d4.setAttribute('d4-value', '');
92
- } else {
93
- if (d4.classList.contains('disabled')) {
94
- d4.s.selectDisplayEl.textContent = placeholder.trim();
95
- return;
96
- }
97
- // 判斷單選或複選
98
- switch (d4.s.selectType) {
99
- case 'single':
100
- const option = allLi[valueIndex].textContent.trim();
101
- d4.s.allLi.forEach(el => {
102
- el.classList.remove('active');
103
- });
104
- allLi[valueIndex].classList.add('active');
105
- d4.s.selectDisplayEl.textContent = option;
106
- d4.s.activeLi = allLi[valueIndex];
107
- d4.s.value = {
108
- index: valueIndex,
109
- id: allLi[valueIndex].getAttribute('data-option'),
110
- el: allLi[valueIndex],
111
- };
112
- break;
113
- case 'multiple':
114
- if (Array.isArray(valueIndex)) {
115
- d4.s.allLi.forEach(li => {
116
- if (valueIndex.indexOf([...d4.s.allLi].indexOf(li)) >= 0) {
117
- li.classList.add('active');
118
- } else {
119
- li.classList.remove('active');
120
- }
121
- });
122
- }
123
- const activeLi = d4.querySelectorAll('.dropdown-list li.active');
124
- if (activeLi.length <= 0) {
125
- d4.s.selectDisplayEl.textContent = placeholder.trim();
126
- } else {
127
- d4.s.selectDisplayEl.textContent = '';
128
- activeLi.forEach(li => {
129
- const id = li.getAttribute('data-option');
130
- const option = li.textContent.trim();
131
- const tagEl = `<div class="option-btn" data-option="${id}"><div class="text">${option}</div><div class="remove-icon"></div></div>`;
132
- d4.s.selectDisplayEl.insertAdjacentHTML(insert.append, tagEl);
133
- });
134
- }
135
- d4.s.activeLi = activeLi;
136
- d4.s.value = [...activeLi].map(option => {
137
- const obj = {
138
- index: [...allLi].indexOf(option),
139
- id: option.getAttribute('data-option'),
140
- el: option,
141
- };
142
- return obj;
143
- });
144
- const valueArray = [...activeLi].map(option => option.getAttribute('data-option'));
145
- d4.setAttribute('d4-value', valueArray.join());
146
- break;
147
- }
148
- }
149
- };
150
-
151
- /**
152
- * 載入台灣縣市資料
153
- * @param {*} d4 d4 Element
154
- */
155
- const loadCityData = d4 => {
156
- const lang = d4.s.cityLang;
157
- // 塞入縣市資料
158
- if (d4.classList.contains('city')) {
159
- d4.s.dropdownEl.querySelector('.dropdown-list').innerHTML = '';
160
- Object.keys(cityData[lang]).forEach(city => {
161
- const li = document.createElement('li');
162
- li.textContent = city;
163
- li.setAttribute('data-option', city);
164
- d4.s.dropdownEl.querySelector('.dropdown-list').append(li);
165
- });
166
- d4.s.allLi = d4.querySelectorAll('.dropdown-list li');
167
- }
168
- };
169
-
170
- /**
171
- * 載入對應地區資料
172
- */
173
- const loadDistData = (d4, city) => {
174
- const lang = d4.s.cityLang;
175
- // 塞入地區資料
176
- cityData[lang][city].forEach((dist, index) => {
177
- const li = document.createElement('li');
178
- li.textContent = dist[0];
179
- li.setAttribute('data-option', dist[0]);
180
- d4.querySelector('.dropdown-list').append(li);
181
- });
182
- };
183
-
184
- /**
185
- * 關閉全部下拉選單
186
- */
187
- const closeAllDropdown = () => {
188
- const allDropdown = getAllElements('dropdown-el[d4-status="open"]');
189
- allDropdown.forEach(el => {
190
- el.close();
191
- });
192
- };
193
-
194
- /**
195
- * 設定卷軸樣式
196
- */
197
- const settingScrollbarStyle = () => {
198
- const { SETTINGS } = fesdDB.dropdown4;
199
- const setProperty = (element, obj) => {
200
- Object.keys(obj).forEach(key => {
201
- element.style.setProperty(`--${key}`, obj[key]);
202
- });
203
- };
204
- setProperty(document.documentElement, SETTINGS.scrollbar);
205
- };
206
-
207
- settingScrollbarStyle();
208
- // 點擊空白處關閉下拉選單
209
- document.addEventListener('click', function () {
210
- closeAllDropdown();
211
- });
212
-
213
- // 創建 Custom Element
214
- class Dropdown4 extends HTMLElement {
215
- constructor() {
216
- super();
217
- this.initialize = false;
218
- }
219
- static get observedAttributes() {
220
- return ['d4-status', 'd4-placeholder', 'd4-value'];
221
- }
222
- attributeChangedCallback(attr, oldVal, newVal) {
223
- const d4 = this;
224
- switch (attr) {
225
- case 'd4-status':
226
- if (oldVal === null || oldVal === newVal) return;
227
- if (newVal === 'open' || newVal === 'close') {
228
- d4.emit(newVal);
229
- }
230
- break;
231
- case 'd4-value':
232
- if (oldVal === null || oldVal === newVal) return;
233
- if (newVal !== '') {
234
- const selectType = d4.hasAttribute('multiple') ? 'multiple' : 'single';
235
- switch (selectType) {
236
- case 'single':
237
- const li = d4.querySelector(`.dropdown-list li[data-option="${newVal}"]`);
238
- if (isElementExist(li)) {
239
- setSelectDisplay(d4, [...d4.s.allLi].indexOf(li));
240
- } else {
241
- setSelectDisplay(d4, -1);
242
- }
243
- break;
244
- case 'multiple':
245
- const valueLiArray = [];
246
- d4.querySelector(`.dropdown-list li`).classList.remove('active');
247
- newVal.split(',').forEach(option => {
248
- const li = d4.querySelector(`.dropdown-list li[data-option="${option}"]`);
249
- if (isElementExist(li)) {
250
- li.classList.add('active');
251
- valueLiArray.push(li);
252
- }
253
- });
254
- const valueIndexArray = valueLiArray.map(li => [...d4.s.allLi].indexOf(li));
255
- setSelectDisplay(d4, valueIndexArray);
256
- break;
257
- }
258
- } else {
259
- setSelectDisplay(d4, -1);
260
- }
261
- d4.emit('change');
262
- break;
263
- case 'd4-placeholder':
264
- if (oldVal === null) return;
265
- if (oldVal !== newVal && d4.s.value.index < 0) {
266
- setSelectDisplay(d4, d4.s.value.index);
267
- }
268
- break;
269
- }
270
- }
271
- connectedCallback() {
272
- const d4 = this;
273
- if (d4.initialize || d4.classList.contains('d4-initialize')) return;
274
- d4.initialize = true;
275
- this.#create();
276
- }
277
- #create() {
278
- this.s = {};
279
- this.__events__ = {};
280
-
281
- if (!this.hasAttribute('d4-status')) {
282
- this.setAttribute('d4-status', 'close');
283
- }
284
- if (!this.hasAttribute('d4-value')) {
285
- this.setAttribute('d4-value', '');
286
- }
287
- this.#mount();
288
- }
289
- #mount() {
290
- this.s.childDom = this.childNodes;
291
- this.s.template = createTemplate(this);
292
- this.innerHTML = '';
293
- this.append(this.s.template);
294
- this.#init();
295
- }
296
- #init() {
297
- const d4 = this;
298
- d4.s.allLi = d4.querySelectorAll('.dropdown-list li');
299
- d4.s.selectDisplayEl = d4.querySelector('.select-display');
300
- d4.s.dropdownEl = d4.querySelector('.dropdown');
301
- d4.s.selectType = d4.hasAttribute('multiple') ? 'multiple' : 'single';
302
- d4.s.cityLang = d4.hasAttribute('city-lang') ? d4.getAttribute('city-lang') : 'zh-tw';
303
- loadCityData(d4);
304
- d4.s.subDropdownTotalH = 0;
305
- const value = d4.getAttribute('d4-value');
306
- switch (d4.s.selectType) {
307
- case 'single':
308
- let valueLi;
309
- // 如果是地區下拉選單
310
- if (d4.classList.contains('dist')) {
311
- const cityDropdown = document.querySelector(`dropdown-el[dist-select="${d4.id}"]`);
312
- //判斷縣市下拉選單是否有值
313
- const cityDropdownHasVal = cityDropdown ? cityDropdown.getAttribute('d4-value') !== '' : false;
314
- if (cityDropdown && cityDropdownHasVal) {
315
- const city = cityDropdown.getAttribute('d4-value');
316
- loadDistData(d4, city);
317
- d4.s.allLi = d4.querySelectorAll('.dropdown-list li');
318
- d4.classList.remove('disabled');
319
- if (d4.getAttribute('d4-value') !== '') {
320
- const dist = value.split(',')[1];
321
- valueLi = d4.querySelector(`.dropdown-list li[data-option="${dist}"]`);
322
- d4.setAttribute('d4-value', dist);
323
- }
324
- }
325
- } else {
326
- valueLi = d4.querySelector(`.dropdown-list li[data-option="${value}"]`);
327
- }
328
- if (isElementExist(valueLi)) {
329
- valueLi.classList.add('active');
330
- d4.s.activeLi = valueLi;
331
- d4.s.value = {
332
- index: [...d4.s.allLi].indexOf(valueLi),
333
- id: value,
334
- el: valueLi,
335
- };
336
- } else {
337
- d4.s.activeLi = undefined;
338
- d4.s.value = {
339
- index: -1,
340
- id: undefined,
341
- el: undefined,
342
- };
343
- }
344
- break;
345
- case 'multiple':
346
- const valueLiArray = [];
347
- value.split(',').forEach(option => {
348
- const li = d4.querySelector(`.dropdown-list li[data-option="${option}"]`);
349
- if (isElementExist(li)) {
350
- valueLiArray.push(li);
351
- }
352
- });
353
- if (valueLiArray.length > 0) {
354
- d4.s.value = {
355
- index: valueLiArray.map(li => [...d4.s.allLi].indexOf(li)),
356
- id: valueLiArray.map(li => li.getAttribute('data-option')),
357
- el: valueLiArray.map(li => li),
358
- };
359
- } else {
360
- d4.s.value = {
361
- index: [],
362
- id: undefined,
363
- el: undefined,
364
- };
365
- }
366
- break;
367
- }
368
- setSelectDisplay(d4, d4.s.value.index);
369
- d4.#event();
370
- d4.classList.add('d4-initialize');
371
- }
372
- #event() {
373
- const d4 = this;
374
- // 下拉選單開關
375
- d4.__events__.dropdownToggle = () => {
376
- d4.addEventListener('click', function (e) {
377
- e.stopPropagation();
378
- const status = d4.getAttribute('d4-status');
379
- switch (status) {
380
- case 'open':
381
- d4.close();
382
- break;
383
- case 'close':
384
- d4.open();
385
- break;
386
- }
387
- });
388
- };
389
-
390
- // 下拉選單完成過渡
391
- d4.__events__.transitionend = () => {
392
- function toggleTransitionend(event) {
393
- if (event.target === this) {
394
- const dropdownStatus = d4.getAttribute('d4-status');
395
- const hasFilter = d4.classList.contains('filter');
396
- switch (dropdownStatus) {
397
- case 'open':
398
- const scroller = d4.querySelector('.dropdown-scroller');
399
- // 捲動到 active 的選項
400
- const scrollToActive = () => {
401
- if (d4.__scroller__) {
402
- const { viewport } = d4.__scroller__.elements();
403
- if (isElementExist(d4.s.activeLi)) {
404
- const halfActiveLiHeight = d4.s.activeLi.clientHeight / 2;
405
- const offsetTop = d4.s.activeLi.offsetTop;
406
- const scroll = offsetTop - scroller.clientHeight / 2 + halfActiveLiHeight > 0 ? offsetTop - scroller.clientHeight / 2 + halfActiveLiHeight : 0;
407
- viewport.scrollTo({
408
- top: scroll,
409
- behavior: 'smooth',
410
- });
411
- } else {
412
- viewport.scrollTo({
413
- top: 0,
414
- behavior: 'smooth',
415
- });
416
- }
417
- }
418
- };
419
- if (hasFilter) {
420
- d4.querySelector('.filter-bar input').disabled = false;
421
- d4.querySelector('.filter-bar input').focus();
422
- }
423
- if (d4.s.selectType === 'single') {
424
- scrollToActive();
425
- }
426
- break;
427
- case 'close':
428
- d4.__scroller__.update(true);
429
- d4.s.dropdownEl.removeAttribute('style');
430
- if (hasFilter) d4.querySelector('.filter-bar input').disabled = true;
431
- break;
432
- }
433
- }
434
- }
435
- d4.s.dropdownEl.addEventListener('transitionend', toggleTransitionend);
436
- };
437
-
438
- // 綁定卷軸
439
- d4.__events__.bindScrollbar = (d4 = this) => {
440
- const scroller = d4.querySelector('.dropdown-scroller');
441
- // 綁定卷軸套件
442
- d4.__scroller__ = OverlayScrollbars(scroller, {
443
- overflowBehavior: {
444
- x: 'hidden',
445
- },
446
- });
447
- };
448
-
449
- // 顯示選的選項
450
- d4.__events__.selectOption = (d4 = this) => {
451
- let computedHeight, totalHeight;
452
- const scroller = d4.querySelector('.dropdown-scroller');
453
- const citySelect = d4.classList.contains('city');
454
- d4.s.allLi = d4.querySelectorAll('.dropdown-list li');
455
- d4.s.allLi.forEach(option => {
456
- option.addEventListener('click', function (e) {
457
- const clickOption = this;
458
- const clickIndex = [...d4.s.allLi].indexOf(clickOption);
459
- // 子下拉選單打開前的總高度
460
- const defaultHeight = parseInt(d4.getAttribute('d4-default-height'));
461
- // 有子層選單
462
- if (clickOption.classList.contains('has-sublayer')) {
463
- e.stopPropagation();
464
- const subDropdown = clickOption.querySelector('.sub-dropdown');
465
- const subDropdownList = subDropdown.querySelector('.sub-dropdown-list');
466
- const subDropdownListMargin = parseInt(getComputedStyle(subDropdownList).marginTop) + parseInt(getComputedStyle(subDropdownList).marginBottom);
467
- subDropdown.style.cssText = `--height: ${subDropdownList.offsetHeight + subDropdownListMargin}px`;
468
- // 子下拉選單高度
469
- const subDropdownH = parseInt(subDropdown.style.cssText.replace('--height:', '').trim());
470
- // 最大高度
471
- const maxHeight = parseInt(getComputedStyle(scroller).maxHeight);
472
- const recalculate = () => {
473
- // 重新計算整個下拉選單的高度
474
- computedHeight = defaultHeight + d4.s.subDropdownTotalH;
475
- totalHeight = computedHeight > maxHeight ? maxHeight : computedHeight;
476
- d4.style.cssText = `--maxHeight: ${totalHeight}px;`;
477
- d4.s.dropdownEl.style.height = `${totalHeight}px`;
478
- };
479
- if (!clickOption.classList.contains('open')) {
480
- // 子層下拉選單打開
481
- clickOption.classList.add('open');
482
- d4.s.subDropdownTotalH += subDropdownH;
483
- recalculate();
484
- } else {
485
- // 子層下拉選單關閉
486
- clickOption.classList.remove('open');
487
- d4.s.subDropdownTotalH -= subDropdownH;
488
- recalculate();
489
- }
490
- const collapse = () => {
491
- d4.__scroller__.update(true);
492
- subDropdown.removeEventListener('transitionend', collapse);
493
- };
494
- subDropdown.addEventListener('transitionend', collapse);
495
- }
496
- // 沒有子層選單
497
- else {
498
- detectSync(d4);
499
- // 判斷單選或複選
500
- switch (d4.s.selectType) {
501
- // 單選
502
- case 'single':
503
- d4.setAttribute('d4-value', clickOption.getAttribute('data-option'));
504
- // 選擇縣市
505
- if (citySelect) {
506
- const lang = d4.s.cityLang;
507
- const city = option.textContent.trim();
508
- const distSelectEl = document.getElementById(d4.getAttribute('dist-select'));
509
- if (distSelectEl) {
510
- distSelectEl.querySelector('.dropdown-list').textContent = '';
511
- setSelectDisplay(distSelectEl, -1);
512
- cityData[lang][city].forEach((dist, index) => {
513
- const li = document.createElement('li');
514
- li.textContent = dist[0];
515
- li.setAttribute('data-option', dist[0]);
516
- distSelectEl.querySelector('.dropdown-list').append(li);
517
- });
518
- d4.__events__.selectOption(distSelectEl);
519
- }
520
- }
521
- if (clickOption.parentNode.closest('li')?.classList.contains('has-sublayer')) {
522
- e.stopPropagation();
523
- d4.close();
524
- }
525
- break;
526
- // 複選
527
- case 'multiple':
528
- e.stopPropagation();
529
- clickOption.classList.toggle('active');
530
- setSelectDisplay(d4, clickIndex);
531
- break;
532
- }
533
- }
534
- });
535
- });
536
- };
537
-
538
- // 篩選功能
539
- d4.__events__.filterHandler = () => {
540
- if (d4.classList.contains('filter')) {
541
- d4.querySelector('.filter-bar').addEventListener('click', function (e) {
542
- e.stopPropagation();
543
- });
544
- d4.querySelector('.filter-input').addEventListener('input', function () {
545
- const val = this.value.toUpperCase();
546
- d4.s.allLi.forEach(el => {
547
- if (!el.textContent.toUpperCase().includes(val)) el.style.display = 'none';
548
- else el.removeAttribute('style');
549
- });
550
- });
551
- }
552
- };
553
-
554
- // 複選標籤移除
555
- d4.__events__.removeTag = () => {
556
- if (d4.s.selectType === 'single') return;
557
- d4.s.selectDisplayEl.addEventListener('click', function (e) {
558
- if (e.target.classList.contains('select-display')) return;
559
- const optionBtn = e.target.classList.contains('option-btn') ? e.target : e.target.parentElement;
560
- if (optionBtn.contains(e.target)) {
561
- e.stopPropagation();
562
- if (e.target.classList.contains('remove-icon')) {
563
- const tag = e.target.parentElement;
564
- const id = tag.getAttribute('data-option');
565
- d4.s.dropdownEl.querySelector(`.dropdown-list li[data-option="${id}"]`).classList.remove('active');
566
- d4.s.activeLi = d4.querySelectorAll('.dropdown-list li.active');
567
- e.target.parentElement.remove();
568
- const activeLiArray = [...d4.s.activeLi];
569
- d4.s.value = activeLiArray.map(option => {
570
- const obj = {
571
- index: [...d4.s.allLi].indexOf(option),
572
- id: option.getAttribute('data-option'),
573
- el: option,
574
- };
575
- return obj;
576
- });
577
- d4.s.activeLi = activeLiArray;
578
- const valueArray = activeLiArray.map(option => option.getAttribute('data-option'));
579
- d4.setAttribute('d4-value', valueArray.join());
580
- if (activeLiArray.length <= 0) {
581
- d4.s.selectDisplayEl.textContent = d4.getAttribute('d4-placeholder').trim();
582
- }
583
- }
584
- }
585
- });
586
- };
587
- d4.__events__.dropdownToggle();
588
- d4.__events__.bindScrollbar();
589
- d4.__events__.selectOption();
590
- d4.__events__.filterHandler();
591
- d4.__events__.removeTag();
592
- d4.__events__.transitionend();
593
- }
594
- open() {
595
- const d4 = this;
596
- const dropdownHeight = d4.querySelector('.dropdown-scroller').clientHeight;
597
- const hasFilter = d4.classList.contains('filter');
598
- const totalHeight = () => {
599
- if (hasFilter) {
600
- return d4.querySelector('.filter-bar').clientHeight + dropdownHeight;
601
- }
602
- return dropdownHeight;
603
- };
604
- closeAllDropdown();
605
- d4.setAttribute('d4-status', 'open');
606
- d4.setAttribute('d4-default-height', totalHeight());
607
- d4.style.cssText = `--maxHeight: ${totalHeight()}px;`;
608
- d4.s.dropdownEl.style.cssText = `
609
- height: ${totalHeight()}px;
610
- z-index: 2;
611
- `;
612
- return this;
613
- }
614
- close() {
615
- const d4 = this;
616
- const allSublayer = d4.s.dropdownEl.querySelectorAll('.has-sublayer');
617
- const defaultHeight = parseInt(d4.getAttribute('d4-default-height'));
618
- d4.setAttribute('d4-status', 'close');
619
- d4.s.dropdownEl.style.height = '0px';
620
- allSublayer.forEach(item => {
621
- item.classList.remove('open');
622
- });
623
- d4.style.cssText = `--maxHeight: ${defaultHeight}px;`;
624
- d4.s.subDropdownTotalH = 0;
625
- return this;
626
- }
627
- scrollTo(scroll) {
628
- const d4 = this;
629
- const { viewport } = d4.__scroller__.elements();
630
- viewport.scrollTo({
631
- top: scroll,
632
- behavior: 'smooth',
633
- });
634
- }
635
- update() {
636
- this.__events__.selectOption();
637
- }
638
- }
639
-
640
- Object.assign(Dropdown4.prototype, SHARED);
641
-
642
- // define custom element
643
- // if (!customElements.get('dropdown-el')) {
644
- // customElements.define('dropdown-el', Dropdown4);
645
- // }
646
-
647
- export default Dropdown4;
@@ -1,26 +0,0 @@
1
- [data-upload-item]
2
- position: relative
3
- input[type='file']
4
- position: absolute
5
- top: 0
6
- right: 0
7
- bottom: 0
8
- left: 0
9
- width: 100%
10
- height: 100%
11
- opacity: 0
12
- z-index: 99
13
- cursor: pointer
14
-
15
- [data-preview]
16
- width: 100%
17
- height: 100%
18
- overflow: hidden
19
- img
20
- display: block
21
- width: 100%
22
- height: 100%
23
- &.cover
24
- object-fit: cover
25
- &.contain
26
- object-fit: contain