rails-active-ui 0.1.0
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.
- checksums.yaml +7 -0
- data/Rakefile +6 -0
- data/app/assets/stylesheets.css +73555 -0
- data/app/components/accordion_component.rb +34 -0
- data/app/components/ad_component.rb +28 -0
- data/app/components/api_component.rb +24 -0
- data/app/components/breadcrumb_component.rb +26 -0
- data/app/components/button_component.rb +49 -0
- data/app/components/calendar_component.rb +34 -0
- data/app/components/card_component.rb +56 -0
- data/app/components/checkbox_component.rb +41 -0
- data/app/components/column_component.rb +62 -0
- data/app/components/comment_component.rb +45 -0
- data/app/components/concerns/alignable.rb +21 -0
- data/app/components/concerns/attachable.rb +16 -0
- data/app/components/concerns/orientable.rb +21 -0
- data/app/components/concerns/positionable.rb +21 -0
- data/app/components/concerns/sizeable.rb +18 -0
- data/app/components/container_component.rb +23 -0
- data/app/components/dimmer_component.rb +30 -0
- data/app/components/divider_component.rb +30 -0
- data/app/components/dropdown_component.rb +63 -0
- data/app/components/embed_component.rb +32 -0
- data/app/components/emoji_component.rb +15 -0
- data/app/components/feed_component.rb +22 -0
- data/app/components/flag_component.rb +15 -0
- data/app/components/flyout_component.rb +41 -0
- data/app/components/form_component.rb +39 -0
- data/app/components/grid_component.rb +85 -0
- data/app/components/h_stack_component.rb +67 -0
- data/app/components/header_component.rb +60 -0
- data/app/components/icon_component.rb +41 -0
- data/app/components/image_component.rb +46 -0
- data/app/components/input_component.rb +52 -0
- data/app/components/item_component.rb +39 -0
- data/app/components/item_group_component.rb +30 -0
- data/app/components/label_component.rb +49 -0
- data/app/components/link_component.rb +23 -0
- data/app/components/list_component.rb +39 -0
- data/app/components/loader_component.rb +33 -0
- data/app/components/menu_component.rb +64 -0
- data/app/components/menu_item_component.rb +52 -0
- data/app/components/message_component.rb +54 -0
- data/app/components/modal_component.rb +50 -0
- data/app/components/nag_component.rb +25 -0
- data/app/components/overlay_component.rb +16 -0
- data/app/components/placeholder_component.rb +39 -0
- data/app/components/popup_component.rb +31 -0
- data/app/components/progress_component.rb +48 -0
- data/app/components/pusher_component.rb +18 -0
- data/app/components/rail_component.rb +31 -0
- data/app/components/rating_component.rb +41 -0
- data/app/components/reset_component.rb +12 -0
- data/app/components/reveal_component.rb +39 -0
- data/app/components/row_component.rb +39 -0
- data/app/components/search_component.rb +44 -0
- data/app/components/segment_component.rb +57 -0
- data/app/components/segment_group_component.rb +36 -0
- data/app/components/shape_component.rb +25 -0
- data/app/components/sidebar_component.rb +33 -0
- data/app/components/site_component.rb +12 -0
- data/app/components/slider_component.rb +46 -0
- data/app/components/state_component.rb +25 -0
- data/app/components/statistic_component.rb +43 -0
- data/app/components/step_component.rb +56 -0
- data/app/components/step_group_component.rb +38 -0
- data/app/components/sticky_component.rb +22 -0
- data/app/components/sub_header_component.rb +15 -0
- data/app/components/sub_menu_component.rb +24 -0
- data/app/components/tab_component.rb +24 -0
- data/app/components/table_cell_component.rb +60 -0
- data/app/components/table_component.rb +160 -0
- data/app/components/table_row_component.rb +43 -0
- data/app/components/text_component.rb +73 -0
- data/app/components/toast_component.rb +36 -0
- data/app/components/transition_component.rb +32 -0
- data/app/components/v_stack_component.rb +31 -0
- data/app/components/visibility_component.rb +22 -0
- data/app/helpers/component_helper.rb +109 -0
- data/app/helpers/fui_helper.rb +53 -0
- data/app/javascript/accordion.js +547 -0
- data/app/javascript/accordion.min.js +11 -0
- data/app/javascript/api.js +1112 -0
- data/app/javascript/api.min.js +11 -0
- data/app/javascript/calendar.js +1960 -0
- data/app/javascript/calendar.min.js +11 -0
- data/app/javascript/checkbox.js +819 -0
- data/app/javascript/checkbox.min.js +11 -0
- data/app/javascript/dimmer.js +686 -0
- data/app/javascript/dimmer.min.js +11 -0
- data/app/javascript/dropdown.js +4019 -0
- data/app/javascript/dropdown.min.js +11 -0
- data/app/javascript/embed.js +646 -0
- data/app/javascript/embed.min.js +11 -0
- data/app/javascript/flyout.js +1405 -0
- data/app/javascript/flyout.min.js +11 -0
- data/app/javascript/form.js +2070 -0
- data/app/javascript/form.min.js +11 -0
- data/app/javascript/jquery.js +10716 -0
- data/app/javascript/jquery.min.js +2 -0
- data/app/javascript/modal.js +1507 -0
- data/app/javascript/modal.min.js +11 -0
- data/app/javascript/nag.js +522 -0
- data/app/javascript/nag.min.js +11 -0
- data/app/javascript/popup.js +1457 -0
- data/app/javascript/popup.min.js +11 -0
- data/app/javascript/progress.js +922 -0
- data/app/javascript/progress.min.js +11 -0
- data/app/javascript/rating.js +496 -0
- data/app/javascript/rating.min.js +11 -0
- data/app/javascript/search.js +1519 -0
- data/app/javascript/search.min.js +11 -0
- data/app/javascript/shape.js +721 -0
- data/app/javascript/shape.min.js +11 -0
- data/app/javascript/sidebar.js +952 -0
- data/app/javascript/sidebar.min.js +11 -0
- data/app/javascript/site.js +415 -0
- data/app/javascript/site.min.js +11 -0
- data/app/javascript/slider.js +1449 -0
- data/app/javascript/slider.min.js +11 -0
- data/app/javascript/state.js +653 -0
- data/app/javascript/state.min.js +11 -0
- data/app/javascript/sticky.js +852 -0
- data/app/javascript/sticky.min.js +11 -0
- data/app/javascript/tab.js +867 -0
- data/app/javascript/tab.min.js +11 -0
- data/app/javascript/toast.js +916 -0
- data/app/javascript/toast.min.js +11 -0
- data/app/javascript/transition.js +955 -0
- data/app/javascript/transition.min.js +11 -0
- data/app/javascript/ui/controllers/fui_accordion_controller.js +45 -0
- data/app/javascript/ui/controllers/fui_api_controller.js +80 -0
- data/app/javascript/ui/controllers/fui_calendar_controller.js +66 -0
- data/app/javascript/ui/controllers/fui_checkbox_controller.js +48 -0
- data/app/javascript/ui/controllers/fui_dimmer_controller.js +45 -0
- data/app/javascript/ui/controllers/fui_dropdown_controller.js +68 -0
- data/app/javascript/ui/controllers/fui_embed_controller.js +49 -0
- data/app/javascript/ui/controllers/fui_flyout_controller.js +49 -0
- data/app/javascript/ui/controllers/fui_form_controller.js +62 -0
- data/app/javascript/ui/controllers/fui_modal_controller.js +61 -0
- data/app/javascript/ui/controllers/fui_nag_controller.js +52 -0
- data/app/javascript/ui/controllers/fui_popup_controller.js +58 -0
- data/app/javascript/ui/controllers/fui_progress_controller.js +60 -0
- data/app/javascript/ui/controllers/fui_rating_controller.js +49 -0
- data/app/javascript/ui/controllers/fui_search_controller.js +76 -0
- data/app/javascript/ui/controllers/fui_shape_controller.js +45 -0
- data/app/javascript/ui/controllers/fui_sidebar_controller.js +48 -0
- data/app/javascript/ui/controllers/fui_site_controller.js +29 -0
- data/app/javascript/ui/controllers/fui_slider_controller.js +53 -0
- data/app/javascript/ui/controllers/fui_state_controller.js +63 -0
- data/app/javascript/ui/controllers/fui_sticky_controller.js +50 -0
- data/app/javascript/ui/controllers/fui_tab_controller.js +57 -0
- data/app/javascript/ui/controllers/fui_toast_controller.js +60 -0
- data/app/javascript/ui/controllers/fui_transition_controller.js +60 -0
- data/app/javascript/ui/controllers/fui_visibility_controller.js +55 -0
- data/app/javascript/ui/index.js +114 -0
- data/app/javascript/visibility.js +1196 -0
- data/app/javascript/visibility.min.js +11 -0
- data/app/lib/component.rb +63 -0
- data/config/importmap.rb +27 -0
- data/config/initializers/ruby_template_handler.rb +31 -0
- data/config/routes.rb +2 -0
- data/lib/tasks/ui_tasks.rake +4 -0
- data/lib/ui/engine.rb +27 -0
- data/lib/ui/version.rb +3 -0
- data/lib/ui.rb +6 -0
- metadata +220 -0
|
@@ -0,0 +1,819 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* # Fomantic-UI 2.9.4 - Checkbox
|
|
3
|
+
* https://github.com/fomantic/Fomantic-UI/
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
* Released under the MIT license
|
|
7
|
+
* https://opensource.org/licenses/MIT
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
(function ($, window, document) {
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
function isFunction(obj) {
|
|
15
|
+
return typeof obj === 'function' && typeof obj.nodeType !== 'number';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
window = window !== undefined && window.Math === Math
|
|
19
|
+
? window
|
|
20
|
+
: globalThis;
|
|
21
|
+
|
|
22
|
+
$.fn.checkbox = function (...args) {
|
|
23
|
+
const $allModules = $(this);
|
|
24
|
+
|
|
25
|
+
let time = Date.now();
|
|
26
|
+
let performance = [];
|
|
27
|
+
|
|
28
|
+
const parameters = args[0];
|
|
29
|
+
const methodInvoked = typeof parameters === 'string';
|
|
30
|
+
const queryArguments = args.slice(1);
|
|
31
|
+
let returnedValue;
|
|
32
|
+
|
|
33
|
+
$allModules.each(function () {
|
|
34
|
+
const settings = $.extend(true, {}, $.fn.checkbox.settings, parameters);
|
|
35
|
+
|
|
36
|
+
const className = settings.className;
|
|
37
|
+
const namespace = settings.namespace;
|
|
38
|
+
const selector = settings.selector;
|
|
39
|
+
const error = settings.error;
|
|
40
|
+
|
|
41
|
+
const eventNamespace = '.' + namespace;
|
|
42
|
+
const moduleNamespace = 'module-' + namespace;
|
|
43
|
+
|
|
44
|
+
let $module = $(this);
|
|
45
|
+
let $label = $(this).children(selector.label);
|
|
46
|
+
let $input = $(this).children(selector.input);
|
|
47
|
+
let input = $input[0];
|
|
48
|
+
|
|
49
|
+
let initialLoad = false;
|
|
50
|
+
let shortcutPressed = false;
|
|
51
|
+
let instance = $module.data(moduleNamespace);
|
|
52
|
+
|
|
53
|
+
let observer;
|
|
54
|
+
const element = this;
|
|
55
|
+
|
|
56
|
+
const module = {
|
|
57
|
+
|
|
58
|
+
initialize: function () {
|
|
59
|
+
module.verbose('Initializing checkbox', settings);
|
|
60
|
+
|
|
61
|
+
module.create.label();
|
|
62
|
+
module.bind.events();
|
|
63
|
+
|
|
64
|
+
module.set.tabbable();
|
|
65
|
+
module.hide.input();
|
|
66
|
+
|
|
67
|
+
module.observeChanges();
|
|
68
|
+
module.instantiate();
|
|
69
|
+
module.setup();
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
instantiate: function () {
|
|
73
|
+
module.verbose('Storing instance of module', module);
|
|
74
|
+
instance = module;
|
|
75
|
+
$module
|
|
76
|
+
.data(moduleNamespace, module);
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
destroy: function () {
|
|
80
|
+
module.verbose('Destroying module');
|
|
81
|
+
module.unbind.events();
|
|
82
|
+
module.show.input();
|
|
83
|
+
$module.removeData(moduleNamespace);
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
fix: {
|
|
87
|
+
reference: function () {
|
|
88
|
+
if ($module.is(selector.input)) {
|
|
89
|
+
module.debug('Behavior called on <input> adjusting invoked element');
|
|
90
|
+
$module = $module.closest(selector.checkbox);
|
|
91
|
+
module.refresh();
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
setup: function () {
|
|
97
|
+
module.set.initialLoad();
|
|
98
|
+
if (module.is.indeterminate()) {
|
|
99
|
+
module.debug('Initial value is indeterminate');
|
|
100
|
+
module.indeterminate();
|
|
101
|
+
} else if (module.is.checked()) {
|
|
102
|
+
module.debug('Initial value is checked');
|
|
103
|
+
module.check();
|
|
104
|
+
} else {
|
|
105
|
+
module.debug('Initial value is unchecked');
|
|
106
|
+
module.uncheck();
|
|
107
|
+
}
|
|
108
|
+
module.remove.initialLoad();
|
|
109
|
+
},
|
|
110
|
+
|
|
111
|
+
refresh: function () {
|
|
112
|
+
$label = $module.children(selector.label);
|
|
113
|
+
$input = $module.children(selector.input);
|
|
114
|
+
input = $input[0];
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
hide: {
|
|
118
|
+
input: function () {
|
|
119
|
+
module.verbose('Modifying <input> z-index to be unselectable');
|
|
120
|
+
$input.addClass(className.hidden);
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
show: {
|
|
124
|
+
input: function () {
|
|
125
|
+
module.verbose('Modifying <input> z-index to be selectable');
|
|
126
|
+
$input.removeClass(className.hidden);
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
|
|
130
|
+
observeChanges: function () {
|
|
131
|
+
observer = new MutationObserver(function (mutations) {
|
|
132
|
+
module.debug('DOM tree modified, updating selector cache');
|
|
133
|
+
module.refresh();
|
|
134
|
+
});
|
|
135
|
+
observer.observe(element, {
|
|
136
|
+
childList: true,
|
|
137
|
+
subtree: true,
|
|
138
|
+
});
|
|
139
|
+
module.debug('Setting up mutation observer', observer);
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
attachEvents: function (selector, event) {
|
|
143
|
+
const $element = $(selector);
|
|
144
|
+
event = isFunction(module[event])
|
|
145
|
+
? module[event]
|
|
146
|
+
: module.toggle;
|
|
147
|
+
if ($element.length > 0) {
|
|
148
|
+
module.debug('Attaching checkbox events to element', selector, event);
|
|
149
|
+
$element
|
|
150
|
+
.on('click' + eventNamespace, event);
|
|
151
|
+
} else {
|
|
152
|
+
module.error(error.notFound);
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
event: {
|
|
157
|
+
change: function (event) {
|
|
158
|
+
if (!module.should.ignoreCallbacks()) {
|
|
159
|
+
settings.onChange.call(input);
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
click: function (event) {
|
|
163
|
+
const $target = $(event.target);
|
|
164
|
+
if ($target.is(selector.input)) {
|
|
165
|
+
module.verbose('Using default check action on initialized checkbox');
|
|
166
|
+
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if ($target.is(selector.link)) {
|
|
170
|
+
module.debug('Clicking link inside checkbox, skipping toggle');
|
|
171
|
+
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
module.toggle();
|
|
175
|
+
$input.trigger('focus');
|
|
176
|
+
event.preventDefault();
|
|
177
|
+
},
|
|
178
|
+
keydown: function (event) {
|
|
179
|
+
const key = event.which;
|
|
180
|
+
const keyCode = {
|
|
181
|
+
enter: 13,
|
|
182
|
+
space: 32,
|
|
183
|
+
escape: 27,
|
|
184
|
+
left: 37,
|
|
185
|
+
up: 38,
|
|
186
|
+
right: 39,
|
|
187
|
+
down: 40,
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const r = module.get.radios().not(selector.disabled);
|
|
191
|
+
const rIndex = r.index($module);
|
|
192
|
+
const rLen = r.length;
|
|
193
|
+
let checkIndex = false;
|
|
194
|
+
|
|
195
|
+
if (key === keyCode.left || key === keyCode.up) {
|
|
196
|
+
checkIndex = (rIndex === 0 ? rLen : rIndex) - 1;
|
|
197
|
+
} else if (key === keyCode.right || key === keyCode.down) {
|
|
198
|
+
checkIndex = rIndex === rLen - 1 ? 0 : rIndex + 1;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (!module.should.ignoreCallbacks() && checkIndex !== false) {
|
|
202
|
+
if (settings.beforeUnchecked.call(input) === false) {
|
|
203
|
+
module.verbose('Option not allowed to be unchecked, cancelling key navigation');
|
|
204
|
+
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
const nextOption = $(r[checkIndex]);
|
|
208
|
+
const nextInput = nextOption.children(selector.input);
|
|
209
|
+
const disallowOption = nextOption.hasClass(className.readOnly) || nextInput.prop('readonly');
|
|
210
|
+
if (disallowOption || settings.beforeChecked.call(nextInput[0]) === false) {
|
|
211
|
+
module.verbose('Next option should not allow check, cancelling key navigation');
|
|
212
|
+
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
shortcutPressed = false;
|
|
218
|
+
if (key === keyCode.escape) {
|
|
219
|
+
module.verbose('Escape key pressed blurring field');
|
|
220
|
+
$input.trigger('blur');
|
|
221
|
+
shortcutPressed = true;
|
|
222
|
+
event.stopPropagation();
|
|
223
|
+
} else if (!module.can.change()) {
|
|
224
|
+
shortcutPressed = true;
|
|
225
|
+
} else if (!event.ctrlKey) {
|
|
226
|
+
if (key === keyCode.space || (key === keyCode.enter && settings.enableEnterKey)) {
|
|
227
|
+
module.verbose('Enter/space key pressed, toggling checkbox');
|
|
228
|
+
module.toggle();
|
|
229
|
+
shortcutPressed = true;
|
|
230
|
+
} else if ($module.is('.toggle, .slider') && !module.is.radio()) {
|
|
231
|
+
if (key === keyCode.left && module.is.checked()) {
|
|
232
|
+
module.uncheck();
|
|
233
|
+
shortcutPressed = true;
|
|
234
|
+
} else if (key === keyCode.right && module.is.unchecked()) {
|
|
235
|
+
module.check();
|
|
236
|
+
shortcutPressed = true;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
keyup: function (event) {
|
|
242
|
+
if (shortcutPressed) {
|
|
243
|
+
event.preventDefault();
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
|
|
248
|
+
check: function () {
|
|
249
|
+
if (!module.should.allowCheck()) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
module.debug('Checking checkbox', $input);
|
|
253
|
+
module.set.checked();
|
|
254
|
+
if (!module.should.ignoreCallbacks()) {
|
|
255
|
+
settings.onChecked.call(input);
|
|
256
|
+
module.trigger.change();
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
|
|
260
|
+
uncheck: function () {
|
|
261
|
+
if (!module.should.allowUncheck()) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
module.debug('Unchecking checkbox');
|
|
265
|
+
module.set.unchecked();
|
|
266
|
+
if (!module.should.ignoreCallbacks()) {
|
|
267
|
+
settings.onUnchecked.call(input);
|
|
268
|
+
module.trigger.change();
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
|
|
272
|
+
indeterminate: function () {
|
|
273
|
+
if (module.should.allowIndeterminate()) {
|
|
274
|
+
module.debug('Checkbox is already indeterminate');
|
|
275
|
+
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
module.debug('Making checkbox indeterminate');
|
|
279
|
+
module.set.indeterminate();
|
|
280
|
+
if (!module.should.ignoreCallbacks()) {
|
|
281
|
+
settings.onIndeterminate.call(input);
|
|
282
|
+
module.trigger.change();
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
|
|
286
|
+
determinate: function () {
|
|
287
|
+
if (module.should.allowDeterminate()) {
|
|
288
|
+
module.debug('Checkbox is already determinate');
|
|
289
|
+
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
module.debug('Making checkbox determinate');
|
|
293
|
+
module.set.determinate();
|
|
294
|
+
if (!module.should.ignoreCallbacks()) {
|
|
295
|
+
settings.onDeterminate.call(input);
|
|
296
|
+
module.trigger.change();
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
|
|
300
|
+
enable: function () {
|
|
301
|
+
if (module.is.enabled()) {
|
|
302
|
+
module.debug('Checkbox is already enabled');
|
|
303
|
+
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
module.debug('Enabling checkbox');
|
|
307
|
+
module.set.enabled();
|
|
308
|
+
if (!module.should.ignoreCallbacks()) {
|
|
309
|
+
settings.onEnable.call(input);
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
|
|
313
|
+
disable: function () {
|
|
314
|
+
if (module.is.disabled()) {
|
|
315
|
+
module.debug('Checkbox is already disabled');
|
|
316
|
+
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
module.debug('Disabling checkbox');
|
|
320
|
+
module.set.disabled();
|
|
321
|
+
if (!module.should.ignoreCallbacks()) {
|
|
322
|
+
settings.onDisable.call(input);
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
|
|
326
|
+
get: {
|
|
327
|
+
radios: function () {
|
|
328
|
+
const name = module.get.name();
|
|
329
|
+
|
|
330
|
+
return $('input[name="' + CSS.escape(name) + '"]').closest(selector.checkbox);
|
|
331
|
+
},
|
|
332
|
+
otherRadios: function () {
|
|
333
|
+
return module.get.radios().not($module);
|
|
334
|
+
},
|
|
335
|
+
name: function () {
|
|
336
|
+
return $input.attr('name');
|
|
337
|
+
},
|
|
338
|
+
},
|
|
339
|
+
|
|
340
|
+
is: {
|
|
341
|
+
initialLoad: function () {
|
|
342
|
+
return initialLoad;
|
|
343
|
+
},
|
|
344
|
+
radio: function () {
|
|
345
|
+
return $input.hasClass(className.radio) || $input.attr('type') === 'radio';
|
|
346
|
+
},
|
|
347
|
+
indeterminate: function () {
|
|
348
|
+
return $input.prop('indeterminate') !== undefined && $input.prop('indeterminate');
|
|
349
|
+
},
|
|
350
|
+
checked: function () {
|
|
351
|
+
return $input.prop('checked') !== undefined && $input.prop('checked');
|
|
352
|
+
},
|
|
353
|
+
disabled: function () {
|
|
354
|
+
return $input.prop('disabled') !== undefined && $input.prop('disabled');
|
|
355
|
+
},
|
|
356
|
+
enabled: function () {
|
|
357
|
+
return !module.is.disabled();
|
|
358
|
+
},
|
|
359
|
+
determinate: function () {
|
|
360
|
+
return !module.is.indeterminate();
|
|
361
|
+
},
|
|
362
|
+
unchecked: function () {
|
|
363
|
+
return !module.is.checked();
|
|
364
|
+
},
|
|
365
|
+
},
|
|
366
|
+
|
|
367
|
+
should: {
|
|
368
|
+
allowCheck: function () {
|
|
369
|
+
if (module.is.determinate() && module.is.checked() && !module.is.initialLoad()) {
|
|
370
|
+
module.debug('Should not allow check, checkbox is already checked');
|
|
371
|
+
|
|
372
|
+
return false;
|
|
373
|
+
}
|
|
374
|
+
if (!module.should.ignoreCallbacks() && settings.beforeChecked.call(input) === false) {
|
|
375
|
+
module.debug('Should not allow check, beforeChecked cancelled');
|
|
376
|
+
|
|
377
|
+
return false;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
return true;
|
|
381
|
+
},
|
|
382
|
+
allowUncheck: function () {
|
|
383
|
+
if (module.is.determinate() && module.is.unchecked() && !module.is.initialLoad()) {
|
|
384
|
+
module.debug('Should not allow uncheck, checkbox is already unchecked');
|
|
385
|
+
|
|
386
|
+
return false;
|
|
387
|
+
}
|
|
388
|
+
if (!module.should.ignoreCallbacks() && settings.beforeUnchecked.call(input) === false) {
|
|
389
|
+
module.debug('Should not allow uncheck, beforeUnchecked cancelled');
|
|
390
|
+
|
|
391
|
+
return false;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
return true;
|
|
395
|
+
},
|
|
396
|
+
allowIndeterminate: function () {
|
|
397
|
+
if (module.is.indeterminate() && !module.is.initialLoad()) {
|
|
398
|
+
module.debug('Should not allow indeterminate, checkbox is already indeterminate');
|
|
399
|
+
|
|
400
|
+
return false;
|
|
401
|
+
}
|
|
402
|
+
if (!module.should.ignoreCallbacks() && settings.beforeIndeterminate.call(input) === false) {
|
|
403
|
+
module.debug('Should not allow indeterminate, beforeIndeterminate cancelled');
|
|
404
|
+
|
|
405
|
+
return false;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
return true;
|
|
409
|
+
},
|
|
410
|
+
allowDeterminate: function () {
|
|
411
|
+
if (module.is.determinate() && !module.is.initialLoad()) {
|
|
412
|
+
module.debug('Should not allow determinate, checkbox is already determinate');
|
|
413
|
+
|
|
414
|
+
return false;
|
|
415
|
+
}
|
|
416
|
+
if (!module.should.ignoreCallbacks() && settings.beforeDeterminate.call(input) === false) {
|
|
417
|
+
module.debug('Should not allow determinate, beforeDeterminate cancelled');
|
|
418
|
+
|
|
419
|
+
return false;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
return true;
|
|
423
|
+
},
|
|
424
|
+
ignoreCallbacks: function () {
|
|
425
|
+
return initialLoad && !settings.fireOnInit;
|
|
426
|
+
},
|
|
427
|
+
},
|
|
428
|
+
|
|
429
|
+
can: {
|
|
430
|
+
change: function () {
|
|
431
|
+
return !($module.hasClass(className.disabled) || $module.hasClass(className.readOnly) || $input.prop('disabled') || $input.prop('readonly'));
|
|
432
|
+
},
|
|
433
|
+
uncheck: function () {
|
|
434
|
+
return typeof settings.uncheckable === 'boolean'
|
|
435
|
+
? settings.uncheckable
|
|
436
|
+
: !module.is.radio();
|
|
437
|
+
},
|
|
438
|
+
},
|
|
439
|
+
|
|
440
|
+
set: {
|
|
441
|
+
initialLoad: function () {
|
|
442
|
+
initialLoad = true;
|
|
443
|
+
},
|
|
444
|
+
checked: function () {
|
|
445
|
+
module.verbose('Setting class to checked');
|
|
446
|
+
$module
|
|
447
|
+
.removeClass(className.indeterminate)
|
|
448
|
+
.addClass(className.checked);
|
|
449
|
+
if (module.is.radio()) {
|
|
450
|
+
module.uncheckOthers();
|
|
451
|
+
}
|
|
452
|
+
if (!module.is.indeterminate() && module.is.checked()) {
|
|
453
|
+
module.debug('Input is already checked, skipping input property change');
|
|
454
|
+
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
module.verbose('Setting state to checked', input);
|
|
458
|
+
$input
|
|
459
|
+
.prop('indeterminate', false)
|
|
460
|
+
.prop('checked', true);
|
|
461
|
+
},
|
|
462
|
+
unchecked: function () {
|
|
463
|
+
module.verbose('Removing checked class');
|
|
464
|
+
$module
|
|
465
|
+
.removeClass(className.indeterminate)
|
|
466
|
+
.removeClass(className.checked);
|
|
467
|
+
if (!module.is.indeterminate() && module.is.unchecked()) {
|
|
468
|
+
module.debug('Input is already unchecked');
|
|
469
|
+
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
module.debug('Setting state to unchecked');
|
|
473
|
+
$input
|
|
474
|
+
.prop('indeterminate', false)
|
|
475
|
+
.prop('checked', false);
|
|
476
|
+
},
|
|
477
|
+
indeterminate: function () {
|
|
478
|
+
module.verbose('Setting class to indeterminate');
|
|
479
|
+
$module
|
|
480
|
+
.addClass(className.indeterminate);
|
|
481
|
+
if (module.is.indeterminate()) {
|
|
482
|
+
module.debug('Input is already indeterminate, skipping input property change');
|
|
483
|
+
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
module.debug('Setting state to indeterminate');
|
|
487
|
+
$input
|
|
488
|
+
.prop('indeterminate', true);
|
|
489
|
+
},
|
|
490
|
+
determinate: function () {
|
|
491
|
+
module.verbose('Removing indeterminate class');
|
|
492
|
+
$module
|
|
493
|
+
.removeClass(className.indeterminate);
|
|
494
|
+
if (module.is.determinate()) {
|
|
495
|
+
module.debug('Input is already determinate, skipping input property change');
|
|
496
|
+
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
module.debug('Setting state to determinate');
|
|
500
|
+
$input
|
|
501
|
+
.prop('indeterminate', false);
|
|
502
|
+
},
|
|
503
|
+
disabled: function () {
|
|
504
|
+
module.verbose('Setting class to disabled');
|
|
505
|
+
$module
|
|
506
|
+
.addClass(className.disabled);
|
|
507
|
+
if (module.is.disabled()) {
|
|
508
|
+
module.debug('Input is already disabled, skipping input property change');
|
|
509
|
+
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
module.debug('Setting state to disabled');
|
|
513
|
+
$input
|
|
514
|
+
.prop('disabled', 'disabled');
|
|
515
|
+
},
|
|
516
|
+
enabled: function () {
|
|
517
|
+
module.verbose('Removing disabled class');
|
|
518
|
+
$module.removeClass(className.disabled);
|
|
519
|
+
if (module.is.enabled()) {
|
|
520
|
+
module.debug('Input is already enabled, skipping input property change');
|
|
521
|
+
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
module.debug('Setting state to enabled');
|
|
525
|
+
$input
|
|
526
|
+
.prop('disabled', false);
|
|
527
|
+
},
|
|
528
|
+
tabbable: function () {
|
|
529
|
+
module.verbose('Adding tabindex to checkbox');
|
|
530
|
+
if ($input.attr('tabindex') === undefined) {
|
|
531
|
+
$input.attr('tabindex', 0);
|
|
532
|
+
}
|
|
533
|
+
},
|
|
534
|
+
},
|
|
535
|
+
|
|
536
|
+
remove: {
|
|
537
|
+
initialLoad: function () {
|
|
538
|
+
initialLoad = false;
|
|
539
|
+
},
|
|
540
|
+
},
|
|
541
|
+
|
|
542
|
+
trigger: {
|
|
543
|
+
change: function () {
|
|
544
|
+
const inputElement = $input[0];
|
|
545
|
+
if (inputElement) {
|
|
546
|
+
const event = new Event('change', { bubbles: true });
|
|
547
|
+
module.verbose('Triggering native change event');
|
|
548
|
+
inputElement.dispatchEvent(event);
|
|
549
|
+
}
|
|
550
|
+
},
|
|
551
|
+
},
|
|
552
|
+
|
|
553
|
+
create: {
|
|
554
|
+
label: function () {
|
|
555
|
+
if ($input.prevAll(selector.label).length > 0) {
|
|
556
|
+
$input.prev(selector.label).detach().insertAfter($input);
|
|
557
|
+
module.debug('Moving existing label', $label);
|
|
558
|
+
} else if (!module.has.label()) {
|
|
559
|
+
$label = $('<label>').insertAfter($input);
|
|
560
|
+
module.debug('Creating label', $label);
|
|
561
|
+
}
|
|
562
|
+
},
|
|
563
|
+
},
|
|
564
|
+
|
|
565
|
+
has: {
|
|
566
|
+
label: function () {
|
|
567
|
+
return $label.length > 0;
|
|
568
|
+
},
|
|
569
|
+
},
|
|
570
|
+
|
|
571
|
+
bind: {
|
|
572
|
+
events: function () {
|
|
573
|
+
module.verbose('Attaching checkbox events');
|
|
574
|
+
$module
|
|
575
|
+
.on('click' + eventNamespace, module.event.click)
|
|
576
|
+
.on('change' + eventNamespace, module.event.change)
|
|
577
|
+
.on('keydown' + eventNamespace, selector.input, module.event.keydown)
|
|
578
|
+
.on('keyup' + eventNamespace, selector.input, module.event.keyup);
|
|
579
|
+
},
|
|
580
|
+
},
|
|
581
|
+
|
|
582
|
+
unbind: {
|
|
583
|
+
events: function () {
|
|
584
|
+
module.debug('Removing events');
|
|
585
|
+
$module
|
|
586
|
+
.off(eventNamespace);
|
|
587
|
+
},
|
|
588
|
+
},
|
|
589
|
+
|
|
590
|
+
uncheckOthers: function () {
|
|
591
|
+
const $radios = module.get.otherRadios();
|
|
592
|
+
module.debug('Unchecking other radios', $radios);
|
|
593
|
+
$radios.removeClass(className.checked);
|
|
594
|
+
},
|
|
595
|
+
|
|
596
|
+
toggle: function () {
|
|
597
|
+
if (!module.can.change()) {
|
|
598
|
+
if (!module.is.radio()) {
|
|
599
|
+
module.debug('Checkbox is read-only or disabled, ignoring toggle');
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
if (module.is.indeterminate() || module.is.unchecked()) {
|
|
605
|
+
module.debug('Currently unchecked');
|
|
606
|
+
module.check();
|
|
607
|
+
} else if (module.is.checked() && module.can.uncheck()) {
|
|
608
|
+
module.debug('Currently checked');
|
|
609
|
+
module.uncheck();
|
|
610
|
+
}
|
|
611
|
+
},
|
|
612
|
+
setting: function (name, value) {
|
|
613
|
+
module.debug('Changing setting', name, value);
|
|
614
|
+
if ($.isPlainObject(name)) {
|
|
615
|
+
$.extend(true, settings, name);
|
|
616
|
+
} else if (value !== undefined) {
|
|
617
|
+
if ($.isPlainObject(settings[name])) {
|
|
618
|
+
$.extend(true, settings[name], value);
|
|
619
|
+
} else {
|
|
620
|
+
settings[name] = value;
|
|
621
|
+
}
|
|
622
|
+
} else {
|
|
623
|
+
return settings[name];
|
|
624
|
+
}
|
|
625
|
+
},
|
|
626
|
+
internal: function (name, value) {
|
|
627
|
+
if ($.isPlainObject(name)) {
|
|
628
|
+
$.extend(true, module, name);
|
|
629
|
+
} else if (value !== undefined) {
|
|
630
|
+
module[name] = value;
|
|
631
|
+
} else {
|
|
632
|
+
return module[name];
|
|
633
|
+
}
|
|
634
|
+
},
|
|
635
|
+
debug: function (...args) {
|
|
636
|
+
if (!settings.silent && settings.debug) {
|
|
637
|
+
if (settings.performance) {
|
|
638
|
+
module.performance.log(args);
|
|
639
|
+
} else {
|
|
640
|
+
module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
|
|
641
|
+
module.debug.apply(console, args);
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
},
|
|
645
|
+
verbose: function (...args) {
|
|
646
|
+
if (!settings.silent && settings.verbose && settings.debug) {
|
|
647
|
+
if (settings.performance) {
|
|
648
|
+
module.performance.log(args);
|
|
649
|
+
} else {
|
|
650
|
+
module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
|
|
651
|
+
module.verbose.apply(console, args);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
},
|
|
655
|
+
error: function (...args) {
|
|
656
|
+
if (!settings.silent) {
|
|
657
|
+
module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
|
|
658
|
+
module.error.apply(console, args);
|
|
659
|
+
}
|
|
660
|
+
},
|
|
661
|
+
performance: {
|
|
662
|
+
log: function (message) {
|
|
663
|
+
let currentTime;
|
|
664
|
+
let executionTime;
|
|
665
|
+
let previousTime;
|
|
666
|
+
if (settings.performance) {
|
|
667
|
+
currentTime = Date.now();
|
|
668
|
+
previousTime = time || currentTime;
|
|
669
|
+
executionTime = currentTime - previousTime;
|
|
670
|
+
time = currentTime;
|
|
671
|
+
performance.push({
|
|
672
|
+
Name: message[0],
|
|
673
|
+
Arguments: message.slice(1),
|
|
674
|
+
Element: element,
|
|
675
|
+
'Execution Time': executionTime,
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
clearTimeout(module.performance.timer);
|
|
679
|
+
module.performance.timer = setTimeout(function () {
|
|
680
|
+
module.performance.display();
|
|
681
|
+
}, 500);
|
|
682
|
+
},
|
|
683
|
+
display: function () {
|
|
684
|
+
let title = settings.name + ':';
|
|
685
|
+
let totalTime = 0;
|
|
686
|
+
time = false;
|
|
687
|
+
clearTimeout(module.performance.timer);
|
|
688
|
+
$.each(performance, function (index, data) {
|
|
689
|
+
totalTime += data['Execution Time'];
|
|
690
|
+
});
|
|
691
|
+
title += ' ' + totalTime + 'ms';
|
|
692
|
+
if (performance.length > 0) {
|
|
693
|
+
console.groupCollapsed(title);
|
|
694
|
+
console.table(performance);
|
|
695
|
+
console.groupEnd();
|
|
696
|
+
}
|
|
697
|
+
performance = [];
|
|
698
|
+
},
|
|
699
|
+
},
|
|
700
|
+
invoke: function (query, passedArguments = queryArguments, context = element) {
|
|
701
|
+
let object = instance;
|
|
702
|
+
let maxDepth;
|
|
703
|
+
let found;
|
|
704
|
+
let response;
|
|
705
|
+
if (typeof query === 'string' && object !== undefined) {
|
|
706
|
+
query = query.split(/[ .]/);
|
|
707
|
+
maxDepth = query.length - 1;
|
|
708
|
+
$.each(query, function (depth, value) {
|
|
709
|
+
const camelCaseValue = depth !== maxDepth
|
|
710
|
+
? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
|
|
711
|
+
: query;
|
|
712
|
+
if ($.isPlainObject(object[camelCaseValue]) && (depth !== maxDepth)) {
|
|
713
|
+
object = object[camelCaseValue];
|
|
714
|
+
} else if (object[camelCaseValue] !== undefined) {
|
|
715
|
+
found = object[camelCaseValue];
|
|
716
|
+
|
|
717
|
+
return false;
|
|
718
|
+
} else if ($.isPlainObject(object[value]) && (depth !== maxDepth)) {
|
|
719
|
+
object = object[value];
|
|
720
|
+
} else if (object[value] !== undefined) {
|
|
721
|
+
found = object[value];
|
|
722
|
+
|
|
723
|
+
return false;
|
|
724
|
+
} else {
|
|
725
|
+
module.error(error.method, query);
|
|
726
|
+
|
|
727
|
+
return false;
|
|
728
|
+
}
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
if (isFunction(found)) {
|
|
732
|
+
response = found.apply(context, passedArguments);
|
|
733
|
+
} else if (found !== undefined) {
|
|
734
|
+
response = found;
|
|
735
|
+
}
|
|
736
|
+
if (Array.isArray(returnedValue)) {
|
|
737
|
+
returnedValue.push(response);
|
|
738
|
+
} else if (returnedValue !== undefined) {
|
|
739
|
+
returnedValue = [returnedValue, response];
|
|
740
|
+
} else if (response !== undefined) {
|
|
741
|
+
returnedValue = response;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
return found;
|
|
745
|
+
},
|
|
746
|
+
};
|
|
747
|
+
|
|
748
|
+
if (methodInvoked) {
|
|
749
|
+
if (instance === undefined) {
|
|
750
|
+
module.initialize();
|
|
751
|
+
}
|
|
752
|
+
module.invoke(parameters);
|
|
753
|
+
} else {
|
|
754
|
+
if (instance !== undefined) {
|
|
755
|
+
instance.invoke('destroy');
|
|
756
|
+
}
|
|
757
|
+
module.initialize();
|
|
758
|
+
}
|
|
759
|
+
});
|
|
760
|
+
|
|
761
|
+
return returnedValue !== undefined
|
|
762
|
+
? returnedValue
|
|
763
|
+
: this;
|
|
764
|
+
};
|
|
765
|
+
|
|
766
|
+
$.fn.checkbox.settings = {
|
|
767
|
+
|
|
768
|
+
name: 'Checkbox',
|
|
769
|
+
namespace: 'checkbox',
|
|
770
|
+
|
|
771
|
+
silent: false,
|
|
772
|
+
debug: false,
|
|
773
|
+
verbose: false,
|
|
774
|
+
performance: true,
|
|
775
|
+
|
|
776
|
+
// delegated event context
|
|
777
|
+
uncheckable: 'auto',
|
|
778
|
+
fireOnInit: false,
|
|
779
|
+
enableEnterKey: true,
|
|
780
|
+
|
|
781
|
+
onChange: function () {},
|
|
782
|
+
|
|
783
|
+
beforeChecked: function () {},
|
|
784
|
+
beforeUnchecked: function () {},
|
|
785
|
+
beforeDeterminate: function () {},
|
|
786
|
+
beforeIndeterminate: function () {},
|
|
787
|
+
|
|
788
|
+
onChecked: function () {},
|
|
789
|
+
onUnchecked: function () {},
|
|
790
|
+
|
|
791
|
+
onDeterminate: function () {},
|
|
792
|
+
onIndeterminate: function () {},
|
|
793
|
+
|
|
794
|
+
onEnable: function () {},
|
|
795
|
+
onDisable: function () {},
|
|
796
|
+
|
|
797
|
+
className: {
|
|
798
|
+
checked: 'checked',
|
|
799
|
+
indeterminate: 'indeterminate',
|
|
800
|
+
disabled: 'disabled',
|
|
801
|
+
hidden: 'hidden',
|
|
802
|
+
radio: 'radio',
|
|
803
|
+
readOnly: 'read-only',
|
|
804
|
+
},
|
|
805
|
+
|
|
806
|
+
error: {
|
|
807
|
+
method: 'The method you called is not defined',
|
|
808
|
+
},
|
|
809
|
+
|
|
810
|
+
selector: {
|
|
811
|
+
checkbox: '.ui.checkbox',
|
|
812
|
+
disabled: '.disabled, :has(input[disabled])',
|
|
813
|
+
label: 'label',
|
|
814
|
+
input: 'input[type="checkbox"], input[type="radio"]',
|
|
815
|
+
link: 'a[href]',
|
|
816
|
+
},
|
|
817
|
+
|
|
818
|
+
};
|
|
819
|
+
})(jQuery, window, document);
|