@finqu/cool 1.2.29 → 1.3.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 (206) hide show
  1. package/README.md +680 -1
  2. package/dist/css/cool.css +23575 -16644
  3. package/dist/css/cool.css.map +1 -154
  4. package/dist/css/cool.min.css +89 -3
  5. package/dist/css/cool.min.css.map +1 -1
  6. package/dist/js/cool.bundle.js +15402 -3800
  7. package/dist/js/cool.bundle.js.map +1 -1
  8. package/dist/js/cool.bundle.min.js +20 -8
  9. package/dist/js/cool.bundle.min.js.map +1 -1
  10. package/dist/js/cool.esm.js +4269 -3360
  11. package/dist/js/cool.esm.js.map +1 -1
  12. package/dist/js/cool.esm.min.js +9 -8
  13. package/dist/js/cool.esm.min.js.map +1 -1
  14. package/dist/js/cool.js +4271 -3362
  15. package/dist/js/cool.js.map +1 -1
  16. package/dist/js/cool.min.js +9 -8
  17. package/dist/js/cool.min.js.map +1 -1
  18. package/package.json +94 -61
  19. package/.babelrc.js +0 -20
  20. package/.browserslistrc +0 -13
  21. package/build/.eslintrc.json +0 -10
  22. package/build/banner.js +0 -14
  23. package/build/build-plugins.js +0 -92
  24. package/build/rollup.config.js +0 -46
  25. package/dist/css/cool-grid.css +0 -4390
  26. package/dist/css/cool-grid.css.map +0 -30
  27. package/dist/css/cool-grid.min.css +0 -7
  28. package/dist/css/cool-grid.min.css.map +0 -1
  29. package/dist/css/cool-reboot.css +0 -286
  30. package/dist/css/cool-reboot.css.map +0 -62
  31. package/dist/css/cool-reboot.min.css +0 -7
  32. package/dist/css/cool-reboot.min.css.map +0 -1
  33. package/html/index.html +0 -2703
  34. package/js/dist/collapse.js +0 -5535
  35. package/js/dist/collapse.js.map +0 -1
  36. package/js/dist/common.js +0 -21996
  37. package/js/dist/common.js.map +0 -1
  38. package/js/dist/cooldropdown.js +0 -467
  39. package/js/dist/cooldropdown.js.map +0 -1
  40. package/js/dist/coolpopover.js +0 -391
  41. package/js/dist/coolpopover.js.map +0 -1
  42. package/js/dist/coolsectiontabs.js +0 -256
  43. package/js/dist/coolsectiontabs.js.map +0 -1
  44. package/js/dist/coolselect.js +0 -796
  45. package/js/dist/coolselect.js.map +0 -1
  46. package/js/dist/cooltooltip.js +0 -360
  47. package/js/dist/cooltooltip.js.map +0 -1
  48. package/js/dist/coolui.js +0 -73
  49. package/js/dist/coolui.js.map +0 -1
  50. package/js/dist/dropdown.js +0 -27421
  51. package/js/dist/dropdown.js.map +0 -1
  52. package/js/dist/popover.js +0 -9472
  53. package/js/dist/popover.js.map +0 -1
  54. package/js/dist/sectiontabs.js +0 -4483
  55. package/js/dist/sectiontabs.js.map +0 -1
  56. package/js/dist/select.js +0 -37080
  57. package/js/dist/select.js.map +0 -1
  58. package/js/dist/tooltip.js +0 -8786
  59. package/js/dist/tooltip.js.map +0 -1
  60. package/js/index.esm.js +0 -21
  61. package/js/index.umd.js +0 -21
  62. package/js/src/abstract-ui-component.js +0 -81
  63. package/js/src/collapse.js +0 -286
  64. package/js/src/common.js +0 -296
  65. package/js/src/dialog.js +0 -579
  66. package/js/src/dropdown.js +0 -525
  67. package/js/src/popover.js +0 -632
  68. package/js/src/section-tabs.js +0 -215
  69. package/js/src/select.js +0 -1342
  70. package/js/src/toast.js +0 -581
  71. package/js/src/tooltip.js +0 -591
  72. package/js/src/util/animate-css.js +0 -22
  73. package/js/src/util/index.js +0 -122
  74. package/js/src/util/perfect-scrollbar.js +0 -1316
  75. package/less/alert.less +0 -345
  76. package/less/badge.less +0 -38
  77. package/less/bootstrap-noconflict.less +0 -23
  78. package/less/bootstrap.less +0 -23
  79. package/less/button-group.less +0 -153
  80. package/less/buttons.less +0 -287
  81. package/less/dialog-noconflict.less +0 -174
  82. package/less/dialog.less +0 -203
  83. package/less/dropdown.less +0 -209
  84. package/less/forms.less +0 -770
  85. package/less/images.less +0 -242
  86. package/less/input-group.less +0 -163
  87. package/less/list-group.less +0 -73
  88. package/less/mixins/aspect-ratio.less +0 -23
  89. package/less/mixins/border-radius.less +0 -24
  90. package/less/mixins/box-shadow.less +0 -4
  91. package/less/mixins/buttons.less +0 -17
  92. package/less/mixins/caret.less +0 -51
  93. package/less/mixins/clearfix.less +0 -10
  94. package/less/mixins/gradients.less +0 -34
  95. package/less/mixins/nav-divider.less +0 -7
  96. package/less/mixins/object-fit.less +0 -13
  97. package/less/mixins/reset-text.less +0 -16
  98. package/less/mixins.less +0 -11
  99. package/less/package.json +0 -11
  100. package/less/pagination.less +0 -69
  101. package/less/popover.less +0 -143
  102. package/less/project.sublime-workspace +0 -774
  103. package/less/reboot.less +0 -235
  104. package/less/section.less +0 -793
  105. package/less/select.less +0 -150
  106. package/less/tables.less +0 -737
  107. package/less/tabs.less +0 -162
  108. package/less/tooltip.less +0 -87
  109. package/less/type.less +0 -71
  110. package/less/utilities/align.less +0 -27
  111. package/less/utilities/animate.less +0 -3512
  112. package/less/utilities/background.less +0 -70
  113. package/less/utilities/borders.less +0 -16
  114. package/less/utilities/color.less +0 -70
  115. package/less/utilities/cursor.less +0 -8
  116. package/less/utilities/display.less +0 -38
  117. package/less/utilities/embed.less +0 -61
  118. package/less/utilities/flex.less +0 -76
  119. package/less/utilities/jquery-ui.less +0 -116
  120. package/less/utilities/lazyload.less +0 -29
  121. package/less/utilities/overflow.less +0 -11
  122. package/less/utilities/pace.less +0 -25
  123. package/less/utilities/placeholder.less +0 -60
  124. package/less/utilities/position.less +0 -42
  125. package/less/utilities/scrollbar.less +0 -152
  126. package/less/utilities/spacing.less +0 -197
  127. package/less/utilities/text.less +0 -68
  128. package/less/utilities/transform.less +0 -7
  129. package/less/utilities.less +0 -21
  130. package/less/variables.less +0 -343
  131. package/scss/LISENCE +0 -15
  132. package/scss/_alert.scss +0 -102
  133. package/scss/_badge.scss +0 -102
  134. package/scss/_button-group.scss +0 -129
  135. package/scss/_buttons.scss +0 -248
  136. package/scss/_custom-forms.scss +0 -444
  137. package/scss/_dialog.scss +0 -160
  138. package/scss/_dropdown.scss +0 -233
  139. package/scss/_forms.scss +0 -258
  140. package/scss/_frame.scss +0 -627
  141. package/scss/_functions.scss +0 -124
  142. package/scss/_grid.scss +0 -35
  143. package/scss/_images.scss +0 -361
  144. package/scss/_input-group.scss +0 -285
  145. package/scss/_list-group.scss +0 -82
  146. package/scss/_mixins.scss +0 -34
  147. package/scss/_navbar.scss +0 -290
  148. package/scss/_notification.scss +0 -13
  149. package/scss/_pagination.scss +0 -88
  150. package/scss/_popover.scss +0 -167
  151. package/scss/_reboot.scss +0 -284
  152. package/scss/_root.scss +0 -15
  153. package/scss/_section.scss +0 -977
  154. package/scss/_select.scss +0 -187
  155. package/scss/_tables.scss +0 -735
  156. package/scss/_tabs.scss +0 -178
  157. package/scss/_toast.scss +0 -182
  158. package/scss/_tooltip.scss +0 -101
  159. package/scss/_type.scss +0 -129
  160. package/scss/_utilities.scss +0 -23
  161. package/scss/_variables.scss +0 -823
  162. package/scss/cool-grid.scss +0 -29
  163. package/scss/cool-reboot.scss +0 -11
  164. package/scss/cool.scss +0 -37
  165. package/scss/mixins/_alert-variant.scss +0 -20
  166. package/scss/mixins/_aspect-ratio.scss +0 -29
  167. package/scss/mixins/_background-variant.scss +0 -25
  168. package/scss/mixins/_badge-variant.scss +0 -36
  169. package/scss/mixins/_breakpoints.scss +0 -102
  170. package/scss/mixins/_buttons.scss +0 -104
  171. package/scss/mixins/_caret.scss +0 -80
  172. package/scss/mixins/_clearfix.scss +0 -10
  173. package/scss/mixins/_float.scss +0 -14
  174. package/scss/mixins/_forms.scss +0 -67
  175. package/scss/mixins/_gradients.scss +0 -40
  176. package/scss/mixins/_grid-framework.scss +0 -72
  177. package/scss/mixins/_grid.scss +0 -60
  178. package/scss/mixins/_nav-divider.scss +0 -9
  179. package/scss/mixins/_notification-variant.scss +0 -7
  180. package/scss/mixins/_object-fit.scss +0 -16
  181. package/scss/mixins/_reset-text.scss +0 -19
  182. package/scss/mixins/_text-emphasis.scss +0 -21
  183. package/scss/mixins/_text-hide.scss +0 -10
  184. package/scss/mixins/_text-truncate.scss +0 -81
  185. package/scss/mixins/_visibility.scss +0 -7
  186. package/scss/project.sublime-workspace +0 -491
  187. package/scss/utilities/_align.scss +0 -41
  188. package/scss/utilities/_animate.scss +0 -3512
  189. package/scss/utilities/_background.scss +0 -14
  190. package/scss/utilities/_borders.scss +0 -146
  191. package/scss/utilities/_clearfix.scss +0 -6
  192. package/scss/utilities/_collapse.scss +0 -33
  193. package/scss/utilities/_cursor.scss +0 -22
  194. package/scss/utilities/_display.scss +0 -16
  195. package/scss/utilities/_embed.scss +0 -78
  196. package/scss/utilities/_flex.scss +0 -52
  197. package/scss/utilities/_lazyload.scss +0 -31
  198. package/scss/utilities/_overflow.scss +0 -6
  199. package/scss/utilities/_perfect-scrollbar.scss +0 -141
  200. package/scss/utilities/_placeholder.scss +0 -77
  201. package/scss/utilities/_position.scss +0 -30
  202. package/scss/utilities/_sizing.scss +0 -32
  203. package/scss/utilities/_spacing.scss +0 -92
  204. package/scss/utilities/_text.scss +0 -99
  205. package/scss/utilities/_user-select.scss +0 -14
  206. package/scss/utilities/_visibility.scss +0 -10
@@ -1,796 +0,0 @@
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