vgapp 0.8.3 → 0.8.5
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.
|
@@ -137,6 +137,7 @@ class VGSidebar extends BaseModule {
|
|
|
137
137
|
toggle(relatedTarget) {
|
|
138
138
|
return this._isShown() ? this.hide() : this.show(relatedTarget);
|
|
139
139
|
}
|
|
140
|
+
_showPopstateHandler = null;
|
|
140
141
|
|
|
141
142
|
/**
|
|
142
143
|
* Открывает сайдбар.
|
|
@@ -151,7 +152,6 @@ class VGSidebar extends BaseModule {
|
|
|
151
152
|
this._params = this._getParams(relatedTarget, this._params);
|
|
152
153
|
}
|
|
153
154
|
|
|
154
|
-
// Событие загрузки (может использоваться для AJAX)
|
|
155
155
|
this._route((status, data) => {
|
|
156
156
|
EventHandler.trigger(this._element, EVENT_KEYS.LOADED, { stats: status, data });
|
|
157
157
|
});
|
|
@@ -168,8 +168,14 @@ class VGSidebar extends BaseModule {
|
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
if (this._params.hash) {
|
|
171
|
-
|
|
172
|
-
|
|
171
|
+
history.pushState(null, '', `#${this._element.id}`);
|
|
172
|
+
|
|
173
|
+
if (this._showPopstateHandler) {
|
|
174
|
+
EventHandler.off(window, EVENT_KEYS.POPSTATE_DATA_API, this._showPopstateHandler);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
this._showPopstateHandler = () => this.hide();
|
|
178
|
+
EventHandler.on(window, EVENT_KEYS.POPSTATE_DATA_API, this._showPopstateHandler);
|
|
173
179
|
}
|
|
174
180
|
|
|
175
181
|
this._element.classList.add(CLASS_NAME_SHOW);
|
|
@@ -216,8 +222,17 @@ class VGSidebar extends BaseModule {
|
|
|
216
222
|
this._scrollBar.reset();
|
|
217
223
|
}
|
|
218
224
|
|
|
219
|
-
if (this._params.hash) {
|
|
220
|
-
history.replaceState(
|
|
225
|
+
if (this._params.hash && window.location.hash === `#${this._element.id}`) {
|
|
226
|
+
history.replaceState(
|
|
227
|
+
'',
|
|
228
|
+
document.title,
|
|
229
|
+
window.location.pathname + window.location.search
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (this._showPopstateHandler) {
|
|
234
|
+
EventHandler.off(window, EVENT_KEYS.POPSTATE_DATA_API, this._showPopstateHandler);
|
|
235
|
+
this._showPopstateHandler = null;
|
|
221
236
|
}
|
|
222
237
|
|
|
223
238
|
EventHandler.trigger(this._element, EVENT_KEYS.HIDDEN);
|
|
@@ -235,7 +250,9 @@ class VGSidebar extends BaseModule {
|
|
|
235
250
|
dispose() {
|
|
236
251
|
super.dispose();
|
|
237
252
|
EventHandler.off(this._element, EVENT_KEYS.HIDE);
|
|
238
|
-
|
|
253
|
+
if (this._showPopstateHandler) {
|
|
254
|
+
EventHandler.off(window, EVENT_KEYS.POPSTATE_DATA_API, this._showPopstateHandler);
|
|
255
|
+
}
|
|
239
256
|
this._scrollBar.reset();
|
|
240
257
|
}
|
|
241
258
|
|
|
@@ -263,24 +280,6 @@ class VGSidebar extends BaseModule {
|
|
|
263
280
|
}
|
|
264
281
|
});
|
|
265
282
|
}
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* Инициализирует поведение закрытия по клику вне (через `dismissTrigger`).
|
|
269
|
-
* @private
|
|
270
|
-
*/
|
|
271
|
-
_dismissElement() {
|
|
272
|
-
dismissTrigger(this);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* Заглушка для возможной AJAX-логики. Может быть переопределена.
|
|
277
|
-
* @param {Function} callback - Колбэк после загрузки.
|
|
278
|
-
* @private
|
|
279
|
-
*/
|
|
280
|
-
_route(callback) {
|
|
281
|
-
// Здесь может быть реализация AJAX-загрузки
|
|
282
|
-
callback(true, null);
|
|
283
|
-
}
|
|
284
283
|
}
|
|
285
284
|
|
|
286
285
|
// Автоматическая инициализация по data-атрибутам
|
|
@@ -326,7 +325,10 @@ EventHandler.on(document, EVENT_KEYS.DOM_LOADED_DATA_API, function () {
|
|
|
326
325
|
const target = Selectors.find(`#${hash}`);
|
|
327
326
|
if (target && target.classList.contains('vg-sidebar') && !isDisabled(target)) {
|
|
328
327
|
const instance = VGSidebar.getOrCreateInstance(target);
|
|
329
|
-
|
|
328
|
+
|
|
329
|
+
if (instance._params.hash) {
|
|
330
|
+
instance.toggle();
|
|
331
|
+
}
|
|
330
332
|
}
|
|
331
333
|
});
|
|
332
334
|
|