@finqu/cool 1.0.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.
Files changed (199) hide show
  1. package/README.md +1 -0
  2. package/build/.eslintrc.json +10 -0
  3. package/build/banner.js +14 -0
  4. package/build/build-plugins.js +92 -0
  5. package/build/rollup.config.js +78 -0
  6. package/dist/css/cool-grid.css +3672 -0
  7. package/dist/css/cool-grid.css.map +30 -0
  8. package/dist/css/cool-grid.min.css +7 -0
  9. package/dist/css/cool-grid.min.css.map +1 -0
  10. package/dist/css/cool-reboot.css +281 -0
  11. package/dist/css/cool-reboot.css.map +58 -0
  12. package/dist/css/cool-reboot.min.css +7 -0
  13. package/dist/css/cool-reboot.min.css.map +1 -0
  14. package/dist/css/cool.css +14841 -0
  15. package/dist/css/cool.css.map +144 -0
  16. package/dist/css/cool.min.css +7 -0
  17. package/dist/css/cool.min.css.map +1 -0
  18. package/dist/js/cool.bundle.js +15304 -0
  19. package/dist/js/cool.bundle.js.map +1 -0
  20. package/dist/js/cool.bundle.min.js +45 -0
  21. package/dist/js/cool.bundle.min.js.map +1 -0
  22. package/dist/js/cool.esm.js +4766 -0
  23. package/dist/js/cool.esm.js.map +1 -0
  24. package/dist/js/cool.esm.min.js +7 -0
  25. package/dist/js/cool.esm.min.js.map +1 -0
  26. package/dist/js/cool.js +4948 -0
  27. package/dist/js/cool.js.map +1 -0
  28. package/dist/js/cool.min.js +7 -0
  29. package/dist/js/cool.min.js.map +1 -0
  30. package/html/index.html +892 -0
  31. package/js/dist/collapse.js +321 -0
  32. package/js/dist/collapse.js.map +1 -0
  33. package/js/dist/common.js +1474 -0
  34. package/js/dist/common.js.map +1 -0
  35. package/js/dist/cooldropdown.js +467 -0
  36. package/js/dist/cooldropdown.js.map +1 -0
  37. package/js/dist/coolpopover.js +391 -0
  38. package/js/dist/coolpopover.js.map +1 -0
  39. package/js/dist/coolsectiontabs.js +256 -0
  40. package/js/dist/coolsectiontabs.js.map +1 -0
  41. package/js/dist/coolselect.js +796 -0
  42. package/js/dist/coolselect.js.map +1 -0
  43. package/js/dist/cooltooltip.js +360 -0
  44. package/js/dist/cooltooltip.js.map +1 -0
  45. package/js/dist/coolui.js +73 -0
  46. package/js/dist/coolui.js.map +1 -0
  47. package/js/dist/dropdown.js +1716 -0
  48. package/js/dist/dropdown.js.map +1 -0
  49. package/js/dist/popover.js +587 -0
  50. package/js/dist/popover.js.map +1 -0
  51. package/js/dist/sectiontabs.js +263 -0
  52. package/js/dist/sectiontabs.js.map +1 -0
  53. package/js/dist/select.js +2029 -0
  54. package/js/dist/select.js.map +1 -0
  55. package/js/dist/tooltip.js +555 -0
  56. package/js/dist/tooltip.js.map +1 -0
  57. package/js/index.esm.js +21 -0
  58. package/js/index.umd.js +21 -0
  59. package/js/src/abstract-ui-component.js +70 -0
  60. package/js/src/collapse.js +258 -0
  61. package/js/src/common.js +280 -0
  62. package/js/src/dialog.js +570 -0
  63. package/js/src/dropdown.js +443 -0
  64. package/js/src/popover.js +615 -0
  65. package/js/src/section-tabs.js +204 -0
  66. package/js/src/select.js +832 -0
  67. package/js/src/toast.js +581 -0
  68. package/js/src/tooltip.js +575 -0
  69. package/js/src/util/animate-css.js +22 -0
  70. package/js/src/util/index.js +112 -0
  71. package/js/src/util/perfect-scrollbar.js +1316 -0
  72. package/less/alert.less +345 -0
  73. package/less/badge.less +38 -0
  74. package/less/bootstrap-noconflict.less +23 -0
  75. package/less/bootstrap.less +23 -0
  76. package/less/button-group.less +153 -0
  77. package/less/buttons.less +287 -0
  78. package/less/dialog-noconflict.less +174 -0
  79. package/less/dialog.less +203 -0
  80. package/less/dropdown.less +209 -0
  81. package/less/forms.less +770 -0
  82. package/less/images.less +242 -0
  83. package/less/input-group.less +163 -0
  84. package/less/list-group.less +73 -0
  85. package/less/mixins/aspect-ratio.less +23 -0
  86. package/less/mixins/border-radius.less +24 -0
  87. package/less/mixins/box-shadow.less +4 -0
  88. package/less/mixins/buttons.less +17 -0
  89. package/less/mixins/caret.less +51 -0
  90. package/less/mixins/clearfix.less +10 -0
  91. package/less/mixins/gradients.less +34 -0
  92. package/less/mixins/nav-divider.less +7 -0
  93. package/less/mixins/object-fit.less +13 -0
  94. package/less/mixins/reset-text.less +16 -0
  95. package/less/mixins.less +11 -0
  96. package/less/package.json +11 -0
  97. package/less/pagination.less +69 -0
  98. package/less/popover.less +143 -0
  99. package/less/project.sublime-workspace +774 -0
  100. package/less/reboot.less +235 -0
  101. package/less/section.less +793 -0
  102. package/less/select.less +150 -0
  103. package/less/tables.less +737 -0
  104. package/less/tabs.less +162 -0
  105. package/less/tooltip.less +87 -0
  106. package/less/type.less +71 -0
  107. package/less/utilities/align.less +27 -0
  108. package/less/utilities/animate.less +3512 -0
  109. package/less/utilities/background.less +70 -0
  110. package/less/utilities/borders.less +16 -0
  111. package/less/utilities/color.less +70 -0
  112. package/less/utilities/cursor.less +8 -0
  113. package/less/utilities/display.less +38 -0
  114. package/less/utilities/embed.less +61 -0
  115. package/less/utilities/flex.less +76 -0
  116. package/less/utilities/jquery-ui.less +116 -0
  117. package/less/utilities/lazyload.less +29 -0
  118. package/less/utilities/overflow.less +11 -0
  119. package/less/utilities/pace.less +25 -0
  120. package/less/utilities/placeholder.less +60 -0
  121. package/less/utilities/position.less +42 -0
  122. package/less/utilities/scrollbar.less +152 -0
  123. package/less/utilities/spacing.less +197 -0
  124. package/less/utilities/text.less +68 -0
  125. package/less/utilities/transform.less +7 -0
  126. package/less/utilities.less +21 -0
  127. package/less/variables.less +343 -0
  128. package/package.json +71 -0
  129. package/scss/LISENCE +15 -0
  130. package/scss/_alert.scss +125 -0
  131. package/scss/_badge.scss +58 -0
  132. package/scss/_button-group.scss +124 -0
  133. package/scss/_buttons.scss +206 -0
  134. package/scss/_custom-forms.scss +423 -0
  135. package/scss/_dialog.scss +149 -0
  136. package/scss/_dropdown.scss +234 -0
  137. package/scss/_forms.scss +257 -0
  138. package/scss/_frame.scss +523 -0
  139. package/scss/_functions.scss +114 -0
  140. package/scss/_grid.scss +35 -0
  141. package/scss/_images.scss +312 -0
  142. package/scss/_input-group.scss +245 -0
  143. package/scss/_list-group.scss +82 -0
  144. package/scss/_mixins.scss +32 -0
  145. package/scss/_navbar.scss +214 -0
  146. package/scss/_pagination.scss +79 -0
  147. package/scss/_popover.scss +165 -0
  148. package/scss/_reboot.scss +279 -0
  149. package/scss/_root.scss +15 -0
  150. package/scss/_section.scss +851 -0
  151. package/scss/_select.scss +166 -0
  152. package/scss/_tables.scss +707 -0
  153. package/scss/_tabs.scss +175 -0
  154. package/scss/_toast.scss +182 -0
  155. package/scss/_tooltip.scss +101 -0
  156. package/scss/_type.scss +90 -0
  157. package/scss/_utilities.scss +21 -0
  158. package/scss/_variables.scss +697 -0
  159. package/scss/cool-grid.scss +29 -0
  160. package/scss/cool-reboot.scss +11 -0
  161. package/scss/cool.scss +36 -0
  162. package/scss/mixins/_alert-variant.scss +40 -0
  163. package/scss/mixins/_aspect-ratio.scss +29 -0
  164. package/scss/mixins/_background-variant.scss +25 -0
  165. package/scss/mixins/_badge-variant.scss +13 -0
  166. package/scss/mixins/_breakpoints.scss +102 -0
  167. package/scss/mixins/_buttons.scss +104 -0
  168. package/scss/mixins/_caret.scss +80 -0
  169. package/scss/mixins/_clearfix.scss +10 -0
  170. package/scss/mixins/_float.scss +14 -0
  171. package/scss/mixins/_forms.scss +51 -0
  172. package/scss/mixins/_gradients.scss +40 -0
  173. package/scss/mixins/_grid-framework.scss +72 -0
  174. package/scss/mixins/_grid.scss +60 -0
  175. package/scss/mixins/_nav-divider.scss +9 -0
  176. package/scss/mixins/_object-fit.scss +16 -0
  177. package/scss/mixins/_reset-text.scss +19 -0
  178. package/scss/mixins/_text-emphasis.scss +21 -0
  179. package/scss/mixins/_text-hide.scss +10 -0
  180. package/scss/mixins/_text-truncate.scss +8 -0
  181. package/scss/project.sublime-workspace +491 -0
  182. package/scss/utilities/_align.scss +41 -0
  183. package/scss/utilities/_animate.scss +3512 -0
  184. package/scss/utilities/_background.scss +14 -0
  185. package/scss/utilities/_borders.scss +146 -0
  186. package/scss/utilities/_clearfix.scss +6 -0
  187. package/scss/utilities/_collapse.scss +33 -0
  188. package/scss/utilities/_cursor.scss +10 -0
  189. package/scss/utilities/_display.scss +16 -0
  190. package/scss/utilities/_embed.scss +78 -0
  191. package/scss/utilities/_flex.scss +50 -0
  192. package/scss/utilities/_lazyload.scss +31 -0
  193. package/scss/utilities/_overflow.scss +6 -0
  194. package/scss/utilities/_perfect-scrollbar.scss +154 -0
  195. package/scss/utilities/_placeholder.scss +76 -0
  196. package/scss/utilities/_position.scss +30 -0
  197. package/scss/utilities/_sizing.scss +32 -0
  198. package/scss/utilities/_spacing.scss +92 -0
  199. package/scss/utilities/_text.scss +97 -0
