/* This file is part of JonDesign's SmoothGallery v2.1beta1. JonDesign's SmoothGallery is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. JonDesign's SmoothGallery is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with JonDesign's SmoothGallery; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Main Developer: Jonathan Schemoul (JonDesign: http://www.jondesign.net/) Contributed code by: - Christian Ehret (bugfix) - Nitrix (bugfix) - Valerio from Mad4Milk for his great help with the carousel scrolling and many other things. - Archie Cowan for helping me find a bugfix on carousel inner width problem. - Tomocchino from #mootools for the preloader class Many thanks to: - The mootools team for the great mootools lib, and it's help and support throughout the project. - Harald Kirschner (digitarald: http://digitarald.de/) for all his great libs. Some used here as plugins. */ /* some quirks to circumvent broken stuff in mt1.2 */ Array.prototype.from=function (item){ if (item == null) return []; return (typeof(item) == 'array') ? item : [item]; }; $A=function (i){return Array.prototype.from(i).slice();}; Array.prototype.extend=function (a){this.push.apply(this,a);return this} if(Function.prototype.passx==undefined){ Function.prototype.passx=function (args, bind){ var self = this; if (args != null) args = Array.prototype.from(args); return function(){ return self.apply(bind, args || arguments); }; }; } Function.prototype.chain=function(f){f();return window.chainjdgallery;} window.chainjdgallery=function(){}; if(undefined == Function.prototype.bind){ Function.prototype.bind=function(that){ var self = this, args = arguments.length > 1 ? Array.slice(arguments, 1) : null, F = function(){}; var bound = function(){ var context = that, length = arguments.length; if (this instanceof bound){ F.prototype = self.prototype; context = new F; } var result = (!args && !length) ? self.call(context) : self.apply(context, args && length ? args.concat(Array.slice(arguments)) : args || arguments); return context == that ? result : context; }; return bound; } }; Function.prototype.periodical=function (c,b,a){return setInterval(this.passx((a==null?[]:a),b),c);}; $defined=function (i){return(i!=null);}; $clear=function (i){clearTimeout(i);clearInterval(i);return null;}; Function.prototype.delay=function (b,c,a){return setTimeout(this.passx(a,c),b)} function morphx(elm,opts){ this.element=elm; this.complete=function(){}; this.options={easing:'linear',duration:1000,complete:this.complete,queue:false}; if(opts) this.options=jQuery.extend(this.options,opts); } morphx.prototype.data=function(){ if(arguments.length==1) return this.element.data(arguments[0]); else if(arguments.length==2) return this.element.data(arguments[0], arguments[0]); } morphx.prototype.start=function(obj,opts){ //this.element.stop(); if(opts)this.options=jQuery.extend(this.options,opts); this.element.animate(obj, this.options); return this; } morphx.prototype.stop=function(){ this.element.stop(); } morphx.prototype.cancel=function(){ this.element.stop(); } morphx.prototype.chain=Function.prototype.chain; morphx.prototype.completefunc=function(f){ this.options.complete=f.bind(this); return this; } morphx.prototype.clearChain=function(){ window.morphxchain=function(){}; } morphx.prototype.css=function(obj){ this.element.css(obj); return this; } var s5_dropdowntext2 = s5_dropdowntext; (function($){ var Scroller = function(element, options){ this.options= { area: 20, velocity: 1, onChange: function(x, y){ //console.log(x,y); this.element.scrollTo(x, y); }.bind(this), fps: 50 }; this.element=null; this.docBody=null; this.listener=null; this.timer=null; this.bound={}; this.initialize(element, options); } Scroller.prototype.initialize= function(element, options){ this.options=$.extend(this.options,options); this.element = element[0]; this.docBody = $('body')[0]; if(this.element.nodeType!=1){ this.listener = this.docBody ; $(this.listener).attr('tag','body'); }else{ this.listener = this.element; $(this.listener).attr('tag','elm'); } this.timer = null; this.bound = { attach: this.attach.bind(this), detach: this.detach.bind(this), getCoords: this.getCoords.bind(this) }; }; Scroller.prototype.start= function(){ $(this.listener).bind('mouseover', this.bound.attach); $(this.listener).bind('mouseleave', this.bound.detach); return this; }; Scroller.prototype.stop= function(){ $(this.listener).unbind('mouseover'); $(this.listener).unbind('mouseleave'); this.detach(); this.timer = clearInterval(this.timer); return this; }; Scroller.prototype.attach= function(){ $(this.listener).bind('mousemove', this.bound.getCoords); }; Scroller.prototype.detach= function(){ $(this.listener).unbind('mousemove'); this.timer = clearInterval(this.timer); }, Scroller.prototype.getCoords= function(event){ event.client={x:event.clientX,y:event.clientY}; event.page={x:event.pageX,y:event.pageY}; this.page = ($(this.listener).attr('tag') == 'body') ? event.client : event.page; if (!this.timer) this.timer = this.scroll.periodical(Math.round(1000 / this.options.fps), this); }, Scroller.prototype.scroll= function(){ var size = {x:$(this.element).width(),y:$(this.element).height()}, scroll = {x:$(this.element).scrollLeft(),y:$(this.element).scrollTop()}, pos = this.element != this.docBody ? {x:$(this.element).offset().left,y:$(this.element).offset().top} : {x: 0, y:0}, scrollSize = {x:$(this.element).children(0).width(),y: $(this.element).children(0).height()}, change = {x: 0, y: 0}, top = this.options.area.top || this.options.area, bottom = this.options.area.bottom || this.options.area; for (var z in this.page){ if (this.page[z] < (top + pos[z]) && scroll[z] != 0){ change[z] = (this.page[z] - top - pos[z]) * this.options.velocity; } else if (this.page[z] + bottom > (size[z] + pos[z]) && scroll[z] + size[z] != scrollSize[z]){ change[z] = (this.page[z] - size[z] + bottom - pos[z]) * this.options.velocity; } change[z] = change[z].round(); } if (change.y || change.x) this.options.onChange(scroll.x + change.x, scroll.y + change.y); } var s5_dropdowntext2 = s5_dropdowntext; var s5_verticalhorizontal2 = s5_verticalhorizontal; // declaring the class var gallery =window.gallery= function(element, options) { this.options= { embedLinks: true, fadeDuration: 500, timed: false, preloader: true, preloaderImage: true, preloaderErrorImage: true, /* Data retrieval */ manualData: null, populateFrom: false, populateData: true, destroyAfterPopulate: true, elementSelector: "div.imageElement", titleSelector: "h3", subtitleSelector: "p", linkSelector: "a.open", imageSelector: "img.full", thumbnailSelector: "img.thumbnail", defaultTransition: "fade", /* InfoPane options */ slideInfoZoneOpacity: s5_slide_opacity, slideInfoZoneSlide: true, /* Carousel options */ carouselMinimizedOpacity: 0.4, carouselMinimizedHeight: 20, carouselMaximizedOpacity: 0.9, thumbHeight: 75, thumbWidth: 100, thumbSpacing: 10, thumbIdleOpacity: 0.2, textShowCarousel: s5_dropdowntext2, showCarouselLabel: true, thumbCloseCarousel: true, useThumbGenerator: false, thumbGenerator: 'resizer.php', useExternalCarousel: false, carouselElement: false, carouselHorizontal: s5_verticalhorizontal2, activateCarouselScroller: true, carouselPreloader: true, textPreloadingCarousel: 'Loading...', /* CSS Classes */ baseClass: 'jdGallery', withArrowsClass: 'withArrows', /* Plugins: HistoryManager */ useHistoryManager: false, customHistoryKey: false, /* Plugins: ReMooz */ useReMooz: false }; this.initialize(element, options); } gallery.prototype.initialize= function(element, options) { this.options=$.extend(this.options, options); $(this).trigger('onInit'); this.currentIter = 0; this.lastIter = 0; this.maxIter = 0; this.galleryElement = element; this.galleryData = this.options.manualData; this.galleryInit = 1; this.galleryElements = Array(); this.thumbnailElements = Array(); $(this.galleryElement).addClass(this.options.baseClass); if (this.options.useReMooz&&(this.options.defaultTransition=="fade")) this.options.defaultTransition="crossfade"; this.populateFrom = element; if (this.options.populateFrom) this.populateFrom = this.options.populateFrom; if (this.options.populateData) this.populateData(); element.css('display',"block"); if (this.options.useHistoryManager) this.initHistory(); if ((this.options.embedLinks)|(this.options.useReMooz)) { this.currentLink = $('').attr({href:'#',title:''}).appendTo(element); if ((!this.options.showArrows) && (!this.options.showCarousel)) this.galleryElement = element = this.currentLink; else this.currentLink.css('display', 'none'); } this.constructElements(); if ((this.galleryData.length>1)&&(this.options.showArrows)) { var leftArrow = $('').bind( 'click', this.prevItem.bind(this) ).appendTo(element); var rightArrow = $('').bind( 'click', this.nextItem.bind(this) ).appendTo(element); $(this.galleryElement).addClass(this.options.withArrowsClass); } this.loadingElement = $('
').appendTo(element); if (this.options.showInfopane) this.initInfoSlideshow(); if (this.options.showCarousel) this.initCarousel(); this.doSlideShow(1); } gallery.prototype.populateData= function() { currentArrayPlace = $(this.galleryData).length; options = this.options; var data = $A(this.galleryData); data.extend(this.populateGallery(this.populateFrom, currentArrayPlace)); this.galleryData = data; $(this).trigger('onPopulated'); }; gallery.prototype.populateGallery= function(element, startNumber) { var data = []; options = this.options; currentArrayPlace = parseInt(startNumber); $(options.elementSelector,element).each(function(i,el) { elementDict = new Object({ image: $(options.imageSelector,el).attr('src'), number: currentArrayPlace, transition: this.options.defaultTransition }); if ((options.showInfopane) | (options.showCarousel)){ elementDict.title= $(options.titleSelector,el)[0].innerHTML; elementDict.description= $(options.subtitleSelector,el)[0].innerHTML } if ((options.embedLinks) | (options.useReMooz)){ while($(options.linkSelector,el)[0] == undefined) ; elementDict.link=$(options.linkSelector,el)[0].href||false; // hides false and open image tooltip popups // linkTitle: el.getElement(options.linkSelector).title||false, elementDict.linkTarget= $(options.linkSelector,el).attr('target')||false; } if ((!options.useThumbGenerator) && (options.showCarousel)){ elementDict.thumbnail=$(options.thumbnailSelector,el).attr('src'); }else if (options.useThumbGenerator) elementDict.thumbnail= options.thumbGenerator + '?imgfile=' + elementDict.image + '&max_width=' + options.thumbWidth + '&max_height=' + options.thumbHeight; data.extend([elementDict]); currentArrayPlace++; if (this.options.destroyAfterPopulate) $(el).remove(); }.bind(this)); return data; }, gallery.prototype.constructElements= function() { el = this.galleryElement; if (this.options.embedLinks && (!this.options.showArrows)) el = this.currentLink; this.maxIter = this.galleryData.length; var currentImg; for(i=0;i<$(this.galleryData).length;i++) { var currentImg = new morphx($('').css({ 'position':'absolute', 'left':'0px', 'right':'0px', 'margin':'0px', 'padding':'0px', 'backgroundPosition':"center center", 'opacity':'0' }).appendTo(el),{duration: this.options.fadeDuration}); if (this.options.preloader) { currentImg.element.source = this.galleryData[i].image; currentImg.element.loaded=false; currentImg.element.load = function(params) { var imageStyle=params[0]; var i=params[1]; if (!imageStyle.loaded) { var imgx=new Image(); this.galleryData[i].imgloader = imgx.onload=function(params2){ img=params2[0]; i=params2[1]; img.css( 'backgroundImage', "url('" + img.source + "')") img.loaded = true; img.width = this.galleryData[i].imgloader.width; img.height = this.galleryData[i].imgloader.height; }.passx([imageStyle, i], this); imgx.src=imageStyle.source; } }.passx([currentImg.element, i],this); } else { currentImg.element.css('backgroundImage', "url('" + this.galleryData[i].image + "')"); } this.galleryElements[parseInt(i)] = currentImg; } }, gallery.prototype.destroySlideShow= function(element) { var myClassName = element.className; var newElement = $('div class="myClassName">'); element.parentNode.replaceChild(newElement, element); }, gallery.prototype.startSlideShow= function() { $(this).trigger('onStart'); this.loadingElement[0].style.display = "none"; this.lastIter = this.maxIter - 1; this.currentIter = 0; this.galleryInit = 0; this.galleryElements[parseInt(this.currentIter)].element.css({opacity: 1}); if (this.options.showInfopane) this.showInfoSlideShow.delay(1000, this); if (this.options.useReMooz) this.makeReMooz.delay(1000, this); var textShowCarousel = formatString(this.options.textShowCarousel, this.currentIter+1, this.maxIter); if (this.options.showCarousel&&(!this.options.carouselPreloader)&&(!this.options.useExternalCarousel)) this.carouselBtn.html(textShowCarousel).attr('title', textShowCarousel); this.prepareTimer(); if (this.options.embedLinks) this.makeLink(this.currentIter); }, gallery.prototype.nextItem= function() { $(this).trigger('onNextCalled'); this.nextIter = this.currentIter+1; if (this.nextIter >= this.maxIter) this.nextIter = 0; this.galleryInit = 0; this.goTo(this.nextIter); }, gallery.prototype.prevItem= function() { $(this).trigger('onPreviousCalled'); this.nextIter = this.currentIter-1; if (this.nextIter <= -1) this.nextIter = this.maxIter - 1; this.galleryInit = 0; this.goTo(this.nextIter); }, gallery.prototype.goTo= function(num) { //console.log(num); this.clearTimer(); if(this.options.preloader) { this.galleryElements[num].element.load(); if (num==0) this.galleryElements[this.maxIter - 1].element.load(); else this.galleryElements[num - 1].element.load(); if (num==(this.maxIter - 1)) this.galleryElements[0].element.load(); else this.galleryElements[num + 1].element.load(); } if (this.options.embedLinks) this.clearLink(); if (this.options.showInfopane) { this.slideInfoZone.clearChain(); this.hideInfoSlideShow().chain(this.changeItem.passx(num, this)); } else this.currentChangeDelay = this.changeItem.delay(500, this, num); if (this.options.embedLinks) this.makeLink(num); this.prepareTimer(); /*if (this.options.showCarousel) this.clearThumbnailsHighlights();*/ }, gallery.prototype.changeItem= function(num) { //console.log(arguments.callee.caller); $(this).trigger('onStartChanging'); this.galleryInit = 0; if (this.currentIter != num) { for(i=0;i