@finqu/cool 1.2.6 → 1.2.7

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,6 +1,6 @@
1
1
  /*!
2
- * Cool UI v1.2.5 (https://finqu.fi)
3
- * Copyright 2011-2019 Finqu Oy
2
+ * Cool UI v1.2.6 (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) {
@@ -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,
@@ -2262,13 +2268,13 @@
2262
2268
  _this3.data = _this3.$el.data('setData');
2263
2269
  }
2264
2270
 
2265
- if (typeof _this3.data[_this3.name].filter !== 'undefined' && self.itemsToExclude) {
2271
+ if (_this3.data[_this3.name] !== 'undefined' && _this3.data[_this3.name].length > 0 && self.itemsToExclude) {
2266
2272
  _this3.data[_this3.name] = _this3.data[_this3.name].filter(function (item) {
2267
2273
  return self.itemsToExclude.indexOf(parseInt(item.id, 10)) === -1;
2268
2274
  });
2269
2275
  }
2270
2276
 
2271
- if (typeof _this3.items.filter !== 'undefined' && self.itemsToExclude) {
2277
+ if (_this3.items !== 'undefined' && _this3.items.lengths > 0 && self.itemsToExclude) {
2272
2278
  _this3.items = _this3.items.filter(function (item) {
2273
2279
  return self.itemsToExclude.indexOf(parseInt(item.id, 10)) === -1;
2274
2280
  });
@@ -2291,10 +2297,12 @@
2291
2297
  if (!_this3.$select.length) {
2292
2298
  var items = _this3._renderItemList(_this3.items);
2293
2299
 
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 ");
2300
+ _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
2301
 
2296
2302
  _this3.$el.append(_this3.$select);
2297
2303
 
2304
+ _this3.$select.find('.select-scrollable-content').append(items);
2305
+
2298
2306
  secondaryResolve();
2299
2307
  } else {
2300
2308
  secondaryResolve();
@@ -2607,11 +2615,27 @@
2607
2615
  item.id = item[self.primaryKeyword].toString();
2608
2616
  return item;
2609
2617
  });
2618
+ var itemIds = items.map(function (item) {
2619
+ return parseInt(item.id, 10);
2620
+ }); // Remove value from data if it doesn't exist anymore
2621
+
2622
+ self.data[self.name] = self.data[self.name].filter(function (value) {
2623
+ return itemIds.indexOf(parseInt(value, 10)) > -1;
2624
+ });
2625
+
2626
+ if (self.data[self.name].length == 0) {
2627
+ self.$selectIconContainer.html(self.selectIconDefault);
2628
+ }
2629
+
2610
2630
  items = items.filter(function (item) {
2611
2631
  return self.data[self.name].indexOf(item.id) > -1 && self.itemsToExclude.indexOf(parseInt(item.id, 10)) === -1 && parseInt(item.id, 10) > 0;
2612
2632
  });
2613
- var result = $(self._renderItemList(items));
2633
+
2634
+ var result = self._renderItemList(items);
2635
+
2614
2636
  $.when(self.$scrollableContent.append(result)).then(function () {
2637
+ var $inputs = self.$scrollableContent.find(':input');
2638
+
2615
2639
  if (self.$scrollableContent[0].offsetHeight < self.$scrollableContent[0].scrollHeight) {
2616
2640
  self.scroll.update();
2617
2641
  self.scroll.settings.suppressScrollY = false;
@@ -2622,22 +2646,22 @@
2622
2646
  self.$scrollableContent.removeClass('ps-show-rail-y');
2623
2647
  }
2624
2648
 
2625
- if (self.$select.find(':input[type="checkbox"]').length) {
2649
+ if (self.$scrollableContent.find(':input[type="checkbox"]').length) {
2626
2650
  self.type = 'checkbox';
2627
- } else if (self.$select.find(':input[type="radio"]').length) {
2651
+ } else if (self.$scrollableContent.find(':input[type="radio"]').length) {
2628
2652
  self.type = 'radio';
2629
2653
  }
2630
2654
 
2631
2655
  if (self.type == 'checkbox') {
2632
2656
  self.data[self.name].forEach(function (value) {
2633
- var $input = self.$select.find(':input').filter(function () {
2657
+ var $input = $inputs.filter(function () {
2634
2658
  return this.value == value;
2635
2659
  });
2636
2660
  $input.prop('checked', true);
2637
2661
  self.onSelect($input[0]);
2638
2662
  });
2639
2663
  } else if (self.type == 'radio') {
2640
- var $input = self.$select.find(':input').filter(function () {
2664
+ var $input = $inputs.filter(function () {
2641
2665
  return this.value == self.data[self.name];
2642
2666
  });
2643
2667
  $input.prop('checked', true);
@@ -2652,22 +2676,35 @@
2652
2676
  });
2653
2677
  });
2654
2678
  } else {
2655
- if (this.$select.find(':input[type="checkbox"]').length) {
2679
+ // Remove value from data if it doesn't exist anymore
2680
+ var $inputs = this.$scrollableContent.find(':input');
2681
+ var inputValues = $inputs.length > 0 ? $inputs.map(function () {
2682
+ return parseInt(this.value, 10);
2683
+ }).get() : [];
2684
+ this.data[this.name] = this.data[this.name].filter(function (value) {
2685
+ return inputValues.indexOf(parseInt(value, 10)) > -1;
2686
+ });
2687
+
2688
+ if (this.data[this.name].length == 0) {
2689
+ this.$selectIconContainer.html(this.selectIconDefault);
2690
+ }
2691
+
2692
+ if (this.$scrollableContent.find(':input[type="checkbox"]').length) {
2656
2693
  this.type = 'checkbox';
2657
- } else if (this.$select.find(':input[type="radio"]').length) {
2694
+ } else if (this.$scrollableContent.find(':input[type="radio"]').length) {
2658
2695
  this.type = 'radio';
2659
2696
  }
2660
2697
 
2661
2698
  if (this.type == 'checkbox') {
2662
2699
  this.data[this.name].forEach(function (value) {
2663
- var $input = self.$select.find(':input').filter(function () {
2700
+ var $input = $inputs.filter(function () {
2664
2701
  return this.value == value;
2665
2702
  });
2666
2703
  $input.prop('checked', true);
2667
2704
  self.onSelect($input[0]);
2668
2705
  });
2669
2706
  } else if (this.type == 'radio') {
2670
- var $input = this.$select.find(':input').filter(function () {
2707
+ var $input = $inputs.filter(function () {
2671
2708
  return this.value == self.data[self.name];
2672
2709
  });
2673
2710
  $input.prop('checked', true);
@@ -2701,7 +2738,9 @@
2701
2738
  items = items.filter(function (item) {
2702
2739
  return self.data[self.name].indexOf(item.id) === -1 && self.itemsToExclude.indexOf(parseInt(item.id, 10)) === -1 && parseInt(item.id, 10) > 0;
2703
2740
  });
2704
- var result = $(self._renderItemList(items));
2741
+
2742
+ var result = self._renderItemList(items);
2743
+
2705
2744
  $.when(self.$scrollableContent.append(result)).then(function () {
2706
2745
  var faNameSpace = self.opts.faPro ? 'fal' : 'fas';
2707
2746
  self.$searchIconContainer.html("<i class=\"" + faNameSpace + " fa-times icon\"></i>");
@@ -2823,10 +2862,21 @@
2823
2862
  ;
2824
2863
 
2825
2864
  _proto.onSelect = function onSelect(el) {
2865
+ var self = this;
2826
2866
  var onSelect = this.opts.onSelect;
2867
+ var data = $(el).parents('.select-item').data();
2868
+
2869
+ if (this.searchApi.length && !$.isEmptyObject(data)) {
2870
+ if ($(el).length && el.checked) {
2871
+ this.items.push(data);
2872
+ } else {
2873
+ this.items = $.grep(this.items, function (item) {
2874
+ return item[self.primaryKeyword] != data.id;
2875
+ });
2876
+ }
2877
+ }
2827
2878
 
2828
2879
  if (typeof onSelect === 'function') {
2829
- var data = this.getItem('id', el.value);
2830
2880
  onSelect.call(el, data, this);
2831
2881
  }
2832
2882
  } // Add more items after plugin is already initialized
@@ -3014,7 +3064,7 @@
3014
3064
  };
3015
3065
 
3016
3066
  _proto._renderItemList = function _renderItemList(items) {
3017
- var result = '';
3067
+ var result = [];
3018
3068
 
3019
3069
  for (var i = 0; i < items.length; ++i) {
3020
3070
  var item = items[i];
@@ -3032,7 +3082,7 @@
3032
3082
  }
3033
3083
  }
3034
3084
 
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 ";
3085
+ 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
3086
  }
3037
3087
 
3038
3088
  return result;