/*! lightgallery - v1.2.0 - 2015-08-26 * http://sachinchoolur.github.io/lightgallery/ * copyright (c) 2015 sachin n; licensed apache 2.0 */ (function($, window, document, undefined) { 'use strict'; var defaults = { hash: true }; var hash = function(element) { this.core = $(element).data('lightgallery'); this.core.s = $.extend({}, defaults, this.core.s); if (this.core.s.hash) { this.oldhash = window.location.hash; this.init(); } return this; }; hash.prototype.init = function() { var _this = this; var _hash; // change hash value on after each slide transition _this.core.$el.on('onafterslide.lg.tm', function(event, previndex, index) { window.location.hash = 'lg=' + _this.core.s.galleryid + '&slide=' + index; }); // listen hash change and change the slide according to slide value $(window).on('hashchange', function() { _hash = window.location.hash; var _idx = parseint(_hash.split('&slide=')[1], 10); // it galleryid doesn't exist in the url close the gallery if ((_hash.indexof('lg=' + _this.core.s.galleryid) > -1)) { _this.core.slide(_idx); } else if (_this.core.lgalleryon) { _this.core.destroy(); } }); }; hash.prototype.destroy = function() { // reset to old hash value if (this.oldhash && this.oldhash.indexof('lg=' + this.core.s.galleryid) < 0) { window.location.hash = this.oldhash; } else { if (history.pushstate) { history.pushstate('', document.title, window.location.pathname + window.location.search); } else { window.location.hash = ''; } } }; $.fn.lightgallery.modules.hash = hash; })(jquery, window, document);