@egjs/flicking-plugins 4.2.2 → 4.2.3

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.
package/dist/plugins.js CHANGED
@@ -4,7 +4,7 @@ name: @egjs/flicking-plugins
4
4
  license: MIT
5
5
  author: NAVER Corp.
6
6
  repository: https://github.com/naver/egjs-flicking-plugins
7
- version: 4.2.2
7
+ version: 4.2.3
8
8
  */
9
9
  (function (global, factory) {
10
10
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@egjs/flicking')) :
@@ -723,46 +723,52 @@ version: 4.2.2
723
723
 
724
724
  this._flicking = null;
725
725
 
726
- this._addEvents = function (synchronizedFlickingOptions) {
727
- synchronizedFlickingOptions.forEach(function (_a) {
726
+ this._addEvents = function () {
727
+ var type = _this._type;
728
+ var synced = _this._synchronizedFlickingOptions;
729
+ synced.forEach(function (_a) {
728
730
  var flicking$1 = _a.flicking,
729
731
  isSlidable = _a.isSlidable,
730
732
  isClickable = _a.isClickable;
731
733
 
732
- if (_this._type === "camera") {
734
+ if (type === SYNC.TYPE.CAMERA) {
733
735
  flicking$1.on(flicking.EVENTS.MOVE, _this._onMove);
734
736
  flicking$1.on(flicking.EVENTS.MOVE_START, _this._onMoveStart);
735
737
  flicking$1.on(flicking.EVENTS.MOVE_END, _this._onMoveEnd);
736
738
  }
737
739
 
738
- if (_this._type === "index" && isSlidable) {
740
+ if (type === SYNC.TYPE.INDEX && isSlidable) {
739
741
  flicking$1.on(flicking.EVENTS.WILL_CHANGE, _this._onIndexChange);
742
+ flicking$1.on(flicking.EVENTS.WILL_RESTORE, _this._onIndexChange);
740
743
  }
741
744
 
742
745
  if (isClickable) {
743
- flicking$1.on(flicking.EVENTS.SELECT, _this._onIndexChange);
746
+ flicking$1.on(flicking.EVENTS.SELECT, _this._onSelect);
744
747
  }
745
748
  });
746
749
  };
747
750
 
748
- this._removeEvents = function (synchronizedFlickingOptions) {
749
- synchronizedFlickingOptions.forEach(function (_a) {
751
+ this._removeEvents = function () {
752
+ var type = _this._type;
753
+ var synced = _this._synchronizedFlickingOptions;
754
+ synced.forEach(function (_a) {
750
755
  var flicking$1 = _a.flicking,
751
756
  isSlidable = _a.isSlidable,
752
757
  isClickable = _a.isClickable;
753
758
 
754
- if (_this._type === "camera") {
759
+ if (type === SYNC.TYPE.CAMERA) {
755
760
  flicking$1.off(flicking.EVENTS.MOVE, _this._onMove);
756
761
  flicking$1.off(flicking.EVENTS.MOVE_START, _this._onMoveStart);
757
762
  flicking$1.off(flicking.EVENTS.MOVE_END, _this._onMoveEnd);
758
763
  }
759
764
 
760
- if (_this._type === "index" && isSlidable) {
765
+ if (type === SYNC.TYPE.INDEX && isSlidable) {
761
766
  flicking$1.off(flicking.EVENTS.WILL_CHANGE, _this._onIndexChange);
767
+ flicking$1.off(flicking.EVENTS.WILL_RESTORE, _this._onIndexChange);
762
768
  }
763
769
 
764
770
  if (isClickable) {
765
- flicking$1.off(flicking.EVENTS.SELECT, _this._onIndexChange);
771
+ flicking$1.off(flicking.EVENTS.SELECT, _this._onSelect);
766
772
  }
767
773
  });
768
774
  };
@@ -783,16 +789,18 @@ version: 4.2.2
783
789
 
784
790
  _this._synchronizedFlickingOptions.forEach(function (_a) {
785
791
  var flicking = _a.flicking;
792
+ if (flicking === e.currentTarget) return;
793
+ var targetPosition = 0;
786
794
 
787
- if (flicking !== e.currentTarget) {
788
- if (camera.position < camera.range.min) {
789
- void flicking.camera.lookAt(camera.position);
790
- } else if (camera.position > camera.range.max) {
791
- void flicking.camera.lookAt(flicking.camera.range.max + camera.position - camera.range.max);
792
- } else {
793
- void flicking.camera.lookAt(flicking.camera.range.min + flicking.camera.rangeDiff * progress);
794
- }
795
+ if (camera.position < camera.range.min) {
796
+ targetPosition = camera.position;
797
+ } else if (camera.position > camera.range.max) {
798
+ targetPosition = flicking.camera.range.max + camera.position - camera.range.max;
799
+ } else {
800
+ targetPosition = flicking.camera.range.min + flicking.camera.rangeDiff * progress;
795
801
  }
802
+
803
+ void flicking.camera.lookAt(targetPosition);
796
804
  });
797
805
  };
798
806
 
@@ -817,59 +825,53 @@ version: 4.2.2
817
825
  });
818
826
  };
819
827
 
820
- this._synchronizeByIndex = function (activeFlicking, index) {
821
- var synchronizedFlickingOptions = _this._synchronizedFlickingOptions;
822
- var activePanel = activeFlicking.panels.find(function (panel) {
823
- return panel.index === index;
828
+ this._onSelect = function (e) {
829
+ void e.currentTarget.moveTo(e.index).catch(function () {
830
+ return void 0;
824
831
  });
825
- var lastPanel = activeFlicking.panels[activeFlicking.panels.length - 1];
826
-
827
- if (!activePanel) {
828
- return;
829
- }
830
832
 
831
- _this._preventEvent(function () {
832
- synchronizedFlickingOptions.forEach(function (_a) {
833
- var flicking = _a.flicking,
834
- activeClass = _a.activeClass; // calculate new target flicking position with active flicking size and target flicking size
833
+ _this._synchronizeByIndex(e.currentTarget, e.index);
834
+ };
835
835
 
836
- var targetLastPanel = flicking.panels[flicking.panels.length - 1];
837
- var targetPos = activePanel.position / (lastPanel.position + lastPanel.size / 2) * (targetLastPanel.position + targetLastPanel.size / 2);
838
- flicking.control.moveToPosition(targetPos, 500).catch(function () {
839
- return void 0;
840
- });
836
+ this._synchronizeByIndex = function (activeFlicking, index) {
837
+ var synchronizedFlickingOptions = _this._synchronizedFlickingOptions;
841
838
 
842
- if (activeClass) {
843
- _this._updateClass({
844
- flicking: flicking,
845
- activeClass: activeClass
846
- }, targetPos);
839
+ _this._preventEvent(function () {
840
+ synchronizedFlickingOptions.forEach(function (options) {
841
+ // Active class should be applied same to the Flicking which triggered event
842
+ _this._updateClass(options, index);
843
+
844
+ var flicking$1 = options.flicking;
845
+ if (flicking$1 === activeFlicking) return;
846
+ var targetIndex = flicking.clamp(index, 0, flicking$1.panels.length);
847
+
848
+ if (flicking$1.animating) {
849
+ // Reserve moveTo once previous animation is finished
850
+ flicking$1.once(flicking.EVENTS.MOVE_END, function () {
851
+ void flicking$1.moveTo(targetIndex).catch(function () {
852
+ return void 0;
853
+ });
854
+ });
855
+ } else {
856
+ void flicking$1.moveTo(targetIndex);
847
857
  }
848
858
  });
849
859
  });
850
860
  };
851
861
 
852
- this._updateClass = function (synchronizedFlickingOption, pos) {
853
- var target = _this._findNearsetPanel(synchronizedFlickingOption.flicking, pos);
854
-
855
- synchronizedFlickingOption.flicking.panels.forEach(function (panel) {
856
- return panel.index === target.index ? addClass(panel.element, synchronizedFlickingOption.activeClass) : removeClass(panel.element, synchronizedFlickingOption.activeClass);
862
+ this._updateClass = function (_a, index) {
863
+ var flicking = _a.flicking,
864
+ activeClass = _a.activeClass;
865
+ if (!activeClass) return;
866
+ flicking.panels.forEach(function (panel) {
867
+ if (panel.index === index) {
868
+ addClass(panel.element, activeClass);
869
+ } else {
870
+ removeClass(panel.element, activeClass);
871
+ }
857
872
  });
858
873
  };
859
874
 
860
- this._findNearsetPanel = function (flicking, pos) {
861
- var nearsetIndex = flicking.panels.reduce(function (nearest, panel, index) {
862
- return Math.abs(panel.position - pos) <= nearest.range ? {
863
- index: index,
864
- range: Math.abs(panel.position - pos)
865
- } : nearest;
866
- }, {
867
- index: 0,
868
- range: Infinity
869
- }).index;
870
- return flicking.panels[nearsetIndex];
871
- };
872
-
873
875
  this._type = type;
874
876
  this._synchronizedFlickingOptions = synchronizedFlickingOptions;
875
877
  }
@@ -880,11 +882,7 @@ version: 4.2.2
880
882
  return this._type;
881
883
  },
882
884
  set: function (val) {
883
- var _this = this;
884
-
885
- this._preventEvent(function () {
886
- _this._type = val;
887
- });
885
+ this._type = val;
888
886
  },
889
887
  enumerable: false,
890
888
  configurable: true
@@ -894,11 +892,7 @@ version: 4.2.2
894
892
  return this._synchronizedFlickingOptions;
895
893
  },
896
894
  set: function (val) {
897
- var _this = this;
898
-
899
- this._preventEvent(function () {
900
- _this._synchronizedFlickingOptions = val;
901
- });
895
+ this._synchronizedFlickingOptions = val;
902
896
  },
903
897
  enumerable: false,
904
898
  configurable: true
@@ -907,16 +901,20 @@ version: 4.2.2
907
901
  __proto.init = function (flicking) {
908
902
  var _this = this;
909
903
 
904
+ var synced = this._synchronizedFlickingOptions;
905
+
910
906
  if (this._flicking) {
911
907
  this.destroy();
912
908
  }
913
909
 
914
910
  this._flicking = flicking;
915
911
 
916
- this._addEvents(this._synchronizedFlickingOptions);
912
+ this._addEvents();
917
913
 
918
- this._synchronizedFlickingOptions.forEach(function (synchronizedFlickingOption) {
919
- _this._updateClass(synchronizedFlickingOption, 0);
914
+ synced.forEach(function (options) {
915
+ var syncedFlicking = options.flicking;
916
+
917
+ _this._updateClass(options, syncedFlicking.defaultIndex);
920
918
  });
921
919
  };
922
920
 
@@ -927,7 +925,7 @@ version: 4.2.2
927
925
  return;
928
926
  }
929
927
 
930
- this._removeEvents(this._synchronizedFlickingOptions);
928
+ this._removeEvents();
931
929
 
932
930
  this._flicking = null;
933
931
  };
@@ -935,23 +933,17 @@ version: 4.2.2
935
933
  __proto.update = function () {
936
934
  var _this = this;
937
935
 
938
- this._synchronizedFlickingOptions.forEach(function (_a) {
939
- var flicking = _a.flicking,
940
- activeClass = _a.activeClass;
941
-
942
- _this._updateClass({
943
- flicking: flicking,
944
- activeClass: activeClass
945
- }, flicking.camera.position);
936
+ this._synchronizedFlickingOptions.forEach(function (options) {
937
+ _this._updateClass(options, options.flicking.index);
946
938
  });
947
939
  };
948
940
 
949
941
  __proto._preventEvent = function (fn) {
950
- this._removeEvents(this._synchronizedFlickingOptions);
942
+ this._removeEvents();
951
943
 
952
944
  fn();
953
945
 
954
- this._addEvents(this._synchronizedFlickingOptions);
946
+ this._addEvents();
955
947
  };
956
948
 
957
949
  return Sync;