@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/declaration/Sync.d.ts +7 -5
- package/declaration/index.d.ts +2 -1
- package/dist/plugins.esm.js +77 -85
- package/dist/plugins.esm.js.map +1 -1
- package/dist/plugins.js +76 -84
- package/dist/plugins.js.map +1 -1
- package/dist/plugins.min.js +2 -2
- package/dist/plugins.min.js.map +1 -1
- package/package.json +3 -2
- package/src/Sync.ts +95 -67
- package/src/index.ts +6 -1
package/declaration/Sync.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import Flicking
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import Flicking from "@egjs/flicking";
|
|
2
|
+
import type { Plugin } from "@egjs/flicking";
|
|
3
|
+
import { SYNC } from "./const";
|
|
4
|
+
export interface SyncOptions {
|
|
5
|
+
type: typeof SYNC.TYPE.CAMERA | typeof SYNC.TYPE.INDEX;
|
|
4
6
|
synchronizedFlickingOptions: SychronizableFlickingOptions[];
|
|
5
7
|
}
|
|
6
|
-
interface SychronizableFlickingOptions {
|
|
8
|
+
export interface SychronizableFlickingOptions {
|
|
7
9
|
flicking: Flicking;
|
|
8
10
|
isClickable?: boolean;
|
|
9
11
|
isSlidable?: boolean;
|
|
@@ -28,8 +30,8 @@ declare class Sync implements Plugin {
|
|
|
28
30
|
private _onMove;
|
|
29
31
|
private _onMoveStart;
|
|
30
32
|
private _onMoveEnd;
|
|
33
|
+
private _onSelect;
|
|
31
34
|
private _synchronizeByIndex;
|
|
32
35
|
private _updateClass;
|
|
33
|
-
private _findNearsetPanel;
|
|
34
36
|
}
|
|
35
37
|
export default Sync;
|
package/declaration/index.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import Parallax from "./Parallax";
|
|
|
2
2
|
import Fade from "./Fade";
|
|
3
3
|
import AutoPlay from "./AutoPlay";
|
|
4
4
|
import Arrow from "./Arrow";
|
|
5
|
-
import Sync from "./Sync";
|
|
5
|
+
import Sync, { SyncOptions, SychronizableFlickingOptions } from "./Sync";
|
|
6
6
|
export * from "./pagination";
|
|
7
7
|
export { Parallax, Fade, AutoPlay, Arrow, Sync };
|
|
8
|
+
export type { SyncOptions, SychronizableFlickingOptions };
|
|
8
9
|
export * from "./const";
|
package/dist/plugins.esm.js
CHANGED
|
@@ -4,9 +4,9 @@ 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.
|
|
7
|
+
version: 4.2.3
|
|
8
8
|
*/
|
|
9
|
-
import { EVENTS, DIRECTION, FlickingError } from '@egjs/flicking';
|
|
9
|
+
import { EVENTS, DIRECTION, FlickingError, clamp } from '@egjs/flicking';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* You can apply parallax effect while panel is moving.
|
|
@@ -719,46 +719,52 @@ function () {
|
|
|
719
719
|
|
|
720
720
|
this._flicking = null;
|
|
721
721
|
|
|
722
|
-
this._addEvents = function (
|
|
723
|
-
|
|
722
|
+
this._addEvents = function () {
|
|
723
|
+
var type = _this._type;
|
|
724
|
+
var synced = _this._synchronizedFlickingOptions;
|
|
725
|
+
synced.forEach(function (_a) {
|
|
724
726
|
var flicking = _a.flicking,
|
|
725
727
|
isSlidable = _a.isSlidable,
|
|
726
728
|
isClickable = _a.isClickable;
|
|
727
729
|
|
|
728
|
-
if (
|
|
730
|
+
if (type === SYNC.TYPE.CAMERA) {
|
|
729
731
|
flicking.on(EVENTS.MOVE, _this._onMove);
|
|
730
732
|
flicking.on(EVENTS.MOVE_START, _this._onMoveStart);
|
|
731
733
|
flicking.on(EVENTS.MOVE_END, _this._onMoveEnd);
|
|
732
734
|
}
|
|
733
735
|
|
|
734
|
-
if (
|
|
736
|
+
if (type === SYNC.TYPE.INDEX && isSlidable) {
|
|
735
737
|
flicking.on(EVENTS.WILL_CHANGE, _this._onIndexChange);
|
|
738
|
+
flicking.on(EVENTS.WILL_RESTORE, _this._onIndexChange);
|
|
736
739
|
}
|
|
737
740
|
|
|
738
741
|
if (isClickable) {
|
|
739
|
-
flicking.on(EVENTS.SELECT, _this.
|
|
742
|
+
flicking.on(EVENTS.SELECT, _this._onSelect);
|
|
740
743
|
}
|
|
741
744
|
});
|
|
742
745
|
};
|
|
743
746
|
|
|
744
|
-
this._removeEvents = function (
|
|
745
|
-
|
|
747
|
+
this._removeEvents = function () {
|
|
748
|
+
var type = _this._type;
|
|
749
|
+
var synced = _this._synchronizedFlickingOptions;
|
|
750
|
+
synced.forEach(function (_a) {
|
|
746
751
|
var flicking = _a.flicking,
|
|
747
752
|
isSlidable = _a.isSlidable,
|
|
748
753
|
isClickable = _a.isClickable;
|
|
749
754
|
|
|
750
|
-
if (
|
|
755
|
+
if (type === SYNC.TYPE.CAMERA) {
|
|
751
756
|
flicking.off(EVENTS.MOVE, _this._onMove);
|
|
752
757
|
flicking.off(EVENTS.MOVE_START, _this._onMoveStart);
|
|
753
758
|
flicking.off(EVENTS.MOVE_END, _this._onMoveEnd);
|
|
754
759
|
}
|
|
755
760
|
|
|
756
|
-
if (
|
|
761
|
+
if (type === SYNC.TYPE.INDEX && isSlidable) {
|
|
757
762
|
flicking.off(EVENTS.WILL_CHANGE, _this._onIndexChange);
|
|
763
|
+
flicking.off(EVENTS.WILL_RESTORE, _this._onIndexChange);
|
|
758
764
|
}
|
|
759
765
|
|
|
760
766
|
if (isClickable) {
|
|
761
|
-
flicking.off(EVENTS.SELECT, _this.
|
|
767
|
+
flicking.off(EVENTS.SELECT, _this._onSelect);
|
|
762
768
|
}
|
|
763
769
|
});
|
|
764
770
|
};
|
|
@@ -779,16 +785,18 @@ function () {
|
|
|
779
785
|
|
|
780
786
|
_this._synchronizedFlickingOptions.forEach(function (_a) {
|
|
781
787
|
var flicking = _a.flicking;
|
|
788
|
+
if (flicking === e.currentTarget) return;
|
|
789
|
+
var targetPosition = 0;
|
|
782
790
|
|
|
783
|
-
if (
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
void flicking.camera.lookAt(flicking.camera.range.min + flicking.camera.rangeDiff * progress);
|
|
790
|
-
}
|
|
791
|
+
if (camera.position < camera.range.min) {
|
|
792
|
+
targetPosition = camera.position;
|
|
793
|
+
} else if (camera.position > camera.range.max) {
|
|
794
|
+
targetPosition = flicking.camera.range.max + camera.position - camera.range.max;
|
|
795
|
+
} else {
|
|
796
|
+
targetPosition = flicking.camera.range.min + flicking.camera.rangeDiff * progress;
|
|
791
797
|
}
|
|
798
|
+
|
|
799
|
+
void flicking.camera.lookAt(targetPosition);
|
|
792
800
|
});
|
|
793
801
|
};
|
|
794
802
|
|
|
@@ -813,59 +821,53 @@ function () {
|
|
|
813
821
|
});
|
|
814
822
|
};
|
|
815
823
|
|
|
816
|
-
this.
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
return panel.index === index;
|
|
824
|
+
this._onSelect = function (e) {
|
|
825
|
+
void e.currentTarget.moveTo(e.index).catch(function () {
|
|
826
|
+
return void 0;
|
|
820
827
|
});
|
|
821
|
-
var lastPanel = activeFlicking.panels[activeFlicking.panels.length - 1];
|
|
822
|
-
|
|
823
|
-
if (!activePanel) {
|
|
824
|
-
return;
|
|
825
|
-
}
|
|
826
828
|
|
|
827
|
-
_this.
|
|
828
|
-
|
|
829
|
-
var flicking = _a.flicking,
|
|
830
|
-
activeClass = _a.activeClass; // calculate new target flicking position with active flicking size and target flicking size
|
|
829
|
+
_this._synchronizeByIndex(e.currentTarget, e.index);
|
|
830
|
+
};
|
|
831
831
|
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
flicking.control.moveToPosition(targetPos, 500).catch(function () {
|
|
835
|
-
return void 0;
|
|
836
|
-
});
|
|
832
|
+
this._synchronizeByIndex = function (activeFlicking, index) {
|
|
833
|
+
var synchronizedFlickingOptions = _this._synchronizedFlickingOptions;
|
|
837
834
|
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
835
|
+
_this._preventEvent(function () {
|
|
836
|
+
synchronizedFlickingOptions.forEach(function (options) {
|
|
837
|
+
// Active class should be applied same to the Flicking which triggered event
|
|
838
|
+
_this._updateClass(options, index);
|
|
839
|
+
|
|
840
|
+
var flicking = options.flicking;
|
|
841
|
+
if (flicking === activeFlicking) return;
|
|
842
|
+
var targetIndex = clamp(index, 0, flicking.panels.length);
|
|
843
|
+
|
|
844
|
+
if (flicking.animating) {
|
|
845
|
+
// Reserve moveTo once previous animation is finished
|
|
846
|
+
flicking.once(EVENTS.MOVE_END, function () {
|
|
847
|
+
void flicking.moveTo(targetIndex).catch(function () {
|
|
848
|
+
return void 0;
|
|
849
|
+
});
|
|
850
|
+
});
|
|
851
|
+
} else {
|
|
852
|
+
void flicking.moveTo(targetIndex);
|
|
843
853
|
}
|
|
844
854
|
});
|
|
845
855
|
});
|
|
846
856
|
};
|
|
847
857
|
|
|
848
|
-
this._updateClass = function (
|
|
849
|
-
var
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
858
|
+
this._updateClass = function (_a, index) {
|
|
859
|
+
var flicking = _a.flicking,
|
|
860
|
+
activeClass = _a.activeClass;
|
|
861
|
+
if (!activeClass) return;
|
|
862
|
+
flicking.panels.forEach(function (panel) {
|
|
863
|
+
if (panel.index === index) {
|
|
864
|
+
addClass(panel.element, activeClass);
|
|
865
|
+
} else {
|
|
866
|
+
removeClass(panel.element, activeClass);
|
|
867
|
+
}
|
|
853
868
|
});
|
|
854
869
|
};
|
|
855
870
|
|
|
856
|
-
this._findNearsetPanel = function (flicking, pos) {
|
|
857
|
-
var nearsetIndex = flicking.panels.reduce(function (nearest, panel, index) {
|
|
858
|
-
return Math.abs(panel.position - pos) <= nearest.range ? {
|
|
859
|
-
index: index,
|
|
860
|
-
range: Math.abs(panel.position - pos)
|
|
861
|
-
} : nearest;
|
|
862
|
-
}, {
|
|
863
|
-
index: 0,
|
|
864
|
-
range: Infinity
|
|
865
|
-
}).index;
|
|
866
|
-
return flicking.panels[nearsetIndex];
|
|
867
|
-
};
|
|
868
|
-
|
|
869
871
|
this._type = type;
|
|
870
872
|
this._synchronizedFlickingOptions = synchronizedFlickingOptions;
|
|
871
873
|
}
|
|
@@ -876,11 +878,7 @@ function () {
|
|
|
876
878
|
return this._type;
|
|
877
879
|
},
|
|
878
880
|
set: function (val) {
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
this._preventEvent(function () {
|
|
882
|
-
_this._type = val;
|
|
883
|
-
});
|
|
881
|
+
this._type = val;
|
|
884
882
|
},
|
|
885
883
|
enumerable: false,
|
|
886
884
|
configurable: true
|
|
@@ -890,11 +888,7 @@ function () {
|
|
|
890
888
|
return this._synchronizedFlickingOptions;
|
|
891
889
|
},
|
|
892
890
|
set: function (val) {
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
this._preventEvent(function () {
|
|
896
|
-
_this._synchronizedFlickingOptions = val;
|
|
897
|
-
});
|
|
891
|
+
this._synchronizedFlickingOptions = val;
|
|
898
892
|
},
|
|
899
893
|
enumerable: false,
|
|
900
894
|
configurable: true
|
|
@@ -903,16 +897,20 @@ function () {
|
|
|
903
897
|
__proto.init = function (flicking) {
|
|
904
898
|
var _this = this;
|
|
905
899
|
|
|
900
|
+
var synced = this._synchronizedFlickingOptions;
|
|
901
|
+
|
|
906
902
|
if (this._flicking) {
|
|
907
903
|
this.destroy();
|
|
908
904
|
}
|
|
909
905
|
|
|
910
906
|
this._flicking = flicking;
|
|
911
907
|
|
|
912
|
-
this._addEvents(
|
|
908
|
+
this._addEvents();
|
|
913
909
|
|
|
914
|
-
|
|
915
|
-
|
|
910
|
+
synced.forEach(function (options) {
|
|
911
|
+
var syncedFlicking = options.flicking;
|
|
912
|
+
|
|
913
|
+
_this._updateClass(options, syncedFlicking.defaultIndex);
|
|
916
914
|
});
|
|
917
915
|
};
|
|
918
916
|
|
|
@@ -923,7 +921,7 @@ function () {
|
|
|
923
921
|
return;
|
|
924
922
|
}
|
|
925
923
|
|
|
926
|
-
this._removeEvents(
|
|
924
|
+
this._removeEvents();
|
|
927
925
|
|
|
928
926
|
this._flicking = null;
|
|
929
927
|
};
|
|
@@ -931,23 +929,17 @@ function () {
|
|
|
931
929
|
__proto.update = function () {
|
|
932
930
|
var _this = this;
|
|
933
931
|
|
|
934
|
-
this._synchronizedFlickingOptions.forEach(function (
|
|
935
|
-
|
|
936
|
-
activeClass = _a.activeClass;
|
|
937
|
-
|
|
938
|
-
_this._updateClass({
|
|
939
|
-
flicking: flicking,
|
|
940
|
-
activeClass: activeClass
|
|
941
|
-
}, flicking.camera.position);
|
|
932
|
+
this._synchronizedFlickingOptions.forEach(function (options) {
|
|
933
|
+
_this._updateClass(options, options.flicking.index);
|
|
942
934
|
});
|
|
943
935
|
};
|
|
944
936
|
|
|
945
937
|
__proto._preventEvent = function (fn) {
|
|
946
|
-
this._removeEvents(
|
|
938
|
+
this._removeEvents();
|
|
947
939
|
|
|
948
940
|
fn();
|
|
949
941
|
|
|
950
|
-
this._addEvents(
|
|
942
|
+
this._addEvents();
|
|
951
943
|
};
|
|
952
944
|
|
|
953
945
|
return Sync;
|