My static website generator using poole https://www.xythobuz.de
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

jquery.yoxview-2.21.js 85KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227
  1. /*!
  2. * jquery.yoxview
  3. * jQuery image gallery viewer
  4. * http://yoxigen.com/yoxview
  5. *
  6. * Copyright (c) 2010 Yossi Kolesnicov
  7. *
  8. * Licensed under the MIT license.
  9. * http://www.opensource.org/licenses/mit-license.php
  10. *
  11. * Date: 13th November, 2010
  12. * Version : 2.2
  13. */
  14. (function($){
  15. if (!$.yoxview)
  16. $.yoxview = new YoxView();
  17. $.fn.yoxview = function(options)
  18. {
  19. if (this.length != 0)
  20. {
  21. if ($.yoxview[options])
  22. return $.yoxview[options].apply(this, Array.prototype.slice.call(arguments, 1));
  23. else if (typeof options === 'object' || !options)
  24. $.yoxview.init(this, options);
  25. else
  26. $.error( 'Method ' + options + ' does not exist on YoxView.' );
  27. }
  28. return this;
  29. };
  30. $(Yox.getTopWindow()).unload(function(){
  31. if ($.yoxview)
  32. {
  33. $.yoxview.unload();
  34. delete $.yoxview;
  35. }
  36. });
  37. function YoxView()
  38. {
  39. var yoxviewPath = (yoxviewPath || Yox.getPath(/(.*\/)jquery\.yoxview/i));
  40. var defaults = {
  41. autoHideInfo: true, // If false, the info bar (with image count and title) is always displayed.
  42. autoPlay: false, // If true, slideshow mode starts when the popup opens
  43. backgroundColor: "#000000",
  44. backgroundOpacity: 0.8,
  45. 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.
  46. cacheBuffer: 5, // The number of images to cache after the current image (directional, depends on the current viewing direction)
  47. cacheImagesInBackground: true, // If true, full-size images are cached even while the gallery hasn't been opened yet.
  48. controlsInitialFadeTime: 1500, // The time, in milliseconds, it takes the menu and prev/next buttons to fade in and out when the popup is opened.
  49. 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
  50. dataFolder: yoxviewPath + "data/",
  51. defaultDimensions: { // Default sizes for different types of media, in case none was specified
  52. flash: { width: 720, height: 560 },
  53. iframe: { width: 1024 }
  54. },
  55. flashVideoPlayer: "jwplayer", // The default player for Flash video files
  56. imagesFolder: yoxviewPath + "images/",
  57. infoBackColor: "#000000",
  58. infoBackOpacity: 0.5,
  59. isRTL : false, // Switch direction. For RTL languages such as Hebrew or Arabic, for example.
  60. lang: "en", // The language for texts. The relevant language file should exist in the lang folder.
  61. langFolder: yoxviewPath + "lang/",
  62. loopPlay: true, // If true, slideshow play starts over after the last image
  63. playDelay: 3000, // Time in milliseconds to display each image
  64. popupMargin: 20, // the minimum margin between the popup and the window
  65. popupResizeTime: 600, // The time in milliseconds it takes to make the resize transition from one image to the next.
  66. renderButtons: true, // Set to false if you want to implement your own Next/Prev buttons, using the API.
  67. renderMenu: true, // Set to false if you want to implement you own menu (Play/Help/Close).
  68. showBarsOnOpen: true, // If true, displays the top (help) bar and bottom (info) bar momentarily when the popup opens.
  69. showButtonsOnOpen: true, // If true, displays the Prev/Next buttons momentarily when the popup opens.
  70. showDescription: true, // Set to false to not show the description text (the title will still show).
  71. textLinksSelector: ".yoxviewLink", // A jQuery selector to identify links that are not thumbnails, which YoxView should try to open.
  72. thumbnailsOptions: { thumbnailsClass: "yoxview_thumbnail" }, // Options for thumbnails generated by YoxView
  73. titleAttribute: "title", // The attribute of an img used for the text in YoxView. Use either "title" or "alt".
  74. titleDisplayDuration: 2000 // The time in ms to display the image's title, after which it fades out.
  75. };
  76. this.infoButtons = {};
  77. this.isOpen = false;
  78. this.yoxviewSkins = {};
  79. var ajaxLoader,
  80. cacheVars = {},
  81. cacheImg = new Image(),
  82. countDisplay,
  83. ctlButtons, // next and prev buttons
  84. elementCount = 0,
  85. currentItemIndex = 0,
  86. currentLanguage = {},
  87. currentMaxSize = {},
  88. currentOptionsSetIndex,
  89. currentViewIndex = 0,
  90. currentViewIsInFrame = window != window.parent,
  91. disableInfo = false,
  92. flashDefaults = { wmode: "transparent", width: "100%", height: "100%", allowfullscreen: "true", allowscriptaccess: "true", hasVersion: 9 },
  93. firstImage = true,
  94. frameOffset,
  95. helpPanel,
  96. hideInfoTimeout,
  97. hideMenuTimeout,
  98. image1, image2,
  99. images,
  100. imagesCount = 0,
  101. infoPanel,
  102. infoPanelContent,
  103. infoPanelLink,
  104. infoPanelMinHeight = 30,
  105. infoPanelWrap,
  106. infoPinLink,
  107. infoPinLinkImg,
  108. infoText,
  109. isFirstPanel = false,
  110. isImageMode = true,
  111. isPlaying = false,
  112. isResizing = false,
  113. itemVar,
  114. loadedViews = [],
  115. loaderTimeout,
  116. loading = false,
  117. mediaButtonsSize = {width: 100, height: 100},
  118. mediaLoader,
  119. mediaPanelClass = "yoxview_mediaPanel",
  120. mediaProviderUrls = {
  121. vimeo: "http://vimeo.com/api/oembed.json",
  122. myspace: "http://vids.myspace.com/index.cfm?fuseaction=oembed"
  123. },
  124. menuHidePosition = -42,
  125. menuPanel,
  126. nextBtn,
  127. notification,
  128. onOpenCallback,
  129. options, optionsSets = [],
  130. panel1, panel2,
  131. playBtnText,
  132. popup,
  133. popupBackground,
  134. popupMargins = {}, defaultPopupMargins = {},
  135. popupTimeout,
  136. popupWindow = $(Yox.getTopWindow()), // the window in which to create the YoxView popup (for use with frames)
  137. popupWrap,
  138. prevBtn,
  139. resumePlay = false,
  140. sprites,
  141. tempImg = new Image(),
  142. thumbnail,
  143. thumbnailImg,
  144. thumbnailPos,
  145. thumbnailProperties,
  146. windowDimensions,
  147. yoxviewLanguages = {},
  148. keyCodes = {
  149. 40: 'DOWN',
  150. 35: 'END',
  151. 13: 'ENTER',
  152. 36: 'HOME',
  153. 37: 'LEFT',
  154. 39: 'RIGHT',
  155. 32: 'SPACE',
  156. 38: 'UP',
  157. 72: 'h',
  158. 27: 'ESCAPE'
  159. },
  160. keyMappings;
  161. // 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:
  162. function initOptionsSet(options){
  163. var optionsSetsLength = optionsSets.length;
  164. for(var i=0; i<optionsSetsLength; i++)
  165. {
  166. if (Yox.compare(optionsSets[i], options))
  167. return i;
  168. }
  169. optionsSets.push(options);
  170. return optionsSetsLength;
  171. }
  172. function getAllowedThumbnailsSelector(options){
  173. return "a:has(img)" + (options.textLinksSelector !== null ? ",a" + options.textLinksSelector : "");
  174. }
  175. this.init = function(views, opt)
  176. {
  177. var options = $.extend(true, {}, defaults, opt);
  178. var optionsSetIndex;
  179. if (optionsSets.length == 0)
  180. {
  181. optionsSets.push(options);
  182. optionsSetIndex = 0;
  183. }
  184. else
  185. optionsSetIndex = opt ? initOptionsSet(options) : null;
  186. function loadContents(){
  187. views.each(function(i, view){
  188. view = $(view);
  189. var viewIndex = loadedViews.length;
  190. view.data("yoxview", {
  191. viewIndex : viewIndex,
  192. cacheVars: {cachedImagesCount: 0, cacheDirectionForward: true, cacheBufferLastIndex: null, currentCacheImg: 0 }
  193. });
  194. var viewData = view.data("yoxview");
  195. if (optionsSetIndex)
  196. viewData.optionsSet = optionsSetIndex;
  197. options.allowedImageUrls = [Yox.Regex.image];
  198. if (options.allowedUrls)
  199. options.allowedImageUrls = options.allowedImageUrls.concat(options.allowedUrls);
  200. // First, get image data from thumbnails:
  201. var isSingleLink = view[0].tagName == "A";
  202. var thumbnails = isSingleLink ? view : view.find(getAllowedThumbnailsSelector(options));
  203. var viewImages = [];
  204. var imageIndex = 0;
  205. thumbnails.each(function(i, thumbnail){
  206. var $thumbnail = $(thumbnail);
  207. var imageData = getImageDataFromThumbnail($thumbnail, options);
  208. if (imageData)
  209. {
  210. viewImages.push(imageData);
  211. if (isSingleLink)
  212. $thumbnail.data("yoxview").imageIndex = imageIndex;
  213. else
  214. $thumbnail.data("yoxview", { imageIndex: imageIndex, viewIndex: viewIndex });
  215. imageIndex++;
  216. }
  217. });
  218. if (options.images)
  219. viewImages = viewImages.concat(options.images);
  220. if (options.dataSource)
  221. {
  222. Yox.dataSources[options.dataSource].getImagesData(options, function(data){
  223. viewImages = viewImages.concat(data.images);
  224. viewData.images = viewImages;
  225. if (data.title && options.thumbnailsOptions && options.thumbnailsOptions.setHeader){
  226. $(options.thumbnailsOptions.headerElement || "<h2>", {
  227. html: data.title,
  228. className: options.thumbnailsOptions.headerClass
  229. }).appendTo(view);
  230. }
  231. var thumbnailsData = data.isGroup
  232. ? [$.extend(data, {
  233. media: {
  234. title: data.title + " (" + data.images.length + " images)",
  235. alt: data.title
  236. }
  237. })]
  238. : data.images;
  239. createThumbnails(view, options, isSingleLink ? null : thumbnailsData, !data.createGroups ? null :
  240. function(e){
  241. var viewData = $(e.currentTarget).data("yoxview");
  242. var thumbnail = $(e.currentTarget);
  243. var thumbnailData = thumbnail.data("yoxthumbs");
  244. if (!viewData.imagesAreSet)
  245. {
  246. thumbnail.css("cursor", "wait");
  247. var newOptions = $.extend({}, options);
  248. if (!newOptions.dataSourceOptions)
  249. newOptions.dataSourceOptions = thumbnailData;
  250. else
  251. $.extend(newOptions.dataSourceOptions, thumbnailData);
  252. Yox.dataSources[options.dataSource].getImagesData(newOptions, function(data){
  253. viewData.images = data.images;
  254. viewData.imagesAreSet = true;
  255. thumbnail.css("cursor", "");
  256. $.yoxview.open(viewData.viewIndex);
  257. });
  258. }
  259. else
  260. {
  261. $.yoxview.open(viewData.viewIndex);
  262. }
  263. }
  264. );
  265. if (data.createGroups)
  266. $.each(view.yoxthumbs("thumbnails"), function(i, thumbnail){
  267. thumbnail.data("yoxview", {viewIndex: ++viewIndex});
  268. loadedViews.push($(thumbnail));
  269. });
  270. else
  271. {
  272. $.each(view.yoxthumbs("thumbnails"), function(i, thumbnail){
  273. var currentViewIndex = imageIndex + i;
  274. var thumbImg = thumbnail.children("img");
  275. if (thumbImg.length == 0)
  276. thumbImg = thumbnail;
  277. viewImages[currentViewIndex].thumbnailImg = thumbImg;
  278. thumbnail.data("yoxview", {imageIndex: i, viewIndex: viewIndex });
  279. });
  280. }
  281. if (!$.yoxview.firstViewWithImages && data.images.length > 0)
  282. {
  283. $.yoxview.firstViewWithImages = view;
  284. if (options.cacheImagesInBackground)
  285. $.yoxview.startCache();
  286. }
  287. });
  288. }
  289. else
  290. {
  291. viewData.images = viewImages;
  292. createThumbnails(view, options);
  293. }
  294. loadedViews.push(view);
  295. if (!$.yoxview.firstViewWithImages && viewData.images && viewData.images != 0)
  296. {
  297. $.yoxview.firstViewWithImages = view;
  298. loadViewImages(view);
  299. if(options.cacheImagesInBackground && imagesCount != 0)
  300. {
  301. calculateCacheBuffer();
  302. cacheImages(0);
  303. }
  304. }
  305. });
  306. }
  307. // Init external files then proceed:
  308. loadLanguage(options.lang, function(langData){
  309. loadSkin(options, function(skin){
  310. if (skin && skin.options)
  311. $.extend(options, skin.options);
  312. Yox.loadDataSource(options, loadContents);
  313. });
  314. });
  315. }
  316. function loadSkin(options, callback)
  317. {
  318. if (options.skin)
  319. {
  320. var skinName = options.skin;
  321. if (!$.yoxview.yoxviewSkins[skinName])
  322. {
  323. var skinUrl = yoxviewPath + "skins/" + skinName + "/yoxview." + skinName;
  324. $.ajax({
  325. url: skinUrl + ".js",
  326. dataType: "script",
  327. success: function(data)
  328. {
  329. if ($.yoxview.yoxviewSkins[skinName].css !== false)
  330. Yox.addStylesheet(top.document, skinUrl + ".css");
  331. if (callback)
  332. callback($.yoxview.yoxviewSkins[skinName]);
  333. },
  334. error: function(){
  335. alert("Error loading skin file " + skinUrl + ".js");
  336. }
  337. });
  338. }
  339. else if (callback)
  340. callback($.yoxview.yoxviewSkins[skinName]);
  341. }
  342. else if (callback)
  343. callback($.yoxview.yoxviewSkins[skinName]);
  344. }
  345. // Load the language file if not already loaded:
  346. function loadLanguage(langName, callback)
  347. {
  348. if (!yoxviewLanguages[langName])
  349. {
  350. yoxviewLanguages[langName] = {};
  351. var langUrl = yoxviewPath + "lang/" + langName + ".js";
  352. $.ajax({
  353. url : langUrl,
  354. async : false,
  355. dataType : "json",
  356. success: function(data){
  357. yoxviewLanguages[langName] = data;
  358. if (callback)
  359. callback(data);
  360. },
  361. error: function(){
  362. alert("Error loading language file " + langUrl);
  363. }
  364. });
  365. }
  366. else if (callback)
  367. callback(yoxviewLanguages[langName]);
  368. }
  369. function resetPopup()
  370. {
  371. if (popup)
  372. {
  373. popupWrap.remove();
  374. popup = undefined;
  375. prevBtn = undefined;
  376. nextBtn = undefined;
  377. image1 = undefined;
  378. image2 = undefined;
  379. panel1 = undefined;
  380. panel2 = undefined;
  381. currentItemIndex = 0;
  382. $.yoxview.infoButtons = {};
  383. }
  384. createPopup();
  385. }
  386. function loadViewImages(view)
  387. {
  388. var viewData = view.data("yoxview");
  389. if (!images || currentViewIndex != viewData.viewIndex)
  390. {
  391. if (!viewData.cacheVars)
  392. viewData.cacheVars = {cachedImagesCount: 0, cacheDirectionForward: true, cacheBufferLastIndex: null, currentCacheImg: 0 };
  393. images = viewData.images;
  394. imagesCount = images.length;
  395. currentViewIndex = viewData.viewIndex;
  396. var isResetPopup = false;
  397. var changeOptions = !currentOptionsSetIndex || (currentOptionsSetIndex != viewData.optionsSet);
  398. if (changeOptions)
  399. {
  400. currentOptionsSetIndex = viewData.optionsSet || 0;
  401. options = optionsSets[currentOptionsSetIndex];
  402. isResetPopup = true;
  403. }
  404. if (options.onLoadImages)
  405. options.onLoadImages({ images: images, viewData: viewData });
  406. else if ((prevBtn && imagesCount == 1) || (popup && !prevBtn && imagesCount > 0))
  407. isResetPopup = true;
  408. if (isResetPopup)
  409. resetPopup();
  410. cacheVars = viewData.cacheVars;
  411. }
  412. }
  413. function getElementDimensions(type, originalDimensions, options)
  414. {
  415. var size = originalDimensions && (originalDimensions.width || originalDimensions.height)
  416. ? { width: parseInt(originalDimensions.width), height: parseInt(originalDimensions.height) }
  417. : options.defaultDimensions[type];
  418. if (isNaN(size.width))
  419. size.width = null;
  420. if (isNaN(size.height))
  421. size.height = null;
  422. return size;
  423. }
  424. var supportedTypes = {
  425. image: function(thumbnail, thumbnailHref, thumbImg, options)
  426. {
  427. var imageData = null;
  428. for(var i=0; i<options.allowedImageUrls.length && !imageData; i++)
  429. {
  430. if (thumbnailHref.match(options.allowedImageUrls[i]))
  431. {
  432. imageData = {
  433. src: thumbnail.attr("href"),
  434. title: thumbImg.attr(options.titleAttribute),
  435. alt: thumbImg.attr("alt")
  436. };
  437. }
  438. }
  439. return imageData;
  440. },
  441. flash: function(thumbnail, thumbnailHref, thumbImg, options)
  442. {
  443. var imageData = null;
  444. var matchFlash = thumbnailHref.match(Yox.Regex.flash);
  445. var matchFlashVideo = matchFlash ? null : thumbnailHref.match(Yox.Regex.flashvideo);
  446. if (matchFlash || matchFlashVideo)
  447. {
  448. var urlData = Yox.getUrlData(thumbnailHref);
  449. var elementSize = getElementDimensions("flash", urlData.queryFields, options);
  450. if (urlData.queryFields)
  451. {
  452. delete urlData.queryFields.width;
  453. delete urlData.queryFields.height;
  454. }
  455. var flashPanel = $("<div>", {
  456. className: "yoxview_element",
  457. html: "<div class='yoxview_error'>Please install the latest version of the <a href='http://www.adobe.com/go/getflashplayer' target='_blank'>Flash player</a> to view content</div>"
  458. });
  459. var flashData = matchFlashVideo
  460. ? Yox.flashVideoPlayers[options.flashVideoPlayer](
  461. options.flashVideoPlayerPath, urlData.path,
  462. (urlData.queryFields && urlData.queryFields.image) ? urlData.queryFields.image :
  463. thumbImg[0].nodeName == "IMG" ? thumbImg.attr("src") : null,
  464. thumbImg.attr(options.titleAttribute))
  465. : urlData.queryFields || {};
  466. if (matchFlash)
  467. flashData.swf = urlData.path;
  468. $.extend(flashData, flashDefaults);
  469. flashPanel.flash(flashData);
  470. imageData = {
  471. "element": flashPanel,
  472. title: thumbImg.attr(options.titleAttribute)
  473. };
  474. $.extend(imageData, elementSize);
  475. }
  476. return imageData;
  477. },
  478. ooembed: function(thumbnail, thumbnailHref, thumbImg, options)
  479. {
  480. var imageData = null;
  481. for(videoProvider in Yox.Regex.video)
  482. {
  483. if (thumbnailHref.match(Yox.Regex.video[videoProvider]))
  484. {
  485. imageData = {
  486. provider: videoProvider,
  487. url: thumbnailHref
  488. };
  489. break;
  490. }
  491. }
  492. return imageData;
  493. },
  494. inline: function(thumbnail, thumbnailHref, thumbImg, options)
  495. {
  496. if (!options.allowInternalLinks)
  497. return null;
  498. var imageData = null;
  499. var urlData = Yox.getUrlData(thumbnailHref);
  500. if (urlData && urlData.anchor)
  501. {
  502. var element = $("#" + urlData.anchor);
  503. if (element.length != 0)
  504. {
  505. var elementSize = { width: parseInt(element.css("width")), height: parseInt(element.css("height")) };
  506. element.css({
  507. position: "absolute",
  508. top: 0,
  509. left: 0,
  510. width: "100%",
  511. height: "100%",
  512. display: "block"
  513. });
  514. imageData = {
  515. type: "inlineElement",
  516. "element": element,
  517. title: element.attr("title")
  518. };
  519. var padding = {
  520. horizontal: parseInt(element.css("padding-right")) + parseInt(element.css("padding-left")),
  521. vertical: parseInt(element.css("padding-top")) + parseInt(element.css("padding-bottom"))
  522. };
  523. elementSize.width = isNaN(elementSize.width) ? null : elementSize.width + padding.horizontal;
  524. elementSize.height = isNaN(elementSize.height) ? null : elementSize.height + padding.vertical;
  525. $.extend(imageData, elementSize);
  526. if (padding.horizontal != 0 || padding.vertical != 0)
  527. imageData.padding = padding;
  528. element.remove();
  529. }
  530. }
  531. return imageData;
  532. },
  533. iframe: function(thumbnail, thumbnailHref, thumbImg, options)
  534. {
  535. var imageData = null;
  536. var thumbnailTarget = thumbnail.attr("target");
  537. if (thumbnailTarget && thumbnailTarget == "yoxview")
  538. {
  539. var urlData = Yox.getUrlData(thumbnailHref);
  540. if (urlData && urlData.path)
  541. {
  542. var iframeSize = getElementDimensions("iframe", urlData.queryFields, options);
  543. if (urlData.queryFields)
  544. {
  545. delete urlData.queryFields.width;
  546. delete urlData.queryFields.height;
  547. }
  548. imageData = {
  549. "element": $("<iframe>", {
  550. src: Yox.urlDataToPath(urlData),
  551. className: "yoxview_element"
  552. }),
  553. title: thumbImg.attr("title"),
  554. frameborder: "0"
  555. }
  556. $.extend(imageData, iframeSize);
  557. }
  558. }
  559. return imageData;
  560. }
  561. };
  562. function getImageDataFromThumbnail(thumbnail, options)
  563. {
  564. var imageData = {};
  565. var thumbnailHref = thumbnail.attr("href");
  566. var thumbImg = thumbnail.children("img:first");
  567. if (thumbImg.length == 0)
  568. thumbImg = thumbnail;
  569. var imageData = {};
  570. for (supportedType in supportedTypes)
  571. {
  572. var media = supportedTypes[supportedType](thumbnail, thumbnailHref, thumbImg, options);
  573. if (media)
  574. {
  575. $.extend(media, {
  576. contentType: supportedType,
  577. elementId: elementCount++
  578. });
  579. imageData.media = media;
  580. break;
  581. }
  582. }
  583. if (!imageData.media)
  584. return null;
  585. imageData.thumbnailImg = thumbImg;
  586. return imageData;
  587. }
  588. function createThumbnails(view, options, additionalImages, onClick)
  589. {
  590. var clickHandler = function(e){
  591. var data = $(e.currentTarget).data("yoxview");
  592. if (!data || data.imageIndex === null)
  593. return true;
  594. else
  595. {
  596. e.preventDefault();
  597. $.yoxview.open($(e.liveFired || e.currentTarget).data("yoxview").viewIndex, data.imageIndex);
  598. }
  599. };
  600. if (view[0].tagName == "A")
  601. view.bind("click.yoxview", clickHandler);
  602. else if (!additionalImages)
  603. view.delegate(getAllowedThumbnailsSelector(options), "click.yoxview", clickHandler);
  604. else
  605. view.yoxthumbs($.extend({
  606. images: additionalImages,
  607. enableOnlyMedia: false,
  608. onClick: onClick || function(e){
  609. e.preventDefault();
  610. if (options.thumbnailsOptions && options.thumbnailsOptions.onClick)
  611. options.thumbnailsOptions.onClick(
  612. $(e.currentTarget).data("yoxview").imageIndex,
  613. $(e.currentTarget),
  614. $(e.liveFired).data("yoxview").viewIndex);
  615. else
  616. $.yoxview.open($(e.liveFired || e.currentTarget).data("yoxview").viewIndex,
  617. $(e.currentTarget).data("yoxview").imageIndex);
  618. return false;
  619. }
  620. }, options.thumbnailsOptions));
  621. }
  622. function setThumbnail(setToPopupImage)
  623. {
  624. var currentView = loadedViews[currentViewIndex];
  625. thumbnail = currentView[0].tagName == "A"
  626. ? currentView
  627. : images[currentItemIndex].thumbnailImg;
  628. if (!thumbnail || thumbnail.length == 0)
  629. thumbnail = images[0].thumbnailImg;
  630. if (thumbnail)
  631. {
  632. var thumbnailSrc = thumbnail.attr("src");
  633. if (setToPopupImage && image1 && thumbnailSrc)
  634. image1.attr("src", thumbnailSrc);
  635. if (currentViewIsInFrame && !frameOffset && window.name)
  636. frameOffset = $(top.document).find("[name='" + window.name + "']").offset();
  637. thumbnailPos = thumbnail.offset();
  638. thumbnailProperties = {
  639. width: thumbnail.width(),
  640. height: thumbnail.height(),
  641. top: Math.round(thumbnailPos.top - popupWindow.scrollTop() + (frameOffset ? frameOffset.top : 0)),
  642. left: Math.round(thumbnailPos.left + (frameOffset ? frameOffset.left : 0))
  643. };
  644. }
  645. }
  646. // Opens the viewer popup.
  647. // Arguments:
  648. // viewIndex: The 0-based index of the view to open, in case there are multiple instances of YoxView on the same page. Default is 0.
  649. // imageIndex: The 0-based index of the image to open, in the specified view. Default is 0.
  650. // callback: A function to call after the gallery has opened.
  651. this.open = function(viewIndex, initialItemIndex, callback)
  652. {
  653. var isJquery = this instanceof jQuery;
  654. if (isJquery)
  655. {
  656. if (viewIndex && typeof(viewIndex) == 'function')
  657. callback = viewIndex;
  658. var itemData = this.data("yoxview");
  659. viewIndex = itemData.viewIndex;
  660. initialItemIndex = itemData.imageIndex;
  661. }
  662. else if (typeof(viewIndex) == 'function')
  663. {
  664. callback = viewIndex;
  665. viewIndex = initialItemIndex = 0;
  666. }
  667. else if (typeof(initialItemIndex) == 'function')
  668. {
  669. callback = initialItemIndex;
  670. initialItemIndex = 0;
  671. }
  672. viewIndex = viewIndex || 0;
  673. initialItemIndex = initialItemIndex || 0;
  674. $(document).bind('keydown.yoxview', catchPress);
  675. loadViewImages(loadedViews[viewIndex]);
  676. if (!popup && imagesCount != 0)
  677. createPopup();
  678. $.yoxview.selectImage(initialItemIndex);
  679. popupWrap.stop().css({ opacity: 0, display: "block" }).animate({ opacity: 1}, "slow", function(){ popupWrap.css("opacity", "") });
  680. if(options.cacheImagesInBackground)
  681. cacheImages(initialItemIndex);
  682. if (callback)
  683. onOpenCallback = callback;
  684. return isJquery ? this : false;
  685. }
  686. this.selectImage = function(itemIndex)
  687. {
  688. $.yoxview.currentImage = images[itemIndex];
  689. currentItemIndex = itemIndex;
  690. setThumbnail(true);
  691. thumbnail.blur();
  692. panel1.css({
  693. "z-index" : "1",
  694. width : "100%",
  695. height : "100%"
  696. });
  697. panel2.css({
  698. "display" : "none",
  699. "z-index" : "2"
  700. });
  701. firstImage = true;
  702. popup.css(thumbnailProperties);
  703. this.select(itemIndex);
  704. }
  705. this.refresh = function()
  706. {
  707. resumePlay = isPlaying;
  708. if (isPlaying)
  709. stopPlay();
  710. setImage(currentItemIndex);
  711. if (resumePlay)
  712. startPlay();
  713. };
  714. //var optionsRequiringUpdate =
  715. this.options = function(opt, value){
  716. if (!opt)
  717. return this;
  718. if (value && typeof(opt) === "string"){
  719. var pName = opt;
  720. opt = {};
  721. opt[pName] = value;
  722. }
  723. if (this instanceof jQuery)
  724. {
  725. var yoxviewData = this.data("yoxview");
  726. if (yoxviewData)
  727. {
  728. $.extend(optionsSets[yoxviewData.optionsSet || 0], opt);
  729. this.yoxview("update");
  730. }
  731. return this;
  732. }
  733. else
  734. {
  735. $.each(optionsSets, function(i, optionsSet){
  736. $.extend(optionsSet, opt);
  737. });
  738. $.yoxview.update();
  739. }
  740. };
  741. // Displays the specified image and shows the (optionally) specified button. Use when the viewer is open.
  742. // Arguments:
  743. // imageIndex: The 0-based index of the image to display.
  744. // pressedBtn: a jQuery element of a button to display momentarily in the viewer.
  745. // For example, if the image has been selected by pressing the Next button
  746. // on the keyboard, specify the Next button. If no button should be display, leave blank.
  747. this.select = function(itemIndex, pressedBtn, viewIndex)
  748. {
  749. if (typeof pressedBtn === "number")
  750. {
  751. viewIndex = pressedBtn;
  752. pressedBtn = undefined;
  753. }
  754. viewIndex = viewIndex || 0;
  755. if (!isResizing)
  756. {
  757. if (itemIndex < 0)
  758. {
  759. itemIndex = imagesCount - 1;
  760. if (options.onEnd)
  761. {
  762. options.onEnd();
  763. return;
  764. }
  765. }
  766. else if (itemIndex == imagesCount)
  767. {
  768. itemIndex = 0;
  769. if (options.onEnd)
  770. {
  771. options.onEnd();
  772. return;
  773. }
  774. }
  775. if (!isPlaying && pressedBtn)
  776. flicker(pressedBtn);
  777. $.yoxview.currentImage = images[itemIndex];
  778. currentItemIndex = itemIndex;
  779. setImage(currentItemIndex);
  780. // Set the cache buffer, if required:
  781. calculateCacheBuffer();
  782. // Handle event onSelect:
  783. if (options.onSelect)
  784. options.onSelect(itemIndex, images[itemIndex]);
  785. }
  786. }
  787. this.prev = function(continuePlaying)
  788. {
  789. cacheVars.cacheDirectionForward = false;
  790. this.select(currentItemIndex - 1, prevBtn);
  791. if (isPlaying && continuePlaying !== true)
  792. stopPlay();
  793. }
  794. this.next = function(continuePlaying)
  795. {
  796. cacheVars.cacheDirectionForward = true;
  797. this.select(currentItemIndex + 1, nextBtn);
  798. if (isPlaying && continuePlaying !== true)
  799. stopPlay();
  800. }
  801. this.first = function()
  802. {
  803. if (!options.disableNotifications)
  804. longFlicker("first");
  805. this.select(0);
  806. if (isPlaying)
  807. stopPlay();
  808. };
  809. this.last = function()
  810. {
  811. if (!options.disableNotifications)
  812. longFlicker("last");
  813. this.select(imagesCount - 1);
  814. if (isPlaying)
  815. stopPlay();
  816. };
  817. this.setDefaults = function(options){
  818. $.extend(true, defaults, options);
  819. };
  820. this.play = function()
  821. {
  822. if (!this.isOpen || imagesCount == 1)
  823. return;
  824. cacheVars.cacheDirectionForward = true;
  825. if (!isPlaying)
  826. {
  827. if (!options.disableNotifications)
  828. longFlicker("play");
  829. startPlay();
  830. }
  831. else
  832. {
  833. if (!options.disableNotifications)
  834. longFlicker("pause");
  835. stopPlay();
  836. }
  837. };
  838. function flicker(button)
  839. {
  840. if (button.css("opacity") == 0)
  841. button.stop().animate({ opacity : 0 }, options.buttonsFadeTime, fadeOut(button));
  842. }
  843. function longFlicker(notificationName)
  844. {
  845. notification.css("background-position", sprites.getBackgroundPosition("notifications", notificationName));
  846. notification.stop().fadeIn(options.buttonsFadeTime, function(){
  847. $(this).delay(500)
  848. .fadeOut(options.buttonsFadeTime);
  849. });
  850. }
  851. function fadeIn(button)
  852. {
  853. $(button).stop().animate({ opacity : 0 }, options.buttonsFadeTime);
  854. }
  855. function fadeOut(button)
  856. {
  857. $(button).stop().animate({ opacity : 0.5 }, options.buttonsFadeTime);
  858. }
  859. this.close = function()
  860. {
  861. if (!this.isOpen)
  862. return;
  863. this.closeHelp();
  864. setThumbnail(false);
  865. resizePopup(thumbnailProperties, function(){ $.yoxview.isOpen = false; });
  866. hideMenuPanel();
  867. if (infoPanel)
  868. hideInfoPanel(function(){
  869. infoText.html("");
  870. });
  871. newPanel.animate({
  872. width: thumbnailProperties.width,
  873. height: thumbnailProperties.height
  874. }, options.popupResizeTime, function(){
  875. newPanel.css("opacity", 1);
  876. });
  877. popupWrap.stop().fadeOut(1000);
  878. if (isPlaying)
  879. stopPlay();
  880. swipePanels();
  881. if (options.onClose)
  882. options.onClose();
  883. $(document).unbind("keydown.yoxview");
  884. isResizing = false;
  885. }
  886. this.help = function()
  887. {
  888. if (!this.isOpen)
  889. return;
  890. if (helpPanel.css("display") == "none")
  891. helpPanel.css("display", "block").stop().animate({ opacity : 0.8 }, options.buttonsFadeTime);
  892. else
  893. this.closeHelp();
  894. }
  895. this.closeHelp = function()
  896. {
  897. if (helpPanel.css("display") != "none")
  898. helpPanel.stop().animate({ opacity: 0 }, options.buttonsFadeTime, function(){
  899. helpPanel.css("display", "none");
  900. });
  901. }
  902. this.clickBtn = function(fn, stopPlaying)
  903. {
  904. if (stopPlaying && isPlaying)
  905. stopPlay();
  906. fn.call(this);
  907. return false;
  908. }
  909. function catchPress(e)
  910. {
  911. if ($.yoxview && $.yoxview.isOpen)
  912. {
  913. var pK = keyCodes[e.keyCode];
  914. var calledFunction = $.yoxview[keyMappings[pK]];
  915. if (calledFunction)
  916. {
  917. e.preventDefault();
  918. calledFunction.apply($.yoxview);
  919. return false;
  920. }
  921. return true;
  922. }
  923. return true;
  924. }
  925. function createMenuButton(_title, btnFunction, stopPlay)
  926. {
  927. var btn = $("<a>", {
  928. href : "#",
  929. click : function(){
  930. return $.yoxview.clickBtn($.yoxview[btnFunction], stopPlay);
  931. }
  932. });
  933. var btnSpan = $("<span>" + _title + "</span>");
  934. btnSpan.css("opacity", "0")
  935. .appendTo(btn);
  936. btn.append(sprites.getSprite("icons", btnFunction));
  937. return btn;
  938. }
  939. // Prev and next buttons:
  940. function createNavButton(_function, _side, singleImage)
  941. {
  942. var navBtnImg = new Image();
  943. navBtnImg.src = options.imagesFolder + _side + ".png";
  944. var navBtn = $("<a>", {
  945. css : {
  946. "background" : "url(" + navBtnImg.src + ") no-repeat " + _side + " center",
  947. "opacity" : "0",
  948. "outline" : "0"
  949. },
  950. className : "yoxview_ctlBtn",
  951. href : "#"
  952. });
  953. navBtn.css(_side, "0");
  954. if (!singleImage)
  955. {
  956. navBtn.click(function(){
  957. this.blur();
  958. return $.yoxview.clickBtn(_function, true);
  959. });
  960. if (options.buttonsFadeTime != 0)
  961. {
  962. navBtn.hover(
  963. function(){
  964. if ($.yoxview.isOpen)
  965. $(this).stop().animate({ opacity : 0.6 }, options.buttonsFadeTime);
  966. },
  967. function(){
  968. $(this).stop().animate({ opacity : 0 }, options.buttonsFadeTime);
  969. }
  970. );
  971. }
  972. }
  973. else
  974. navBtn.css("cursor", "default");
  975. return navBtn;
  976. }
  977. popupWindow.bind("resize.yoxview", function(){
  978. windowDimensions = getWindowDimensions();
  979. if ($.yoxview.isOpen)
  980. $.yoxview.resize();
  981. });
  982. function calculateMargins()
  983. {
  984. var margins = typeof(options.popupMargin) == "number" ? [String(options.popupMargin)] : options.popupMargin.split(" ", 4);
  985. popupMargins.top = parseInt(margins[0]);
  986. switch(margins.length){
  987. case 1:
  988. popupMargins.bottom = popupMargins.right = popupMargins.left = popupMargins.top;
  989. break;
  990. case 2:
  991. popupMargins.bottom = popupMargins.top;
  992. popupMargins.right = popupMargins.left = parseInt(margins[1]);
  993. break;
  994. case 3:
  995. popupMargins.bottom = parseInt(margins[2]);
  996. popupMargins.right = popupMargins.left = parseInt(margins[1]);
  997. break;
  998. default:
  999. $.extend(popupMargins, {
  1000. right: parseInt(margins[1]),
  1001. bottom: parseInt(margins[2]),
  1002. left: parseInt(margins[3])
  1003. });
  1004. break;
  1005. }
  1006. popupMargins.totalHeight = popupMargins.top + popupMargins.bottom;
  1007. popupMargins.totalWidth = popupMargins.left + popupMargins.right;
  1008. if (options.renderInfoExternally)
  1009. $.extend(defaultPopupMargins, popupMargins);
  1010. }
  1011. function createPopup()
  1012. {
  1013. calculateMargins();
  1014. windowDimensions = getWindowDimensions();
  1015. sprites = new Yox.Sprites({
  1016. notifications: {
  1017. width: 59,
  1018. height: 59,
  1019. sprites: [ 'empty', 'playRTL', 'play', 'pause', 'last', 'first' ]
  1020. },
  1021. icons: {
  1022. width: 18,
  1023. height: 18,
  1024. sprites: ['close', 'help', 'playpause', 'link', 'pin', 'unpin', 'play', 'pause', 'right', 'left']
  1025. },
  1026. menu: {
  1027. height: 42,
  1028. sprites: ['back']
  1029. }
  1030. }, options.imagesFolder + "sprites.png", options.imagesFolder + "empty.gif");
  1031. keyMappings ={
  1032. RIGHT: options.isRTL ? 'prev' : 'next',
  1033. DOWN: 'next',
  1034. UP: 'prev',
  1035. LEFT: options.isRTL ? 'next' : 'prev',
  1036. ENTER: 'play',
  1037. HOME: 'first',
  1038. END: 'last',
  1039. SPACE: 'next',
  1040. h: 'help',
  1041. ESCAPE: 'close'
  1042. };
  1043. currentLanguage = yoxviewLanguages[options.lang];
  1044. var skin = options.skin ? $.yoxview.yoxviewSkins[options.skin] : null;
  1045. popup = $("<div>", {
  1046. id: 'yoxview',
  1047. click: function(e){ e.stopPropagation(); }
  1048. });
  1049. popupWrap = $("<div>", {
  1050. id: "yoxview_popupWrap",
  1051. click: function(e){ e.preventDefault(); $.yoxview.clickBtn($.yoxview.close, true); }
  1052. });
  1053. if (options.skin)
  1054. popupWrap.attr("className", "yoxview_" + options.skin);
  1055. if (options.backgroundOpacity === 0)
  1056. popupWrap.css("background", "none")
  1057. else if (Yox.Support.rgba())
  1058. popupWrap.css("background-color", Yox.hex2rgba(options.backgroundColor, options.backgroundOpacity));
  1059. popupWrap.appendTo($(top.document.getElementsByTagName("body")[0])).append(popup);
  1060. panel1 = $("<div>", {
  1061. className: "yoxview_imgPanel",
  1062. css: {
  1063. "z-index": "2"
  1064. }
  1065. });
  1066. panel2 = $("<div>", {
  1067. className: "yoxview_imgPanel",
  1068. css: {
  1069. "z-index": "1",
  1070. "display": "none"
  1071. }
  1072. });
  1073. // the first image:
  1074. image1 = $("<img />", {
  1075. className : "yoxview_fadeImg",
  1076. css : {
  1077. "display" : "block",
  1078. "width" : "100%",
  1079. "height" : "100%"
  1080. }
  1081. });
  1082. // the second image:
  1083. image2 = $("<img />", {
  1084. className : "yoxview_fadeImg",
  1085. css : {
  1086. "display" : "block",
  1087. "width" : "100%",
  1088. "height" : "100%"
  1089. }
  1090. });
  1091. panel1.data("yoxviewPanel", {image: image1})
  1092. .append(image1).appendTo(popup);
  1093. panel2.data("yoxviewPanel", {image: image2})
  1094. panel2.append(image2).appendTo(popup);
  1095. var singleImage = imagesCount == 1;
  1096. if (singleImage && !images[0].media.title)
  1097. options.renderInfo = false;
  1098. // the menu:
  1099. if (options.renderMenu !== false)
  1100. {
  1101. var menuPanelWrap = $("<div>", {
  1102. className : "yoxview_popupBarPanel yoxview_top"
  1103. });
  1104. if (options.autoHideMenu !== false)
  1105. {
  1106. menuPanelWrap.hover(
  1107. function(){
  1108. if ($.yoxview.isOpen)
  1109. showMenuPanel();
  1110. },
  1111. function(){
  1112. if ($.yoxview.isOpen)
  1113. hideMenuPanel();
  1114. }
  1115. );
  1116. }
  1117. menuPanel = $("<div>", {
  1118. id : "yoxview_menuPanel"
  1119. });
  1120. if (Yox.Support.rgba() && options.menuBackgroundColor)
  1121. menuPanel.css("background", Yox.hex2rgba(options.menuBackgroundColor, options.menuBackgroundOpacity || 0.8));
  1122. var helpBtn = createMenuButton(currentLanguage.Help, "help", false);
  1123. $.yoxview.infoButtons.playBtn = createMenuButton(currentLanguage.Slideshow, "play", false);
  1124. playBtnText = $.yoxview.infoButtons.playBtn.children("span");
  1125. menuPanel.append(
  1126. createMenuButton(currentLanguage.Close, "close", true),
  1127. helpBtn,
  1128. $.yoxview.infoButtons.playBtn
  1129. );
  1130. if (singleImage)
  1131. {
  1132. $.yoxview.infoButtons.playBtn.css("display", "none");
  1133. helpBtn.css("display", "none");
  1134. menuPanel.css({
  1135. width: 58
  1136. });
  1137. }
  1138. menuPanel.find("a:last-child").attr("class", "last");
  1139. menuPanelWrap.append(menuPanel).appendTo(popup);
  1140. menuPanel.delegate("a", "mouseenter", function(){
  1141. $(this).stop().animate({ top : "8px" }, "fast").find("span").stop().animate({opacity:1}, "fast");
  1142. })
  1143. .delegate("a", "mouseleave", function(){
  1144. $(this).stop().animate({ top : "0" }, "fast").find("span").stop().animate({opacity:0}, "fast");
  1145. });
  1146. }
  1147. if (options.renderButtons !== false && (!singleImage || !$.support.opacity))
  1148. {
  1149. // prev and next buttons:
  1150. prevBtn = createNavButton($.yoxview.prev, options.isRTL ? "right" : "left", singleImage);
  1151. nextBtn = createNavButton($.yoxview.next, options.isRTL ? "left" : "right", singleImage);
  1152. popup.append(prevBtn, nextBtn);
  1153. if (singleImage && !$.support.opacity)
  1154. {
  1155. ctlButtons = $();
  1156. }
  1157. else
  1158. ctlButtons = popup.find(".yoxview_ctlBtn");
  1159. }
  1160. else
  1161. ctlButtons = $();
  1162. // add the ajax loader:
  1163. ajaxLoader = $("<div>", {
  1164. id: "yoxview_ajaxLoader",
  1165. className: "yoxview_notification",
  1166. css: {
  1167. "display": "none"
  1168. }
  1169. });
  1170. ajaxLoader.append($("<img>", {
  1171. src: options.imagesFolder + "popup_ajax_loader.gif",
  1172. alt: currentLanguage.Loading,
  1173. css: {
  1174. width: 32,
  1175. height: 32,
  1176. "background-image": "url(" + options.imagesFolder + "sprites.png)",
  1177. "background-position": sprites.getBackgroundPosition("notifications", "empty")
  1178. }
  1179. }))
  1180. .appendTo(popup);
  1181. // notification image
  1182. if (!options.disableNotifications)
  1183. {
  1184. notification = $("<img>", {
  1185. className: "yoxview_notification"
  1186. });
  1187. popup.append(notification);
  1188. }
  1189. // help:
  1190. helpPanel = $("<div>", {
  1191. id : "yoxview_helpPanel",
  1192. href : "#",
  1193. title : currentLanguage.CloseHelp,
  1194. css : {
  1195. "background" : "url(" + options.imagesFolder + "help_panel.png) no-repeat center top",
  1196. "direction" : currentLanguage.Direction,
  1197. "opacity" : "0"
  1198. },
  1199. click : function(){
  1200. return $.yoxview.clickBtn($.yoxview.help, false);
  1201. }
  1202. });
  1203. var helpTitle = document.createElement("h1");
  1204. helpTitle.innerHTML = currentLanguage.Help.toUpperCase();
  1205. var helpText = document.createElement("p");
  1206. helpText.innerHTML = currentLanguage.HelpText;
  1207. var closeHelp = document.createElement("span");
  1208. closeHelp.id = "yoxview_closeHelp";
  1209. closeHelp.innerHTML = currentLanguage.CloseHelp;
  1210. helpPanel.append(helpTitle).append(helpText).append(closeHelp).appendTo(popup);
  1211. // popup info:
  1212. if (options.renderInfo !== false)
  1213. {
  1214. infoPanel = $("<div>", {
  1215. id: "yoxview_infoPanel",
  1216. click: function(e){ e.stopPropagation(); }
  1217. });
  1218. if (options.infoBackOpacity === 0)
  1219. {
  1220. infoPanel.css("background", "none");
  1221. infoPanelContent = infoPanel;
  1222. }
  1223. else
  1224. {
  1225. if (Yox.Support.rgba())
  1226. {
  1227. infoPanelContent = infoPanel;
  1228. infoPanel.css("background-color", Yox.hex2rgba(options.infoBackColor, options.infoBackOpacity));
  1229. }
  1230. else
  1231. {
  1232. infoPanel.append(
  1233. $("<div>", {
  1234. id : "yoxview_infoPanelBack",
  1235. css : {
  1236. "background" : options.infoBackColor,
  1237. "opacity" : options.infoBackOpacity
  1238. }
  1239. })
  1240. );
  1241. infoPanelContent = $("<div>", {
  1242. id: "yoxview_infoPanelContent"
  1243. });
  1244. }
  1245. }
  1246. countDisplay = $("<span>", {
  1247. id: "yoxview_count"
  1248. });
  1249. infoText = $("<div>", {
  1250. id: "yoxview_infoText"
  1251. });
  1252. if (singleImage)
  1253. {
  1254. infoText.css("margin-left", "10px");
  1255. countDisplay.css("display", "none");
  1256. }
  1257. infoPanelContent.append(countDisplay);
  1258. if (options.renderInfoPin !== false)
  1259. {
  1260. infoPinLinkImg = sprites.getSprite("icons", options.autoHideInfo ? "pin" : "unpin");
  1261. infoPinLink = $("<a>", {
  1262. className: "yoxviewInfoLink",
  1263. href: "#",
  1264. title: options.autoHideInfo ? currentLanguage.PinInfo : currentLanguage.UnpinInfo,
  1265. css: { display: 'inline' },
  1266. click: function(e){
  1267. e.preventDefault();
  1268. options.autoHideInfo = !options.autoHideInfo;
  1269. infoPinLinkImg.css("background-position", sprites.getBackgroundPosition("icons", options.autoHideInfo ? "pin" : "unpin"));
  1270. this.title = options.autoHideInfo ? currentLanguage.PinInfo : currentLanguage.UnpinInfo;
  1271. }
  1272. });
  1273. infoPinLink.append(infoPinLinkImg).appendTo(infoPanelContent);
  1274. }
  1275. if (skin && skin.infoButtons)
  1276. {
  1277. var skinButtons = skin.infoButtons(options, currentLanguage, sprites, popupWrap, popup);
  1278. if (options.infoButtons)
  1279. $.extend(options.infoButtons, skinButtons);
  1280. else
  1281. options.infoButtons = skinButtons;
  1282. }
  1283. if (options.infoButtons)
  1284. {
  1285. $.extend($.yoxview.infoButtons, options.infoButtons);
  1286. for (infoButton in options.infoButtons)
  1287. {
  1288. options.infoButtons[infoButton].attr("className", "yoxviewInfoLink").css("display", "block").appendTo(infoPanelContent);
  1289. }
  1290. }
  1291. if (options.linkToOriginalContext !== false)
  1292. {
  1293. infoPanelLink = $("<a>", {
  1294. className: "yoxviewInfoLink",
  1295. target: "_blank",
  1296. title: currentLanguage.OriginalContext
  1297. });
  1298. infoPanelLink.append(sprites.getSprite("icons", "link")).appendTo(infoPanelContent);
  1299. }
  1300. infoPanelContent.append(infoText);
  1301. if (!Yox.Support.rgba())
  1302. infoPanel.append(infoPanelContent);
  1303. infoPanel.appendTo(options.renderInfoExternally ? popupWrap : popup);
  1304. if (!options.renderInfoExternally)
  1305. {
  1306. infoPanelWrap = $("<div>", {
  1307. className : "yoxview_popupBarPanel yoxview_bottom"
  1308. });
  1309. infoPanelWrap.hover(
  1310. function(){
  1311. if ($.yoxview.isOpen && !disableInfo && options.autoHideInfo !== false)
  1312. setInfoPanelHeight();
  1313. },
  1314. function(){
  1315. if ($.yoxview.isOpen && !disableInfo && options.autoHideInfo !== false)
  1316. hideInfoPanel();
  1317. }
  1318. );
  1319. infoPanel.wrap(infoPanelWrap);
  1320. infoPanelWrap = infoPanel.parent();
  1321. }
  1322. }
  1323. // set the background if no RGBA support found:
  1324. if (!Yox.Support.rgba())
  1325. {
  1326. popupBackground = $("<div>", {
  1327. css : {
  1328. "position" : "fixed",
  1329. "height" : "100%",
  1330. "width" : "100%",
  1331. "top" : "0",
  1332. "left" : "0",
  1333. "background" : options.backgroundColor,
  1334. "z-index" : "1",
  1335. "opacity" : options.backgroundOpacity
  1336. }
  1337. }).appendTo(popupWrap);
  1338. }
  1339. }
  1340. // Cache stuff:
  1341. $(cacheImg).load(function()
  1342. {
  1343. $.extend(images[cacheVars.currentCacheImg].media, {
  1344. width: this.width,
  1345. height: this.height,
  1346. loaded: true
  1347. });
  1348. advanceCache();
  1349. })
  1350. .error(function(){
  1351. advanceCache();
  1352. });
  1353. function advanceCache()
  1354. {
  1355. cacheVars.cachedImagesCount++;
  1356. if (cacheVars.cachedImagesCount == imagesCount)
  1357. cacheVars.cacheComplete = true;
  1358. else
  1359. getCacheBuffer();
  1360. }
  1361. this.startCache = function()
  1362. {
  1363. loadViewImages(this.firstViewWithImages);
  1364. calculateCacheBuffer();
  1365. cacheImages(0);
  1366. }
  1367. function getCacheBuffer()
  1368. {
  1369. if (!options.cacheBuffer || cacheVars.currentCacheImg != cacheVars.cacheBufferLastIndex)
  1370. cacheImages(cacheVars.currentCacheImg + (cacheVars.cacheDirectionForward ? 1 : -1));
  1371. }
  1372. function calculateCacheBuffer()
  1373. {
  1374. if (options.cacheBuffer)
  1375. {
  1376. cacheVars.cacheBufferLastIndex = cacheVars.cacheDirectionForward ? currentItemIndex + options.cacheBuffer : currentItemIndex - options.cacheBuffer;
  1377. if (cacheVars.cacheBufferLastIndex < 0)
  1378. cacheVars.cacheBufferLastIndex += imagesCount;
  1379. else if (cacheVars.cacheBufferLastIndex >= imagesCount)
  1380. cacheVars.cacheBufferLastIndex -= imagesCount;
  1381. }
  1382. }
  1383. function cacheImages(imageIndexToCache)
  1384. {
  1385. if (cacheVars.cacheComplete)
  1386. return;
  1387. if (imageIndexToCache == imagesCount)
  1388. imageIndexToCache = 0;
  1389. else if (imageIndexToCache < 0)
  1390. imageIndexToCache += imagesCount;
  1391. var image = images[imageIndexToCache].media;
  1392. cacheVars.currentCacheImg = imageIndexToCache;
  1393. if (image && !image.loaded)
  1394. {
  1395. if (!image.contentType || image.contentType === "image")
  1396. cacheImg.src = image.src;
  1397. else
  1398. loadMedia(image, function(){
  1399. advanceCache();
  1400. });
  1401. }
  1402. else
  1403. getCacheBuffer();
  1404. }
  1405. // End cache stuff
  1406. function showLoaderIcon()
  1407. {
  1408. loading = true;
  1409. clearTimeout(loaderTimeout);
  1410. ajaxLoader.stop();
  1411. loaderTimeout = setTimeout(function(){
  1412. ajaxLoader.css("opacity", "0.6").fadeIn(options.buttonsFadeTime);
  1413. },
  1414. options.buttonsFadeTime
  1415. );
  1416. }
  1417. function hideLoaderIcon()
  1418. {
  1419. loading = false;
  1420. clearTimeout(loaderTimeout);
  1421. ajaxLoader.stop().fadeOut(options.buttonsFadeTime);
  1422. }
  1423. function setImage(itemIndex)
  1424. {
  1425. if (!isPlaying)
  1426. showLoaderIcon();
  1427. loadAndDisplayMedia($.yoxview.currentImage.media);
  1428. }
  1429. function resizePopup(popupPosition, callback)
  1430. {
  1431. popup.stop().animate(popupPosition, options.popupResizeTime, callback);
  1432. //popup.stop().animate(popupPosition, 5000, callback);
  1433. }
  1434. function startPlay()
  1435. {
  1436. if (imagesCount == 1)
  1437. return;
  1438. isPlaying = true;
  1439. if(playBtnText)
  1440. playBtnText.text(currentLanguage.Pause);
  1441. else if ($.yoxview.infoButtons.playBtn)
  1442. $.yoxview.infoButtons.playBtn.attr("title", currentLanguage.Pause);
  1443. if ($.yoxview.infoButtons.playBtn)
  1444. $.yoxview.infoButtons.playBtn.find("img").css("background-position", sprites.getBackgroundPosition("icons", "pause"));
  1445. if (currentItemIndex < imagesCount - 1)
  1446. {
  1447. popupTimeout = setTimeout(
  1448. function(){
  1449. $.yoxview.next(true);
  1450. },
  1451. options.playDelay
  1452. );
  1453. }
  1454. else
  1455. {
  1456. if (options.loopPlay)
  1457. popupTimeout = setTimeout(
  1458. function(){
  1459. $.yoxview.select(0, null);
  1460. },
  1461. options.playDelay
  1462. );
  1463. else
  1464. stopPlay();
  1465. if (options.onEnd)
  1466. setTimeout(options.onEnd, options.playDelay);
  1467. }
  1468. }
  1469. function stopPlay()
  1470. {
  1471. clearTimeout(popupTimeout);
  1472. isPlaying = false;
  1473. if (playBtnText)
  1474. playBtnText.text(currentLanguage.Play);
  1475. else if ($.yoxview.infoButtons.playBtn)
  1476. $.yoxview.infoButtons.playBtn.attr("title", currentLanguage.Play);
  1477. if ($.yoxview.infoButtons.playBtn)
  1478. $.yoxview.infoButtons.playBtn.find("img").css("background-position", sprites.getBackgroundPosition("icons", "play"));
  1479. }
  1480. function blink(_element)
  1481. {
  1482. _element.animate({ opacity : 0.8 }, 1000, function()
  1483. {
  1484. $(this).animate({opacity: 0.2}, 1000, blink($(this)));
  1485. });
  1486. }
  1487. var newPanel = panel2;
  1488. var oldPanel = panel1;
  1489. function getWindowDimensions()
  1490. {
  1491. var widthVal = popupWindow.width();
  1492. var heightVal = popupWindow.height();
  1493. var returnValue = {
  1494. height : heightVal,
  1495. width : widthVal,
  1496. usableArea: {
  1497. height : heightVal - popupMargins.totalHeight,
  1498. width : widthVal - popupMargins.totalWidth
  1499. }
  1500. };
  1501. return returnValue;
  1502. }
  1503. function getImagePosition(imageSize)
  1504. {
  1505. var imagePosition = (imageSize.width && imageSize.height)
  1506. ? Yox.fitImageSize(imageSize, windowDimensions.usableArea)
  1507. : {
  1508. width: imageSize.width ? Math.min(imageSize.width, windowDimensions.usableArea.width) : windowDimensions.usableArea.width,
  1509. height: imageSize.height ? Math.min(imageSize.height, windowDimensions.usableArea.height) : windowDimensions.usableArea.height
  1510. };
  1511. imagePosition.top = popupMargins.top + Math.round((windowDimensions.usableArea.height - imagePosition.height) / 2);
  1512. imagePosition.left = popupMargins.left + Math.round((windowDimensions.usableArea.width - imagePosition.width) / 2);
  1513. return imagePosition;
  1514. }
  1515. this.resize = function(updateInfoPanel)
  1516. {
  1517. if (isPlaying)
  1518. {
  1519. resumePlay = true;
  1520. stopPlay();
  1521. }
  1522. var newImagePosition = getImagePosition(currentMaxSize);
  1523. newPanel.css({ width: "100%", height: "100%"});
  1524. isResizing = true;
  1525. if (!isImageMode)
  1526. ctlButtons.css({top: Math.round((newImagePosition.height - mediaButtonsSize.height) / 2)});
  1527. resizePopup(newImagePosition,
  1528. function(){
  1529. var newImageSize = { width: popup.width(), height: popup.height() };
  1530. if (currentMaxSize.padding)
  1531. {
  1532. newImageSize.width -= currentMaxSize.padding.horizontal;
  1533. newImageSize.height -= currentMaxSize.padding.vertical;
  1534. }
  1535. newPanel.css(newImageSize);
  1536. isResizing = false;
  1537. if (infoPanel && updateInfoPanel !== false)
  1538. setInfoPanelHeight();
  1539. if (resumePlay)
  1540. {
  1541. startPlay();
  1542. resumePlay = false;
  1543. }
  1544. }
  1545. );
  1546. }
  1547. function setInfoPanelHeight(callback)
  1548. {
  1549. clearTimeout(hideInfoTimeout);
  1550. var titleHeight = infoText.outerHeight();
  1551. if (titleHeight < infoPanelMinHeight)
  1552. titleHeight = infoPanelMinHeight;
  1553. if (infoPanel.height() !== titleHeight){
  1554. infoPanel.stop().animate({height : titleHeight}, 500, function(){
  1555. if (options.renderInfoExternally){
  1556. var infoPanelPosition = infoPanel.position();
  1557. $.extend(popupMargins, defaultPopupMargins);
  1558. if (infoPanelPosition.top === 0)
  1559. popupMargins.top += titleHeight;
  1560. else
  1561. popupMargins.bottom += titleHeight;
  1562. popupMargins.totalHeight = popupMargins.top + popupMargins.bottom;
  1563. windowDimensions = getWindowDimensions();
  1564. $.yoxview.resize(false);
  1565. }
  1566. if (callback)
  1567. callback();
  1568. });
  1569. }
  1570. }
  1571. function hideInfoPanel(callback)
  1572. {
  1573. clearTimeout(hideInfoTimeout);
  1574. infoPanel.stop().animate({ height: 0 }, 500, function(){
  1575. if (callback)
  1576. callback();
  1577. });
  1578. }
  1579. function hideMenuPanel(callback)
  1580. {
  1581. if (menuPanel)
  1582. {
  1583. clearTimeout(hideMenuTimeout);
  1584. menuPanel.stop().animate({ top: menuHidePosition }, 500, function(){
  1585. if (callback)
  1586. callback();
  1587. });
  1588. }
  1589. }
  1590. function showMenuPanel(callback)
  1591. {
  1592. if (menuPanel)
  1593. {
  1594. clearTimeout(hideMenuTimeout);
  1595. menuPanel.stop().animate({ top: 0 }, 500, function(){
  1596. if (callback)
  1597. callback();
  1598. });
  1599. }
  1600. }
  1601. function swipePanels()
  1602. {
  1603. oldPanel = newPanel;
  1604. newPanel = isFirstPanel ? panel2 : panel1;
  1605. isFirstPanel = !isFirstPanel;
  1606. }
  1607. function changeMedia(media)
  1608. {
  1609. var mediaIsImage = media.contentType === "image" || !media.contentType;
  1610. if (mediaIsImage && disableInfo && infoPanelWrap)
  1611. infoPanelWrap.css("display", "block");
  1612. clearTimeout(hideInfoTimeout);
  1613. swipePanels();
  1614. var panelData = newPanel.data("yoxviewPanel");
  1615. currentMaxSize.width = media.width;
  1616. currentMaxSize.height = media.height;
  1617. currentMaxSize.padding = media.padding;
  1618. if (infoPanel)
  1619. {
  1620. var infoTextValue = media.title || "";
  1621. if (options.showDescription && media.description)
  1622. infoTextValue += infoTextValue != ""
  1623. ? "<div id='yoxview_infoTextDescription'>" + media.description + "</div>"
  1624. : media.description;
  1625. infoText.html(infoTextValue);
  1626. if (imagesCount > 1)
  1627. countDisplay.html(currentItemIndex + 1 + "/" + imagesCount);
  1628. if (infoPanelLink)
  1629. {
  1630. if ($.yoxview.currentImage.link)
  1631. infoPanelLink.attr("href", $.yoxview.currentImage.link).css("display", "inline");
  1632. else
  1633. infoPanelLink.css("display", "none");
  1634. }
  1635. }
  1636. var newImagePosition = getImagePosition(media);
  1637. if (mediaIsImage)
  1638. {
  1639. currentImageElement = isFirstPanel ? image1 : image2;
  1640. currentImageElement.attr({
  1641. src : media.src,
  1642. title : media.title,
  1643. alt: media.alt
  1644. });
  1645. panelData.image = currentImageElement;
  1646. // change to image mode:
  1647. if (!panelData.isImage && panelData.element)
  1648. {
  1649. panelData.element.css("display", "none");
  1650. panelData.image.css("display", "block");
  1651. panelData.isImage = true;
  1652. }
  1653. if (!isImageMode)
  1654. {
  1655. if (options.renderButtons)
  1656. ctlButtons.css({"height": "100%", "width": "50%", "top": "0"});
  1657. disableInfo = false;
  1658. isImageMode = true;
  1659. }
  1660. }
  1661. else
  1662. {
  1663. if (panelData.element && panelData.elementId != media.elementId)
  1664. {
  1665. panelData.element.remove();
  1666. panelData.element = undefined;
  1667. }
  1668. if (!panelData.element)
  1669. {
  1670. if (media.html)
  1671. {
  1672. panelData.element = $("<div>", {
  1673. className: mediaPanelClass
  1674. });
  1675. popup.append(panelData.element);
  1676. }
  1677. else
  1678. {
  1679. popup.append(media.element);
  1680. panelData.element = media.element;
  1681. }
  1682. }
  1683. if (media.html)
  1684. panelData.element.html(media.html);
  1685. newPanel = panelData.element;
  1686. if (isImageMode)
  1687. {
  1688. if (infoPanelWrap)
  1689. {
  1690. if (options.autoHideInfo !== false)
  1691. hideInfoPanel();
  1692. infoPanelWrap.css("display", "none");
  1693. disableInfo = true;
  1694. }
  1695. if (options.renderButtons)
  1696. ctlButtons.css({
  1697. "width": mediaButtonsSize.width,
  1698. "height": mediaButtonsSize.height
  1699. });
  1700. isImageMode = false;
  1701. }
  1702. if (options.renderButtons)
  1703. ctlButtons.css({top: (newImagePosition.height - mediaButtonsSize.height) / 2 });
  1704. // change to element mode:
  1705. if (panelData.isImage === undefined || panelData.isImage)
  1706. {
  1707. panelData.element.css("display", "block");
  1708. panelData.image.css("display", "none");
  1709. panelData.isImage = false;
  1710. }
  1711. }
  1712. var newImageDimensions = { width: newImagePosition.width, height: newImagePosition.height };
  1713. newPanel.css(firstImage ? { width: "100%", height: "100%" } : newImageDimensions);
  1714. if (loading)
  1715. hideLoaderIcon();
  1716. isResizing = true;
  1717. resizePopup(newImagePosition,
  1718. function()
  1719. {
  1720. if (firstImage)
  1721. {
  1722. $.yoxview.isOpen = true;
  1723. newPanel.css(newImageDimensions);
  1724. if (options.controlsInitialDisplayTime > 0)
  1725. {
  1726. if (options.showButtonsOnOpen)
  1727. ctlButtons.animate({opacity: 0.5}, options.controlsInitialFadeTime, function(){
  1728. if(options.buttonsFadeTime != 0)
  1729. $(this).delay(options.controlsInitialDisplayTime).animate({opacity : 0}, options.controlsInitialFadeTime);
  1730. });
  1731. if (options.showBarsOnOpen)
  1732. {
  1733. showMenuPanel(function(){
  1734. if (options.autoHideMenu !== false)
  1735. hideMenuTimeout = setTimeout(function(){
  1736. hideMenuPanel();
  1737. },
  1738. options.controlsInitialDisplayTime
  1739. );
  1740. });
  1741. if (infoPanel)
  1742. setInfoPanelHeight(function(){
  1743. if (options.autoHideInfo !== false)
  1744. hideInfoTimeout = setTimeout(function(){ hideInfoPanel(); }, options.controlsInitialDisplayTime);
  1745. });
  1746. }
  1747. }
  1748. if (options.autoPlay)
  1749. $.yoxview.play();
  1750. if (options.onOpen)
  1751. options.onOpen();
  1752. if (onOpenCallback)
  1753. {
  1754. onOpenCallback();
  1755. onOpenCallback = undefined;
  1756. }
  1757. firstImage = false;
  1758. }
  1759. if (currentMaxSize.padding)
  1760. {
  1761. var newImageWidth = popup.width();
  1762. var newImageHeight = popup.height();
  1763. if (currentMaxSize.padding)
  1764. {
  1765. newImageWidth -= currentMaxSize.padding.horizontal;
  1766. newImageHeight -= currentMaxSize.padding.vertical;
  1767. }
  1768. newPanel.css({ "width" : newImageWidth + "px", "height" : newImageHeight + "px" });
  1769. }
  1770. isResizing = false;
  1771. }
  1772. );
  1773. newPanel.css({'z-index': '2', opacity: 1});
  1774. if (oldPanel)
  1775. oldPanel.css('z-index', '1');
  1776. if (!firstImage){
  1777. newPanel.fadeIn(options.popupResizeTime, function(){
  1778. if (oldPanel)
  1779. oldPanel.css('display', 'none');
  1780. if (infoPanel)
  1781. setInfoPanelHeight(function(){
  1782. if (options.autoHideInfo !== false)
  1783. hideInfoTimeout = setTimeout(function(){ hideInfoPanel(); }, options.titleDisplayDuration);
  1784. });
  1785. if (imagesCount > 1)
  1786. {
  1787. if (options.cacheImagesInBackground && !cacheVars.cacheComplete)
  1788. cacheImages(currentItemIndex + (cacheVars.cacheDirectionForward ? 1 : -1));
  1789. if (isPlaying)
  1790. startPlay();
  1791. }
  1792. });
  1793. }
  1794. else{
  1795. newPanel.css({ display: "block", width: "100%", height: "100%" });
  1796. }
  1797. }
  1798. $(tempImg).load(function()
  1799. {
  1800. if (this.width == 0)
  1801. {
  1802. displayError("Image error");
  1803. return;
  1804. }
  1805. changeMedia($.extend({}, $.yoxview.currentImage.media, {
  1806. width: this.width,
  1807. height: this.height
  1808. }));
  1809. })
  1810. .error(function(){
  1811. displayError("Image not found:<br /><span class='errorUrl'>" + this.src + "</span>");
  1812. });
  1813. function loadMediaFromProvider(provider, url, availableSize, onLoad, onError)
  1814. {
  1815. jQuery.jsonp({
  1816. url: (mediaProviderUrls[provider] || "http://oohembed.com/oohembed/"),
  1817. data: jQuery.extend({
  1818. "url" : url,
  1819. "format": "json"
  1820. }, availableSize),
  1821. dataType: 'jsonp',
  1822. callbackParameter: "callback",
  1823. success: function(data)
  1824. {
  1825. var media = {
  1826. title: data.title,
  1827. width: data.width,
  1828. height: data.height,
  1829. type: data.type
  1830. };
  1831. if (data.type === "video")
  1832. {
  1833. media.html = data.html
  1834. .replace(/<embed /, "<embed wmode=\"transparent\" ")
  1835. .replace(/<param/, "<param name=\"wmode\" value=\"transparent\"><param")
  1836. .replace(/width=\"[\d]+\"/ig, "width=\"100%\"")
  1837. .replace(/height=\"[\d]+\"/ig, "height=\"100%\"");
  1838. }
  1839. else if (data.type === "photo")
  1840. {
  1841. jQuery.extend(media, {
  1842. src: data.url,
  1843. alt: data.title,
  1844. type: "image"
  1845. });
  1846. }
  1847. onLoad(media);
  1848. },
  1849. error: function(errorSender, errorMsg){
  1850. if (onError)
  1851. onError(errorSender, errorMsg);
  1852. }
  1853. });
  1854. };
  1855. function loadAndDisplayMedia(media)
  1856. {
  1857. try
  1858. {
  1859. if (!media)
  1860. throw("Error: Media is unavailable.");
  1861. if (media.contentType === "image" || !media.contentType)
  1862. {
  1863. // Resets the src attribute for the image - avoids a rendering problem in Chrome.
  1864. // $.opacity is tested so this isn't applied in IE (up to IE8),
  1865. // since it creates a problem with the image's fading:
  1866. if ($.support.opacity)
  1867. tempImg.src = "";
  1868. tempImg.src = media.src;
  1869. }
  1870. else
  1871. {
  1872. if (!media.loaded && media.contentType == "ooembed")
  1873. {
  1874. loadMedia(
  1875. media,
  1876. function(loadedMedia){
  1877. changeMedia(loadedMedia);
  1878. },
  1879. function(errorSender)
  1880. {
  1881. displayError("Error getting data from:<br /><span class='errorUrl'>" + errorSender.data.url + "</span>");
  1882. }
  1883. );
  1884. }
  1885. else
  1886. changeMedia($.yoxview.currentImage.media);
  1887. }
  1888. }
  1889. catch(error)
  1890. {
  1891. displayError(error);
  1892. }
  1893. }
  1894. function loadMedia(media, onLoad, onError)
  1895. {
  1896. if (media.contentType == "ooembed")
  1897. {
  1898. loadMediaFromProvider(
  1899. media.provider,
  1900. media.url,
  1901. options.defaultDimensions.video,
  1902. function(mediaData){
  1903. $.extend(media, mediaData, {loaded: true});
  1904. if (onLoad)
  1905. onLoad(media);
  1906. },
  1907. onError
  1908. );
  1909. }
  1910. }
  1911. function displayError(errorMsg)
  1912. {
  1913. changeMedia({
  1914. html: "<span class='yoxview_error'>" + errorMsg + "</span>",
  1915. width: 500,
  1916. height: 300,
  1917. type: "error",
  1918. title: ""
  1919. });
  1920. }
  1921. this.update = function(){
  1922. var options;
  1923. if (this instanceof jQuery)
  1924. {
  1925. options = optionsSets[this.data("yoxview").optionsSet || 0];
  1926. this.yoxview("unload", function(caller){ caller.yoxview(options) });
  1927. return this;
  1928. }
  1929. else
  1930. {
  1931. options = optionsSets[0];
  1932. this.unload();
  1933. $.each(loadedViews, function(i, view){
  1934. view.yoxview(options);
  1935. });
  1936. }
  1937. }
  1938. this.unload = function(callback){
  1939. var caller = this;
  1940. if (!options)
  1941. return(this);
  1942. function doUnload(){
  1943. var allowedThumbnailsSelector = getAllowedThumbnailsSelector(options);
  1944. function removeFromView(view){
  1945. view.undelegate(allowedThumbnailsSelector, "click.yoxview")
  1946. .removeData("yoxview")
  1947. .yoxthumbs("unload", "yoxview")
  1948. .find(allowedThumbnailsSelector).removeData("yoxview");
  1949. }
  1950. function removeFromDocument(){
  1951. popupWindow.unbind(".yoxview");
  1952. if (popup){
  1953. popupWrap.remove();
  1954. popup = undefined;
  1955. }
  1956. }
  1957. if (caller instanceof jQuery)
  1958. {
  1959. if (caller.data("yoxview"))
  1960. removeFromView(caller);
  1961. }
  1962. else
  1963. {
  1964. jQuery.each(loadedViews, function(i, view){
  1965. removeFromView(view);
  1966. });
  1967. removeFromDocument();
  1968. }
  1969. if (callback)
  1970. callback(caller);
  1971. else
  1972. return caller;
  1973. }
  1974. if (options.onBeforeUnload)
  1975. options.onBeforeUnload(doUnload)
  1976. else
  1977. doUnload();
  1978. };
  1979. }
  1980. })(jQuery);