;(function($) { 'use strict'; var instancenum = 0, $html = $('html'), $document = $(document), $window = $(window); function simplelightbox(options) { this.options = $.extend({}, simplelightbox.defaults, options); this.ens = '.slb' + (++instancenum); this.init(); } simplelightbox.defaults = { elementclass: '', htmlclass: 'slbactive', closebtnclass: '', nextbtnclass: '', prevbtnclass: '', loadingclass: '', closebtncaption: 'close', nextbtncaption: 'next', prevbtncaption: 'previous', loadingcaption: 'loading...', bindtoitems: true, closeonoverlayclick: true, nextonimageclick: true, showcaptions: true, captionattribute: 'title', urlattribute: 'href', startat: 0, loadingtimeout: 100, appendtarget: $('body'), beforesetcontent: null, beforeclose: null, beforedestroy: null, videoregex: new regexp(/youtube.com|vimeo.com/) }; $.extend(simplelightbox.prototype, { items: [], captions: [], init: function() { var self = this; if (this.options.$items) { this.$items = this.options.$items; this.$items.each(function() { var $item = $(this); self.items.push($item.attr(self.options.urlattribute)); self.captions.push($item.attr(self.options.captionattribute)); }); this.options.bindtoitems && this.$items.on('click' + this.ens, function(e) { e.preventdefault(); self.showposition(self.$items.index($(e.currenttarget))); }); } else if (this.options.items) { this.items = this.options.items; } if (this.options.captions) { this.captions = this.options.captions; } }, next: function() { return this.showposition(this.currentposition + 1); }, prev: function() { return this.showposition(this.currentposition - 1); }, normalizeposition: function(position) { if (position >= this.items.length) { position = 0; } else if (position < 0) { position = this.items.length - 1; } return position; }, showposition: function(position) { var self = this; this.currentposition = this.normalizeposition(position); return this.setuplightboxhtml().prepareitem(this.currentposition, this.setcontent).show(); }, prepareitem: function(position, callback) { var self = this, url = this.items[position]; this.loadingtimeout = settimeout(function() { self.setcontent('
').show(); }, this.options.loadingtimeout); if (this.options.videoregex.test(url)) { callback.call(self, $('')); } else { var $imagecont = $(''); this.$currentimage = $imagecont.find('.slbimage'); if (this.options.showcaptions && this.captions[position]) { $imagecont.append(' '); } this.loadimage(url, function() { self.setimagedimensions(); callback.call(self, $imagecont); self.loadimage(self.items[self.normalizeposition(self.currentposition + 1)]); }); } return this; }, loadimage: function(url, callback) { if (!this.options.videoregex.test(url)) { var image = new image(); callback && (image.onload = callback); image.src = url; } }, setuplightboxhtml: function() { var o = this.options; if (!this.$el) { this.$el = $( '