@finqu/cool 1.2.6 → 1.2.8

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.
@@ -1,13 +1,13 @@
1
1
  /*!
2
- * Cool UI v1.2.5 (https://finqu.fi)
3
- * Copyright 2011-2019 Finqu Oy
2
+ * Cool UI v1.2.7 (https://finqu.fi)
3
+ * Copyright 2011-2020 Finqu Oy
4
4
  * Licensed under the ISC license - (http://opensource.org/licenses/ISC)
5
5
  */
6
6
  (function (global, factory) {
7
7
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery')) :
8
8
  typeof define === 'function' && define.amd ? define(['jquery'], factory) :
9
9
  (global = global || self, global.cool = factory());
10
- }(this, function () { 'use strict';
10
+ }(this, (function () { 'use strict';
11
11
 
12
12
  /*!
13
13
  * perfect-scrollbar v1.4.0
@@ -1675,6 +1675,7 @@
1675
1675
  _proto.buildCache = function buildCache() {
1676
1676
  this.$el = $(this.el);
1677
1677
  this.$container = this.$el.data('container') ? $(this.$el.data('container')) : $(this.opts.container);
1678
+ this.containerAutoDetect = this.$el.data('containerAutoDetect') ? this.$el.data('containerAutoDetect') : this.opts.containerAutoDetect;
1678
1679
  this.id = 'popover-' + this.generateUUID();
1679
1680
  this.animation = this.$el.data('animation') ? this.$el.data('animation') : this.opts.animation;
1680
1681
  this.animationIn = this.$el.data('animationIn') ? this.$el.data('animationIn') : this.opts.animationIn;
@@ -1685,6 +1686,10 @@
1685
1686
  this.placementChanged = false;
1686
1687
  this.title = this.$el.data('title') ? this.$el.data('title') : this.opts.title;
1687
1688
  this.content = this.$el.data('content') ? this.$el.data('content') : this.opts.content;
1689
+
1690
+ if (this.containerAutoDetect) {
1691
+ this.$container = this.$el.offsetParent();
1692
+ }
1688
1693
  } // Bind events that trigger methods
1689
1694
  ;
1690
1695
 
@@ -2109,6 +2114,7 @@
2109
2114
 
2110
2115
  $.fn[NAME].defaults = {
2111
2116
  container: '.content-inner',
2117
+ containerAutoDetect: false,
2112
2118
  trigger: 'focus',
2113
2119
  placement: 'bottom',
2114
2120
  animation: true,
@@ -2233,6 +2239,7 @@
2233
2239
  _this3.data[_this3.name] = [];
2234
2240
  _this3.searchData = [];
2235
2241
  _this3.searchApi = _this3.$el.data('searchApi') ? _this3.$el.data('searchApi') : _this3.opts.searchApi;
2242
+ _this3.searchRequest = null;
2236
2243
  _this3.type = _this3.$el.data('type') ? _this3.$el.data('type') : _this3.opts.type;
2237
2244
  _this3.contentOpen = false;
2238
2245
  _this3.searchPlaceholder = _this3.$el.data('search-placeholder') ? _this3.$el.data('search-placeholder') : _this3.opts.searchPlaceholder;
@@ -2262,13 +2269,13 @@
2262
2269
  _this3.data = _this3.$el.data('setData');
2263
2270
  }
2264
2271
 
2265
- if (typeof _this3.data[_this3.name].filter !== 'undefined' && self.itemsToExclude) {
2272
+ if (_this3.data[_this3.name] !== 'undefined' && _this3.data[_this3.name].length > 0 && self.itemsToExclude) {
2266
2273
  _this3.data[_this3.name] = _this3.data[_this3.name].filter(function (item) {
2267
2274
  return self.itemsToExclude.indexOf(parseInt(item.id, 10)) === -1;
2268
2275
  });
2269
2276
  }
2270
2277
 
2271
- if (typeof _this3.items.filter !== 'undefined' && self.itemsToExclude) {
2278
+ if (_this3.items !== 'undefined' && _this3.items.lengths > 0 && self.itemsToExclude) {
2272
2279
  _this3.items = _this3.items.filter(function (item) {
2273
2280
  return self.itemsToExclude.indexOf(parseInt(item.id, 10)) === -1;
2274
2281
  });
@@ -2291,10 +2298,12 @@
2291
2298
  if (!_this3.$select.length) {
2292
2299
  var items = _this3._renderItemList(_this3.items);
2293
2300
 
2294
- _this3.$select = $("\n <div class=\"select-content\">\n\n " + _this3._renderSearch() + "\n\n <div class=\"select-scrollable-content\">" + items + "</div>\n\n " + _this3._renderFooter() + "\n\n </div>\n ");
2301
+ _this3.$select = $("\n <div class=\"select-content\">\n\n " + _this3._renderSearch() + "\n\n <div class=\"select-scrollable-content\"></div>\n\n " + _this3._renderFooter() + "\n\n </div>\n ");
2295
2302
 
2296
2303
  _this3.$el.append(_this3.$select);
2297
2304
 
2305
+ _this3.$select.find('.select-scrollable-content').append(items);
2306
+
2298
2307
  secondaryResolve();
2299
2308
  } else {
2300
2309
  secondaryResolve();
@@ -2607,11 +2616,27 @@
2607
2616
  item.id = item[self.primaryKeyword].toString();
2608
2617
  return item;
2609
2618
  });
2619
+ var itemIds = items.map(function (item) {
2620
+ return parseInt(item.id, 10);
2621
+ }); // Remove value from data if it doesn't exist anymore
2622
+
2623
+ self.data[self.name] = self.data[self.name].filter(function (value) {
2624
+ return itemIds.indexOf(parseInt(value, 10)) > -1;
2625
+ });
2626
+
2627
+ if (self.data[self.name].length == 0) {
2628
+ self.$selectIconContainer.html(self.selectIconDefault);
2629
+ }
2630
+
2610
2631
  items = items.filter(function (item) {
2611
2632
  return self.data[self.name].indexOf(item.id) > -1 && self.itemsToExclude.indexOf(parseInt(item.id, 10)) === -1 && parseInt(item.id, 10) > 0;
2612
2633
  });
2613
- var result = $(self._renderItemList(items));
2634
+
2635
+ var result = self._renderItemList(items);
2636
+
2614
2637
  $.when(self.$scrollableContent.append(result)).then(function () {
2638
+ var $inputs = self.$scrollableContent.find(':input');
2639
+
2615
2640
  if (self.$scrollableContent[0].offsetHeight < self.$scrollableContent[0].scrollHeight) {
2616
2641
  self.scroll.update();
2617
2642
  self.scroll.settings.suppressScrollY = false;
@@ -2622,22 +2647,22 @@
2622
2647
  self.$scrollableContent.removeClass('ps-show-rail-y');
2623
2648
  }
2624
2649
 
2625
- if (self.$select.find(':input[type="checkbox"]').length) {
2650
+ if (self.$scrollableContent.find(':input[type="checkbox"]').length) {
2626
2651
  self.type = 'checkbox';
2627
- } else if (self.$select.find(':input[type="radio"]').length) {
2652
+ } else if (self.$scrollableContent.find(':input[type="radio"]').length) {
2628
2653
  self.type = 'radio';
2629
2654
  }
2630
2655
 
2631
2656
  if (self.type == 'checkbox') {
2632
2657
  self.data[self.name].forEach(function (value) {
2633
- var $input = self.$select.find(':input').filter(function () {
2658
+ var $input = $inputs.filter(function () {
2634
2659
  return this.value == value;
2635
2660
  });
2636
2661
  $input.prop('checked', true);
2637
2662
  self.onSelect($input[0]);
2638
2663
  });
2639
2664
  } else if (self.type == 'radio') {
2640
- var $input = self.$select.find(':input').filter(function () {
2665
+ var $input = $inputs.filter(function () {
2641
2666
  return this.value == self.data[self.name];
2642
2667
  });
2643
2668
  $input.prop('checked', true);
@@ -2652,22 +2677,35 @@
2652
2677
  });
2653
2678
  });
2654
2679
  } else {
2655
- if (this.$select.find(':input[type="checkbox"]').length) {
2680
+ // Remove value from data if it doesn't exist anymore
2681
+ var $inputs = this.$scrollableContent.find(':input');
2682
+ var inputValues = $inputs.length > 0 ? $inputs.map(function () {
2683
+ return parseInt(this.value, 10);
2684
+ }).get() : [];
2685
+ this.data[this.name] = this.data[this.name].filter(function (value) {
2686
+ return inputValues.indexOf(parseInt(value, 10)) > -1;
2687
+ });
2688
+
2689
+ if (this.data[this.name].length == 0) {
2690
+ this.$selectIconContainer.html(this.selectIconDefault);
2691
+ }
2692
+
2693
+ if (this.$scrollableContent.find(':input[type="checkbox"]').length) {
2656
2694
  this.type = 'checkbox';
2657
- } else if (this.$select.find(':input[type="radio"]').length) {
2695
+ } else if (this.$scrollableContent.find(':input[type="radio"]').length) {
2658
2696
  this.type = 'radio';
2659
2697
  }
2660
2698
 
2661
2699
  if (this.type == 'checkbox') {
2662
2700
  this.data[this.name].forEach(function (value) {
2663
- var $input = self.$select.find(':input').filter(function () {
2701
+ var $input = $inputs.filter(function () {
2664
2702
  return this.value == value;
2665
2703
  });
2666
2704
  $input.prop('checked', true);
2667
2705
  self.onSelect($input[0]);
2668
2706
  });
2669
2707
  } else if (this.type == 'radio') {
2670
- var $input = this.$select.find(':input').filter(function () {
2708
+ var $input = $inputs.filter(function () {
2671
2709
  return this.value == self.data[self.name];
2672
2710
  });
2673
2711
  $input.prop('checked', true);
@@ -2690,10 +2728,16 @@
2690
2728
  if (this.searchString.length) {
2691
2729
  if (this.searchApi.length) {
2692
2730
  this.$scrollableContent.find('input:not(:checked)').parents('.select-item').not('.static-item').remove();
2693
- $.ajax({
2731
+
2732
+ if (this.searchRequest !== null) {
2733
+ this.searchRequest.abort();
2734
+ }
2735
+
2736
+ this.searchRequest = $.ajax({
2694
2737
  method: 'GET',
2695
2738
  url: this.searchApi + this.searchString
2696
2739
  }).done(function (data) {
2740
+ self.searchRequest = null;
2697
2741
  var items = data.map(function (item) {
2698
2742
  item.id = item[self.primaryKeyword].toString();
2699
2743
  return item;
@@ -2701,7 +2745,9 @@
2701
2745
  items = items.filter(function (item) {
2702
2746
  return self.data[self.name].indexOf(item.id) === -1 && self.itemsToExclude.indexOf(parseInt(item.id, 10)) === -1 && parseInt(item.id, 10) > 0;
2703
2747
  });
2704
- var result = $(self._renderItemList(items));
2748
+
2749
+ var result = self._renderItemList(items);
2750
+
2705
2751
  $.when(self.$scrollableContent.append(result)).then(function () {
2706
2752
  var faNameSpace = self.opts.faPro ? 'fal' : 'fas';
2707
2753
  self.$searchIconContainer.html("<i class=\"" + faNameSpace + " fa-times icon\"></i>");
@@ -2823,10 +2869,21 @@
2823
2869
  ;
2824
2870
 
2825
2871
  _proto.onSelect = function onSelect(el) {
2872
+ var self = this;
2826
2873
  var onSelect = this.opts.onSelect;
2874
+ var data = $(el).parents('.select-item').data();
2875
+
2876
+ if (this.searchApi.length && !$.isEmptyObject(data)) {
2877
+ if ($(el).length && el.checked) {
2878
+ this.items.push(data);
2879
+ } else {
2880
+ this.items = $.grep(this.items, function (item) {
2881
+ return item[self.primaryKeyword] != data.id;
2882
+ });
2883
+ }
2884
+ }
2827
2885
 
2828
2886
  if (typeof onSelect === 'function') {
2829
- var data = this.getItem('id', el.value);
2830
2887
  onSelect.call(el, data, this);
2831
2888
  }
2832
2889
  } // Add more items after plugin is already initialized
@@ -3014,7 +3071,7 @@
3014
3071
  };
3015
3072
 
3016
3073
  _proto._renderItemList = function _renderItemList(items) {
3017
- var result = '';
3074
+ var result = [];
3018
3075
 
3019
3076
  for (var i = 0; i < items.length; ++i) {
3020
3077
  var item = items[i];
@@ -3032,7 +3089,7 @@
3032
3089
  }
3033
3090
  }
3034
3091
 
3035
- result += "\n\n <div class=\"select-item\">\n\n <div class=\"select-item-" + this.type + "\">\n\n <div class=\"styled-" + this.type + "\">\n\n <input type=\"" + this.type + "\" id=\"select-" + this.name + "-" + items[i].id + "\" value=\"" + items[i].id + "\" tabindex=\"-1\">\n\n <label for=\"select-" + this.name + "-" + items[i].id + "\">\n\n <span class=\"radio-inner\">\n <svg viewBox=\"0 0 18 18\">\n <polyline points=\"1.5 6 4.5 9 10.5 1\"></polyline>\n </svg>\n </span>\n\n <span class=\"" + this.type + "-label\"" + (typeof this.labelTemplate !== 'function' ? ' data-label' : '') + ">\n " + label + "\n </span>\n\n </label>\n\n </div>\n\n </div>\n\n </div>\n\n ";
3092
+ result.push($("\n\n <div class=\"select-item\">\n\n <div class=\"select-item-" + this.type + "\">\n\n <div class=\"styled-" + this.type + "\">\n\n <input type=\"" + this.type + "\" id=\"select-" + this.name + "-" + items[i].id + "\" value=\"" + items[i].id + "\" tabindex=\"-1\">\n\n <label for=\"select-" + this.name + "-" + items[i].id + "\">\n\n <span class=\"radio-inner\">\n <svg viewBox=\"0 0 18 18\">\n <polyline points=\"1.5 6 4.5 9 10.5 1\"></polyline>\n </svg>\n </span>\n\n <span class=\"" + this.type + "-label\"" + (typeof this.labelTemplate !== 'function' ? ' data-label' : '') + ">\n " + label + "\n </span>\n\n </label>\n\n </div>\n\n </div>\n\n </div>\n\n ").data(item));
3036
3093
  }
3037
3094
 
3038
3095
  return result;
@@ -5461,5 +5518,5 @@
5461
5518
 
5462
5519
  return index_umd;
5463
5520
 
5464
- }));
5521
+ })));
5465
5522
  //# sourceMappingURL=cool.bundle.js.map