/*! * jquery.yoxview * jQuery image gallery viewer * http://yoxigen.com/yoxview * * Copyright (c) 2010 Yossi Kolesnicov * * Licensed under the MIT license. * http://www.opensource.org/licenses/mit-license.php * * Date: 13th November, 2010 * Version : 2.2 */ (function($){ if (!$.yoxview) $.yoxview = new YoxView(); $.fn.yoxview = function(options) { if (this.length != 0) { if ($.yoxview[options]) return $.yoxview[options].apply(this, Array.prototype.slice.call(arguments, 1)); else if (typeof options === 'object' || !options) $.yoxview.init(this, options); else $.error( 'Method ' + options + ' does not exist on YoxView.' ); } return this; }; $(Yox.getTopWindow()).unload(function(){ if ($.yoxview) { $.yoxview.unload(); delete $.yoxview; } }); function YoxView() { var yoxviewPath = (yoxviewPath || Yox.getPath(/(.*\/)jquery\.yoxview/i)); var defaults = { autoHideInfo: true, // If false, the info bar (with image count and title) is always displayed. autoPlay: false, // If true, slideshow mode starts when the popup opens backgroundColor: "#000000", backgroundOpacity: 0.8, buttonsFadeTime: 300, // The time, in milliseconds, it takes the buttons to fade in/out when hovered on. Set to 0 to force the Prev/Next buttons to remain visible. cacheBuffer: 5, // The number of images to cache after the current image (directional, depends on the current viewing direction) cacheImagesInBackground: true, // If true, full-size images are cached even while the gallery hasn't been opened yet. controlsInitialFadeTime: 1500, // The time, in milliseconds, it takes the menu and prev/next buttons to fade in and out when the popup is opened. controlsInitialDisplayTime: 1000, // The time, in milliseconds, to display the menu and prev/next buttons when the popup is opened. Set to 0 to not display them by default dataFolder: yoxviewPath + "data/", defaultDimensions: { // Default sizes for different types of media, in case none was specified flash: { width: 720, height: 560 }, iframe: { width: 1024 } }, flashVideoPlayer: "jwplayer", // The default player for Flash video files imagesFolder: yoxviewPath + "images/", infoBackColor: "#000000", infoBackOpacity: 0.5, isRTL : false, // Switch direction. For RTL languages such as Hebrew or Arabic, for example. lang: "en", // The language for texts. The relevant language file should exist in the lang folder. langFolder: yoxviewPath + "lang/", loopPlay: true, // If true, slideshow play starts over after the last image playDelay: 3000, // Time in milliseconds to display each image popupMargin: 20, // the minimum margin between the popup and the window popupResizeTime: 600, // The time in milliseconds it takes to make the resize transition from one image to the next. renderButtons: true, // Set to false if you want to implement your own Next/Prev buttons, using the API. renderMenu: true, // Set to false if you want to implement you own menu (Play/Help/Close). showBarsOnOpen: true, // If true, displays the top (help) bar and bottom (info) bar momentarily when the popup opens. showButtonsOnOpen: true, // If true, displays the Prev/Next buttons momentarily when the popup opens. showDescription: true, // Set to false to not show the description text (the title will still show). textLinksSelector: ".yoxviewLink", // A jQuery selector to identify links that are not thumbnails, which YoxView should try to open. thumbnailsOptions: { thumbnailsClass: "yoxview_thumbnail" }, // Options for thumbnails generated by YoxView titleAttribute: "title", // The attribute of an img used for the text in YoxView. Use either "title" or "alt". titleDisplayDuration: 2000 // The time in ms to display the image's title, after which it fades out. }; this.infoButtons = {}; this.isOpen = false; this.yoxviewSkins = {}; var ajaxLoader, cacheVars = {}, cacheImg = new Image(), countDisplay, ctlButtons, // next and prev buttons elementCount = 0, currentItemIndex = 0, currentLanguage = {}, currentMaxSize = {}, currentOptionsSetIndex, currentViewIndex = 0, currentViewIsInFrame = window != window.parent, disableInfo = false, flashDefaults = { wmode: "transparent", width: "100%", height: "100%", allowfullscreen: "true", allowscriptaccess: "true", hasVersion: 9 }, firstImage = true, frameOffset, helpPanel, hideInfoTimeout, hideMenuTimeout, image1, image2, images, imagesCount = 0, infoPanel, infoPanelContent, infoPanelLink, infoPanelMinHeight = 30, infoPanelWrap, infoPinLink, infoPinLinkImg, infoText, isFirstPanel = false, isImageMode = true, isPlaying = false, isResizing = false, itemVar, loadedViews = [], loaderTimeout, loading = false, mediaButtonsSize = {width: 100, height: 100}, mediaLoader, mediaPanelClass = "yoxview_mediaPanel", mediaProviderUrls = { vimeo: "http://vimeo.com/api/oembed.json", myspace: "http://vids.myspace.com/index.cfm?fuseaction=oembed" }, menuHidePosition = -42, menuPanel, nextBtn, notification, onOpenCallback, options, optionsSets = [], panel1, panel2, playBtnText, popup, popupBackground, popupMargins = {}, defaultPopupMargins = {}, popupTimeout, popupWindow = $(Yox.getTopWindow()), // the window in which to create the YoxView popup (for use with frames) popupWrap, prevBtn, resumePlay = false, sprites, tempImg = new Image(), thumbnail, thumbnailImg, thumbnailPos, thumbnailProperties, windowDimensions, yoxviewLanguages = {}, keyCodes = { 40: 'DOWN', 35: 'END', 13: 'ENTER', 36: 'HOME', 37: 'LEFT', 39: 'RIGHT', 32: 'SPACE', 38: 'UP', 72: 'h', 27: 'ESCAPE' }, keyMappings; // If the given options object is equal to any in the options set, return the existing set's index. Otherwise, add the new set and return its index: function initOptionsSet(options){ var optionsSetsLength = optionsSets.length; for(var i=0; i", { html: data.title, className: options.thumbnailsOptions.headerClass }).appendTo(view); } var thumbnailsData = data.isGroup ? [$.extend(data, { media: { title: data.title + " (" + data.images.length + " images)", alt: data.title } })] : data.images; createThumbnails(view, options, isSingleLink ? null : thumbnailsData, !data.createGroups ? null : function(e){ var viewData = $(e.currentTarget).data("yoxview"); var thumbnail = $(e.currentTarget); var thumbnailData = thumbnail.data("yoxthumbs"); if (!viewData.imagesAreSet) { thumbnail.css("cursor", "wait"); var newOptions = $.extend({}, options); if (!newOptions.dataSourceOptions) newOptions.dataSourceOptions = thumbnailData; else $.extend(newOptions.dataSourceOptions, thumbnailData); Yox.dataSources[options.dataSource].getImagesData(newOptions, function(data){ viewData.images = data.images; viewData.imagesAreSet = true; thumbnail.css("cursor", ""); $.yoxview.open(viewData.viewIndex); }); } else { $.yoxview.open(viewData.viewIndex); } } ); if (data.createGroups) $.each(view.yoxthumbs("thumbnails"), function(i, thumbnail){ thumbnail.data("yoxview", {viewIndex: ++viewIndex}); loadedViews.push($(thumbnail)); }); else { $.each(view.yoxthumbs("thumbnails"), function(i, thumbnail){ var currentViewIndex = imageIndex + i; var thumbImg = thumbnail.children("img"); if (thumbImg.length == 0) thumbImg = thumbnail; viewImages[currentViewIndex].thumbnailImg = thumbImg; thumbnail.data("yoxview", {imageIndex: i, viewIndex: viewIndex }); }); } if (!$.yoxview.firstViewWithImages && data.images.length > 0) { $.yoxview.firstViewWithImages = view; if (options.cacheImagesInBackground) $.yoxview.startCache(); } }); } else { viewData.images = viewImages; createThumbnails(view, options); } loadedViews.push(view); if (!$.yoxview.firstViewWithImages && viewData.images && viewData.images != 0) { $.yoxview.firstViewWithImages = view; loadViewImages(view); if(options.cacheImagesInBackground && imagesCount != 0) { calculateCacheBuffer(); cacheImages(0); } } }); } // Init external files then proceed: loadLanguage(options.lang, function(langData){ loadSkin(options, function(skin){ if (skin && skin.options) $.extend(options, skin.options); Yox.loadDataSource(options, loadContents); }); }); } function loadSkin(options, callback) { if (options.skin) { var skinName = options.skin; if (!$.yoxview.yoxviewSkins[skinName]) { var skinUrl = yoxviewPath + "skins/" + skinName + "/yoxview." + skinName; $.ajax({ url: skinUrl + ".js", dataType: "script", success: function(data) { if ($.yoxview.yoxviewSkins[skinName].css !== false) Yox.addStylesheet(top.document, skinUrl + ".css"); if (callback) callback($.yoxview.yoxviewSkins[skinName]); }, error: function(){ alert("Error loading skin file " + skinUrl + ".js"); } }); } else if (callback) callback($.yoxview.yoxviewSkins[skinName]); } else if (callback) callback($.yoxview.yoxviewSkins[skinName]); } // Load the language file if not already loaded: function loadLanguage(langName, callback) { if (!yoxviewLanguages[langName]) { yoxviewLanguages[langName] = {}; var langUrl = yoxviewPath + "lang/" + langName + ".js"; $.ajax({ url : langUrl, async : false, dataType : "json", success: function(data){ yoxviewLanguages[langName] = data; if (callback) callback(data); }, error: function(){ alert("Error loading language file " + langUrl); } }); } else if (callback) callback(yoxviewLanguages[langName]); } function resetPopup() { if (popup) { popupWrap.remove(); popup = undefined; prevBtn = undefined; nextBtn = undefined; image1 = undefined; image2 = undefined; panel1 = undefined; panel2 = undefined; currentItemIndex = 0; $.yoxview.infoButtons = {}; } createPopup(); } function loadViewImages(view) { var viewData = view.data("yoxview"); if (!images || currentViewIndex != viewData.viewIndex) { if (!viewData.cacheVars) viewData.cacheVars = {cachedImagesCount: 0, cacheDirectionForward: true, cacheBufferLastIndex: null, currentCacheImg: 0 }; images = viewData.images; imagesCount = images.length; currentViewIndex = viewData.viewIndex; var isResetPopup = false; var changeOptions = !currentOptionsSetIndex || (currentOptionsSetIndex != viewData.optionsSet); if (changeOptions) { currentOptionsSetIndex = viewData.optionsSet || 0; options = optionsSets[currentOptionsSetIndex]; isResetPopup = true; } if (options.onLoadImages) options.onLoadImages({ images: images, viewData: viewData }); else if ((prevBtn && imagesCount == 1) || (popup && !prevBtn && imagesCount > 0)) isResetPopup = true; if (isResetPopup) resetPopup(); cacheVars = viewData.cacheVars; } } function getElementDimensions(type, originalDimensions, options) { var size = originalDimensions && (originalDimensions.width || originalDimensions.height) ? { width: parseInt(originalDimensions.width), height: parseInt(originalDimensions.height) } : options.defaultDimensions[type]; if (isNaN(size.width)) size.width = null; if (isNaN(size.height)) size.height = null; return size; } var supportedTypes = { image: function(thumbnail, thumbnailHref, thumbImg, options) { var imageData = null; for(var i=0; i", { className: "yoxview_element", html: "
Please install the latest version of the Flash player to view content
" }); var flashData = matchFlashVideo ? Yox.flashVideoPlayers[options.flashVideoPlayer]( options.flashVideoPlayerPath, urlData.path, (urlData.queryFields && urlData.queryFields.image) ? urlData.queryFields.image : thumbImg[0].nodeName == "IMG" ? thumbImg.attr("src") : null, thumbImg.attr(options.titleAttribute)) : urlData.queryFields || {}; if (matchFlash) flashData.swf = urlData.path; $.extend(flashData, flashDefaults); flashPanel.flash(flashData); imageData = { "element": flashPanel, title: thumbImg.attr(options.titleAttribute) }; $.extend(imageData, elementSize); } return imageData; }, ooembed: function(thumbnail, thumbnailHref, thumbImg, options) { var imageData = null; for(videoProvider in Yox.Regex.video) { if (thumbnailHref.match(Yox.Regex.video[videoProvider])) { imageData = { provider: videoProvider, url: thumbnailHref }; break; } } return imageData; }, inline: function(thumbnail, thumbnailHref, thumbImg, options) { if (!options.allowInternalLinks) return null; var imageData = null; var urlData = Yox.getUrlData(thumbnailHref); if (urlData && urlData.anchor) { var element = $("#" + urlData.anchor); if (element.length != 0) { var elementSize = { width: parseInt(element.css("width")), height: parseInt(element.css("height")) }; element.css({ position: "absolute", top: 0, left: 0, width: "100%", height: "100%", display: "block" }); imageData = { type: "inlineElement", "element": element, title: element.attr("title") }; var padding = { horizontal: parseInt(element.css("padding-right")) + parseInt(element.css("padding-left")), vertical: parseInt(element.css("padding-top")) + parseInt(element.css("padding-bottom")) }; elementSize.width = isNaN(elementSize.width) ? null : elementSize.width + padding.horizontal; elementSize.height = isNaN(elementSize.height) ? null : elementSize.height + padding.vertical; $.extend(imageData, elementSize); if (padding.horizontal != 0 || padding.vertical != 0) imageData.padding = padding; element.remove(); } } return imageData; }, iframe: function(thumbnail, thumbnailHref, thumbImg, options) { var imageData = null; var thumbnailTarget = thumbnail.attr("target"); if (thumbnailTarget && thumbnailTarget == "yoxview") { var urlData = Yox.getUrlData(thumbnailHref); if (urlData && urlData.path) { var iframeSize = getElementDimensions("iframe", urlData.queryFields, options); if (urlData.queryFields) { delete urlData.queryFields.width; delete urlData.queryFields.height; } imageData = { "element": $("