/* This file is part of JonDesign's SmoothGallery v2.0. 3.2.0 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://jondesign/) 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. */ // declaring the class var gallery = { initialize: function(element, options) { setoptions({ showArrows: true, showCarousel: true, showInfopane: true, embedLinks: true, fadeDuration: 200, timed: false, delay: 5000, preloader: true, preloaderImage: true, preloaderErrorImage: true, /* Data retrieval */ manualData: [], populateFrom: false, populateData: true, destroyAfterPopulate: true, elementSelector: "imageelement", titleSelector: "h2", subtitleSelector: "p", linkSelector: "open", imageSelector: "full", thumbnailSelector: "thumbnail", defaultTransition: 'fadeslideleft', /* InfoPane options */ slideInfoZoneOpacity: 0.95, slideInfoZoneSlide: true, /* Carousel options */ carouselMinimizedOpacity: 0.4, carouselMinimizedHeight: 20, carouselMaximizedOpacity: 0.9, thumbHeight: 75, thumbWidth: 100, thumbSpacing: 10, thumbIdleOpacity: 0.6, textShowCarousel: 'Featured Content', showCarouselLabel: true, thumbCloseCarousel: true, useThumbGenerator: false, thumbGenerator: 'php', useExternalCarousel: false, carouselElement: false, carouselHorizontal: true, activateCarouselScroller: true, carouselPreloader: true, textPreloadingCarousel: 'Loading...', /* CSS Classes */ baseClass: 'jdGallery', withArrowsClass: 'withArrows', /* Plugins: HistoryManager */ useHistoryManager: false, customHistoryKey: false }, options); fireevent('onInit'); currentiter = 0; lastiter = 0; maxiter = 0; galleryelement = element; gallerydata = manualdata; galleryinit = 1; galleryelements = Array(); thumbnailelements = Array(); addclass(baseclass); populatefrom = element; if (populatefrom) populatefrom = populatefrom; if (populatedata) populatedata(); display="block"; if (usehistorymanager) inithistory(); if (embedlinks) { currentlink = new Element('a').addClass('open').setProperties({ href: '#', title: '' }).injectInside(element); if ((!showarrows) && (!showcarousel)) galleryelement = element = currentlink; else setstyle('display', 'none'); } constructelements(); if ((length>1)&&(showarrows)) { var leftArrow = new Element('a').addClass('left').addEvent( 'click', bind(this) ).injectInside(element); var rightArrow = new Element('a').addClass('right').addEvent( 'click', bind(this) ).injectInside(element); addclass(witharrowsclass); } loadingelement = new Element('div').addClass('loadingElement').injectInside(element); if (showinfopane) initinfoslideshow(); if (showcarousel) initcarousel(); doslideshow(1); }, populateData: function() { currentArrayPlace = length; options = options; var data = $A(gallerydata); extend(populategallery(populatefrom, currentArrayPlace)); gallerydata = data; fireevent('onPopulated'); }, populateGallery: function(element, startNumber) { var data = []; options = options; currentArrayPlace = startNumber; getelements(elementselector).each(function(el) { elementDict = { image: getelement(imageselector).getProperty('src'), number: currentArrayPlace, transition: defaulttransition }; extend = $extend; if ((showinfopane) | (showcarousel)) extend({ title: getelement(titleselector).innerHTML, description: getelement(subtitleselector).innerHTML }); if (embedlinks) extend({ link: getelement(linkselector).href||false, linkTitle: getelement(linkselector).title||false, linkTarget: getelement(linkselector).getProperty('target')||false }); if ((!usethumbgenerator) && (showcarousel)) extend({ thumbnail: getelement(thumbnailselector).getProperty('src') }); else if (usethumbgenerator) extend({ thumbnail: thumbgenerator + '?imgfile=' + image + '&max_width=' + thumbwidth + '&max_height=' + thumbheight }); extend([elementDict]); currentArrayPlace++; if (destroyafterpopulate) remove(); }); return data; }, constructElements: function() { el = galleryelement; maxiter = length; var currentImg; for(i=0;i= maxiter) nextiter = 0; galleryinit = 0; goto(nextiter); }, prevItem: function() { fireevent('onPreviousCalled'); nextiter = currentiter-1; if (nextiter <= -1) nextiter = maxiter - 1; galleryinit = 0; goto(nextiter); }, goTo: function(num) { cleartimer(); if(preloader) { galleryelements[num].load(); if (num==0) galleryelements[maxiter - 1].load(); else galleryelements[num - 1].load(); if (num==(maxiter - 1)) galleryelements[0].load(); else galleryelements[num + 1].load(); } if (embedlinks) clearlink(); if (showinfopane) { clearchain(); hideinfoslideshow().chain(pass(num, this)); } else currentchangedelay = delay(500, this, num); if (embedlinks) makelink(num); preparetimer(); /*if (showcarousel) clearthumbnailshighlights();*/ }, changeItem: function(num) { fireevent('onStartChanging'); galleryinit = 0; if (currentiter != num) { for(i=0;i' + (number + 1) + "/" + maxiter + ": " + title); }.pass(currentImg, this), 'mouseout': function (myself) { cleartimer(); start(thumbidleopacity); }.pass(currentImg, this), 'click': function (myself) { goto(number); if (thumbclosecarousel) hidecarousel(); }.pass(currentImg, this) }); relatedimage = gallerydata[i]; thumbnailelements[parseInt(i)] = currentImg; } }, log: function(value) { if(log) log(value); }, preloadThumbnails: function() { var thumbnails = []; for(i=0;i oldPos) start({opacity: 1}); else { set({opacity: 1}); start({opacity: 0}); } }, crossfade: function(oldFx, newFx, oldPos, newPos){ transition = transition = linear; duration = duration = fadeduration; start({opacity: 1}); start({opacity: 0}); }, fadebg: function(oldFx, newFx, oldPos, newPos){ transition = transition = linear; duration = duration = fadeduration / 2; start({opacity: 0}).chain(pass([{opacity: 1}], newFx)); } }); /* All code copyright 2007 Jonathan Schemoul */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Follows: Preloader (class) * Simple class for preloading images with support for progress reporting * Copyright 2007 Tomocchino. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ var Preloader = new Class({ Implements: [Events, Options], options: { root : '', period : 100 }, initialize: function(options){ setoptions(options); }, load: function(sources) { index = 0; images = []; sources = temps = sources; total = this. length; fireevent('onStart', [index, total]); timer = periodical(period, this); each(function(source, index){ images[index] = new image(root + source, { 'onload' : function(){ index++; if(images[index]) fireevent('onLoad', [images[index], index, source]); }.bind(this), 'onerror' : function(){ index++; fireevent('onError', [splice(index, 1), index, source]); }.bind(this), 'onabort' : function(){ index++; fireevent('onError', [splice(index, 1), index, source]); }.bind(this) }); }, this); }, progress: function() { fireevent('onProgress', [min(index, total), total]); if(index >= total) complete(); }, complete: function(){ $clear(timer); fireevent('onComplete', [images]); }, cancel: function(){ $clear(timer); } }); implement(new Events, new Options); /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Follows: formatString (function) * Original name: printf * Copyright Yahoo. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ function formatString() { var num = length; var oStr = arguments[0]; for (var i = 1; i < num; i++) { var pattern = "\\{" + (i-1) + "\\}"; var re = new RegExp(pattern, "g"); oStr = replace(re, arguments[i]); } return oStr; }