zidan-select 2.3.0 → 2.3.1
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/README.md +75 -40
- package/dist/file/plugin-file-core.css +8 -1
- package/dist/file/plugin-file-core.min.css +2 -2
- package/dist/file/plugin-file-theme.css +1 -1
- package/dist/file/plugin-file-theme.min.css +1 -1
- package/dist/file/zidan-file.d.ts +1 -1
- package/dist/file/zidan-file.js +94 -25
- package/dist/file/zidan-file.min.js +2 -2
- package/dist/plugin-core.css +109 -1
- package/dist/plugin-core.min.css +2 -2
- package/dist/plugin-theme.css +1 -1
- package/dist/plugin-theme.min.css +1 -1
- package/dist/select/plugin-select-core.css +1 -1
- package/dist/select/plugin-select-core.min.css +1 -1
- package/dist/select/plugin-select-theme.css +1 -1
- package/dist/select/plugin-select-theme.min.css +1 -1
- package/dist/select/zidan-select.d.ts +1 -1
- package/dist/select/zidan-select.js +102 -8
- package/dist/select/zidan-select.min.js +2 -2
- package/dist/zidan-form.js +252 -55
- package/dist/zidan-form.min.js +2 -2
- package/docs/build.md +11 -5
- package/docs/html-and-wordpress.md +20 -20
- package/docs/index.html +8 -0
- package/docs/options.md +44 -11
- package/docs/validation.md +8 -0
- package/package.json +5 -2
- package/plugin-core.css +109 -1
- package/plugin-theme.css +1 -1
- package/zidan-form.d.ts +10 -1
- package/zidan-form.js +252 -55
package/dist/zidan-form.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* ZidanForm v2.3.
|
|
2
|
+
* ZidanForm v2.3.1
|
|
3
3
|
* Zero-dependency form enhancement library: select / combobox / tags,
|
|
4
4
|
* checkboxes, switches, radio groups, file upload with drag & drop and
|
|
5
5
|
* upload progress, text / number / phone / date / range inputs and textarea.
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
})(typeof window !== 'undefined' ? window : this, function (global) {
|
|
33
33
|
'use strict';
|
|
34
34
|
|
|
35
|
-
var VERSION = '2.3.
|
|
35
|
+
var VERSION = '2.3.1';
|
|
36
36
|
|
|
37
37
|
// Loading the file twice (classic script + module wrapper, or two bundles)
|
|
38
38
|
// must not replace the classes and orphan the live instances.
|
|
@@ -582,6 +582,24 @@
|
|
|
582
582
|
return list.indexOf(candidate) === -1 ? fallback : candidate;
|
|
583
583
|
}
|
|
584
584
|
|
|
585
|
+
/* rangeTicks: JS array, JSON array, comma list or a tick count */
|
|
586
|
+
function parseRangeTicks(value) {
|
|
587
|
+
if (Array.isArray(value)) return value.slice();
|
|
588
|
+
if (typeof value === 'string') {
|
|
589
|
+
var raw = value.trim();
|
|
590
|
+
if (raw.charAt(0) === '[') {
|
|
591
|
+
try {
|
|
592
|
+
var parsed = JSON.parse(raw);
|
|
593
|
+
if (Array.isArray(parsed)) return parsed;
|
|
594
|
+
} catch (err) { /* fall back to the tick count */ }
|
|
595
|
+
} else if (raw.indexOf(',') !== -1) {
|
|
596
|
+
return raw.split(',').map(function (part) { return Number(part.trim()); })
|
|
597
|
+
.filter(function (number) { return isFinite(number); });
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
return value;
|
|
601
|
+
}
|
|
602
|
+
|
|
585
603
|
/* theme/framework/layout resolution shared by every field and the select */
|
|
586
604
|
function resolveScope(node, options) {
|
|
587
605
|
var opts = options || {};
|
|
@@ -985,6 +1003,9 @@
|
|
|
985
1003
|
input.setAttribute('aria-controls', this.id + '-listbox');
|
|
986
1004
|
input.setAttribute('aria-autocomplete', (opts.searchable || this.mode !== 'select') ? 'list' : 'none');
|
|
987
1005
|
input.setAttribute('aria-haspopup', 'listbox');
|
|
1006
|
+
/* a plain select is not type-to-filter: keep its text field read-only so
|
|
1007
|
+
typing cannot filter or hide the options */
|
|
1008
|
+
if (this.mode === 'select' && !opts.searchable) input.readOnly = true;
|
|
988
1009
|
if (opts.ariaLabel || opts.label) input.setAttribute('aria-label', opts.ariaLabel || opts.label);
|
|
989
1010
|
if (opts.disabled) input.disabled = true;
|
|
990
1011
|
this._applyCustomClass(input, 'input');
|
|
@@ -994,6 +1015,16 @@
|
|
|
994
1015
|
labelEl = el('label', 'zs-label', { for: input.id });
|
|
995
1016
|
labelEl.textContent = opts.label;
|
|
996
1017
|
if (this.layout !== 'floating-label') rootEl.classList.add('zs-root--has-static-label');
|
|
1018
|
+
|
|
1019
|
+
// Hide the author's <label>: this label replaces it, and showing both
|
|
1020
|
+
// would print the same text twice above the control.
|
|
1021
|
+
var authorLabel = this.el.labels && this.el.labels[0] ? this.el.labels[0] : null;
|
|
1022
|
+
if (authorLabel && authorLabel.closest && authorLabel.closest('.zs-root')) authorLabel = null;
|
|
1023
|
+
this._authorLabel = authorLabel || null;
|
|
1024
|
+
if (authorLabel) {
|
|
1025
|
+
authorLabel.hidden = true;
|
|
1026
|
+
authorLabel.setAttribute('data-zs-hidden-label', 'true');
|
|
1027
|
+
}
|
|
997
1028
|
}
|
|
998
1029
|
|
|
999
1030
|
var clearBtn = el('button', 'zs-clear', {
|
|
@@ -1022,9 +1053,7 @@
|
|
|
1022
1053
|
var dropdown = el('div', 'zs-dropdown');
|
|
1023
1054
|
dropdown.id = this.id + '-listbox';
|
|
1024
1055
|
dropdown.setAttribute('role', 'listbox');
|
|
1025
|
-
|
|
1026
|
-
dropdown.setAttribute('aria-multiselectable', String(!!(opts.multiple || this.mode === 'tags')));
|
|
1027
|
-
}
|
|
1056
|
+
dropdown.setAttribute('aria-multiselectable', String(!!(opts.multiple || this.mode === 'tags')));
|
|
1028
1057
|
this._applyCustomClass(dropdown, 'dropdown');
|
|
1029
1058
|
|
|
1030
1059
|
var live = el('div', 'zs-live', { 'aria-live': 'polite', 'aria-atomic': 'true' });
|
|
@@ -1102,6 +1131,22 @@
|
|
|
1102
1131
|
};
|
|
1103
1132
|
this.form.addEventListener('reset', this.onFormReset);
|
|
1104
1133
|
}
|
|
1134
|
+
|
|
1135
|
+
/* `required` is a JS-only option as well as a native attribute. A native
|
|
1136
|
+
select can carry it directly; a mount-mode div needs a submit guard. */
|
|
1137
|
+
if (opts.required && this.native && this.native.tagName === 'SELECT' && !this.native.required) {
|
|
1138
|
+
this.native.required = true;
|
|
1139
|
+
this._nativeRequiredAdded = true;
|
|
1140
|
+
} else if (opts.required && !this.native && this.form) {
|
|
1141
|
+
this.onFormSubmit = function (event) {
|
|
1142
|
+
if (self.value_.length) return;
|
|
1143
|
+
event.preventDefault();
|
|
1144
|
+
self.setValidation('invalid');
|
|
1145
|
+
if (self.input && self.input.focus) self.input.focus();
|
|
1146
|
+
self.announce('Please select an option.');
|
|
1147
|
+
};
|
|
1148
|
+
this.form.addEventListener('submit', this.onFormSubmit);
|
|
1149
|
+
}
|
|
1105
1150
|
return this.syncEl;
|
|
1106
1151
|
};
|
|
1107
1152
|
|
|
@@ -1202,7 +1247,9 @@
|
|
|
1202
1247
|
|
|
1203
1248
|
if (!this.opts.multiple && this.mode !== 'tags') next = next.slice(0, 1);
|
|
1204
1249
|
this.value_ = next;
|
|
1205
|
-
|
|
1250
|
+
/* a preset/manual invalid state is only cleared by a real value change, not
|
|
1251
|
+
by the initial value applied during construction */
|
|
1252
|
+
if (next.length && this.opts.validation === 'invalid' && !cfg.silent) this.opts.validation = null;
|
|
1206
1253
|
this._render();
|
|
1207
1254
|
this._syncNative();
|
|
1208
1255
|
if (!cfg.silent) {
|
|
@@ -1915,6 +1962,22 @@
|
|
|
1915
1962
|
return false;
|
|
1916
1963
|
}
|
|
1917
1964
|
|
|
1965
|
+
/* allowFreeText: false limits tags to the supplied option/suggestion list */
|
|
1966
|
+
if (this.mode === 'tags' && !opts.allowFreeText) {
|
|
1967
|
+
var pool = this.suggestions && this.suggestions.length ? this.suggestions : this.items;
|
|
1968
|
+
var needle = opts.caseSensitive ? raw : raw.toLowerCase();
|
|
1969
|
+
var listed = false;
|
|
1970
|
+
for (var s = 0; s < pool.length; s += 1) {
|
|
1971
|
+
var itemValue = opts.caseSensitive ? String(pool[s].value) : String(pool[s].value).toLowerCase();
|
|
1972
|
+
var itemLabel = opts.caseSensitive ? String(pool[s].label) : String(pool[s].label).toLowerCase();
|
|
1973
|
+
if (itemValue === needle || itemLabel === needle) { listed = true; break; }
|
|
1974
|
+
}
|
|
1975
|
+
if (!listed) {
|
|
1976
|
+
if (!cfg.silent) this._tagError('"' + raw + '" is not in the list.');
|
|
1977
|
+
return false;
|
|
1978
|
+
}
|
|
1979
|
+
}
|
|
1980
|
+
|
|
1918
1981
|
var formatted = raw;
|
|
1919
1982
|
if (typeof opts.formatTag === 'function') {
|
|
1920
1983
|
var formattedResult = opts.formatTag(raw, { instance: this, tags: this.getTags() });
|
|
@@ -1991,6 +2054,14 @@
|
|
|
1991
2054
|
var key = event.key;
|
|
1992
2055
|
var items = this._visibleItems();
|
|
1993
2056
|
|
|
2057
|
+
/* Space opens a closed combobox/listbox (WAI-ARIA), unless the user is
|
|
2058
|
+
already typing a search or tag query in an open control. */
|
|
2059
|
+
if ((key === ' ' || key === 'Spacebar') && !this.opened) {
|
|
2060
|
+
event.preventDefault();
|
|
2061
|
+
this.open();
|
|
2062
|
+
return;
|
|
2063
|
+
}
|
|
2064
|
+
|
|
1994
2065
|
if (key === 'ArrowDown' || key === 'ArrowUp') {
|
|
1995
2066
|
event.preventDefault();
|
|
1996
2067
|
if (!this.opened) {
|
|
@@ -2126,6 +2197,8 @@
|
|
|
2126
2197
|
|
|
2127
2198
|
this.onInput = function () {
|
|
2128
2199
|
var value = self.input.value;
|
|
2200
|
+
/* plain selects are not searchable: typing must not filter the list */
|
|
2201
|
+
if (self.mode === 'select' && !self.opts.searchable) return;
|
|
2129
2202
|
self.query = value;
|
|
2130
2203
|
if (self.opened) {
|
|
2131
2204
|
if (typeof self.opts.fetchOptions === 'function' && self.query.length >= (self.opts.minChars || 0)) {
|
|
@@ -2519,6 +2592,11 @@
|
|
|
2519
2592
|
this.clearCache();
|
|
2520
2593
|
if (this.resizeObserver) this.resizeObserver.disconnect();
|
|
2521
2594
|
if (this.form && this.onFormReset) this.form.removeEventListener('reset', this.onFormReset);
|
|
2595
|
+
if (this.form && this.onFormSubmit) this.form.removeEventListener('submit', this.onFormSubmit);
|
|
2596
|
+
if (this._nativeRequiredAdded && this.native) {
|
|
2597
|
+
this.native.required = false;
|
|
2598
|
+
this._nativeRequiredAdded = false;
|
|
2599
|
+
}
|
|
2522
2600
|
|
|
2523
2601
|
doc.removeEventListener('pointerdown', this.onDocumentPointerDown, true);
|
|
2524
2602
|
global.removeEventListener('resize', this.onWindowResize);
|
|
@@ -2528,6 +2606,12 @@
|
|
|
2528
2606
|
|
|
2529
2607
|
if (this.root && this.root.parentNode) this.root.parentNode.removeChild(this.root);
|
|
2530
2608
|
|
|
2609
|
+
if (this._authorLabel) {
|
|
2610
|
+
this._authorLabel.hidden = false;
|
|
2611
|
+
this._authorLabel.removeAttribute('data-zs-hidden-label');
|
|
2612
|
+
this._authorLabel = null;
|
|
2613
|
+
}
|
|
2614
|
+
|
|
2531
2615
|
if (this.native) {
|
|
2532
2616
|
this.native.hidden = false;
|
|
2533
2617
|
this.native.classList.remove('zs-native');
|
|
@@ -2569,6 +2653,8 @@
|
|
|
2569
2653
|
var RADIO_VARIANTS = ['stacked', 'inline', 'card', 'button', 'tile'];
|
|
2570
2654
|
var FILE_VARIANTS = ['dropzone', 'button', 'avatar', 'gallery', 'compact'];
|
|
2571
2655
|
var RANGE_VARIANTS = ['default', 'gradient', 'stepped', 'minimal'];
|
|
2656
|
+
var RANGE_BUBBLE_MODES = ['always', 'active', 'never'];
|
|
2657
|
+
var RANGE_BUBBLE_POSITIONS = ['top', 'bottom'];
|
|
2572
2658
|
|
|
2573
2659
|
function textWithout(rootNode, skip) {
|
|
2574
2660
|
var out = '';
|
|
@@ -2607,6 +2693,7 @@
|
|
|
2607
2693
|
this.destroyed = false;
|
|
2608
2694
|
this._listeners = [];
|
|
2609
2695
|
this._cleanups = [];
|
|
2696
|
+
this._describedByBefore = [];
|
|
2610
2697
|
this.formEl = target.form || (target.closest ? target.closest('form') : null);
|
|
2611
2698
|
var scope = resolveScope(target, this.opts);
|
|
2612
2699
|
this.theme = scope.theme;
|
|
@@ -2738,11 +2825,12 @@
|
|
|
2738
2825
|
this._setCustomValidity(message && custom ? message : '');
|
|
2739
2826
|
if (message) {
|
|
2740
2827
|
if (show) this.setError(message);
|
|
2741
|
-
else this.setValidation('invalid');
|
|
2828
|
+
else this.setValidation('invalid', true);
|
|
2742
2829
|
return this;
|
|
2743
2830
|
}
|
|
2744
2831
|
if (this.errorMessage) this.setError(null);
|
|
2745
|
-
|
|
2832
|
+
/* keep an initial or manually set invalid state until the user interacts */
|
|
2833
|
+
if (this.validation === 'invalid' && !this._presetValidation) this.setValidation(null, true);
|
|
2746
2834
|
return this;
|
|
2747
2835
|
};
|
|
2748
2836
|
|
|
@@ -2807,6 +2895,22 @@
|
|
|
2807
2895
|
return Promise.resolve(!result.error);
|
|
2808
2896
|
};
|
|
2809
2897
|
|
|
2898
|
+
ZidanFieldBase.prototype._trackDescribedBy = function (input) {
|
|
2899
|
+
if (!input || !input.getAttribute) return;
|
|
2900
|
+
for (var i = 0; i < this._describedByBefore.length; i += 1) {
|
|
2901
|
+
if (this._describedByBefore[i][0] === input) return;
|
|
2902
|
+
}
|
|
2903
|
+
this._describedByBefore.push([input, input.getAttribute('aria-describedby')]);
|
|
2904
|
+
};
|
|
2905
|
+
|
|
2906
|
+
ZidanFieldBase.prototype._addDescribedBy = function (input, id) {
|
|
2907
|
+
if (!input || !input.getAttribute || !id) return;
|
|
2908
|
+
this._trackDescribedBy(input);
|
|
2909
|
+
var current = (input.getAttribute('aria-describedby') || '').split(/\s+/).filter(Boolean);
|
|
2910
|
+
if (current.indexOf(id) === -1) current.push(id);
|
|
2911
|
+
input.setAttribute('aria-describedby', current.join(' '));
|
|
2912
|
+
};
|
|
2913
|
+
|
|
2810
2914
|
ZidanFieldBase.prototype._syncDescribedBy = function () {
|
|
2811
2915
|
if (!this.el || !this.el.getAttribute) return;
|
|
2812
2916
|
var errorId = this.id + '-error';
|
|
@@ -2815,6 +2919,7 @@
|
|
|
2815
2919
|
var targets = this.validationTargets();
|
|
2816
2920
|
targets.forEach(function (input) {
|
|
2817
2921
|
if (!input || !input.getAttribute) return;
|
|
2922
|
+
this._trackDescribedBy(input);
|
|
2818
2923
|
var current = (input.getAttribute('aria-describedby') || '').split(/\s+/).filter(Boolean);
|
|
2819
2924
|
var next = current.filter(function (id) { return id !== errorId && id !== hintId; });
|
|
2820
2925
|
if (hintId) next.push(hintId);
|
|
@@ -2882,10 +2987,17 @@
|
|
|
2882
2987
|
});
|
|
2883
2988
|
self.on(input, 'blur', function () {
|
|
2884
2989
|
self.touched = true;
|
|
2990
|
+
self._presetValidation = false;
|
|
2991
|
+
self._mirrorValidity();
|
|
2992
|
+
});
|
|
2993
|
+
self.on(input, 'input', function () {
|
|
2994
|
+
self._presetValidation = false;
|
|
2995
|
+
self._mirrorValidity();
|
|
2996
|
+
});
|
|
2997
|
+
self.on(input, 'change', function () {
|
|
2998
|
+
self._presetValidation = false;
|
|
2885
2999
|
self._mirrorValidity();
|
|
2886
3000
|
});
|
|
2887
|
-
self.on(input, 'input', function () { self._mirrorValidity(); });
|
|
2888
|
-
self.on(input, 'change', function () { self._mirrorValidity(); });
|
|
2889
3001
|
});
|
|
2890
3002
|
this.on(this.formEl, 'reset', function () {
|
|
2891
3003
|
global.setTimeout(function () {
|
|
@@ -2934,8 +3046,10 @@
|
|
|
2934
3046
|
return true;
|
|
2935
3047
|
};
|
|
2936
3048
|
|
|
2937
|
-
ZidanFieldBase.prototype.setValidation = function (state) {
|
|
3049
|
+
ZidanFieldBase.prototype.setValidation = function (state, internal) {
|
|
2938
3050
|
this.validation = VALIDATION_STATES.indexOf(state) === -1 ? null : state;
|
|
3051
|
+
/* public calls pin the state; internal mirrors may clear it again */
|
|
3052
|
+
if (!internal) this._presetValidation = this.validation === 'invalid';
|
|
2939
3053
|
var invalid = this.validation === 'invalid' || !!this.errorMessage;
|
|
2940
3054
|
if (this.root) {
|
|
2941
3055
|
this.root.classList.toggle('zs-field--invalid', invalid);
|
|
@@ -3026,7 +3140,16 @@
|
|
|
3026
3140
|
this._cleanups.forEach(function (fn) { fn(); });
|
|
3027
3141
|
this._cleanups.length = 0;
|
|
3028
3142
|
this.emit('destroy', {});
|
|
3029
|
-
|
|
3143
|
+
/* radio groups use the author's <fieldset> as their root: removing it would
|
|
3144
|
+
delete the original radios too, so only remove roots the field created. */
|
|
3145
|
+
if (this.root && this.root !== this.el && this.root.parentNode) this.root.parentNode.removeChild(this.root);
|
|
3146
|
+
this._describedByBefore.forEach(function (entry) {
|
|
3147
|
+
var input = entry[0];
|
|
3148
|
+
if (!input || !input.getAttribute) return;
|
|
3149
|
+
if (entry[1] === null || entry[1] === undefined) input.removeAttribute('aria-describedby');
|
|
3150
|
+
else input.setAttribute('aria-describedby', entry[1]);
|
|
3151
|
+
});
|
|
3152
|
+
this._describedByBefore = [];
|
|
3030
3153
|
if (this.el.__zidanField === this) delete this.el.__zidanField;
|
|
3031
3154
|
ZidanForm._unregister(this);
|
|
3032
3155
|
return this;
|
|
@@ -3130,8 +3253,7 @@
|
|
|
3130
3253
|
if (hintText) {
|
|
3131
3254
|
var hint = el('p', 'zs-field__hint', { id: this.id + '-hint' }, hintText);
|
|
3132
3255
|
root.appendChild(hint);
|
|
3133
|
-
|
|
3134
|
-
this._cleanups.push(function () { input.removeAttribute('aria-describedby'); });
|
|
3256
|
+
this._addDescribedBy(input, this.id + '-hint');
|
|
3135
3257
|
}
|
|
3136
3258
|
|
|
3137
3259
|
this.check = check;
|
|
@@ -3220,6 +3342,12 @@
|
|
|
3220
3342
|
|
|
3221
3343
|
function ZidanRadioGroup(target, options) {
|
|
3222
3344
|
if (!(this instanceof ZidanRadioGroup)) return new ZidanRadioGroup(target, options);
|
|
3345
|
+
/* radios are enhanced as a group, never one input at a time */
|
|
3346
|
+
if (isElement(target) && /^INPUT$/i.test(target.tagName)) {
|
|
3347
|
+
var group = target.closest ? target.closest('fieldset, [data-zidan-radio-group]') : null;
|
|
3348
|
+
if (!group) throw new Error('ZidanRadioGroup: expected a <fieldset> containing the radio inputs.');
|
|
3349
|
+
target = group;
|
|
3350
|
+
}
|
|
3223
3351
|
ZidanFieldBase.call(this, target, options, 'radio-group');
|
|
3224
3352
|
var variant = pickList(this.opts.variant || target.getAttribute('data-zidan-variant'), RADIO_VARIANTS, 'stacked');
|
|
3225
3353
|
this.variant = variant;
|
|
@@ -3229,7 +3357,14 @@
|
|
|
3229
3357
|
target.setAttribute('data-zs-kind', 'radio-group');
|
|
3230
3358
|
target.setAttribute('data-zs-variant', variant);
|
|
3231
3359
|
this._applyScope(target);
|
|
3232
|
-
|
|
3360
|
+
var hadRole = target.hasAttribute('role');
|
|
3361
|
+
if (!hadRole) target.setAttribute('role', 'radiogroup');
|
|
3362
|
+
this._teardown = function () {
|
|
3363
|
+
target.classList.remove('zs-radio-group');
|
|
3364
|
+
['data-zs-kind', 'data-zs-variant', 'data-zs-theme', 'data-zs-framework', 'data-zs-layout']
|
|
3365
|
+
.forEach(function (name) { target.removeAttribute(name); });
|
|
3366
|
+
if (!hadRole) target.removeAttribute('role');
|
|
3367
|
+
};
|
|
3233
3368
|
this._labels = [];
|
|
3234
3369
|
this._enhance();
|
|
3235
3370
|
this._bindValidity();
|
|
@@ -3559,6 +3694,22 @@
|
|
|
3559
3694
|
|
|
3560
3695
|
self.on(clearBtn, 'click', function () { self.clear(); });
|
|
3561
3696
|
|
|
3697
|
+
/* Delegated once: the list is rebuilt on every upload progress tick, so
|
|
3698
|
+
per-item listeners would grow without bound. */
|
|
3699
|
+
self.on(list, 'click', function (event) {
|
|
3700
|
+
var button = event.target && event.target.closest ? event.target.closest('button') : null;
|
|
3701
|
+
if (!button || !list.contains(button)) return;
|
|
3702
|
+
var item = button.closest('.zs-file-item');
|
|
3703
|
+
var index = item ? parseInt(item.getAttribute('data-zs-file-index'), 10) : -1;
|
|
3704
|
+
var file = index >= 0 ? self.getFiles()[index] : null;
|
|
3705
|
+
if (!file) return;
|
|
3706
|
+
event.preventDefault();
|
|
3707
|
+
event.stopPropagation();
|
|
3708
|
+
if (button.classList.contains('zs-file-cancel')) self.cancelUpload(file);
|
|
3709
|
+
else if (button.classList.contains('zs-file-retry')) self.retryUpload(file);
|
|
3710
|
+
else if (button.classList.contains('zs-file-remove')) self.removeFile(file);
|
|
3711
|
+
});
|
|
3712
|
+
|
|
3562
3713
|
this._bindValidity();
|
|
3563
3714
|
this.on(this.formEl, 'reset', function () {
|
|
3564
3715
|
global.setTimeout(function () {
|
|
@@ -3855,6 +4006,7 @@
|
|
|
3855
4006
|
var state = self._stateFor(file, false) || { status: 'idle', progress: 0, error: '', result: null };
|
|
3856
4007
|
var item = el('li', 'zs-file-item');
|
|
3857
4008
|
item.setAttribute('data-zs-upload-state', state.status);
|
|
4009
|
+
item.setAttribute('data-zs-file-index', String(index));
|
|
3858
4010
|
|
|
3859
4011
|
var thumb = el('span', 'zs-file-thumb');
|
|
3860
4012
|
if (/^image\//.test(file.type)) {
|
|
@@ -3904,30 +4056,15 @@
|
|
|
3904
4056
|
if (state.status === 'uploading') {
|
|
3905
4057
|
var cancel = el('button', 'zs-file-cancel', { type: 'button', 'aria-label': 'Cancel upload of ' + file.name });
|
|
3906
4058
|
cancel.textContent = opts.cancelLabel || 'Cancel';
|
|
3907
|
-
self.on(cancel, 'click', function (event) {
|
|
3908
|
-
event.preventDefault();
|
|
3909
|
-
event.stopPropagation();
|
|
3910
|
-
self.cancelUpload(file);
|
|
3911
|
-
});
|
|
3912
4059
|
actions.appendChild(cancel);
|
|
3913
4060
|
} else if (state.status === 'error' || state.status === 'canceled') {
|
|
3914
4061
|
var retry = el('button', 'zs-file-retry', { type: 'button', 'aria-label': 'Retry upload of ' + file.name });
|
|
3915
4062
|
retry.textContent = opts.retryLabel || 'Retry';
|
|
3916
|
-
self.on(retry, 'click', function (event) {
|
|
3917
|
-
event.preventDefault();
|
|
3918
|
-
event.stopPropagation();
|
|
3919
|
-
self.retryUpload(file);
|
|
3920
|
-
});
|
|
3921
4063
|
actions.appendChild(retry);
|
|
3922
4064
|
}
|
|
3923
4065
|
|
|
3924
4066
|
var remove = el('button', 'zs-file-remove', { type: 'button', 'aria-label': 'Remove ' + file.name });
|
|
3925
4067
|
remove.textContent = '\u00d7';
|
|
3926
|
-
self.on(remove, 'click', function (event) {
|
|
3927
|
-
event.preventDefault();
|
|
3928
|
-
event.stopPropagation();
|
|
3929
|
-
self.removeFile(file);
|
|
3930
|
-
});
|
|
3931
4068
|
actions.appendChild(remove);
|
|
3932
4069
|
|
|
3933
4070
|
item.appendChild(thumb);
|
|
@@ -4284,8 +4421,10 @@
|
|
|
4284
4421
|
iso = String(iso).toUpperCase();
|
|
4285
4422
|
var country = PHONE_COUNTRIES[iso];
|
|
4286
4423
|
if (!country) return;
|
|
4424
|
+
/* ISO + dial only: Windows renders flag emoji as the two ISO letters,
|
|
4425
|
+
which duplicated the code ("GB GB +44"). */
|
|
4287
4426
|
var optionNode = el('option', null, { value: iso },
|
|
4288
|
-
|
|
4427
|
+
iso + ' +' + country.dial);
|
|
4289
4428
|
countrySelect.appendChild(optionNode);
|
|
4290
4429
|
});
|
|
4291
4430
|
countrySelect.value = phoneCountry;
|
|
@@ -4370,12 +4509,23 @@
|
|
|
4370
4509
|
if (isRange) {
|
|
4371
4510
|
var rangeVariant = pickList(fieldOption(input, opts, 'rangeVariant', 'range-variant', 'default'), RANGE_VARIANTS, 'default');
|
|
4372
4511
|
var rangeBubbleOn = fieldBool(input, opts, 'rangeBubble', 'range-bubble', true);
|
|
4512
|
+
var rangeBubbleMode = pickList(fieldOption(input, opts, 'rangeBubbleMode', 'range-bubble-mode', 'always'), RANGE_BUBBLE_MODES, 'always');
|
|
4513
|
+
var rangeBubblePosition = pickList(fieldOption(input, opts, 'rangeBubblePosition', 'range-bubble-position', 'top'), RANGE_BUBBLE_POSITIONS, 'top');
|
|
4514
|
+
var rangeFillOn = fieldBool(input, opts, 'rangeFill', 'range-fill', true);
|
|
4373
4515
|
var rangeScaleOn = fieldBool(input, opts, 'rangeMinMax', 'range-minmax', true);
|
|
4516
|
+
var showBubble = rangeBubbleOn && rangeBubbleMode !== 'never';
|
|
4517
|
+
var bubbleVisible = showBubble && rangeVariant !== 'minimal';
|
|
4374
4518
|
rangeWrap = el('div', 'zs-range');
|
|
4375
4519
|
rangeWrap.setAttribute('data-zs-range', rangeVariant);
|
|
4376
|
-
|
|
4520
|
+
rangeWrap.classList.toggle('zs-range--fill-off', !rangeFillOn);
|
|
4521
|
+
rangeWrap.classList.toggle('zs-range--no-bubble', !bubbleVisible);
|
|
4522
|
+
if (showBubble) {
|
|
4377
4523
|
rangeBubble = el('output', 'zs-range-bubble', { for: this.id, 'aria-hidden': 'true' });
|
|
4378
4524
|
rangeWrap.appendChild(rangeBubble);
|
|
4525
|
+
if (bubbleVisible) {
|
|
4526
|
+
rangeWrap.classList.toggle('zs-range--bubble-active', rangeBubbleMode === 'active');
|
|
4527
|
+
rangeWrap.classList.toggle('zs-range--bubble-bottom', rangeBubblePosition === 'bottom');
|
|
4528
|
+
}
|
|
4379
4529
|
}
|
|
4380
4530
|
rangeWrap.appendChild(input);
|
|
4381
4531
|
rangeTicksEl = el('div', 'zs-range-ticks', { 'aria-hidden': 'true' });
|
|
@@ -4393,7 +4543,11 @@
|
|
|
4393
4543
|
this.rangeTicksEl = rangeTicksEl;
|
|
4394
4544
|
this.rangeScale = rangeScale;
|
|
4395
4545
|
this.rangeFormat = opts.rangeFormat || input.getAttribute('data-zidan-range-format') || null;
|
|
4396
|
-
this.
|
|
4546
|
+
this.rangeBubbleMode = rangeBubbleMode;
|
|
4547
|
+
this.rangeBubblePosition = rangeBubblePosition;
|
|
4548
|
+
this.rangeMinLabel = String(fieldOption(input, opts, 'rangeMinLabel', 'range-min-label', ''));
|
|
4549
|
+
this.rangeMaxLabel = String(fieldOption(input, opts, 'rangeMaxLabel', 'range-max-label', ''));
|
|
4550
|
+
this.rangeTicksOption = parseRangeTicks(fieldOption(input, opts, 'rangeTicks', 'range-ticks', 0));
|
|
4397
4551
|
this.rangeTickLabels = fieldBool(input, opts, 'rangeTickLabels', 'range-tick-labels', false);
|
|
4398
4552
|
this.rangeLabelMap = opts.rangeLabels || null;
|
|
4399
4553
|
this.rangeSignature = '';
|
|
@@ -4613,7 +4767,8 @@
|
|
|
4613
4767
|
|
|
4614
4768
|
var outputSelector = opts.output || input.getAttribute('data-zidan-output');
|
|
4615
4769
|
if (isRange && outputSelector) {
|
|
4616
|
-
var out =
|
|
4770
|
+
var out = null;
|
|
4771
|
+
try { out = doc.querySelector(outputSelector); } catch (err) { out = null; }
|
|
4617
4772
|
if (out) {
|
|
4618
4773
|
this.rangeOutput = out;
|
|
4619
4774
|
}
|
|
@@ -4685,28 +4840,45 @@
|
|
|
4685
4840
|
return { min: min, max: max };
|
|
4686
4841
|
};
|
|
4687
4842
|
|
|
4843
|
+
ZidanTextField.prototype._rangeLabelFor = function (value) {
|
|
4844
|
+
if (this.rangeLabelMap && this.rangeLabelMap[value] !== undefined) {
|
|
4845
|
+
return String(this.rangeLabelMap[value]);
|
|
4846
|
+
}
|
|
4847
|
+
return this._formatRangeValue(value);
|
|
4848
|
+
};
|
|
4849
|
+
|
|
4688
4850
|
ZidanTextField.prototype._renderRangeTicks = function () {
|
|
4689
4851
|
if (!this.rangeTicksEl) return;
|
|
4690
4852
|
var bounds = this._rangeBounds();
|
|
4691
4853
|
var option = this.rangeTicksOption;
|
|
4854
|
+
var labelsOn = !!this.rangeTickLabels;
|
|
4855
|
+
this.rangeTicksEl.textContent = '';
|
|
4692
4856
|
var values = [];
|
|
4693
|
-
if (Array.isArray(option))
|
|
4694
|
-
|
|
4857
|
+
if (Array.isArray(option)) {
|
|
4858
|
+
values = option.map(Number).filter(function (n) { return isFinite(n); });
|
|
4859
|
+
} else {
|
|
4695
4860
|
var count = parseInt(option, 10);
|
|
4696
|
-
if (
|
|
4697
|
-
|
|
4861
|
+
if (count > 1) {
|
|
4862
|
+
for (var i = 0; i < count; i += 1) values.push(bounds.min + ((bounds.max - bounds.min) * i) / (count - 1));
|
|
4863
|
+
}
|
|
4698
4864
|
}
|
|
4699
|
-
|
|
4865
|
+
/* Labeled ticks at both ends replace the min/max scale, so the start and end
|
|
4866
|
+
numbers are printed once instead of twice. */
|
|
4867
|
+
var coversEnds = labelsOn && !!this.rangeScale && values.length > 0 &&
|
|
4868
|
+
values.indexOf(bounds.min) !== -1 && values.indexOf(bounds.max) !== -1;
|
|
4869
|
+
if (this.rangeScale) this.rangeScale.classList.toggle('zs-range-scale--hidden', coversEnds);
|
|
4870
|
+
/* with no scale row, tick labels need their own room so they cannot overlap
|
|
4871
|
+
whatever follows the range */
|
|
4872
|
+
this.range.classList.toggle('zs-range--labels-no-scale', labelsOn && !this.rangeScale && values.length > 0);
|
|
4700
4873
|
values.forEach(function (value) {
|
|
4701
4874
|
var pct = bounds.max > bounds.min ? (value - bounds.min) / (bounds.max - bounds.min) : 0;
|
|
4702
4875
|
var tick = el('span', 'zs-range-tick');
|
|
4703
4876
|
tick.style.setProperty('--zs-range-tick-pct', (clamp(pct, 0, 1) * 100).toFixed(2) + '%');
|
|
4704
|
-
if (
|
|
4705
|
-
|
|
4706
|
-
? this.rangeLabelMap[value]
|
|
4707
|
-
: this._formatRangeValue(value);
|
|
4708
|
-
tick.textContent = label;
|
|
4877
|
+
if (labelsOn) {
|
|
4878
|
+
tick.textContent = this._rangeLabelFor(value);
|
|
4709
4879
|
tick.classList.add('zs-range-tick--labeled');
|
|
4880
|
+
if (pct <= 0) tick.classList.add('zs-range-tick--start');
|
|
4881
|
+
else if (pct >= 1) tick.classList.add('zs-range-tick--end');
|
|
4710
4882
|
}
|
|
4711
4883
|
this.rangeTicksEl.appendChild(tick);
|
|
4712
4884
|
}, this);
|
|
@@ -4721,12 +4893,24 @@
|
|
|
4721
4893
|
pct = clamp(pct, 0, 1);
|
|
4722
4894
|
this.range.style.setProperty('--zs-range-pct', pct.toFixed(4));
|
|
4723
4895
|
this.range.style.setProperty('--zs-range-fill', (pct * 100).toFixed(2) + '%');
|
|
4724
|
-
if (this.rangeBubble)
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
this.
|
|
4896
|
+
if (this.rangeBubble) {
|
|
4897
|
+
this.rangeBubble.textContent = this._formatRangeValue(numeric);
|
|
4898
|
+
/* at the ends, align the bubble inside the track instead of half outside it */
|
|
4899
|
+
this.rangeBubble.classList.toggle('zs-range-bubble--start', pct <= 0);
|
|
4900
|
+
this.rangeBubble.classList.toggle('zs-range-bubble--end', pct >= 1);
|
|
4728
4901
|
}
|
|
4729
|
-
|
|
4902
|
+
if (this.rangeScale) {
|
|
4903
|
+
this.rangeScale.firstChild.textContent = this.rangeMinLabel || this._formatRangeValue(bounds.min);
|
|
4904
|
+
this.rangeScale.lastChild.textContent = this.rangeMaxLabel || this._formatRangeValue(bounds.max);
|
|
4905
|
+
}
|
|
4906
|
+
/* the formatted value is what the user sees and what assistive tech should read */
|
|
4907
|
+
if (this.rangeFormat) this.el.setAttribute('aria-valuetext', this._formatRangeValue(numeric));
|
|
4908
|
+
else this.el.removeAttribute('aria-valuetext');
|
|
4909
|
+
var signature = [
|
|
4910
|
+
bounds.min, bounds.max, this.el.step, JSON.stringify(this.rangeTicksOption), this.rangeTickLabels,
|
|
4911
|
+
JSON.stringify(this.rangeLabelMap || null), this.rangeMinLabel, this.rangeMaxLabel,
|
|
4912
|
+
String(this.rangeFormat || '')
|
|
4913
|
+
].join('|');
|
|
4730
4914
|
if (signature !== this.rangeSignature) {
|
|
4731
4915
|
this.rangeSignature = signature;
|
|
4732
4916
|
this._renderRangeTicks();
|
|
@@ -4736,8 +4920,9 @@
|
|
|
4736
4920
|
ZidanTextField.prototype._syncRangeOutput = function (value) {
|
|
4737
4921
|
if (this.range) this._syncRange(value);
|
|
4738
4922
|
if (this.rangeOutput) {
|
|
4739
|
-
this.
|
|
4740
|
-
this.rangeOutput.
|
|
4923
|
+
var display = this.range ? this._formatRangeValue(value) : value;
|
|
4924
|
+
this.rangeOutput.textContent = display;
|
|
4925
|
+
this.rangeOutput.value = display;
|
|
4741
4926
|
}
|
|
4742
4927
|
};
|
|
4743
4928
|
|
|
@@ -4932,8 +5117,9 @@
|
|
|
4932
5117
|
}
|
|
4933
5118
|
if (this.range) this._syncRange(value);
|
|
4934
5119
|
if (this.rangeOutput) {
|
|
4935
|
-
this.
|
|
4936
|
-
this.rangeOutput.
|
|
5120
|
+
var display = this.range ? this._formatRangeValue(value) : value;
|
|
5121
|
+
this.rangeOutput.textContent = display;
|
|
5122
|
+
this.rangeOutput.value = display;
|
|
4937
5123
|
}
|
|
4938
5124
|
if (this.stepper) {
|
|
4939
5125
|
var min = parseFloat(input.min);
|
|
@@ -4957,6 +5143,7 @@
|
|
|
4957
5143
|
};
|
|
4958
5144
|
|
|
4959
5145
|
ZidanTextField.prototype._teardown = function () {
|
|
5146
|
+
if (this.range) this.el.removeAttribute('aria-valuetext');
|
|
4960
5147
|
if (this._restoreInput) this._restoreInput();
|
|
4961
5148
|
};
|
|
4962
5149
|
|
|
@@ -5022,7 +5209,11 @@
|
|
|
5022
5209
|
// (output, counter, clearable, …) work without a data attribute
|
|
5023
5210
|
var kind = fieldKindFor(node) || inferredTextKind(node);
|
|
5024
5211
|
if (!kind) return;
|
|
5025
|
-
if (kind === 'radio'
|
|
5212
|
+
if (kind === 'radio' || kind === 'radio-group') {
|
|
5213
|
+
if (/^INPUT$/i.test(node.tagName)) {
|
|
5214
|
+
node = node.closest ? node.closest('fieldset, [data-zidan-radio-group]') : null;
|
|
5215
|
+
if (!node) return;
|
|
5216
|
+
}
|
|
5026
5217
|
kind = 'radio-group';
|
|
5027
5218
|
}
|
|
5028
5219
|
var instance = createField(node, kind, options || {});
|
|
@@ -5037,7 +5228,13 @@
|
|
|
5037
5228
|
if (!isElement(node) || node.__zidanField) return;
|
|
5038
5229
|
var kind = fieldKindFor(node);
|
|
5039
5230
|
if (!kind) return;
|
|
5040
|
-
if (kind === 'radio'
|
|
5231
|
+
if (kind === 'radio' || kind === 'radio-group') {
|
|
5232
|
+
if (/^INPUT$/i.test(node.tagName)) {
|
|
5233
|
+
node = node.closest ? node.closest('fieldset, [data-zidan-radio-group]') : null;
|
|
5234
|
+
if (!node) return;
|
|
5235
|
+
}
|
|
5236
|
+
kind = 'radio-group';
|
|
5237
|
+
}
|
|
5041
5238
|
var instance = createField(node, kind, options || {});
|
|
5042
5239
|
if (instance) instances.push(instance);
|
|
5043
5240
|
});
|