/* * jquery rebox [http://trentrichardson.com/examples/jquery-rebox] * by: trent richardson [http://trentrichardson.com] * * copyright 2014 trent richardson * dual licensed under the mit license. * http://trentrichardson.com/impromptu/mit-license.txt */ (function($){ $.rebox = function($this, options){ this.settings = $.extend(true, {}, $.rebox.defaults, options); this.$el = $this; // parent container holding items this.$box = null; // the lightbox modal this.$items = null; // recomputed each time its opened this.idx = 0; // of the $items which index are we on this.enable(); }; $.rebox.defaults = { theme: 'rebox', // class name parent gets (for your css) selector: null, // the selector to delegate to, should be to the which contains an prev: '', // use an image, text, whatever for the previous button next: '', // use an image, text, whatever for the next button loading: '%', // use an image, text, whatever for the loading notification close: '', // use an image, text, whatever for the close button speed: 400, // speed to fade in or out zindex: 1000, // zindex to apply to the outer container cycle: true, // whether to cycle through galleries or stop at ends captionattr: 'title', // name of the attribute to grab the caption from template: 'image', // the default template to be used (see templates below) templates: { // define templates to create the elements you need function($item, settings) image: function($item, settings, callback){ return $('').load(callback); } } }; $.rebox.setdefaults = function(options){ $.rebox.defaults = $.extend(true, {}, $.rebox.defaults, options); }; $.rebox.lookup = { i: 0 }; $.extend($.rebox.prototype, { enable: function(){ var t = this; return t.$el.on('click.rebox', t.settings.selector, function(e){ e.preventdefault(); t.open(this); }); }, open: function(i){ var t = this; // figure out where to start t.$items = t.settings.selector === null? t.$el : t.$el.find(t.settings.selector); if(isnan(i)){ i = t.$items.index(i); } // build the rebox t.$box = $('