@tabler/core 1.0.0-beta18 → 1.0.0-beta19
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/dist/css/demo.css +2 -2
- package/dist/css/demo.min.css +2 -2
- package/dist/css/demo.rtl.css +2 -2
- package/dist/css/demo.rtl.min.css +2 -2
- package/dist/css/tabler-flags.css +2 -2
- package/dist/css/tabler-flags.min.css +2 -2
- package/dist/css/tabler-flags.rtl.css +2 -2
- package/dist/css/tabler-flags.rtl.min.css +2 -2
- package/dist/css/tabler-payments.css +2 -2
- package/dist/css/tabler-payments.min.css +2 -2
- package/dist/css/tabler-payments.rtl.css +2 -2
- package/dist/css/tabler-payments.rtl.min.css +2 -2
- package/dist/css/tabler-social.css +2 -2
- package/dist/css/tabler-social.min.css +2 -2
- package/dist/css/tabler-social.rtl.css +2 -2
- package/dist/css/tabler-social.rtl.min.css +2 -2
- package/dist/css/tabler-vendors.css +19 -2
- package/dist/css/tabler-vendors.min.css +3 -3
- package/dist/css/tabler-vendors.rtl.css +19 -2
- package/dist/css/tabler-vendors.rtl.min.css +3 -3
- package/dist/css/tabler.css +36 -31
- package/dist/css/tabler.min.css +4 -4
- package/dist/css/tabler.rtl.css +36 -31
- package/dist/css/tabler.rtl.min.css +4 -4
- package/dist/js/demo-theme.js +2 -2
- package/dist/js/demo-theme.min.js +2 -2
- package/dist/js/demo.js +2 -2
- package/dist/js/demo.min.js +2 -2
- package/dist/js/tabler.esm.js +2 -2
- package/dist/js/tabler.esm.min.js +3 -3
- package/dist/js/tabler.js +2 -2
- package/dist/js/tabler.min.js +4 -4
- package/dist/libs/star-rating.js/dist/star-rating.cjs.js +481 -0
- package/dist/libs/star-rating.js/dist/star-rating.css +220 -0
- package/dist/libs/star-rating.js/dist/star-rating.esm.js +479 -0
- package/dist/libs/star-rating.js/dist/star-rating.esm.min.js +1 -0
- package/dist/libs/star-rating.js/dist/star-rating.js +491 -0
- package/dist/libs/star-rating.js/dist/star-rating.min.css +8 -0
- package/dist/libs/star-rating.js/dist/star-rating.min.js +8 -0
- package/package.json +9 -3
- package/src/scss/_variables.scss +1 -1
- package/src/scss/layout/_navbar.scss +1 -70
- package/src/scss/tabler-vendors.scss +1 -0
- package/src/scss/ui/_grid.scss +2 -2
- package/src/scss/ui/_tables.scss +12 -11
- package/src/scss/vendor/_stars-rating.scss +20 -0
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function _classCallCheck(instance, Constructor) {
|
|
4
|
+
if (!(instance instanceof Constructor)) {
|
|
5
|
+
throw new TypeError("Cannot call a class as a function");
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function _defineProperties(target, props) {
|
|
10
|
+
for (var i = 0; i < props.length; i++) {
|
|
11
|
+
var descriptor = props[i];
|
|
12
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
13
|
+
descriptor.configurable = true;
|
|
14
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
15
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
20
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
21
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
22
|
+
return Constructor;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var defaults = {
|
|
26
|
+
classNames: {
|
|
27
|
+
active: 'gl-active',
|
|
28
|
+
base: 'gl-star-rating',
|
|
29
|
+
selected: 'gl-selected'
|
|
30
|
+
},
|
|
31
|
+
clearable: true,
|
|
32
|
+
maxStars: 10,
|
|
33
|
+
prebuilt: false,
|
|
34
|
+
stars: null,
|
|
35
|
+
tooltip: 'Select a Rating'
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
var addRemoveClass = function addRemoveClass(el, bool, className) {
|
|
39
|
+
el.classList[bool ? 'add' : 'remove'](className);
|
|
40
|
+
};
|
|
41
|
+
var createSpanEl = function createSpanEl(attributes) {
|
|
42
|
+
var el = document.createElement('span');
|
|
43
|
+
attributes = attributes || {};
|
|
44
|
+
|
|
45
|
+
for (var key in attributes) {
|
|
46
|
+
el.setAttribute(key, attributes[key]);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return el;
|
|
50
|
+
};
|
|
51
|
+
var inRange = function inRange(value, min, max) {
|
|
52
|
+
return /^\d+$/.test(value) && min <= value && value <= max;
|
|
53
|
+
};
|
|
54
|
+
var insertSpanEl = function insertSpanEl(el, after, attributes) {
|
|
55
|
+
var newEl = createSpanEl(attributes);
|
|
56
|
+
el.parentNode.insertBefore(newEl, after ? el.nextSibling : el);
|
|
57
|
+
return newEl;
|
|
58
|
+
};
|
|
59
|
+
var merge = function merge() {
|
|
60
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
61
|
+
args[_key] = arguments[_key];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// adapted from https://github.com/firstandthird/aug
|
|
65
|
+
var results = {};
|
|
66
|
+
args.forEach(function (prop) {
|
|
67
|
+
Object.keys(prop || {}).forEach(function (propName) {
|
|
68
|
+
if (args[0][propName] === undefined) return; // restrict keys to the defaults
|
|
69
|
+
|
|
70
|
+
var propValue = prop[propName];
|
|
71
|
+
|
|
72
|
+
if (type(propValue) === 'Object' && type(results[propName]) === 'Object') {
|
|
73
|
+
results[propName] = merge(results[propName], propValue);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
results[propName] = propValue;
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
return results;
|
|
81
|
+
};
|
|
82
|
+
var type = function type(value) {
|
|
83
|
+
return {}.toString.call(value).slice(8, -1);
|
|
84
|
+
};
|
|
85
|
+
var values = function values(selectEl) {
|
|
86
|
+
var values = [];
|
|
87
|
+
[].forEach.call(selectEl.options, function (el) {
|
|
88
|
+
var value = parseInt(el.value, 10) || 0;
|
|
89
|
+
|
|
90
|
+
if (value > 0) {
|
|
91
|
+
values.push({
|
|
92
|
+
index: el.index,
|
|
93
|
+
text: el.text,
|
|
94
|
+
value: value
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
return values.sort(function (a, b) {
|
|
99
|
+
return a.value - b.value;
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
var Widget = /*#__PURE__*/function () {
|
|
104
|
+
function Widget(el, props) {
|
|
105
|
+
_classCallCheck(this, Widget);
|
|
106
|
+
|
|
107
|
+
// (HTMLElement, object):void
|
|
108
|
+
this.direction = window.getComputedStyle(el, null).getPropertyValue('direction');
|
|
109
|
+
this.el = el;
|
|
110
|
+
this.events = {
|
|
111
|
+
change: this.onChange.bind(this),
|
|
112
|
+
keydown: this.onKeyDown.bind(this),
|
|
113
|
+
mousedown: this.onPointerDown.bind(this),
|
|
114
|
+
mouseleave: this.onPointerLeave.bind(this),
|
|
115
|
+
mousemove: this.onPointerMove.bind(this),
|
|
116
|
+
reset: this.onReset.bind(this),
|
|
117
|
+
touchend: this.onPointerDown.bind(this),
|
|
118
|
+
touchmove: this.onPointerMove.bind(this)
|
|
119
|
+
};
|
|
120
|
+
this.indexActive = null; // the active span index
|
|
121
|
+
|
|
122
|
+
this.indexSelected = null; // the selected span index
|
|
123
|
+
|
|
124
|
+
this.props = props;
|
|
125
|
+
this.tick = null;
|
|
126
|
+
this.ticking = false;
|
|
127
|
+
this.values = values(el);
|
|
128
|
+
this.widgetEl = null;
|
|
129
|
+
|
|
130
|
+
if (this.el.widget) {
|
|
131
|
+
this.el.widget.destroy(); // remove any stale event listeners
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (inRange(this.values.length, 1, this.props.maxStars)) {
|
|
135
|
+
this.build();
|
|
136
|
+
} else {
|
|
137
|
+
this.destroy();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
_createClass(Widget, [{
|
|
142
|
+
key: "build",
|
|
143
|
+
value: function build() {
|
|
144
|
+
// ():void
|
|
145
|
+
this.destroy();
|
|
146
|
+
this.buildWidget();
|
|
147
|
+
this.selectValue(this.indexSelected = this.selected(), false); // set the initial value but do not trigger change event
|
|
148
|
+
|
|
149
|
+
this.handleEvents('add');
|
|
150
|
+
this.el.widget = this; // store a reference to this widget on the SELECT so that we can remove stale event listeners
|
|
151
|
+
}
|
|
152
|
+
}, {
|
|
153
|
+
key: "buildWidget",
|
|
154
|
+
value: function buildWidget() {
|
|
155
|
+
var _this = this;
|
|
156
|
+
|
|
157
|
+
// ():void
|
|
158
|
+
var parentEl, widgetEl;
|
|
159
|
+
|
|
160
|
+
if (this.props.prebuilt) {
|
|
161
|
+
parentEl = this.el.parentNode;
|
|
162
|
+
widgetEl = parentEl.querySelector('.' + this.props.classNames.base + '--stars');
|
|
163
|
+
} else {
|
|
164
|
+
parentEl = insertSpanEl(this.el, false, {
|
|
165
|
+
"class": this.props.classNames.base
|
|
166
|
+
});
|
|
167
|
+
parentEl.appendChild(this.el);
|
|
168
|
+
widgetEl = insertSpanEl(this.el, true, {
|
|
169
|
+
"class": this.props.classNames.base + '--stars'
|
|
170
|
+
});
|
|
171
|
+
this.values.forEach(function (item, index) {
|
|
172
|
+
var el = createSpanEl({
|
|
173
|
+
'data-index': index,
|
|
174
|
+
'data-value': item.value
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
if ('function' === typeof _this.props.stars) {
|
|
178
|
+
_this.props.stars.call(_this, el, item, index);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
[].forEach.call(el.children, function (el) {
|
|
182
|
+
return el.style.pointerEvents = 'none';
|
|
183
|
+
});
|
|
184
|
+
widgetEl.innerHTML += el.outerHTML;
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
parentEl.dataset.starRating = '';
|
|
189
|
+
parentEl.classList.add(this.props.classNames.base + '--' + this.direction);
|
|
190
|
+
|
|
191
|
+
if (this.props.tooltip) {
|
|
192
|
+
widgetEl.setAttribute('role', 'tooltip');
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
this.widgetEl = widgetEl;
|
|
196
|
+
}
|
|
197
|
+
}, {
|
|
198
|
+
key: "changeIndexTo",
|
|
199
|
+
value: function changeIndexTo(index, force) {
|
|
200
|
+
var _this2 = this;
|
|
201
|
+
|
|
202
|
+
// (int):void
|
|
203
|
+
if (this.indexActive !== index || force) {
|
|
204
|
+
[].forEach.call(this.widgetEl.children, function (el, i) {
|
|
205
|
+
// i starts at zero
|
|
206
|
+
addRemoveClass(el, i <= index, _this2.props.classNames.active);
|
|
207
|
+
addRemoveClass(el, i === _this2.indexSelected, _this2.props.classNames.selected);
|
|
208
|
+
});
|
|
209
|
+
this.widgetEl.setAttribute('data-rating', index + 1);
|
|
210
|
+
|
|
211
|
+
if ('function' !== typeof this.props.stars && !this.props.prebuilt) {
|
|
212
|
+
// @v3 compat
|
|
213
|
+
this.widgetEl.classList.remove('s' + 10 * (this.indexActive + 1));
|
|
214
|
+
this.widgetEl.classList.add('s' + 10 * (index + 1));
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (this.props.tooltip) {
|
|
218
|
+
var _this$values$index;
|
|
219
|
+
|
|
220
|
+
var label = index < 0 ? this.props.tooltip : (_this$values$index = this.values[index]) === null || _this$values$index === void 0 ? void 0 : _this$values$index.text;
|
|
221
|
+
this.widgetEl.setAttribute('aria-label', label);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
this.indexActive = index;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
this.ticking = false;
|
|
228
|
+
}
|
|
229
|
+
}, {
|
|
230
|
+
key: "destroy",
|
|
231
|
+
value: function destroy() {
|
|
232
|
+
// ():void
|
|
233
|
+
this.indexActive = null; // the active span index
|
|
234
|
+
|
|
235
|
+
this.indexSelected = this.selected(); // the selected span index
|
|
236
|
+
|
|
237
|
+
var parentEl = this.el.parentNode;
|
|
238
|
+
|
|
239
|
+
if (parentEl.classList.contains(this.props.classNames.base)) {
|
|
240
|
+
if (this.props.prebuilt) {
|
|
241
|
+
this.widgetEl = parentEl.querySelector('.' + this.props.classNames.base + '--stars');
|
|
242
|
+
parentEl.classList.remove(this.props.classNames.base + '--' + this.direction);
|
|
243
|
+
delete parentEl.dataset.starRating;
|
|
244
|
+
} else {
|
|
245
|
+
parentEl.parentNode.replaceChild(this.el, parentEl);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
this.handleEvents('remove');
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
delete this.el.widget; // remove the widget reference
|
|
252
|
+
}
|
|
253
|
+
}, {
|
|
254
|
+
key: "eventListener",
|
|
255
|
+
value: function eventListener(el, action, events, items) {
|
|
256
|
+
var _this3 = this;
|
|
257
|
+
|
|
258
|
+
// (HTMLElement, string, array, object):void
|
|
259
|
+
events.forEach(function (ev) {
|
|
260
|
+
return el[action + 'EventListener'](ev, _this3.events[ev], items || false);
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
}, {
|
|
264
|
+
key: "handleEvents",
|
|
265
|
+
value: function handleEvents(action) {
|
|
266
|
+
// (string):void
|
|
267
|
+
var formEl = this.el.closest('form');
|
|
268
|
+
|
|
269
|
+
if (formEl && formEl.tagName === 'FORM') {
|
|
270
|
+
this.eventListener(formEl, action, ['reset']);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
this.eventListener(this.el, action, ['change']); // always trigger the change event, even when SELECT is disabled
|
|
274
|
+
|
|
275
|
+
if ('add' === action && this.el.disabled) return;
|
|
276
|
+
this.eventListener(this.el, action, ['keydown']);
|
|
277
|
+
this.eventListener(this.widgetEl, action, ['mousedown', 'mouseleave', 'mousemove', 'touchend', 'touchmove'], false);
|
|
278
|
+
}
|
|
279
|
+
}, {
|
|
280
|
+
key: "indexFromEvent",
|
|
281
|
+
value: function indexFromEvent(ev) {
|
|
282
|
+
var _ev$touches, _ev$changedTouches;
|
|
283
|
+
|
|
284
|
+
// (MouseEvent|TouchEvent):void
|
|
285
|
+
var origin = ((_ev$touches = ev.touches) === null || _ev$touches === void 0 ? void 0 : _ev$touches[0]) || ((_ev$changedTouches = ev.changedTouches) === null || _ev$changedTouches === void 0 ? void 0 : _ev$changedTouches[0]) || ev;
|
|
286
|
+
var el = document.elementFromPoint(origin.clientX, origin.clientY);
|
|
287
|
+
|
|
288
|
+
if (el.parentNode === this.widgetEl) {
|
|
289
|
+
return [].slice.call(el.parentNode.children).indexOf(el);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
return this.indexActive;
|
|
293
|
+
}
|
|
294
|
+
}, {
|
|
295
|
+
key: "onChange",
|
|
296
|
+
value: function onChange() {
|
|
297
|
+
// ():void
|
|
298
|
+
this.changeIndexTo(this.selected(), true);
|
|
299
|
+
}
|
|
300
|
+
}, {
|
|
301
|
+
key: "onKeyDown",
|
|
302
|
+
value: function onKeyDown(ev) {
|
|
303
|
+
// (KeyboardEvent):void
|
|
304
|
+
var key = ev.key.slice(5);
|
|
305
|
+
if (!~['Left', 'Right'].indexOf(key)) return;
|
|
306
|
+
ev.preventDefault();
|
|
307
|
+
var increment = key === 'Left' ? -1 : 1;
|
|
308
|
+
|
|
309
|
+
if (this.direction === 'rtl') {
|
|
310
|
+
increment *= -1;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
var maxIndex = this.values.length - 1;
|
|
314
|
+
var minIndex = -1;
|
|
315
|
+
var index = Math.min(Math.max(this.selected() + increment, minIndex), maxIndex);
|
|
316
|
+
this.selectValue(index, true); // trigger change event
|
|
317
|
+
}
|
|
318
|
+
}, {
|
|
319
|
+
key: "onPointerDown",
|
|
320
|
+
value: function onPointerDown(ev) {
|
|
321
|
+
// (MouseEvent|TouchEvent):void
|
|
322
|
+
ev.preventDefault(); // this.el.focus(); // highlight the rating field
|
|
323
|
+
|
|
324
|
+
var index = this.indexFromEvent(ev);
|
|
325
|
+
|
|
326
|
+
if (this.props.clearable && index === this.indexSelected) {
|
|
327
|
+
index = -1; // remove the value
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
this.selectValue(index, true); // trigger change event
|
|
331
|
+
}
|
|
332
|
+
}, {
|
|
333
|
+
key: "onPointerLeave",
|
|
334
|
+
value: function onPointerLeave(ev) {
|
|
335
|
+
var _this4 = this;
|
|
336
|
+
|
|
337
|
+
// (MouseEvent):void
|
|
338
|
+
ev.preventDefault();
|
|
339
|
+
cancelAnimationFrame(this.tick);
|
|
340
|
+
requestAnimationFrame(function () {
|
|
341
|
+
return _this4.changeIndexTo(_this4.indexSelected);
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
}, {
|
|
345
|
+
key: "onPointerMove",
|
|
346
|
+
value: function onPointerMove(ev) {
|
|
347
|
+
var _this5 = this;
|
|
348
|
+
|
|
349
|
+
// (MouseEvent|TouchEvent):void
|
|
350
|
+
ev.preventDefault();
|
|
351
|
+
|
|
352
|
+
if (!this.ticking) {
|
|
353
|
+
this.tick = requestAnimationFrame(function () {
|
|
354
|
+
return _this5.changeIndexTo(_this5.indexFromEvent(ev));
|
|
355
|
+
});
|
|
356
|
+
this.ticking = true;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}, {
|
|
360
|
+
key: "onReset",
|
|
361
|
+
value: function onReset() {
|
|
362
|
+
var _this$el$querySelecto;
|
|
363
|
+
|
|
364
|
+
// ():void
|
|
365
|
+
var index = this.valueIndex((_this$el$querySelecto = this.el.querySelector('[selected]')) === null || _this$el$querySelecto === void 0 ? void 0 : _this$el$querySelecto.value);
|
|
366
|
+
this.selectValue(index || -1, false); // do not trigger change event
|
|
367
|
+
}
|
|
368
|
+
}, {
|
|
369
|
+
key: "selected",
|
|
370
|
+
value: function selected() {
|
|
371
|
+
// ():int
|
|
372
|
+
return this.valueIndex(this.el.value); // get the selected span index
|
|
373
|
+
}
|
|
374
|
+
}, {
|
|
375
|
+
key: "selectValue",
|
|
376
|
+
value: function selectValue(index, triggerChangeEvent) {
|
|
377
|
+
var _this$values$index2;
|
|
378
|
+
|
|
379
|
+
// (int, bool):void
|
|
380
|
+
this.el.value = ((_this$values$index2 = this.values[index]) === null || _this$values$index2 === void 0 ? void 0 : _this$values$index2.value) || ''; // first set the new value
|
|
381
|
+
|
|
382
|
+
this.indexSelected = this.selected(); // get the actual index from the selected value
|
|
383
|
+
|
|
384
|
+
if (false === triggerChangeEvent) {
|
|
385
|
+
this.changeIndexTo(this.selected(), true);
|
|
386
|
+
} else {
|
|
387
|
+
this.el.dispatchEvent(new Event('change'));
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}, {
|
|
391
|
+
key: "valueIndex",
|
|
392
|
+
value: function valueIndex(value) {
|
|
393
|
+
return this.values.findIndex(function (val) {
|
|
394
|
+
return val.value === +value;
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
}]);
|
|
398
|
+
|
|
399
|
+
return Widget;
|
|
400
|
+
}();
|
|
401
|
+
|
|
402
|
+
var StarRating = /*#__PURE__*/function () {
|
|
403
|
+
function StarRating(selector, props) {
|
|
404
|
+
_classCallCheck(this, StarRating);
|
|
405
|
+
|
|
406
|
+
// (HTMLSelectElement|NodeList|string, object):void
|
|
407
|
+
this.destroy = this.destroy.bind(this);
|
|
408
|
+
this.props = props;
|
|
409
|
+
this.rebuild = this.rebuild.bind(this);
|
|
410
|
+
this.selector = selector;
|
|
411
|
+
this.widgets = [];
|
|
412
|
+
this.build();
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
_createClass(StarRating, [{
|
|
416
|
+
key: "build",
|
|
417
|
+
value: function build() {
|
|
418
|
+
var _this = this;
|
|
419
|
+
|
|
420
|
+
// (HTMLSelectElement|NodeList|string, object):void
|
|
421
|
+
this.queryElements(this.selector).forEach(function (el) {
|
|
422
|
+
var options = merge(defaults, _this.props, JSON.parse(el.getAttribute('data-options')));
|
|
423
|
+
|
|
424
|
+
if ('SELECT' === el.tagName && !el.widget) {
|
|
425
|
+
// check for an existing Widget reference
|
|
426
|
+
if (!options.prebuilt && el.parentNode.classList.contains(options.classNames.base)) {
|
|
427
|
+
_this.unwrap(el);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
_this.widgets.push(new Widget(el, options));
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
}, {
|
|
435
|
+
key: "destroy",
|
|
436
|
+
value: function destroy() {
|
|
437
|
+
// ():void
|
|
438
|
+
this.widgets.forEach(function (widget) {
|
|
439
|
+
return widget.destroy();
|
|
440
|
+
});
|
|
441
|
+
this.widgets = [];
|
|
442
|
+
}
|
|
443
|
+
}, {
|
|
444
|
+
key: "queryElements",
|
|
445
|
+
value: function queryElements(selector) {
|
|
446
|
+
// (HTMLSelectElement|NodeList|string):array
|
|
447
|
+
if ('HTMLSelectElement' === type(selector)) {
|
|
448
|
+
return [selector];
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
if ('NodeList' === type(selector)) {
|
|
452
|
+
return [].slice.call(selector);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
if ('String' === type(selector)) {
|
|
456
|
+
return [].slice.call(document.querySelectorAll(selector));
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
return [];
|
|
460
|
+
}
|
|
461
|
+
}, {
|
|
462
|
+
key: "rebuild",
|
|
463
|
+
value: function rebuild() {
|
|
464
|
+
// ():void
|
|
465
|
+
this.destroy();
|
|
466
|
+
this.build();
|
|
467
|
+
}
|
|
468
|
+
}, {
|
|
469
|
+
key: "unwrap",
|
|
470
|
+
value: function unwrap(el) {
|
|
471
|
+
var removeEl = el.parentNode;
|
|
472
|
+
var parentEl = removeEl.parentNode;
|
|
473
|
+
parentEl.insertBefore(el, removeEl);
|
|
474
|
+
parentEl.removeChild(removeEl);
|
|
475
|
+
}
|
|
476
|
+
}]);
|
|
477
|
+
|
|
478
|
+
return StarRating;
|
|
479
|
+
}();
|
|
480
|
+
|
|
481
|
+
module.exports = StarRating;
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--gl-star-color: #fdd835;
|
|
3
|
+
--gl-star-color-inactive: #dcdce6;
|
|
4
|
+
--gl-star-empty: url('../img/star-empty.svg');
|
|
5
|
+
--gl-star-full: url('../img/star-full.svg');
|
|
6
|
+
--gl-star-size: 24px;
|
|
7
|
+
--gl-tooltip-border-radius: 4px;
|
|
8
|
+
--gl-tooltip-font-size: 0.875rem;
|
|
9
|
+
--gl-tooltip-font-weight: 400;
|
|
10
|
+
--gl-tooltip-line-height: 1;
|
|
11
|
+
--gl-tooltip-margin: 12px;
|
|
12
|
+
--gl-tooltip-padding: .5em 1em;
|
|
13
|
+
--gl-tooltip-size: 6px;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
[data-star-rating] > select {
|
|
17
|
+
-webkit-clip-path: circle(1px at 0 0) !important;
|
|
18
|
+
clip-path: circle(1px at 0 0) !important;
|
|
19
|
+
clip: rect(1px, 1px, 1px, 1px) !important;
|
|
20
|
+
height: 1px !important;
|
|
21
|
+
margin: 0 !important;
|
|
22
|
+
overflow: hidden !important;
|
|
23
|
+
padding: 0 !important;
|
|
24
|
+
position: absolute !important;
|
|
25
|
+
top: 0 !important;
|
|
26
|
+
visibility: visible !important;
|
|
27
|
+
white-space: nowrap !important;
|
|
28
|
+
width: 1px !important;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
[data-star-rating] > select {
|
|
32
|
+
-webkit-appearance: none;
|
|
33
|
+
-moz-appearance: none;
|
|
34
|
+
appearance: none;
|
|
35
|
+
pointer-events: none;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
[data-star-rating] > select::before,
|
|
39
|
+
[data-star-rating] > select::after {
|
|
40
|
+
display: none !important;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
[data-star-rating].gl-star-rating--ltr > select {
|
|
44
|
+
left: 0 !important;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
[data-star-rating].gl-star-rating--rtl > select {
|
|
48
|
+
right: 0 !important;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
[data-star-rating] {
|
|
52
|
+
align-items: center;
|
|
53
|
+
display: flex;
|
|
54
|
+
position: relative;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.gl-star-rating:not([data-star-rating]) .gl-star-rating--stars {
|
|
58
|
+
display: none;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
[data-star-rating] .gl-star-rating--stars {
|
|
62
|
+
align-items: center;
|
|
63
|
+
cursor: pointer;
|
|
64
|
+
display: flex;
|
|
65
|
+
position: relative;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
[data-star-rating] > select:focus + .gl-star-rating--stars span:first-child::before {
|
|
69
|
+
box-shadow: 0 0 0 3px -moz-mac-focusring;
|
|
70
|
+
box-shadow: 0 0 0 3px -webkit-focus-ring-color;
|
|
71
|
+
box-shadow: 0 0 0 3px Highlight;
|
|
72
|
+
content: '';
|
|
73
|
+
display: block;
|
|
74
|
+
height: 100%;
|
|
75
|
+
outline: 1px solid transparent;
|
|
76
|
+
pointer-events: none;
|
|
77
|
+
position: absolute;
|
|
78
|
+
width: 100%;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
[data-star-rating] select[disabled] + .gl-star-rating--stars {
|
|
82
|
+
cursor: default;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
[data-star-rating] .gl-star-rating--stars > span {
|
|
86
|
+
display: flex;
|
|
87
|
+
height: 24px;
|
|
88
|
+
height: 24px;
|
|
89
|
+
height: var(--gl-star-size);
|
|
90
|
+
margin: 0;
|
|
91
|
+
width: 24px;
|
|
92
|
+
width: 24px;
|
|
93
|
+
width: var(--gl-star-size);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
[data-star-rating] .gl-star-rating--stars[aria-label]::before,
|
|
97
|
+
[data-star-rating] .gl-star-rating--stars[aria-label]::after {
|
|
98
|
+
-webkit-backface-visibility: hidden;
|
|
99
|
+
backface-visibility: hidden;
|
|
100
|
+
bottom: auto;
|
|
101
|
+
box-sizing: border-box;
|
|
102
|
+
left: 100%;
|
|
103
|
+
pointer-events: none;
|
|
104
|
+
position: absolute;
|
|
105
|
+
top: 50%;
|
|
106
|
+
opacity: .9;
|
|
107
|
+
transform-origin: top;
|
|
108
|
+
transform: translate3d(0,-50%,0);
|
|
109
|
+
white-space: nowrap;
|
|
110
|
+
z-index: 10;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
[data-star-rating] .gl-star-rating--stars[aria-label]::before {
|
|
114
|
+
background-size: 100% auto !important;
|
|
115
|
+
background-position: 50% !important;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
[data-star-rating] .gl-star-rating--stars[aria-label]::before {
|
|
119
|
+
background: url('data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 12 31"%3E%3Cpath fill="%23111" d="M12.002 31C12.002 25 0 19.838 0 15.5 0 11.24 12 6 12 0l.002 31z"/%3E%3C/svg%3E') no-repeat;
|
|
120
|
+
content: '';
|
|
121
|
+
height: 18px;
|
|
122
|
+
margin-bottom: 0;
|
|
123
|
+
margin-left: 6px;
|
|
124
|
+
margin-left: 6px;
|
|
125
|
+
margin-left: var(--gl-tooltip-size);
|
|
126
|
+
width: 6px;
|
|
127
|
+
width: 6px;
|
|
128
|
+
width: var(--gl-tooltip-size);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
[data-star-rating] .gl-star-rating--stars[aria-label]::after {
|
|
132
|
+
background: #111;
|
|
133
|
+
border-radius: 4px;
|
|
134
|
+
border-radius: 4px;
|
|
135
|
+
border-radius: var(--gl-tooltip-border-radius);
|
|
136
|
+
color: #fff;
|
|
137
|
+
content: attr(aria-label);
|
|
138
|
+
font-size: 0.875rem;
|
|
139
|
+
font-size: 0.875rem;
|
|
140
|
+
font-size: var(--gl-tooltip-font-size);
|
|
141
|
+
font-weight: normal;
|
|
142
|
+
margin-left: 12px;
|
|
143
|
+
margin-left: 12px;
|
|
144
|
+
margin-left: var(--gl-tooltip-margin);
|
|
145
|
+
padding: .5em 1em;
|
|
146
|
+
padding: .5em 1em;
|
|
147
|
+
padding: var(--gl-tooltip-padding);
|
|
148
|
+
text-transform: none;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
[data-star-rating].gl-star-rating--rtl .gl-star-rating--stars[aria-label]::before,
|
|
152
|
+
[data-star-rating].gl-star-rating--rtl .gl-star-rating--stars[aria-label]::after {
|
|
153
|
+
left: auto;
|
|
154
|
+
right: 100%;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
[data-star-rating].gl-star-rating--rtl .gl-star-rating--stars[aria-label]::before {
|
|
158
|
+
transform: scaleX(-1) translate3d(0,-50%,0);
|
|
159
|
+
margin-left: 0;
|
|
160
|
+
margin-right: 6px;
|
|
161
|
+
margin-right: 6px;
|
|
162
|
+
margin-right: var(--gl-tooltip-size);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
[data-star-rating].gl-star-rating--rtl .gl-star-rating--stars[aria-label]::after {
|
|
166
|
+
margin-left: 0;
|
|
167
|
+
margin-right: 12px;
|
|
168
|
+
margin-right: 12px;
|
|
169
|
+
margin-right: var(--gl-tooltip-margin);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
[data-star-rating] svg {
|
|
173
|
+
height: 100%;
|
|
174
|
+
width: 100%;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
[data-star-rating] .gl-star-half {
|
|
178
|
+
fill: none;
|
|
179
|
+
stroke: none;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
[data-star-rating] .gl-star-full {
|
|
183
|
+
fill: #dcdce6;
|
|
184
|
+
fill: #dcdce6;
|
|
185
|
+
fill: var(--gl-star-color-inactive);
|
|
186
|
+
stroke: #dcdce6;
|
|
187
|
+
stroke: #dcdce6;
|
|
188
|
+
stroke: var(--gl-star-color-inactive);
|
|
189
|
+
transition: fill 0.15s ease-in-out, stroke 0.15s ease-in-out;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
[data-star-rating] .gl-active .gl-star-full {
|
|
193
|
+
fill: #fdd835;
|
|
194
|
+
fill: #fdd835;
|
|
195
|
+
fill: var(--gl-star-color);
|
|
196
|
+
stroke: #fdd835;
|
|
197
|
+
stroke: #fdd835;
|
|
198
|
+
stroke: var(--gl-star-color);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/* Compatibilty with v3 */
|
|
202
|
+
|
|
203
|
+
.gl-star-rating--stars[class*=" s"] > span {
|
|
204
|
+
background-image: url('../img/star-empty.svg') !important;
|
|
205
|
+
background-image: url('../img/star-empty.svg') !important;
|
|
206
|
+
background-image: var(--gl-star-empty) !important;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.gl-star-rating--stars[class*=" s"] > span {
|
|
210
|
+
background-position: center;
|
|
211
|
+
background-repeat: no-repeat;
|
|
212
|
+
background-size: 90%;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.gl-star-rating--stars[class*=" s"] > span.gl-active,
|
|
216
|
+
.gl-star-rating--stars[class*=" s"] > span.gl-active.gl-selected {
|
|
217
|
+
background-image: url('../img/star-full.svg') !important;
|
|
218
|
+
background-image: url('../img/star-full.svg') !important;
|
|
219
|
+
background-image: var(--gl-star-full) !important;
|
|
220
|
+
}
|