@@ -0,0 +1,796 @@
1
+ /*!
2
+ * Cool UI coolselect.js v1.0.0 (https://finqu.fi)
3
+ * Copyright 2011-2019 Finqu Oy
4
+ * Licensed under the ISC license - (http://opensource.org/licenses/ISC)
5
+ */
6
+ (function (global, factory) {
7
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
8
+ typeof define === 'function' && define.amd ? define(factory) :
9
+ (global = global || self, global.CoolSelect = factory());
10
+ }(this, function () { 'use strict';
11
+
12
+ const {
13
+ jQuery
14
+ } = window;
15
+
16
+ const debounce = function (func, wait, immediate) {
17
+ var timeout;
18
+ return function () {
19
+ var context = this,
20
+ args = arguments;
21
+
22
+ var later = function () {
23
+ timeout = null;
24
+ if (!immediate) func.apply(context, args);
25
+ };
26
+
27
+ var callNow = immediate && !timeout;
28
+ clearTimeout(timeout);
29
+ timeout = setTimeout(later, wait);
30
+ if (callNow) func.apply(context, args);
31
+ };
32
+ };
33
+
34
+ const touchEvents = function () {
35
+ if ('ontouchstart' in window || window.DocumentTouch && document instanceof DocumentTouch) {
36
+ return true;
37
+ }
38
+ };
39
+
40
+ class AbstractUIComponent {
41
+ // Create callback
42
+ onCreate() {
43
+ var onCreate = this.opts.onCreate;
44
+
45
+ if (typeof onCreate === 'function') {
46
+ onCreate.call(this.el);
47
+ }
48
+ } // Update callback
49
+
50
+
51
+ onUpdate() {
52
+ var onUpdate = this.opts.onUpdate;
53
+
54
+ if (typeof onUpdate === 'function') {
55
+ onUpdate.call(this.el);
56
+ }
57
+ } // Destroy callback
58
+
59
+
60
+ onDestroy() {
61
+ var onDestroy = this.opts.onDestroy;
62
+
63
+ if (typeof onDestroy === 'function') {
64
+ onDestroy.call(this.el);
65
+ }
66
+ } // Show callback
67
+
68
+
69
+ onShow() {
70
+ var onShow = this.opts.onShow;
71
+
72
+ if (typeof onShow === 'function') {
73
+ onShow.call(this.el);
74
+ }
75
+ } // Close callback
76
+
77
+
78
+ onClose() {
79
+ var onClose = this.opts.onClose;
80
+
81
+ if (typeof onClose === 'function') {
82
+ onClose.call(this.el);
83
+ }
84
+ }
85
+
86
+ debug(...args) {
87
+ if (this.opts.debug) {
88
+ if (typeof this.opts.debug === 'function') {
89
+ this.opts.debug(...args);
90
+ } else {
91
+ console.log(...args);
92
+ }
93
+ }
94
+ }
95
+
96
+ }
97
+
98
+ const NAME = 'coolSelect';
99
+ const DATA_KEY = 'plugin_coolSelect';
100
+
101
+ class CoolSelect extends AbstractUIComponent {
102
+ constructor(el, opts) {
103
+ super();
104
+ this.el = el;
105
+ this.opts = jQuery.extend({}, jQuery.fn[NAME].defaults, opts);
106
+ this.name = null;
107
+ this.scrollContentHeight = null;
108
+ this.items = [];
109
+ this.data = {};
110
+ this.searchData = []; // search api URL to query data
111
+
112
+ this.searchApi = this.opts.searchApi; // Tells which type the select objects are (radio|select)
113
+
114
+ this.type = null; // Is the content visible?
115
+
116
+ this.contentOpen = null; // Tells if we have a search in our element
117
+
118
+ this.showSearch = null; // Tells if we have a footer in our element
119
+
120
+ this.showFooter = null; // For custom scroll function callback to store the object
121
+ // in order to update the scroll
122
+
123
+ this.scroll = null;
124
+ this.init();
125
+ } // Init plugin
126
+
127
+
128
+ init() {
129
+ jQuery.when(this.buildCache()).then(() => {
130
+ this.buildScroll();
131
+ this.bindEvents();
132
+
133
+ if (this.data[this.name].length > 0) {
134
+ this.setData();
135
+ }
136
+
137
+ this.onCreate();
138
+ });
139
+ } // Remove plugin instance completely
140
+
141
+
142
+ destroy() {
143
+ this.unbindEvents();
144
+ this.$el.removeData();
145
+ this.onDestroy();
146
+ } // Update plugin data
147
+
148
+
149
+ update() {
150
+ this.buildCache();
151
+ this.bindEvents();
152
+ this.onUpdate();
153
+ } // Cache DOM nodes for performance
154
+
155
+
156
+ buildCache() {
157
+ this.$el = jQuery(this.el);
158
+ this.$selectHeader = this.$el.find('.select-header');
159
+ this.$selectIconContainer = this.$selectHeader.find('.select-icon');
160
+ this.name = this.$el.data('name') ? this.$el.data('name') : this.opts.name;
161
+ this.scrollContentHeight = this.$el.data('scrollContentHeight') ? this.$el.data('scrollContentHeight') : this.opts.scrollContentHeight;
162
+ this.items = this.$el.data('items') ? this.$el.data('items') : this.opts.items;
163
+ this.data = {};
164
+ this.data[this.name] = [];
165
+ this.searchData = [];
166
+ this.searchApi = this.$el.data('searchApi') ? this.$el.data('searchApi') : this.opts.searchApi;
167
+ this.type = this.$el.data('type') ? this.$el.data('type') : this.opts.type;
168
+ this.contentOpen = false;
169
+
170
+ if (this.$el.data('setData') && this.$el.data('setData') != '') {
171
+ this.data = this.$el.data('setData');
172
+ }
173
+
174
+ if (this.$el.find('.select-search')) {
175
+ this.showSearch = true;
176
+ } else {
177
+ this.showSearch = this.$el.data('showSearch') ? this.$el.data('showSearch') : this.opts.showSearch;
178
+ }
179
+
180
+ if (this.$el.find('.select-footer')) {
181
+ this.showFooter = true;
182
+ } else {
183
+ this.showFooter = this.$el.data('showFooter') ? this.$el.data('showFooter') : this.opts.showFooter;
184
+ }
185
+
186
+ if (this.items.length) {
187
+ let items = this._renderItemList(this.items);
188
+
189
+ this.$select = jQuery(`
190
+ <div class="select-content">
191
+
192
+ ${this._renderSearch()}
193
+
194
+ <div class="select-scrollable-content">${items}</div>
195
+
196
+ ${this._renderFooter()}
197
+
198
+ </div>
199
+ `);
200
+ this.$el.append(this.$select);
201
+ this.$scrollableContent = this.$select.find('.select-scrollable-content') ? this.$select.find('.select-scrollable-content') : false;
202
+ this.$selectItems = this.$select.find('.select-item');
203
+ this.$selectLabels = this.$select.find('[data-label]');
204
+
205
+ if (this.showSearch) {
206
+ this.$searchContainer = this.$select.find('.select-search');
207
+ this.$searchInput = this.$select.find('[name="select-search"]');
208
+ this.$searchIconContainer = this.$select.find('.select-search-icon');
209
+ this.$clearSearchButton = this.$select.find('[data-clear-search]');
210
+ }
211
+
212
+ if (this.showFooter) {
213
+ this.$footerContainer = this.$select.find('.select-footer');
214
+ this.$closeButton = this.$select.find('[data-select-close]');
215
+ }
216
+
217
+ jQuery.each(this.$selectLabels, function (i, el) {
218
+ this.searchData.push({
219
+ id: i,
220
+ val: jQuery(el).text().trim()
221
+ });
222
+ });
223
+
224
+ if (this.opts.debug) {
225
+ this.debug(this.$el);
226
+ this.debug(this.$select);
227
+ this.debug(this.$scrollableContent);
228
+ this.debug('Name: ' + this.name);
229
+ this.debug('Show search: ' + this.showSearch);
230
+ this.debug('Show footer: ' + this.showFooter);
231
+ this.debug('Scroll content height: ' + this.scrollContentHeight + 'px');
232
+ this.debug(this.items);
233
+ this.debug(this.searchData);
234
+ }
235
+ } else {
236
+ this.$select = this.$el.find('.select-content');
237
+ this.$scrollableContent = this.$select.find('.select-scrollable-content');
238
+ this.$selectItems = this.$select.find('.select-item');
239
+ this.$selectLabels = this.$select.find('[data-label]');
240
+
241
+ if (this.showSearch) {
242
+ this.$searchContainer = this.$select.find('.select-search');
243
+ this.$searchInput = this.$select.find('[name="select-search"]');
244
+ this.$searchIconContainer = this.$select.find('.select-search-icon');
245
+ this.$clearSearchButton = this.$select.find('[data-clear-search]');
246
+ }
247
+
248
+ if (this.showFooter) {
249
+ this.$footerContainer = this.$select.find('.select-footer');
250
+ this.$closeButton = this.$select.find('[data-select-close]');
251
+ }
252
+
253
+ jQuery.each(this.$selectLabels, (i, el) => {
254
+ this.searchData.push({
255
+ id: i,
256
+ val: jQuery(el).text().trim()
257
+ });
258
+ });
259
+
260
+ if (this.opts.debug) {
261
+ this.debug(this.$el);
262
+ this.debug(this.$select);
263
+ this.debug(this.$scrollableContent);
264
+ this.debug('Name: ' + this.name);
265
+ this.debug('Show search: ' + this.showSearch);
266
+ this.debug('Show footer: ' + this.showFooter);
267
+ this.debug('Scroll content height: ' + this.scrollContentHeight + 'px');
268
+ this.debug(this.items);
269
+ this.debug(this.searchData);
270
+ }
271
+
272
+ return true;
273
+ }
274
+ } // Build scroll
275
+
276
+
277
+ buildScroll() {
278
+ if (this.$scrollableContent.length > 0) {
279
+ var scrollContentHeight = this.scrollContentHeight;
280
+
281
+ if (this.showSearch) {
282
+ scrollContentHeight = scrollContentHeight - (this.$searchContainer.outerHeight(true) || 0);
283
+ }
284
+
285
+ if (this.showFooter) {
286
+ scrollContentHeight = scrollContentHeight - (this.$footerContainer.outerHeight(true) || 0);
287
+ }
288
+
289
+ this.$scrollableContent.css({
290
+ 'max-height': scrollContentHeight - parseInt(this.$scrollableContent.css('marginTop'), 10) - parseInt(this.$scrollableContent.css('marginBottom'), 10) + 'px'
291
+ });
292
+
293
+ if (touchEvents || typeof this.opts.buildScroll !== 'function') {
294
+ this.$scrollableContent.css({
295
+ 'overflow-y': 'auto'
296
+ });
297
+ } else if (typeof this.opts.buildScroll === 'function') {
298
+ this.scroll = this.opts.buildScroll(this.$scrollableContent); // this.$scrollableContent.addClass('ps-dark');
299
+ // this.scroll = new PerfectScrollbar(this.$scrollableContent[0], {
300
+ // wheelSpeed: 1,
301
+ // wheelPropagation: false,
302
+ // minScrollbarLength: 20,
303
+ // scrollYMarginOffset : -1,
304
+ // suppressScrollY: true,
305
+ // suppressScrollX: true,
306
+ // });
307
+ // if (this.$scrollableContent[0].offsetHeight < this.$scrollableContent[0].scrollHeight) {
308
+ // this.$scrollableContent.addClass('ps-show-rail-y');
309
+ // this.scroll.settings.suppressScrollY = false;
310
+ // }
311
+ }
312
+ }
313
+ } // Bind events that trigger methods
314
+
315
+
316
+ bindEvents() {
317
+ var plugin = this;
318
+ plugin.$selectHeader.on('click' + '.' + NAME, function () {
319
+ if (plugin.contentOpen) {
320
+ plugin.close.call(plugin);
321
+ } else {
322
+ plugin.show.call(plugin);
323
+ }
324
+ });
325
+ plugin.$el.on('change' + '.' + NAME, 'input[type="checkbox"]', function () {
326
+ var val = jQuery(this).val();
327
+
328
+ if (this.checked) {
329
+ plugin.data[plugin.name].indexOf(val) === -1 ? plugin.data[plugin.name].push(val) : false;
330
+ } else {
331
+ plugin.data[plugin.name] = plugin.data[plugin.name].filter(n => n != val);
332
+ }
333
+
334
+ plugin.onSelect(this);
335
+ });
336
+ plugin.$el.on('change' + '.' + NAME, 'input[type="radio"]', function () {
337
+ var val = jQuery(this).val();
338
+
339
+ if (this.checked) {
340
+ plugin.data[plugin.name] = val;
341
+ plugin.$select.find('input[type="radio"]').not(jQuery(this)).prop('checked', false);
342
+ plugin.$select.find('input[type="radio"]').not(jQuery(this)).removeClass('checked');
343
+ } else {
344
+ plugin.data[plugin.name] = [];
345
+ }
346
+ });
347
+ plugin.$el.on('click' + '.' + NAME, 'input[type="radio"]', function () {
348
+ if (jQuery(this).hasClass('checked')) {
349
+ plugin.data[plugin.name] = [];
350
+ jQuery(this).prop('checked', false);
351
+ jQuery(this).removeClass('checked');
352
+ } else {
353
+ jQuery(this).addClass('checked');
354
+ }
355
+
356
+ plugin.onSelect(this);
357
+ }); // if (this.scroll) {
358
+ // plugin.$scrollableContent.find('.ps__thumb-y').mousedown(function() {
359
+ // plugin.$scrollableContent.addClass('ps-mousedown-scroll');
360
+ // });
361
+ // $(document).mouseup(function() {
362
+ // if (plugin.$scrollableContent.hasClass('ps-mousedown-scroll')) {
363
+ // plugin.$scrollableContent.removeClass('ps-mousedown-scroll');
364
+ // }
365
+ // });
366
+ // }
367
+
368
+ if (this.showSearch) {
369
+ plugin.$searchInput.on('keydown' + '.' + NAME, debounce(function () {
370
+ plugin.searchString = jQuery(this).val().trim();
371
+ plugin.search.call(plugin);
372
+ }, 250));
373
+ plugin.$searchInput.on('focusin' + '.' + NAME, function () {
374
+ plugin.$searchContainer.addClass('focused');
375
+ });
376
+ plugin.$searchInput.on('focusout' + '.' + NAME, function () {
377
+ plugin.$searchContainer.removeClass('focused');
378
+ });
379
+ plugin.$clearSearchButton.on('click' + '.' + NAME, function () {
380
+ if (plugin.searchString.length) {
381
+ plugin.$searchInput.val('');
382
+ plugin.searchString = '';
383
+ plugin.search.call(plugin);
384
+ } else {
385
+ return;
386
+ }
387
+ });
388
+ }
389
+
390
+ if (this.showFooter) {
391
+ plugin.$closeButton.on('click' + '.' + NAME, function () {
392
+ plugin.close.call(plugin);
393
+ });
394
+ }
395
+
396
+ jQuery(document).on('touchstart click', function (e) {
397
+ if (!plugin.$el.is(e.target) && plugin.$el.has(e.target).length === 0 && plugin.contentOpen) {
398
+ plugin.close.call(plugin);
399
+ }
400
+ });
401
+ } // Unbind events that trigger methods
402
+
403
+
404
+ unbindEvents() {
405
+ this.$el.off('.' + NAME);
406
+ } // Get data
407
+
408
+
409
+ getData(data) {
410
+ if (data) {
411
+ return this.data[data];
412
+ } else {
413
+ return this.data;
414
+ }
415
+ } // Set data
416
+
417
+
418
+ setData() {
419
+ var plugin = this;
420
+ var type = null;
421
+ this.$selectIconContainer.html('<i class="' + this.opts.faPro ? 'fal' : 'fas' + ' fa-check text-green icon"></i>');
422
+
423
+ if (this.searchApi.length) {
424
+ var searchUrl = this.searchApi;
425
+ var itemCount = this.data[this.name].length;
426
+ var currentCount = 0;
427
+ this.data[this.name].forEach(function (value) {
428
+ searchUrl += encodeURIComponent('#' + value);
429
+ currentCount++;
430
+
431
+ if (currentCount !== itemCount) {
432
+ searchUrl += '+';
433
+ }
434
+ });
435
+ app.request(searchUrl).success(function (data) {
436
+ var items = data.map(function (item) {
437
+ if (item.name) {
438
+ var label = item.name;
439
+ } else if (item.label) {
440
+ var label = item.label;
441
+ } else if (item.value) {
442
+ var label = item.value;
443
+ }
444
+
445
+ return {
446
+ id: item.id.toString(),
447
+ label: label
448
+ };
449
+ });
450
+ var items = items.filter(function (item) {
451
+ return plugin.data[plugin.name].indexOf(item.id) > -1;
452
+ });
453
+ var result = jQuery(plugin._renderItemList(items)); // var result = $(plugin.hbs['ui/select/templates/partials/select-item']({
454
+ // selectType: plugin.type,
455
+ // selectName: plugin.name,
456
+ // items: items
457
+ // })).i18n();
458
+
459
+ jQuery.when(plugin.$scrollableContent.append(result)).then(function () {
460
+ if (plugin.scroll && typeof plugin.scroll.update === 'function') {
461
+ plugin.scroll.update();
462
+ } // if (plugin.$scrollableContent[0].offsetHeight < plugin.$scrollableContent[0].scrollHeight) {
463
+ // plugin.scroll.update();
464
+ // plugin.scroll.settings.suppressScrollY = false;
465
+ // plugin.$scrollableContent.addClass('ps-show-rail-y');
466
+ // } else {
467
+ // plugin.scroll.update();
468
+ // plugin.scroll.settings.suppressScrollY = true;
469
+ // plugin.$scrollableContent.removeClass('ps-show-rail-y');
470
+ // }
471
+
472
+
473
+ if (plugin.$select.find(':input[type="checkbox"]').length) {
474
+ type = 'checkbox';
475
+ } else if (plugin.$select.find(':input[type="radio"]').length) {
476
+ type = 'radio';
477
+ }
478
+
479
+ if (type == 'checkbox') {
480
+ plugin.data[plugin.name].forEach(function (value) {
481
+ var $input = plugin.$select.find(':input').filter(function () {
482
+ return this.value == value;
483
+ });
484
+ $input.prop('checked', true);
485
+ plugin.onSelect($input[0]);
486
+ });
487
+ } else if (type == 'radio') {
488
+ var $input = plugin.$select.find(':input').filter(function () {
489
+ return this.value == plugin.data[plugin.name];
490
+ });
491
+ $input.prop('checked', true);
492
+ $input.addClass('checked');
493
+ plugin.onSelect($input[0]);
494
+ }
495
+ });
496
+ }).get();
497
+ } else {
498
+ if (plugin.$select.find(':input[type="checkbox"]').length) {
499
+ type = 'checkbox';
500
+ } else if (plugin.$select.find(':input[type="radio"]').length) {
501
+ type = 'radio';
502
+ }
503
+
504
+ if (type == 'checkbox') {
505
+ this.data[this.name].forEach(function (value) {
506
+ var $input = plugin.$select.find(':input').filter(function () {
507
+ return this.value == value;
508
+ });
509
+ $input.prop('checked', true);
510
+ plugin.onSelect($input[0]);
511
+ });
512
+ } else if (type == 'radio') {
513
+ var $input = plugin.$select.find(':input').filter(function () {
514
+ return this.value == plugin.data[plugin.name];
515
+ });
516
+ $input.prop('checked', true);
517
+ $input.addClass('checked');
518
+ plugin.onSelect($input[0]);
519
+ }
520
+ }
521
+ } // Search
522
+
523
+
524
+ search() {
525
+ var plugin = this;
526
+
527
+ if (this.searchString.length) {
528
+ if (this.searchApi.length) {
529
+ this.$scrollableContent.find('input:not(:checked)').parents('.select-item').not('.static-item').remove();
530
+ app.request(this.searchApi + this.searchString).success(function (data) {
531
+ var items = data.map(function (item) {
532
+ return {
533
+ id: item.id.toString(),
534
+ label: item.name || item.label || item.value || null
535
+ };
536
+ });
537
+ var items = items.filter(function (item) {
538
+ return !(plugin.data[plugin.name].indexOf(item.id) > -1);
539
+ }); // Remove 0 id from results
540
+
541
+ var items = items.filter(function (item) {
542
+ return [0].indexOf(item.id) > -1;
543
+ });
544
+ var result = jQuery(plugin._renderItemList(items));
545
+ jQuery.when(plugin.$scrollableContent.append(result)).then(function () {
546
+ if (this.scroll && typeof this.scroll.update === 'function') {
547
+ this.scroll.update();
548
+ } // plugin.$searchIconContainer.html('<i class="fal fa-times icon"></i>');
549
+ // plugin.$searchIconContainer.attr('data-clear-search', 'true');
550
+ // if (plugin.$scrollableContent[0].offsetHeight < plugin.$scrollableContent[0].scrollHeight) {
551
+ // plugin.scroll.update();
552
+ // plugin.scroll.settings.suppressScrollY = false;
553
+ // plugin.$scrollableContent.addClass('ps-show-rail-y');
554
+ // } else {
555
+ // plugin.scroll.update();
556
+ // plugin.scroll.settings.suppressScrollY = true;
557
+ // plugin.$scrollableContent.removeClass('ps-show-rail-y');
558
+ // }
559
+
560
+ });
561
+ }).get();
562
+ } else {
563
+ var results = this.searchData.filter(function (item) {
564
+ return item.val.toLocaleLowerCase().indexOf(plugin.searchString.toLocaleLowerCase()) > -1;
565
+ });
566
+ this.$selectItems.removeClass('d-none');
567
+ this.$selectItems.removeClass('visible');
568
+ results.forEach(function (item) {
569
+ jQuery(plugin.$selectItems[item.id]).addClass('visible');
570
+ });
571
+ this.$selectItems.not('.visible').addClass('d-none');
572
+ this.$searchIconContainer.html('<i class="' + this.opts.faPro ? 'fal' : 'fas' + ' fa-times icon"></i>');
573
+ this.$searchIconContainer.attr('data-clear-search', 'true');
574
+ }
575
+ } else {
576
+ if (this.searchApi.length) {
577
+ this.$scrollableContent.find('input:not(:checked)').parents('.select-item').not('.static-item').remove();
578
+ this.$searchIconContainer.html('<i class="' + this.opts.faPro ? 'fal' : 'fas' + ' fa-search icon"></i>');
579
+ this.$searchIconContainer.attr('data-clear-search', '');
580
+ } else {
581
+ this.$selectItems.removeClass('d-none');
582
+ this.$selectItems.removeClass('visible');
583
+ this.$searchIconContainer.html('<i class="' + this.opts.faPro ? 'fal' : 'fas' + ' fa-search icon"></i>');
584
+ this.$searchIconContainer.attr('data-clear-search', '');
585
+ }
586
+ }
587
+
588
+ if (this.scroll && typeof this.scroll.update === 'function') {
589
+ this.scroll.update();
590
+ }
591
+
592
+ this.onUpdate();
593
+ } // Show
594
+
595
+
596
+ show() {
597
+ if (this.$el.hasClass('show')) {
598
+ return;
599
+ }
600
+
601
+ var $otherSelects = jQuery('.select.show');
602
+
603
+ if ($otherSelects.length) {
604
+ var zindex = parseInt($otherSelects.first().css('z-index'), 10) + 2;
605
+ }
606
+
607
+ this.$el.css({
608
+ 'max-height': this.scrollContentHeight + this.$selectHeader.outerHeight(true) + 'px'
609
+ });
610
+ this.$el.addClass('show');
611
+
612
+ if (!$otherSelects.length) {
613
+ var zindex = parseInt(this.$el.css('z-index'), 10) + 1;
614
+ }
615
+
616
+ this.$el.css({
617
+ 'z-index': zindex
618
+ });
619
+
620
+ if (this.scroll && typeof this.scroll.show === 'function') {
621
+ this.scroll.update(); // if (this.$scrollableContent[0].offsetHeight < this.$scrollableContent[0].scrollHeight) {
622
+ // this.$scrollableContent[0].scrollTop = 1;
623
+ // this.$scrollableContent[0].scrollTop = 0;
624
+ // }
625
+ }
626
+
627
+ this.$selectIconContainer.html(`<i class="${this.opts.faPro ? 'fal' : 'fas'} fa-angle-up"></i`);
628
+ this.contentOpen = true;
629
+ this.onShow();
630
+ } // Close
631
+
632
+
633
+ close() {
634
+ var plugin = this;
635
+ this.$el.css('max-height', '');
636
+ this.$el.removeClass('show');
637
+ setTimeout(() => {
638
+ plugin.$el.removeAttr('style');
639
+ }, 300);
640
+
641
+ if (this.data[this.name].length > 0) {
642
+ this.$selectIconContainer.html(`<i class="${this.opts.faPro ? 'fal' : 'fas'} fa-check text-green icon"></i>`);
643
+ } else {
644
+ this.$selectIconContainer.html(`<i class="${this.opts.faPro ? 'fal' : 'fas'} fa-angle-down"></i>`);
645
+ }
646
+
647
+ this.contentOpen = false;
648
+ this.onClose();
649
+ }
650
+
651
+ onSelect(el) {
652
+ var onSelect = this.opts.onSelect;
653
+
654
+ if (typeof onSelect === 'function') {
655
+ onSelect.call(el);
656
+ }
657
+ }
658
+
659
+ _renderItemList(items) {
660
+ let html = '';
661
+
662
+ for (let i = 0; i < items.length; ++i) {
663
+ html += `
664
+ <div class="select-item">
665
+
666
+ <div class="select-item-${this.type}">
667
+
668
+ <div class="styled-${this.type}">">
669
+
670
+ <input type="${this.type}">" id="select-${this.name}-${items[i].id}" value="${items[i].id}">
671
+
672
+ <label for="select-${this.name}-${items[i].id}">
673
+
674
+ <span class="radio-inner">
675
+ <svg viewBox="0 0 18 18">
676
+ <polyline points="1.5 6 4.5 9 10.5 1"></polyline>
677
+ </svg>
678
+ </span>
679
+
680
+ <span class="${this.type}">-label" data-label>
681
+ ${items[i].label}
682
+ </span>
683
+
684
+ </label>
685
+
686
+ </div>
687
+
688
+ </div>
689
+
690
+ </div>
691
+ `;
692
+ }
693
+ }
694
+
695
+ _renderSearch() {
696
+ if (!this.showSearch) {
697
+ return '';
698
+ }
699
+
700
+ return `
701
+ <div class="select-search">
702
+
703
+ <div class="select-search-input">
704
+
705
+ <input type="text" name="select-search" value="" placeholder="${this.opts.searchPlaceholder}">
706
+
707
+ </div>
708
+
709
+ <div class="select-search-icon">
710
+
711
+ <i class="${this.opts.faPro ? 'fal' : 'fas'} fa-search icon"></i>
712
+
713
+ </div>
714
+
715
+ </div>
716
+ `;
717
+ }
718
+
719
+ _renderFooter() {
720
+ if (!this.showFooter) {
721
+ return '';
722
+ }
723
+
724
+ return `
725
+ <div class="select-footer">
726
+
727
+ <button class="btn btn-primary" type="button" data-select-close>
728
+ ${this.opts.btnCloseText}
729
+ </button>
730
+
731
+ </div>
732
+ `;
733
+ }
734
+
735
+ static _jQueryInterface(config) {
736
+ return this.each(function () {
737
+ let data = jQuery(this).data(DATA_KEY);
738
+
739
+ const _config = typeof config === 'object' && config;
740
+
741
+ if (!data) {
742
+ data = new CoolSelect(this, _config);
743
+ jQuery(this).data(DATA_KEY, data);
744
+ }
745
+
746
+ if (typeof config === 'string') {
747
+ if (typeof data[config] === 'undefined') {
748
+ throw new TypeError(`No method named "${config}"`);
749
+ }
750
+
751
+ data[config]();
752
+ }
753
+ });
754
+ }
755
+
756
+ }
757
+
758
+ if (typeof jQuery !== 'undefined') {
759
+ // jQuery
760
+ const JQUERY_NO_CONFLICT = jQuery.fn[NAME];
761
+ jQuery.fn[NAME] = CoolSelect._jQueryInterface;
762
+ jQuery.fn[NAME].Constructor = CoolSelect;
763
+
764
+ jQuery.fn[NAME].noConflict = () => {
765
+ jQuery.fn[NAME] = JQUERY_NO_CONFLICT;
766
+ return CoolSelect._jQueryInterface;
767
+ };
768
+
769
+ jQuery.fn[NAME].defaults = {
770
+ name: '',
771
+ type: 'checkbox',
772
+ scrollContentHeight: 100,
773
+ faPro: false,
774
+ items: [],
775
+ showSearch: false,
776
+ showFooter: false,
777
+ searchApi: false,
778
+ onCreate: null,
779
+ onUpdate: null,
780
+ onDestroy: null,
781
+ onShow: null,
782
+ onClose: null,
783
+ onSearch: null,
784
+ onSelect: null,
785
+ // function that should return object with update method
786
+ buildScroll: null,
787
+ searchPlaceholder: null,
788
+ btnCloseText: null,
789
+ debug: false
790
+ };
791
+ }
792
+
793
+ return CoolSelect;
794
+
795
+ }));
796
+ //# sourceMappingURL=coolselect.js.map