Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
init() {
const swiper = this;
if (!swiper.params.history) return;
if (!window.history || !window.history.pushState) {
swiper.params.history.enabled = false;
swiper.params.hashNavigation.enabled = true;
return;
}
const history = swiper.history;
history.initialized = true;
history.paths = History.getPathValues();
if (!history.paths.key && !history.paths.value) return;
history.scrollToSlide(0, history.paths.value, swiper.params.runCallbacksOnInit);
if (!swiper.params.history.replaceState) {
window.addEventListener('popstate', swiper.history.setHistoryPopState);
}
},
destroy() {
init() {
const swiper = this;
if (!swiper.params.history) return;
if (!window.history || !window.history.pushState) {
swiper.params.history.enabled = false;
swiper.params.hashNavigation.enabled = true;
return;
}
const history = swiper.history;
history.initialized = true;
history.paths = History.getPathValues();
if (!history.paths.key && !history.paths.value) return;
history.scrollToSlide(0, history.paths.value, swiper.params.runCallbacksOnInit);
if (!swiper.params.history.replaceState) {
window.addEventListener('popstate', swiper.history.setHistoryPopState);
}
},
destroy() {
setHash() {
const swiper = this;
if (!swiper.hashNavigation.initialized || !swiper.params.hashNavigation.enabled) return;
if (swiper.params.hashNavigation.replaceState && window.history && window.history.replaceState) {
window.history.replaceState(null, null, (`#${swiper.slides.eq(swiper.activeIndex).attr('data-hash')}` || ''));
} else {
const slide = swiper.slides.eq(swiper.activeIndex);
const hash = slide.attr('data-hash') || slide.attr('data-history');
document.location.hash = hash || '';
}
},
init() {
setHash() {
const swiper = this;
if (!swiper.hashNavigation.initialized || !swiper.params.hashNavigation.enabled) return;
if (swiper.params.hashNavigation.replaceState && window.history && window.history.replaceState) {
window.history.replaceState(null, null, (`#${swiper.slides.eq(swiper.activeIndex).attr('data-hash')}` || ''));
} else {
const slide = swiper.slides.eq(swiper.activeIndex);
const hash = slide.attr('data-hash') || slide.attr('data-history');
document.location.hash = hash || '';
}
},
init() {
back() {
History.allowChange = false;
window.history.back();
},
allowChange: true,
push(viewId, viewState, url) {
if (!History.allowChange) {
History.queue.push(() => {
History.push(viewId, viewState, url);
});
return;
}
History.previousState = History.state;
const newState = Utils.extend({}, (History.previousState || {}), {
[viewId]: viewState,
});
History.state = newState;
window.history.pushState(newState, '', url);
},
replace(viewId, viewState, url) {
setHistory(key, index) {
const swiper = this;
if (!swiper.history.initialized || !swiper.params.history.enabled) return;
const slide = swiper.slides.eq(index);
let value = History.slugify(slide.attr('data-history'));
if (!window.location.pathname.includes(key)) {
value = `${key}/${value}`;
}
const currentState = window.history.state;
if (currentState && currentState.value === value) {
return;
}
if (swiper.params.history.replaceState) {
window.history.replaceState({ value }, null, value);
} else {
window.history.pushState({ value }, null, value);
}
},
slugify(text) {
setHistory(key, index) {
const swiper = this;
if (!swiper.history.initialized || !swiper.params.history.enabled) return;
const slide = swiper.slides.eq(index);
let value = History.slugify(slide.attr('data-history'));
if (!window.location.pathname.includes(key)) {
value = `${key}/${value}`;
}
const currentState = window.history.state;
if (currentState && currentState.value === value) {
return;
}
if (swiper.params.history.replaceState) {
window.history.replaceState({ value }, null, value);
} else {
window.history.pushState({ value }, null, value);
}
},
slugify(text) {
setHistory(key, index) {
const swiper = this;
if (!swiper.history.initialized || !swiper.params.history.enabled) return;
const slide = swiper.slides.eq(index);
let value = History.slugify(slide.attr('data-history'));
if (!window.location.pathname.includes(key)) {
value = `${key}/${value}`;
}
const currentState = window.history.state;
if (currentState && currentState.value === value) {
return;
}
if (swiper.params.history.replaceState) {
window.history.replaceState({ value }, null, value);
} else {
window.history.pushState({ value }, null, value);
}
},
slugify(text) {
setHistory(key, index) {
const swiper = this;
if (!swiper.history.initialized || !swiper.params.history.enabled) return;
const slide = swiper.slides.eq(index);
let value = History.slugify(slide.attr('data-history'));
if (!window.location.pathname.includes(key)) {
value = `${key}/${value}`;
}
const currentState = window.history.state;
if (currentState && currentState.value === value) {
return;
}
if (swiper.params.history.replaceState) {
window.history.replaceState({ value }, null, value);
} else {
window.history.pushState({ value }, null, value);
}
},
slugify(text) {