luda 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +5 -0
- data/assets/javascripts/luda-degradation.js +131 -0
- data/assets/javascripts/luda-degradation.js.map +1 -0
- data/assets/javascripts/luda-degradation.min.js +7 -0
- data/assets/javascripts/luda-degradation.min.js.map +1 -0
- data/assets/javascripts/luda-sprockets.js +11 -0
- data/assets/javascripts/luda.js +2024 -0
- data/assets/javascripts/luda.js.map +1 -0
- data/assets/javascripts/luda.min.js +7 -0
- data/assets/javascripts/luda.min.js.map +1 -0
- data/assets/javascripts/luda/behaviours/enter-click.js +38 -0
- data/assets/javascripts/luda/behaviours/focus.js +103 -0
- data/assets/javascripts/luda/behaviours/radio-tab.js +69 -0
- data/assets/javascripts/luda/behaviours/readonly.js +57 -0
- data/assets/javascripts/luda/behaviours/toggle.js +104 -0
- data/assets/javascripts/luda/collections/carousel.js +314 -0
- data/assets/javascripts/luda/collections/dropdown.js +269 -0
- data/assets/javascripts/luda/collections/form-dropdown.js +112 -0
- data/assets/javascripts/luda/collections/tab.js +117 -0
- data/assets/javascripts/luda/component.js +240 -0
- data/assets/javascripts/luda/constants.js +18 -0
- data/assets/javascripts/luda/degradation.js +125 -0
- data/assets/javascripts/luda/dom.js +81 -0
- data/assets/javascripts/luda/elements/form-file.js +104 -0
- data/assets/javascripts/luda/elements/form-select.js +212 -0
- data/assets/javascripts/luda/event.js +193 -0
- data/assets/javascripts/luda/index.js +20 -0
- data/assets/javascripts/luda/install.js +75 -0
- data/assets/javascripts/luda/singleton.js +77 -0
- data/assets/javascripts/luda/utilities.js +16 -0
- data/assets/stylesheets/luda/_core/_base.sass +430 -0
- data/assets/stylesheets/luda/_core/_functions.sass +240 -0
- data/assets/stylesheets/luda/_core/_variables.sass +710 -0
- data/assets/stylesheets/luda/_core/behaviours/_disabled.sass +12 -0
- data/assets/stylesheets/luda/_core/behaviours/_focus.sass +7 -0
- data/assets/stylesheets/luda/_core/behaviours/_readonly.sass +16 -0
- data/assets/stylesheets/luda/_core/behaviours/_toggle.sass +4 -0
- data/assets/stylesheets/luda/_core/collections/_alert.sass +24 -0
- data/assets/stylesheets/luda/_core/collections/_avatar.sass +117 -0
- data/assets/stylesheets/luda/_core/collections/_breadcrumb.sass +21 -0
- data/assets/stylesheets/luda/_core/collections/_button-group.sass +67 -0
- data/assets/stylesheets/luda/_core/collections/_button-icon.sass +46 -0
- data/assets/stylesheets/luda/_core/collections/_carousel.sass +132 -0
- data/assets/stylesheets/luda/_core/collections/_dropdown.sass +60 -0
- data/assets/stylesheets/luda/_core/collections/_form-button.sass +23 -0
- data/assets/stylesheets/luda/_core/collections/_form-dropdown.sass +21 -0
- data/assets/stylesheets/luda/_core/collections/_form-group.sass +48 -0
- data/assets/stylesheets/luda/_core/collections/_form-icon.sass +71 -0
- data/assets/stylesheets/luda/_core/collections/_media.sass +55 -0
- data/assets/stylesheets/luda/_core/collections/_modal.sass +12 -0
- data/assets/stylesheets/luda/_core/collections/_nav.sass +162 -0
- data/assets/stylesheets/luda/_core/collections/_tab.sass +18 -0
- data/assets/stylesheets/luda/_core/elements/_badge.sass +19 -0
- data/assets/stylesheets/luda/_core/elements/_baseline.sass +22 -0
- data/assets/stylesheets/luda/_core/elements/_button.sass +136 -0
- data/assets/stylesheets/luda/_core/elements/_container.sass +8 -0
- data/assets/stylesheets/luda/_core/elements/_grid.sass +55 -0
- data/assets/stylesheets/luda/_core/elements/_icon.sass +110 -0
- data/assets/stylesheets/luda/_core/elements/_overlay.sass +11 -0
- data/assets/stylesheets/luda/_core/elements/_progress.sass +31 -0
- data/assets/stylesheets/luda/_core/elements/_scrollbar.sass +21 -0
- data/assets/stylesheets/luda/_core/elements/_table.sass +102 -0
- data/assets/stylesheets/luda/_core/elements/_turbolinks-progress-bar.sass +5 -0
- data/assets/stylesheets/luda/_core/elements/form/_form-check-radio.sass +105 -0
- data/assets/stylesheets/luda/_core/elements/form/_form-element.sass +83 -0
- data/assets/stylesheets/luda/_core/elements/form/_form-helper.sass +66 -0
- data/assets/stylesheets/luda/_core/elements/form/_form-label.sass +20 -0
- data/assets/stylesheets/luda/_core/elements/form/_form-range.sass +92 -0
- data/assets/stylesheets/luda/_core/elements/form/_form-row.sass +214 -0
- data/assets/stylesheets/luda/_core/elements/typography/_code.sass +27 -0
- data/assets/stylesheets/luda/_core/elements/typography/_link.sass +15 -0
- data/assets/stylesheets/luda/_core/elements/typography/_list.sass +14 -0
- data/assets/stylesheets/luda/_core/elements/typography/_mark.sass +7 -0
- data/assets/stylesheets/luda/_core/elements/typography/_quote.sass +68 -0
- data/assets/stylesheets/luda/_core/elements/typography/_sub-sup.sass +16 -0
- data/assets/stylesheets/luda/_core/elements/typography/_typography.sass +52 -0
- data/assets/stylesheets/luda/_core/mixins/_browser.sass +15 -0
- data/assets/stylesheets/luda/_core/mixins/_button.sass +90 -0
- data/assets/stylesheets/luda/_core/mixins/_dropdown.sass +40 -0
- data/assets/stylesheets/luda/_core/mixins/_focus.sass +3 -0
- data/assets/stylesheets/luda/_core/mixins/_form.sass +27 -0
- data/assets/stylesheets/luda/_core/mixins/_install.sass +7 -0
- data/assets/stylesheets/luda/_core/mixins/_media-query.sass +66 -0
- data/assets/stylesheets/luda/_core/mixins/_overlay.sass +14 -0
- data/assets/stylesheets/luda/_core/mixins/_sass-lint-fix.sass +3 -0
- data/assets/stylesheets/luda/_core/mixins/_typography.sass +40 -0
- data/assets/stylesheets/luda/_core/utilities/_align.sass +19 -0
- data/assets/stylesheets/luda/_core/utilities/_background.sass +88 -0
- data/assets/stylesheets/luda/_core/utilities/_color.sass +36 -0
- data/assets/stylesheets/luda/_core/utilities/_display.sass +40 -0
- data/assets/stylesheets/luda/_core/utilities/_flex.sass +114 -0
- data/assets/stylesheets/luda/_core/utilities/_float.sass +21 -0
- data/assets/stylesheets/luda/_core/utilities/_opacity.sass +19 -0
- data/assets/stylesheets/luda/_core/utilities/_overflow.sass +18 -0
- data/assets/stylesheets/luda/_core/utilities/_position.sass +48 -0
- data/assets/stylesheets/luda/_core/utilities/_shape.sass +62 -0
- data/assets/stylesheets/luda/_core/utilities/_size.sass +67 -0
- data/assets/stylesheets/luda/_core/utilities/_space.sass +227 -0
- data/assets/stylesheets/luda/_core/utilities/_text.sass +85 -0
- data/assets/stylesheets/luda/_core/utilities/_visibility.sass +11 -0
- data/assets/stylesheets/luda/_core/utilities/_z-index.sass +19 -0
- data/assets/stylesheets/luda/_default.sass +51 -0
- data/assets/stylesheets/luda/core/_base.sass +430 -0
- data/assets/stylesheets/luda/core/_functions.sass +240 -0
- data/assets/stylesheets/luda/core/_variables.sass +710 -0
- data/assets/stylesheets/luda/core/behaviours/_disabled.sass +12 -0
- data/assets/stylesheets/luda/core/behaviours/_focus.sass +7 -0
- data/assets/stylesheets/luda/core/behaviours/_readonly.sass +16 -0
- data/assets/stylesheets/luda/core/behaviours/_toggle.sass +4 -0
- data/assets/stylesheets/luda/core/collections/_alert.sass +24 -0
- data/assets/stylesheets/luda/core/collections/_avatar.sass +117 -0
- data/assets/stylesheets/luda/core/collections/_breadcrumb.sass +21 -0
- data/assets/stylesheets/luda/core/collections/_button-group.sass +67 -0
- data/assets/stylesheets/luda/core/collections/_button-icon.sass +46 -0
- data/assets/stylesheets/luda/core/collections/_carousel.sass +132 -0
- data/assets/stylesheets/luda/core/collections/_dropdown.sass +60 -0
- data/assets/stylesheets/luda/core/collections/_form-button.sass +23 -0
- data/assets/stylesheets/luda/core/collections/_form-dropdown.sass +21 -0
- data/assets/stylesheets/luda/core/collections/_form-group.sass +48 -0
- data/assets/stylesheets/luda/core/collections/_form-icon.sass +71 -0
- data/assets/stylesheets/luda/core/collections/_media.sass +55 -0
- data/assets/stylesheets/luda/core/collections/_modal.sass +12 -0
- data/assets/stylesheets/luda/core/collections/_nav.sass +162 -0
- data/assets/stylesheets/luda/core/collections/_tab.sass +18 -0
- data/assets/stylesheets/luda/core/elements/_badge.sass +19 -0
- data/assets/stylesheets/luda/core/elements/_baseline.sass +22 -0
- data/assets/stylesheets/luda/core/elements/_button.sass +136 -0
- data/assets/stylesheets/luda/core/elements/_container.sass +8 -0
- data/assets/stylesheets/luda/core/elements/_grid.sass +55 -0
- data/assets/stylesheets/luda/core/elements/_icon.sass +110 -0
- data/assets/stylesheets/luda/core/elements/_overlay.sass +11 -0
- data/assets/stylesheets/luda/core/elements/_progress.sass +31 -0
- data/assets/stylesheets/luda/core/elements/_scrollbar.sass +21 -0
- data/assets/stylesheets/luda/core/elements/_table.sass +102 -0
- data/assets/stylesheets/luda/core/elements/_turbolinks-progress-bar.sass +5 -0
- data/assets/stylesheets/luda/core/elements/form/_form-check-radio.sass +105 -0
- data/assets/stylesheets/luda/core/elements/form/_form-element.sass +83 -0
- data/assets/stylesheets/luda/core/elements/form/_form-helper.sass +66 -0
- data/assets/stylesheets/luda/core/elements/form/_form-label.sass +20 -0
- data/assets/stylesheets/luda/core/elements/form/_form-range.sass +92 -0
- data/assets/stylesheets/luda/core/elements/form/_form-row.sass +214 -0
- data/assets/stylesheets/luda/core/elements/typography/_code.sass +27 -0
- data/assets/stylesheets/luda/core/elements/typography/_link.sass +15 -0
- data/assets/stylesheets/luda/core/elements/typography/_list.sass +14 -0
- data/assets/stylesheets/luda/core/elements/typography/_mark.sass +7 -0
- data/assets/stylesheets/luda/core/elements/typography/_quote.sass +68 -0
- data/assets/stylesheets/luda/core/elements/typography/_sub-sup.sass +16 -0
- data/assets/stylesheets/luda/core/elements/typography/_typography.sass +52 -0
- data/assets/stylesheets/luda/core/mixins/_browser.sass +15 -0
- data/assets/stylesheets/luda/core/mixins/_button.sass +90 -0
- data/assets/stylesheets/luda/core/mixins/_dropdown.sass +40 -0
- data/assets/stylesheets/luda/core/mixins/_focus.sass +3 -0
- data/assets/stylesheets/luda/core/mixins/_form.sass +27 -0
- data/assets/stylesheets/luda/core/mixins/_install.sass +7 -0
- data/assets/stylesheets/luda/core/mixins/_media-query.sass +66 -0
- data/assets/stylesheets/luda/core/mixins/_overlay.sass +14 -0
- data/assets/stylesheets/luda/core/mixins/_sass-lint-fix.sass +3 -0
- data/assets/stylesheets/luda/core/mixins/_typography.sass +40 -0
- data/assets/stylesheets/luda/core/utilities/_align.sass +19 -0
- data/assets/stylesheets/luda/core/utilities/_background.sass +88 -0
- data/assets/stylesheets/luda/core/utilities/_color.sass +36 -0
- data/assets/stylesheets/luda/core/utilities/_display.sass +40 -0
- data/assets/stylesheets/luda/core/utilities/_flex.sass +114 -0
- data/assets/stylesheets/luda/core/utilities/_float.sass +21 -0
- data/assets/stylesheets/luda/core/utilities/_opacity.sass +19 -0
- data/assets/stylesheets/luda/core/utilities/_overflow.sass +18 -0
- data/assets/stylesheets/luda/core/utilities/_position.sass +48 -0
- data/assets/stylesheets/luda/core/utilities/_shape.sass +62 -0
- data/assets/stylesheets/luda/core/utilities/_size.sass +67 -0
- data/assets/stylesheets/luda/core/utilities/_space.sass +227 -0
- data/assets/stylesheets/luda/core/utilities/_text.sass +85 -0
- data/assets/stylesheets/luda/core/utilities/_visibility.sass +11 -0
- data/assets/stylesheets/luda/core/utilities/_z-index.sass +19 -0
- data/assets/stylesheets/luda/default/_banner.sass +7 -0
- data/assets/stylesheets/luda/default/_base.sass +6 -0
- data/assets/stylesheets/luda/default/_functions.sass +1 -0
- data/assets/stylesheets/luda/default/_mixins.sass +10 -0
- data/assets/stylesheets/luda/default/_variables.sass +1 -0
- data/assets/stylesheets/luda/default/behaviours/_disabled.sass +5 -0
- data/assets/stylesheets/luda/default/behaviours/_focus.sass +5 -0
- data/assets/stylesheets/luda/default/behaviours/_readonly.sass +5 -0
- data/assets/stylesheets/luda/default/behaviours/_toggle.sass +5 -0
- data/assets/stylesheets/luda/default/collections/_alert.sass +6 -0
- data/assets/stylesheets/luda/default/collections/_avatar.sass +7 -0
- data/assets/stylesheets/luda/default/collections/_breadcrumb.sass +6 -0
- data/assets/stylesheets/luda/default/collections/_button-group.sass +7 -0
- data/assets/stylesheets/luda/default/collections/_button-icon.sass +8 -0
- data/assets/stylesheets/luda/default/collections/_carousel.sass +7 -0
- data/assets/stylesheets/luda/default/collections/_dropdown.sass +8 -0
- data/assets/stylesheets/luda/default/collections/_form-button.sass +9 -0
- data/assets/stylesheets/luda/default/collections/_form-dropdown.sass +8 -0
- data/assets/stylesheets/luda/default/collections/_form-group.sass +11 -0
- data/assets/stylesheets/luda/default/collections/_form-icon.sass +8 -0
- data/assets/stylesheets/luda/default/collections/_media.sass +7 -0
- data/assets/stylesheets/luda/default/collections/_modal.sass +7 -0
- data/assets/stylesheets/luda/default/collections/_nav.sass +10 -0
- data/assets/stylesheets/luda/default/collections/_tab.sass +9 -0
- data/assets/stylesheets/luda/default/elements/_badge.sass +6 -0
- data/assets/stylesheets/luda/default/elements/_baseline.sass +6 -0
- data/assets/stylesheets/luda/default/elements/_button.sass +7 -0
- data/assets/stylesheets/luda/default/elements/_container.sass +6 -0
- data/assets/stylesheets/luda/default/elements/_form.sass +13 -0
- data/assets/stylesheets/luda/default/elements/_grid.sass +6 -0
- data/assets/stylesheets/luda/default/elements/_icon.sass +6 -0
- data/assets/stylesheets/luda/default/elements/_overlay.sass +6 -0
- data/assets/stylesheets/luda/default/elements/_progress.sass +6 -0
- data/assets/stylesheets/luda/default/elements/_scrollbar.sass +6 -0
- data/assets/stylesheets/luda/default/elements/_table.sass +6 -0
- data/assets/stylesheets/luda/default/elements/_turbolinks-progress-bar.sass +6 -0
- data/assets/stylesheets/luda/default/elements/_typography.sass +12 -0
- data/assets/stylesheets/luda/default/elements/form/_form-check-radio.sass +5 -0
- data/assets/stylesheets/luda/default/elements/form/_form-element.sass +5 -0
- data/assets/stylesheets/luda/default/elements/form/_form-helper.sass +5 -0
- data/assets/stylesheets/luda/default/elements/form/_form-label.sass +5 -0
- data/assets/stylesheets/luda/default/elements/form/_form-range.sass +5 -0
- data/assets/stylesheets/luda/default/elements/form/_form-row.sass +5 -0
- data/assets/stylesheets/luda/default/elements/typography/_code.sass +5 -0
- data/assets/stylesheets/luda/default/elements/typography/_link.sass +5 -0
- data/assets/stylesheets/luda/default/elements/typography/_list.sass +4 -0
- data/assets/stylesheets/luda/default/elements/typography/_mark.sass +5 -0
- data/assets/stylesheets/luda/default/elements/typography/_quote.sass +5 -0
- data/assets/stylesheets/luda/default/elements/typography/_sub-sup.sass +5 -0
- data/assets/stylesheets/luda/default/elements/typography/_typography.sass +5 -0
- data/assets/stylesheets/luda/default/index.sass +56 -0
- data/assets/stylesheets/luda/default/utilities/_align.sass +5 -0
- data/assets/stylesheets/luda/default/utilities/_background.sass +5 -0
- data/assets/stylesheets/luda/default/utilities/_color.sass +5 -0
- data/assets/stylesheets/luda/default/utilities/_display.sass +5 -0
- data/assets/stylesheets/luda/default/utilities/_flex.sass +5 -0
- data/assets/stylesheets/luda/default/utilities/_float.sass +5 -0
- data/assets/stylesheets/luda/default/utilities/_opacity.sass +5 -0
- data/assets/stylesheets/luda/default/utilities/_overflow.sass +5 -0
- data/assets/stylesheets/luda/default/utilities/_position.sass +5 -0
- data/assets/stylesheets/luda/default/utilities/_shape.sass +5 -0
- data/assets/stylesheets/luda/default/utilities/_size.sass +5 -0
- data/assets/stylesheets/luda/default/utilities/_space.sass +5 -0
- data/assets/stylesheets/luda/default/utilities/_text.sass +5 -0
- data/assets/stylesheets/luda/default/utilities/_visibility.sass +5 -0
- data/assets/stylesheets/luda/default/utilities/_z-index.sass +5 -0
- data/lib/luda.rb +72 -0
- data/lib/luda/config.rb +3 -0
- data/lib/luda/engine.rb +11 -0
- data/lib/luda/version.rb +3 -0
- metadata +302 -0
@@ -0,0 +1,104 @@
|
|
1
|
+
//= require ../install
|
2
|
+
//= require ../dom
|
3
|
+
//= require ../event
|
4
|
+
//= require ../component
|
5
|
+
(function (global, factory) {
|
6
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../install.js'), require('../dom.js'), require('../event.js'), require('../component.js')) :
|
7
|
+
typeof define === 'function' && define.amd ? define(['../install.js', '../dom.js', '../event.js', '../component.js'], factory) :
|
8
|
+
(factory());
|
9
|
+
}(this, (function () { 'use strict';
|
10
|
+
|
11
|
+
luda((function() {
|
12
|
+
var _Class;
|
13
|
+
|
14
|
+
_Class = class extends luda.Component {
|
15
|
+
_getConfig() {
|
16
|
+
var _$file, _$simulator;
|
17
|
+
_$file = luda.$child(this.constructor._FILE_SELECTOR, this._$component);
|
18
|
+
_$simulator = luda.$child(this.constructor._SIMULATOR_SELECTOR, this._$component);
|
19
|
+
return {_$file, _$simulator};
|
20
|
+
}
|
21
|
+
|
22
|
+
_constructor() {
|
23
|
+
({_$file: this._$file, _$simulator: this._$simulator} = this._getConfig());
|
24
|
+
return this._init();
|
25
|
+
}
|
26
|
+
|
27
|
+
_onMutations() {
|
28
|
+
return this._constructor();
|
29
|
+
}
|
30
|
+
|
31
|
+
_insertSimulator() {
|
32
|
+
this._$simulator = document.createElement('input');
|
33
|
+
this._$simulator.tabIndex = -1;
|
34
|
+
return luda.$after(this._$simulator, this._$file);
|
35
|
+
}
|
36
|
+
|
37
|
+
_setPlaceholderValue() {
|
38
|
+
return this._$simulator.placeholder = this._$file.getAttribute(this.constructor._PLACEHOLDER_ATTRIBUTE);
|
39
|
+
}
|
40
|
+
|
41
|
+
_setSimulatorValue() {
|
42
|
+
var values;
|
43
|
+
values = [];
|
44
|
+
Array.from(this._$file.files).map(function(file) {
|
45
|
+
return values.push(file.name);
|
46
|
+
});
|
47
|
+
if (values.length) {
|
48
|
+
return this._$simulator.value = values.join(this.constructor._VALUE_SPLITOR);
|
49
|
+
} else if (this._$file.hasAttribute(this.constructor._VALUE_ATTRIBUTE)) {
|
50
|
+
return this._$simulator.value = this._$file.getAttribute(this.constructor._VALUE_ATTRIBUTE);
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
_init() {
|
55
|
+
if (this._$file) {
|
56
|
+
if (!this._$simulator) {
|
57
|
+
this._insertSimulator();
|
58
|
+
}
|
59
|
+
if (this._$file.hasAttribute(this.constructor._PLACEHOLDER_ATTRIBUTE)) {
|
60
|
+
this._setPlaceholderValue();
|
61
|
+
}
|
62
|
+
return this._setSimulatorValue();
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
static _init() {
|
67
|
+
var self;
|
68
|
+
self = this;
|
69
|
+
luda.on('change', `${this._SELECTOR} ${this._FILE_SELECTOR}`, function(e) {
|
70
|
+
return self.query(luda.$parent(self._SELECTOR, this))._setSimulatorValue();
|
71
|
+
});
|
72
|
+
return luda.on(luda._FORM_RESET, this._SELECTOR, function(e) {
|
73
|
+
return setTimeout(() => {
|
74
|
+
return self.query(this)._setSimulatorValue();
|
75
|
+
});
|
76
|
+
});
|
77
|
+
}
|
78
|
+
|
79
|
+
};
|
80
|
+
|
81
|
+
_Class._SCOPE = 'fmFile';
|
82
|
+
|
83
|
+
_Class._VALUE_SPLITOR = ' ';
|
84
|
+
|
85
|
+
_Class._SELECTOR = '.fm-file';
|
86
|
+
|
87
|
+
_Class._FILE_SELECTOR = 'input[type=file]';
|
88
|
+
|
89
|
+
_Class._SIMULATOR_SELECTOR = 'input:not([type=file])';
|
90
|
+
|
91
|
+
_Class._PLACEHOLDER_ATTRIBUTE = 'placeholder';
|
92
|
+
|
93
|
+
_Class._VALUE_ATTRIBUTE = 'value';
|
94
|
+
|
95
|
+
_Class._observerConfig = {
|
96
|
+
childList: true,
|
97
|
+
subtree: true
|
98
|
+
};
|
99
|
+
|
100
|
+
return _Class;
|
101
|
+
|
102
|
+
}).call(this));
|
103
|
+
|
104
|
+
})));
|
@@ -0,0 +1,212 @@
|
|
1
|
+
//= require ../install
|
2
|
+
//= require ../dom
|
3
|
+
//= require ../event
|
4
|
+
//= require ../component
|
5
|
+
(function (global, factory) {
|
6
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../install.js'), require('../dom.js'), require('../event.js'), require('../component.js')) :
|
7
|
+
typeof define === 'function' && define.amd ? define(['../install.js', '../dom.js', '../event.js', '../component.js'], factory) :
|
8
|
+
(factory());
|
9
|
+
}(this, (function () { 'use strict';
|
10
|
+
|
11
|
+
luda((function() {
|
12
|
+
var _Class;
|
13
|
+
|
14
|
+
_Class = class extends luda.Component {
|
15
|
+
select(indexOrIndexArray) {
|
16
|
+
var selectedIndexes;
|
17
|
+
if (this._$select.multiple) {
|
18
|
+
if (this._$multipleSelectPlaceholder) {
|
19
|
+
selectedIndexes = indexOrIndexArray;
|
20
|
+
} else {
|
21
|
+
selectedIndexes = indexOrIndexArray.map(function(index) {
|
22
|
+
return index + 1;
|
23
|
+
});
|
24
|
+
}
|
25
|
+
Array.from(this._$select.options).forEach(function($option, index) {
|
26
|
+
return $option.selected = selectedIndexes.includes(index);
|
27
|
+
});
|
28
|
+
return this._markSelectedOption();
|
29
|
+
} else {
|
30
|
+
this._$select.selectedIndex = selectedIndex;
|
31
|
+
this._setSingleSelectSimulatorValue();
|
32
|
+
return this._markSelectedOption();
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
_getConfig() {
|
37
|
+
var _$defaultSelectedOptions, _$multipleSelectPlaceholder, _$select, _$singleSelectSimulator, _defaultSelectedOptionMarked;
|
38
|
+
_$select = luda.$child(this.constructor._SELECT_SELECTOR, this._$component);
|
39
|
+
_$singleSelectSimulator = luda.$child(this.constructor._SINGLE_SELECT_SIMULATOR_SELECTOR, this._$component);
|
40
|
+
_$multipleSelectPlaceholder = luda.$child(`.${this.constructor._MULTIPLE_SELECT_PLACEHOLDER_CSS_CLASS}`, this._$component);
|
41
|
+
_$defaultSelectedOptions = luda.$children(`[${this.constructor._DEFAULT_SELECTED_OPTION_ATTRIBUTE}]`, this._$component);
|
42
|
+
_defaultSelectedOptionMarked = this._$component.hasAttribute(this.constructor._INITED_ATTRIBUTE);
|
43
|
+
return {_$select, _$singleSelectSimulator, _$multipleSelectPlaceholder, _$defaultSelectedOptions, _defaultSelectedOptionMarked};
|
44
|
+
}
|
45
|
+
|
46
|
+
_constructor() {
|
47
|
+
({_$select: this._$select, _$singleSelectSimulator: this._$singleSelectSimulator, _$multipleSelectPlaceholder: this._$multipleSelectPlaceholder, _$defaultSelectedOptions: this._$defaultSelectedOptions, _defaultSelectedOptionMarked: this._defaultSelectedOptionMarked} = this._getConfig());
|
48
|
+
if (this._$select) {
|
49
|
+
if (this._$select.multiple) {
|
50
|
+
return this._initMultipleSelect();
|
51
|
+
} else {
|
52
|
+
return this._initSingleSelect();
|
53
|
+
}
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
_onMutations() {
|
58
|
+
return this._constructor();
|
59
|
+
}
|
60
|
+
|
61
|
+
_markSelectedOption() {
|
62
|
+
if (this._observer) {
|
63
|
+
this._disconnect();
|
64
|
+
}
|
65
|
+
Array.from(this._$select.options).forEach(function($option) {
|
66
|
+
if ($option.selected) {
|
67
|
+
return $option.setAttribute('selected', 'selected');
|
68
|
+
} else {
|
69
|
+
return $option.removeAttribute('selected');
|
70
|
+
}
|
71
|
+
});
|
72
|
+
if (!this._observer) {
|
73
|
+
return this._observe();
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
_markDefaultSelectedOption() {
|
78
|
+
this._$component.setAttribute(this.constructor._INITED_ATTRIBUTE, '');
|
79
|
+
return Array.from(this._$select.options).forEach(($option) => {
|
80
|
+
if ($option.selected) {
|
81
|
+
return $option.setAttribute(this.constructor._DEFAULT_SELECTED_OPTION_ATTRIBUTE, '');
|
82
|
+
}
|
83
|
+
});
|
84
|
+
}
|
85
|
+
|
86
|
+
_setSingleSelectedDefaultSelectedOption() {
|
87
|
+
var hasSelected;
|
88
|
+
hasSelected = Array.from(this._$select.options).some(function($option) {
|
89
|
+
return $option.getAttribute('selected') === 'selected';
|
90
|
+
});
|
91
|
+
if (!hasSelected) {
|
92
|
+
return this._$select.selectedIndex = -1;
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
_insertSingleSelectSimulator() {
|
97
|
+
this._$singleSelectSimulator = document.createElement('input');
|
98
|
+
this._$singleSelectSimulator.tabIndex = -1;
|
99
|
+
return luda.$after(this._$singleSelectSimulator, this._$select);
|
100
|
+
}
|
101
|
+
|
102
|
+
_setSingleSelectPlaceholderValue() {
|
103
|
+
return this._$singleSelectSimulator.placeholder = this._$select.getAttribute(this.constructor._PLACEHOLDER_ATTRIBUTE);
|
104
|
+
}
|
105
|
+
|
106
|
+
_setSingleSelectSimulatorValue() {
|
107
|
+
var $selectedOption;
|
108
|
+
if ($selectedOption = this._$select.options[this._$select.selectedIndex]) {
|
109
|
+
return this._$singleSelectSimulator.value = $selectedOption.innerText;
|
110
|
+
} else {
|
111
|
+
return this._$singleSelectSimulator.value = '';
|
112
|
+
}
|
113
|
+
}
|
114
|
+
|
115
|
+
_initSingleSelect() {
|
116
|
+
if (!this._$singleSelectSimulator) {
|
117
|
+
this._insertSingleSelectSimulator();
|
118
|
+
}
|
119
|
+
if (this._$select.hasAttribute(this.constructor._PLACEHOLDER_ATTRIBUTE)) {
|
120
|
+
this._setSingleSelectedDefaultSelectedOption();
|
121
|
+
this._setSingleSelectPlaceholderValue();
|
122
|
+
}
|
123
|
+
if (!this._defaultSelectedOptionMarked) {
|
124
|
+
this._markDefaultSelectedOption();
|
125
|
+
}
|
126
|
+
this._setSingleSelectSimulatorValue();
|
127
|
+
return this._markSelectedOption();
|
128
|
+
}
|
129
|
+
|
130
|
+
_insertMultipleSelectBlankOption() {
|
131
|
+
this._$multipleSelectPlaceholder = document.createElement('option');
|
132
|
+
this._$multipleSelectPlaceholder.className = this.constructor._MULTIPLE_SELECT_PLACEHOLDER_CSS_CLASS;
|
133
|
+
this._$multipleSelectPlaceholder.disabled = true;
|
134
|
+
return luda.$prepend(this._$multipleSelectPlaceholder, this._$select);
|
135
|
+
}
|
136
|
+
|
137
|
+
_setMultipleSelectPlaceholderValue() {
|
138
|
+
return this._$multipleSelectPlaceholder.innerText = this._$select.getAttribute(this.constructor._PLACEHOLDER_ATTRIBUTE);
|
139
|
+
}
|
140
|
+
|
141
|
+
_initMultipleSelect() {
|
142
|
+
if (!this._$multipleSelectPlaceholder) {
|
143
|
+
if (this._$select.hasAttribute(this.constructor._PLACEHOLDER_ATTRIBUTE)) {
|
144
|
+
this._insertMultipleSelectBlankOption();
|
145
|
+
this._setMultipleSelectPlaceholderValue();
|
146
|
+
}
|
147
|
+
}
|
148
|
+
if (!this._defaultSelectedOptionMarked) {
|
149
|
+
return this._markDefaultSelectedOption();
|
150
|
+
}
|
151
|
+
}
|
152
|
+
|
153
|
+
_reset() {
|
154
|
+
if (this._$select) {
|
155
|
+
Array.from(this._$select.options).forEach(($option) => {
|
156
|
+
return $option.selected = this._$defaultSelectedOptions.includes($option);
|
157
|
+
});
|
158
|
+
if (!this._$select.multiple) {
|
159
|
+
this._setSingleSelectSimulatorValue();
|
160
|
+
}
|
161
|
+
return this._markSelectedOption();
|
162
|
+
}
|
163
|
+
}
|
164
|
+
|
165
|
+
static _init() {
|
166
|
+
var self;
|
167
|
+
self = this;
|
168
|
+
luda.on('change', `${this._SELECTOR} ${this._SELECT_SELECTOR}`, function(e) {
|
169
|
+
var instance;
|
170
|
+
instance = self.query(luda.$parent(self._SELECTOR, this));
|
171
|
+
if (!this.multiple) {
|
172
|
+
instance._setSingleSelectSimulatorValue();
|
173
|
+
}
|
174
|
+
return instance._markSelectedOption();
|
175
|
+
});
|
176
|
+
return luda.on(luda._FORM_RESET, this._SELECTOR, function(e) {
|
177
|
+
return setTimeout(() => {
|
178
|
+
return self.query(this)._reset();
|
179
|
+
});
|
180
|
+
});
|
181
|
+
}
|
182
|
+
|
183
|
+
};
|
184
|
+
|
185
|
+
_Class._SCOPE = 'fmSelect';
|
186
|
+
|
187
|
+
_Class._SELECTOR = '.fm-select';
|
188
|
+
|
189
|
+
_Class._SELECT_SELECTOR = 'select';
|
190
|
+
|
191
|
+
_Class._SINGLE_SELECT_SIMULATOR_SELECTOR = 'input';
|
192
|
+
|
193
|
+
_Class._PLACEHOLDER_ATTRIBUTE = 'placeholder';
|
194
|
+
|
195
|
+
_Class._MULTIPLE_SELECT_PLACEHOLDER_CSS_CLASS = 'fm-select-multiple-placeholder';
|
196
|
+
|
197
|
+
_Class._DEFAULT_SELECTED_OPTION_ATTRIBUTE = 'data-fm-select-default-selected';
|
198
|
+
|
199
|
+
_Class._INITED_ATTRIBUTE = 'data-fm-select-inited';
|
200
|
+
|
201
|
+
_Class._observerConfig = {
|
202
|
+
childList: true,
|
203
|
+
attributes: true,
|
204
|
+
subtree: true,
|
205
|
+
attributeFilter: ['selected']
|
206
|
+
};
|
207
|
+
|
208
|
+
return _Class;
|
209
|
+
|
210
|
+
}).call(this));
|
211
|
+
|
212
|
+
})));
|
@@ -0,0 +1,193 @@
|
|
1
|
+
//= require ./install
|
2
|
+
//= require ./dom
|
3
|
+
(function (global, factory) {
|
4
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('./install.js'), require('./dom.js')) :
|
5
|
+
typeof define === 'function' && define.amd ? define(['./install.js', './dom.js'], factory) :
|
6
|
+
(factory());
|
7
|
+
}(this, (function () { 'use strict';
|
8
|
+
|
9
|
+
var splice = [].splice;
|
10
|
+
|
11
|
+
luda({
|
12
|
+
_SWIPE_DISTANCE: 10,
|
13
|
+
_EVENT_TYPE_PREFIX: 'luda',
|
14
|
+
_SWIPE_LEFT: 'swipeleft',
|
15
|
+
_SWIPE_RIGHT: 'swiperight',
|
16
|
+
_SWIPE_UP: 'swipeup',
|
17
|
+
_SWIPE_DOWN: 'swipedown',
|
18
|
+
_SWIPE_LEFT_OR_UP: 'swipeleft or swipeup',
|
19
|
+
_SWIPE_RIGHT_OR_DOWN: 'swiperight or swipedown',
|
20
|
+
_DOC_READY: 'docready',
|
21
|
+
_FORM_RESET: 'reset',
|
22
|
+
eventPath: function(event) {
|
23
|
+
var path;
|
24
|
+
if (event.composedPath) {
|
25
|
+
return path = event.composedPath();
|
26
|
+
} else if (event.path) {
|
27
|
+
return path = event.path;
|
28
|
+
} else {
|
29
|
+
return path = [event.target].concat(luda.$parents('*', event.target));
|
30
|
+
}
|
31
|
+
},
|
32
|
+
on: function(event, ...selector) {
|
33
|
+
var handler, ref;
|
34
|
+
ref = selector, [...selector] = ref, [handler] = splice.call(selector, -1);
|
35
|
+
switch (event) {
|
36
|
+
case this._DOC_READY:
|
37
|
+
return this._onDocReady(handler);
|
38
|
+
case this._FORM_RESET:
|
39
|
+
return this._onReset(selector[0], handler);
|
40
|
+
case this._SWIPE_LEFT:
|
41
|
+
case this._SWIPE_RIGHT:
|
42
|
+
case this._SWIPE_UP:
|
43
|
+
case this._SWIPE_DOWN:
|
44
|
+
case this._SWIPE_LEFT_OR_UP:
|
45
|
+
case this._SWIPE_RIGHT_OR_DOWN:
|
46
|
+
return this._onSwipe(event, selector[0], handler);
|
47
|
+
default:
|
48
|
+
return this._on(event, selector[0], handler);
|
49
|
+
}
|
50
|
+
},
|
51
|
+
onOpposite: function(event, selector, handler) {
|
52
|
+
var _self;
|
53
|
+
_self = this;
|
54
|
+
return document.addEventListener(event, function(e) {
|
55
|
+
var trigger;
|
56
|
+
trigger = _self.eventPath(e).every(function($element) {
|
57
|
+
return !$element.matches || !$element.matches(selector);
|
58
|
+
});
|
59
|
+
if (trigger) {
|
60
|
+
return handler(e);
|
61
|
+
}
|
62
|
+
});
|
63
|
+
},
|
64
|
+
dispatch: function($target, type, detail, options = {}) {
|
65
|
+
var evt;
|
66
|
+
if (typeof options.bubbles !== 'boolean') {
|
67
|
+
options.bubbles = true;
|
68
|
+
}
|
69
|
+
if (typeof options.cancelable !== 'boolean') {
|
70
|
+
options.cancelable = true;
|
71
|
+
}
|
72
|
+
if (typeof options.composed !== 'boolean') {
|
73
|
+
options.composed = true;
|
74
|
+
}
|
75
|
+
evt = new Event(`${this._EVENT_TYPE_PREFIX}:${type}`, options);
|
76
|
+
evt.detail = detail;
|
77
|
+
$target.dispatchEvent(evt);
|
78
|
+
return evt;
|
79
|
+
},
|
80
|
+
_onDocReady: function(handler) {
|
81
|
+
if (document.readyState === 'loading') {
|
82
|
+
return document.addEventListener('DOMContentLoaded', handler);
|
83
|
+
} else {
|
84
|
+
return handler();
|
85
|
+
}
|
86
|
+
},
|
87
|
+
_onReset: function(selector, handler) {
|
88
|
+
return document.addEventListener('reset', function(e) {
|
89
|
+
if (selector != null) {
|
90
|
+
return luda.$children(selector, e.target).forEach(function($element) {
|
91
|
+
return handler.bind($element)(e);
|
92
|
+
});
|
93
|
+
} else {
|
94
|
+
return handler(e);
|
95
|
+
}
|
96
|
+
});
|
97
|
+
},
|
98
|
+
_onSwipe: function(event, selector, handler) {
|
99
|
+
var $touchStartElement, _self, touchStartE, touchStartX, touchStartY, watch;
|
100
|
+
_self = this;
|
101
|
+
watch = false;
|
102
|
+
$touchStartElement = document;
|
103
|
+
touchStartE = null;
|
104
|
+
touchStartX = 0;
|
105
|
+
touchStartY = 0;
|
106
|
+
document.addEventListener('touchstart', function(e) {
|
107
|
+
if (e.touches.length === 1) {
|
108
|
+
touchStartX = e.touches[0].screenX;
|
109
|
+
touchStartY = e.touches[0].screenY;
|
110
|
+
if (selector != null) {
|
111
|
+
return _self.eventPath(e).some(function($element) {
|
112
|
+
if ($element.matches && $element.matches(selector)) {
|
113
|
+
$touchStartElement = $element;
|
114
|
+
touchStartE = e;
|
115
|
+
watch = true;
|
116
|
+
return true;
|
117
|
+
}
|
118
|
+
});
|
119
|
+
} else {
|
120
|
+
return watch = true;
|
121
|
+
}
|
122
|
+
}
|
123
|
+
});
|
124
|
+
return document.addEventListener('touchmove', function(e) {
|
125
|
+
var eventX, eventXOrY, eventY, touchDistanceX, touchDistanceY;
|
126
|
+
if (watch && e.touches.length === 1) {
|
127
|
+
touchDistanceX = e.touches[0].screenX - touchStartX;
|
128
|
+
touchDistanceY = e.touches[0].screenY - touchStartY;
|
129
|
+
eventX = void 0;
|
130
|
+
eventY = void 0;
|
131
|
+
eventXOrY = void 0;
|
132
|
+
if (Math.abs(touchDistanceX) >= _self._SWIPE_DISTANCE) {
|
133
|
+
if (touchDistanceX > 0) {
|
134
|
+
eventX = _self._SWIPE_RIGHT;
|
135
|
+
} else {
|
136
|
+
eventX = _self._SWIPE_LEFT;
|
137
|
+
}
|
138
|
+
}
|
139
|
+
if (Math.abs(touchDistanceY) >= _self._SWIPE_DISTANCE) {
|
140
|
+
if (touchDistanceY > 0) {
|
141
|
+
eventY = _self._SWIPE_DOWN;
|
142
|
+
} else {
|
143
|
+
eventY = _self._SWIPE_UP;
|
144
|
+
}
|
145
|
+
}
|
146
|
+
if (eventX === _self._SWIPE_LEFT || eventY === _self._SWIPE_UP) {
|
147
|
+
eventXOrY = _self._SWIPE_LEFT_OR_UP;
|
148
|
+
}
|
149
|
+
if (eventX === _self._SWIPE_RIGHT || eventY === _self._SWIPE_DOWN) {
|
150
|
+
eventXOrY = _self._SWIPE_RIGHT_OR_DOWN;
|
151
|
+
}
|
152
|
+
if (((eventX != null) && eventX === event) || ((eventY != null) && eventY === event) || eventXOrY === event) {
|
153
|
+
if (selector != null) {
|
154
|
+
return _self.eventPath(e).some(function($element) {
|
155
|
+
if ($element === $touchStartElement) {
|
156
|
+
watch = false;
|
157
|
+
handler.bind($element)(touchStartE, e);
|
158
|
+
return true;
|
159
|
+
}
|
160
|
+
});
|
161
|
+
} else {
|
162
|
+
watch = false;
|
163
|
+
return handler(touchStartE, e);
|
164
|
+
}
|
165
|
+
}
|
166
|
+
}
|
167
|
+
});
|
168
|
+
},
|
169
|
+
_on: function(event, selector, handler) {
|
170
|
+
var _self;
|
171
|
+
if (selector === window) {
|
172
|
+
return window.addEventListener(event, function(e) {
|
173
|
+
return handler(e);
|
174
|
+
});
|
175
|
+
} else {
|
176
|
+
_self = this;
|
177
|
+
return document.addEventListener(event, function(e) {
|
178
|
+
if (selector != null) {
|
179
|
+
return _self.eventPath(e).some(function($element) {
|
180
|
+
if ($element.matches && $element.matches(selector)) {
|
181
|
+
handler.bind($element)(e);
|
182
|
+
return true;
|
183
|
+
}
|
184
|
+
});
|
185
|
+
} else {
|
186
|
+
return handler(e);
|
187
|
+
}
|
188
|
+
});
|
189
|
+
}
|
190
|
+
}
|
191
|
+
});
|
192
|
+
|
193
|
+
})));
|