(function($) { 'use strict'; // create outer variables var wrapper, container, ajax, modal, content, info, prev, next, close, keybind, rsz, loadedcontent = {}; // set default parameters var defaultsettings = { arrowkeys: true, // left and right arrow keys for controls, esc to close controls: true, // display next / prev controls loop: true, // loop back to the beginning maxwidth: null, // maximum amount of pixels for width maxheight: null, // maximum amount of pixels for height maxscreen: 90, // percentage of screen size (overrides maxwidth and maxheight) updatersz: true, // update on window resize callback: null, // callback function after every panel load lockscroll: true, // prevent scrolling when pop-up is open contenttype: 'image', // type of content to load, ajaxcontainer: 'body > *', // html element to laod into ajax }; // end options var methods = { init : function(settings) { return this.click(function(e) { $(this).galpop('openbox',settings); e.preventdefault(); }); // end click }, // end init openbox : function(settings,target,index) { // override default options settings = $.extend({}, defaultsettings, settings); // bind variables wrapper.data({ controls: settings.controls, loop: settings.loop, maxwidth: settings.maxwidth, maxheight: settings.maxheight, maxscreen: settings.maxscreen, callback: settings.callback, contenttype: settings.contenttype, }); // end data var url = target; var rel = ''; var group = this; var ajaxcontainer = ((this.data('galpop-container')) ? this.data('galpop-container') : settings.ajaxcontainer); if (!index) { index = 0; } // group items if is an array if( object.prototype.tostring.call( target ) === '[object array]' ) { group = target; url = group[index]; } // if no target, use normal link if (!target) { url = this.attr('href'); rel = this.data('galpop-group'); group = $('[data-galpop-group="'+ rel +'"]'); index = group.index(this); if (settings.arrowkeys) { $(document).on('keydown',keybind); } if (settings.updatersz) { $(window).resize(rsz); } if (settings.lockscroll) { $('html').addclass('lock-scroll'); } } wrapper.data({ rel: rel, group: group, index: index, status: true, count: group.length, ajaxcontainer: ajaxcontainer, }); wrapper.fadein(500,'swing'); // load the item this.galpop('preload',url); return this; }, // end open box closebox : function() { wrapper.removeclass('complete').fadeout(500,'swing',function() { content.empty(); info.hide().empty(); $(this).data('status',false); prev.hide(); next.hide(); container.removeattr('style'); wrapper.removeclass('loaded-ajax loaded-image loaded-iframe'); // remove bound functions $(document).off('keydown',keybind); $(window).off('resize',rsz); $('html').removeclass('lock-scroll'); }); }, // end close box preload : function(url) { var contenttype = wrapper.data('contenttype'); switch (contenttype) { case 'ajax': wrapper.addclass('loaded-ajax'); this.galpop('loadajax',url); break; case 'iframe': wrapper.addclass('loaded-iframe'); this.galpop('loadiframe',url); break; case 'image': default: wrapper.addclass('loaded-image'); this.galpop('loadimage',url); break; } return this; }, // end preload loadimage : function(url) { var image = new image(); image.src = url; loadedcontent.object = image; loadedcontent.resizable = true; image.onload = function() { // alert('good'); wrapper.galpop('display'); }; // end onload image.onerror = function() { // alert(url +' contains a broken image!'); console.log(url +' contains a broken image!'); }; // end onerror return this; }, // load image loadiframe : function(url) { var iframe = $('