1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | var __assign = function() {
|
24 | __assign = Object.assign || function __assign(t) {
|
25 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
26 | s = arguments[i];
|
27 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
28 | }
|
29 | return t;
|
30 | };
|
31 | return __assign.apply(this, arguments);
|
32 | };
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | var lGEvents = {
|
40 | afterAppendSlide: 'lgAfterAppendSlide',
|
41 | init: 'lgInit',
|
42 | hasVideo: 'lgHasVideo',
|
43 | containerResize: 'lgContainerResize',
|
44 | updateSlides: 'lgUpdateSlides',
|
45 | afterAppendSubHtml: 'lgAfterAppendSubHtml',
|
46 | beforeOpen: 'lgBeforeOpen',
|
47 | afterOpen: 'lgAfterOpen',
|
48 | slideItemLoad: 'lgSlideItemLoad',
|
49 | beforeSlide: 'lgBeforeSlide',
|
50 | afterSlide: 'lgAfterSlide',
|
51 | posterClick: 'lgPosterClick',
|
52 | dragStart: 'lgDragStart',
|
53 | dragMove: 'lgDragMove',
|
54 | dragEnd: 'lgDragEnd',
|
55 | beforeNextSlide: 'lgBeforeNextSlide',
|
56 | beforePrevSlide: 'lgBeforePrevSlide',
|
57 | beforeClose: 'lgBeforeClose',
|
58 | afterClose: 'lgAfterClose',
|
59 | rotateLeft: 'lgRotateLeft',
|
60 | rotateRight: 'lgRotateRight',
|
61 | flipHorizontal: 'lgFlipHorizontal',
|
62 | flipVertical: 'lgFlipVertical',
|
63 | autoplay: 'lgAutoplay',
|
64 | autoplayStart: 'lgAutoplayStart',
|
65 | autoplayStop: 'lgAutoplayStop',
|
66 | };
|
67 |
|
68 | var hashSettings = {
|
69 | hash: true,
|
70 | galleryId: '1',
|
71 | customSlideName: false,
|
72 | };
|
73 |
|
74 | var Hash = (function () {
|
75 | function Hash(instance, $LG) {
|
76 |
|
77 | this.core = instance;
|
78 | this.$LG = $LG;
|
79 |
|
80 | this.settings = __assign(__assign({}, hashSettings), this.core.settings);
|
81 | return this;
|
82 | }
|
83 | Hash.prototype.init = function () {
|
84 | var _this = this;
|
85 | if (!this.settings.hash) {
|
86 | return;
|
87 | }
|
88 | this.oldHash = window.location.hash;
|
89 | setTimeout(function () {
|
90 | _this.buildFromHash();
|
91 | }, 100);
|
92 |
|
93 | this.core.LGel.on(lGEvents.afterSlide + ".hash", this.onAfterSlide.bind(this));
|
94 | this.core.LGel.on(lGEvents.afterClose + ".hash", this.onCloseAfter.bind(this));
|
95 |
|
96 | this.$LG(window).on("hashchange.lg.hash.global" + this.core.lgId, this.onHashchange.bind(this));
|
97 | };
|
98 | Hash.prototype.onAfterSlide = function (event) {
|
99 | var slideName = this.core.galleryItems[event.detail.index].slideName;
|
100 | slideName = this.settings.customSlideName
|
101 | ? slideName || event.detail.index
|
102 | : event.detail.index;
|
103 | if (history.replaceState) {
|
104 | history.replaceState(null, '', window.location.pathname +
|
105 | window.location.search +
|
106 | '#lg=' +
|
107 | this.settings.galleryId +
|
108 | '&slide=' +
|
109 | slideName);
|
110 | }
|
111 | else {
|
112 | window.location.hash =
|
113 | 'lg=' + this.settings.galleryId + '&slide=' + slideName;
|
114 | }
|
115 | };
|
116 | |
117 |
|
118 |
|
119 |
|
120 |
|
121 | Hash.prototype.getIndexFromUrl = function (hash) {
|
122 | if (hash === void 0) { hash = window.location.hash; }
|
123 | var slideName = hash.split('&slide=')[1];
|
124 | var _idx = 0;
|
125 | if (this.settings.customSlideName) {
|
126 | for (var index = 0; index < this.core.galleryItems.length; index++) {
|
127 | var dynamicEl = this.core.galleryItems[index];
|
128 | if (dynamicEl.slideName === slideName) {
|
129 | _idx = index;
|
130 | break;
|
131 | }
|
132 | }
|
133 | }
|
134 | else {
|
135 | _idx = parseInt(slideName, 10);
|
136 | }
|
137 | return isNaN(_idx) ? 0 : _idx;
|
138 | };
|
139 |
|
140 | Hash.prototype.buildFromHash = function () {
|
141 |
|
142 | var _hash = window.location.hash;
|
143 | if (_hash.indexOf('lg=' + this.settings.galleryId) > 0) {
|
144 |
|
145 | this.$LG(document.body).addClass('lg-from-hash');
|
146 | var index = this.getIndexFromUrl(_hash);
|
147 | this.core.openGallery(index);
|
148 | return true;
|
149 | }
|
150 | };
|
151 | Hash.prototype.onCloseAfter = function () {
|
152 |
|
153 | if (this.oldHash &&
|
154 | this.oldHash.indexOf('lg=' + this.settings.galleryId) < 0) {
|
155 | if (history.replaceState) {
|
156 | history.replaceState(null, '', this.oldHash);
|
157 | }
|
158 | else {
|
159 | window.location.hash = this.oldHash;
|
160 | }
|
161 | }
|
162 | else {
|
163 | if (history.replaceState) {
|
164 | history.replaceState(null, document.title, window.location.pathname + window.location.search);
|
165 | }
|
166 | else {
|
167 | window.location.hash = '';
|
168 | }
|
169 | }
|
170 | };
|
171 | Hash.prototype.onHashchange = function () {
|
172 | if (!this.core.lgOpened)
|
173 | return;
|
174 | var _hash = window.location.hash;
|
175 | var index = this.getIndexFromUrl(_hash);
|
176 |
|
177 | if (_hash.indexOf('lg=' + this.settings.galleryId) > -1) {
|
178 | this.core.slide(index, false, false);
|
179 | }
|
180 | else if (this.core.lGalleryOn) {
|
181 | this.core.closeGallery();
|
182 | }
|
183 | };
|
184 | Hash.prototype.closeGallery = function () {
|
185 | if (this.settings.hash) {
|
186 | this.$LG(document.body).removeClass('lg-from-hash');
|
187 | }
|
188 | };
|
189 | Hash.prototype.destroy = function () {
|
190 | this.core.LGel.off('.lg.hash');
|
191 | this.core.LGel.off('.hash');
|
192 | this.$LG(window).off("hashchange.lg.hash.global" + this.core.lgId);
|
193 | };
|
194 | return Hash;
|
195 | }());
|
196 |
|
197 | export default Hash;
|
198 |
|