annotate test-data/res_files/js/jquery.galleriffic.js @ 63:11708af40030 draft

planemo upload for repository https://github.com/GReD-Clermont/sRNAPipe/ commit a461e07471d3897046e14389171a2c03d09b912d
author pierre.pouchin
date Thu, 24 Jan 2019 13:09:46 -0500
parents 9185ca0a7b43
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
61
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
1 /**
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
2 * jQuery Galleriffic plugin
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
3 *
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
4 * Copyright (c) 2008 Trent Foley (http://trentacular.com)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
5 * Licensed under the MIT License:
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
6 * http://www.opensource.org/licenses/mit-license.php
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
7 *
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
8 * Much thanks to primary contributer Ponticlaro (http://www.ponticlaro.com)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
9 */
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
10 ;(function($) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
11 // Globally keep track of all images by their unique hash. Each item is an image data object.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
12 var allImages = {};
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
13 var imageCounter = 0;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
14
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
15 // Galleriffic static class
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
16 $.galleriffic = {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
17 version: '2.0.1',
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
18
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
19 // Strips invalid characters and any leading # characters
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
20 normalizeHash: function(hash) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
21 return hash.replace(/^.*#/, '').replace(/\?.*$/, '');
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
22 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
23
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
24 getImage: function(hash) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
25 if (!hash)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
26 return undefined;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
27
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
28 hash = $.galleriffic.normalizeHash(hash);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
29 return allImages[hash];
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
30 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
31
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
32 // Global function that looks up an image by its hash and displays the image.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
33 // Returns false when an image is not found for the specified hash.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
34 // @param {String} hash This is the unique hash value assigned to an image.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
35 gotoImage: function(hash) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
36 var imageData = $.galleriffic.getImage(hash);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
37 if (!imageData)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
38 return false;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
39
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
40 var gallery = imageData.gallery;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
41 gallery.gotoImage(imageData);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
42
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
43 return true;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
44 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
45
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
46 // Removes an image from its respective gallery by its hash.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
47 // Returns false when an image is not found for the specified hash or the
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
48 // specified owner gallery does match the located images gallery.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
49 // @param {String} hash This is the unique hash value assigned to an image.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
50 // @param {Object} ownerGallery (Optional) When supplied, the located images
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
51 // gallery is verified to be the same as the specified owning gallery before
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
52 // performing the remove operation.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
53 removeImageByHash: function(hash, ownerGallery) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
54 var imageData = $.galleriffic.getImage(hash);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
55 if (!imageData)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
56 return false;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
57
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
58 var gallery = imageData.gallery;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
59 if (ownerGallery && ownerGallery != gallery)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
60 return false;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
61
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
62 return gallery.removeImageByIndex(imageData.index);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
63 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
64 };
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
65
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
66 var defaults = {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
67 delay: 3000,
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
68 numThumbs: 20,
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
69 preloadAhead: 40, // Set to -1 to preload all images
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
70 enableTopPager: false,
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
71 enableBottomPager: true,
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
72 maxPagesToShow: 7,
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
73 imageContainerSel: '',
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
74 captionContainerSel: '',
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
75 controlsContainerSel: '',
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
76 loadingContainerSel: '',
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
77 renderSSControls: true,
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
78 renderNavControls: true,
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
79 playLinkText: 'Play',
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
80 pauseLinkText: 'Pause',
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
81 prevLinkText: 'Previous',
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
82 nextLinkText: 'Next',
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
83 nextPageLinkText: 'Next ›',
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
84 prevPageLinkText: '‹ Prev',
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
85 enableHistory: false,
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
86 enableKeyboardNavigation: true,
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
87 autoStart: false,
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
88 syncTransitions: false,
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
89 defaultTransitionDuration: 1000,
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
90 onSlideChange: undefined, // accepts a delegate like such: function(prevIndex, nextIndex) { ... }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
91 onTransitionOut: undefined, // accepts a delegate like such: function(slide, caption, isSync, callback) { ... }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
92 onTransitionIn: undefined, // accepts a delegate like such: function(slide, caption, isSync) { ... }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
93 onPageTransitionOut: undefined, // accepts a delegate like such: function(callback) { ... }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
94 onPageTransitionIn: undefined, // accepts a delegate like such: function() { ... }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
95 onImageAdded: undefined, // accepts a delegate like such: function(imageData, $li) { ... }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
96 onImageRemoved: undefined // accepts a delegate like such: function(imageData, $li) { ... }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
97 };
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
98
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
99 // Primary Galleriffic initialization function that should be called on the thumbnail container.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
100 $.fn.galleriffic = function(settings) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
101 // Extend Gallery Object
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
102 $.extend(this, {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
103 // Returns the version of the script
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
104 version: $.galleriffic.version,
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
105
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
106 // Current state of the slideshow
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
107 isSlideshowRunning: false,
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
108 slideshowTimeout: undefined,
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
109
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
110 // This function is attached to the click event of generated hyperlinks within the gallery
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
111 clickHandler: function(e, link) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
112 this.pause();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
113
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
114 if (!this.enableHistory) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
115 // The href attribute holds the unique hash for an image
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
116 var hash = $.galleriffic.normalizeHash($(link).attr('href'));
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
117 $.galleriffic.gotoImage(hash);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
118 e.preventDefault();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
119 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
120 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
121
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
122 // Appends an image to the end of the set of images. Argument listItem can be either a jQuery DOM element or arbitrary html.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
123 // @param listItem Either a jQuery object or a string of html of the list item that is to be added to the gallery.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
124 appendImage: function(listItem) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
125 this.addImage(listItem, false, false);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
126 return this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
127 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
128
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
129 // Inserts an image into the set of images. Argument listItem can be either a jQuery DOM element or arbitrary html.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
130 // @param listItem Either a jQuery object or a string of html of the list item that is to be added to the gallery.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
131 // @param {Integer} position The index within the gallery where the item shouold be added.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
132 insertImage: function(listItem, position) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
133 this.addImage(listItem, false, true, position);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
134 return this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
135 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
136
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
137 // Adds an image to the gallery and optionally inserts/appends it to the DOM (thumbExists)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
138 // @param listItem Either a jQuery object or a string of html of the list item that is to be added to the gallery.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
139 // @param {Boolean} thumbExists Specifies whether the thumbnail already exists in the DOM or if it needs to be added.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
140 // @param {Boolean} insert Specifies whether the the image is appended to the end or inserted into the gallery.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
141 // @param {Integer} position The index within the gallery where the item shouold be added.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
142 addImage: function(listItem, thumbExists, insert, position) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
143 var $li = ( typeof listItem === "string" ) ? $(listItem) : listItem;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
144 var $aThumb = $li.find('a.thumb');
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
145 var slideUrl = $aThumb.attr('href');
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
146 var title = $aThumb.attr('title');
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
147 var $caption = $li.find('.caption').remove();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
148 var hash = $aThumb.attr('name');
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
149
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
150 // Increment the image counter
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
151 imageCounter++;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
152
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
153 // Autogenerate a hash value if none is present or if it is a duplicate
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
154 if (!hash || allImages[''+hash]) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
155 hash = imageCounter;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
156 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
157
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
158 // Set position to end when not specified
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
159 if (!insert)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
160 position = this.data.length;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
161
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
162 var imageData = {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
163 title:title,
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
164 slideUrl:slideUrl,
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
165 caption:$caption,
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
166 hash:hash,
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
167 gallery:this,
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
168 index:position
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
169 };
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
170
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
171 // Add the imageData to this gallery's array of images
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
172 if (insert) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
173 this.data.splice(position, 0, imageData);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
174
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
175 // Reset index value on all imageData objects
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
176 this.updateIndices(position);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
177 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
178 else {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
179 this.data.push(imageData);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
180 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
181
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
182 var gallery = this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
183
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
184 // Add the element to the DOM
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
185 if (!thumbExists) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
186 // Update thumbs passing in addition post transition out handler
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
187 this.updateThumbs(function() {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
188 var $thumbsUl = gallery.find('ul.thumbs');
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
189 if (insert)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
190 $thumbsUl.children(':eq('+position+')').before($li);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
191 else
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
192 $thumbsUl.append($li);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
193
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
194 if (gallery.onImageAdded)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
195 gallery.onImageAdded(imageData, $li);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
196 });
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
197 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
198
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
199 // Register the image globally
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
200 allImages[''+hash] = imageData;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
201
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
202 // Setup attributes and click handler
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
203 $aThumb.attr('rel', 'history')
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
204 .attr('href', '#'+hash)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
205 .removeAttr('name')
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
206 .click(function(e) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
207 gallery.clickHandler(e, this);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
208 });
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
209
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
210 return this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
211 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
212
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
213 // Removes an image from the gallery based on its index.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
214 // Returns false when the index is out of range.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
215 removeImageByIndex: function(index) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
216 if (index < 0 || index >= this.data.length)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
217 return false;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
218
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
219 var imageData = this.data[index];
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
220 if (!imageData)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
221 return false;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
222
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
223 this.removeImage(imageData);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
224
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
225 return true;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
226 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
227
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
228 // Convenience method that simply calls the global removeImageByHash method.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
229 removeImageByHash: function(hash) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
230 return $.galleriffic.removeImageByHash(hash, this);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
231 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
232
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
233 // Removes an image from the gallery.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
234 removeImage: function(imageData) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
235 var index = imageData.index;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
236
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
237 // Remove the image from the gallery data array
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
238 this.data.splice(index, 1);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
239
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
240 // Remove the global registration
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
241 delete allImages[''+imageData.hash];
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
242
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
243 // Remove the image's list item from the DOM
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
244 this.updateThumbs(function() {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
245 var $li = gallery.find('ul.thumbs')
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
246 .children(':eq('+index+')')
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
247 .remove();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
248
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
249 if (gallery.onImageRemoved)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
250 gallery.onImageRemoved(imageData, $li);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
251 });
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
252
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
253 // Update each image objects index value
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
254 this.updateIndices(index);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
255
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
256 return this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
257 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
258
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
259 // Updates the index values of the each of the images in the gallery after the specified index
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
260 updateIndices: function(startIndex) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
261 for (i = startIndex; i < this.data.length; i++) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
262 this.data[i].index = i;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
263 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
264
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
265 return this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
266 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
267
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
268 // Scraped the thumbnail container for thumbs and adds each to the gallery
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
269 initializeThumbs: function() {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
270 this.data = [];
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
271 var gallery = this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
272
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
273 this.find('ul.thumbs > li').each(function(i) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
274 gallery.addImage($(this), true, false);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
275 });
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
276
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
277 return this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
278 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
279
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
280 isPreloadComplete: false,
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
281
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
282 // Initalizes the image preloader
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
283 preloadInit: function() {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
284 if (this.preloadAhead == 0) return this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
285
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
286 this.preloadStartIndex = this.currentImage.index;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
287 var nextIndex = this.getNextIndex(this.preloadStartIndex);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
288 return this.preloadRecursive(this.preloadStartIndex, nextIndex);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
289 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
290
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
291 // Changes the location in the gallery the preloader should work
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
292 // @param {Integer} index The index of the image where the preloader should restart at.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
293 preloadRelocate: function(index) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
294 // By changing this startIndex, the current preload script will restart
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
295 this.preloadStartIndex = index;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
296 return this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
297 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
298
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
299 // Recursive function that performs the image preloading
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
300 // @param {Integer} startIndex The index of the first image the current preloader started on.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
301 // @param {Integer} currentIndex The index of the current image to preload.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
302 preloadRecursive: function(startIndex, currentIndex) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
303 // Check if startIndex has been relocated
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
304 if (startIndex != this.preloadStartIndex) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
305 var nextIndex = this.getNextIndex(this.preloadStartIndex);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
306 return this.preloadRecursive(this.preloadStartIndex, nextIndex);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
307 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
308
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
309 var gallery = this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
310
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
311 // Now check for preloadAhead count
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
312 var preloadCount = currentIndex - startIndex;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
313 if (preloadCount < 0)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
314 preloadCount = this.data.length-1-startIndex+currentIndex;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
315 if (this.preloadAhead >= 0 && preloadCount > this.preloadAhead) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
316 // Do this in order to keep checking for relocated start index
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
317 setTimeout(function() { gallery.preloadRecursive(startIndex, currentIndex); }, 500);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
318 return this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
319 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
320
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
321 var imageData = this.data[currentIndex];
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
322 if (!imageData)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
323 return this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
324
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
325 // If already loaded, continue
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
326 if (imageData.image)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
327 return this.preloadNext(startIndex, currentIndex);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
328
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
329 // Preload the image
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
330 var image = new Image();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
331
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
332 image.onload = function() {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
333 imageData.image = this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
334 gallery.preloadNext(startIndex, currentIndex);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
335 };
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
336
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
337 image.alt = imageData.title;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
338 image.src = imageData.slideUrl;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
339
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
340 return this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
341 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
342
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
343 // Called by preloadRecursive in order to preload the next image after the previous has loaded.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
344 // @param {Integer} startIndex The index of the first image the current preloader started on.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
345 // @param {Integer} currentIndex The index of the current image to preload.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
346 preloadNext: function(startIndex, currentIndex) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
347 var nextIndex = this.getNextIndex(currentIndex);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
348 if (nextIndex == startIndex) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
349 this.isPreloadComplete = true;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
350 } else {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
351 // Use setTimeout to free up thread
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
352 var gallery = this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
353 setTimeout(function() { gallery.preloadRecursive(startIndex, nextIndex); }, 100);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
354 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
355
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
356 return this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
357 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
358
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
359 // Safe way to get the next image index relative to the current image.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
360 // If the current image is the last, returns 0
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
361 getNextIndex: function(index) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
362 var nextIndex = index+1;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
363 if (nextIndex >= this.data.length)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
364 nextIndex = 0;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
365 return nextIndex;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
366 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
367
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
368 // Safe way to get the previous image index relative to the current image.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
369 // If the current image is the first, return the index of the last image in the gallery.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
370 getPrevIndex: function(index) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
371 var prevIndex = index-1;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
372 if (prevIndex < 0)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
373 prevIndex = this.data.length-1;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
374 return prevIndex;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
375 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
376
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
377 // Pauses the slideshow
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
378 pause: function() {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
379 this.isSlideshowRunning = false;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
380 if (this.slideshowTimeout) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
381 clearTimeout(this.slideshowTimeout);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
382 this.slideshowTimeout = undefined;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
383 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
384
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
385 if (this.$controlsContainer) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
386 this.$controlsContainer
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
387 .find('div.ss-controls a').removeClass().addClass('play')
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
388 .attr('title', this.playLinkText)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
389 .attr('href', '#play')
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
390 .html(this.playLinkText);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
391 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
392
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
393 return this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
394 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
395
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
396 // Plays the slideshow
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
397 play: function() {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
398 this.isSlideshowRunning = true;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
399
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
400 if (this.$controlsContainer) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
401 this.$controlsContainer
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
402 .find('div.ss-controls a').removeClass().addClass('pause')
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
403 .attr('title', this.pauseLinkText)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
404 .attr('href', '#pause')
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
405 .html(this.pauseLinkText);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
406 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
407
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
408 if (!this.slideshowTimeout) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
409 var gallery = this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
410 this.slideshowTimeout = setTimeout(function() { gallery.ssAdvance(); }, this.delay);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
411 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
412
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
413 return this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
414 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
415
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
416 // Toggles the state of the slideshow (playing/paused)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
417 toggleSlideshow: function() {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
418 if (this.isSlideshowRunning)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
419 this.pause();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
420 else
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
421 this.play();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
422
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
423 return this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
424 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
425
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
426 // Advances the slideshow to the next image and delegates navigation to the
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
427 // history plugin when history is enabled
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
428 // enableHistory is true
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
429 ssAdvance: function() {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
430 if (this.isSlideshowRunning)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
431 this.next(true);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
432
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
433 return this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
434 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
435
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
436 // Advances the gallery to the next image.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
437 // @param {Boolean} dontPause Specifies whether to pause the slideshow.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
438 // @param {Boolean} bypassHistory Specifies whether to delegate navigation to the history plugin when history is enabled.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
439 next: function(dontPause, bypassHistory) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
440 this.gotoIndex(this.getNextIndex(this.currentImage.index), dontPause, bypassHistory);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
441 return this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
442 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
443
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
444 // Navigates to the previous image in the gallery.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
445 // @param {Boolean} dontPause Specifies whether to pause the slideshow.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
446 // @param {Boolean} bypassHistory Specifies whether to delegate navigation to the history plugin when history is enabled.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
447 previous: function(dontPause, bypassHistory) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
448 this.gotoIndex(this.getPrevIndex(this.currentImage.index), dontPause, bypassHistory);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
449 return this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
450 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
451
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
452 // Navigates to the next page in the gallery.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
453 // @param {Boolean} dontPause Specifies whether to pause the slideshow.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
454 // @param {Boolean} bypassHistory Specifies whether to delegate navigation to the history plugin when history is enabled.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
455 nextPage: function(dontPause, bypassHistory) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
456 var page = this.getCurrentPage();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
457 var lastPage = this.getNumPages() - 1;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
458 if (page < lastPage) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
459 var startIndex = page * this.numThumbs;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
460 var nextPage = startIndex + this.numThumbs;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
461 this.gotoIndex(nextPage, dontPause, bypassHistory);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
462 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
463
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
464 return this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
465 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
466
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
467 // Navigates to the previous page in the gallery.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
468 // @param {Boolean} dontPause Specifies whether to pause the slideshow.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
469 // @param {Boolean} bypassHistory Specifies whether to delegate navigation to the history plugin when history is enabled.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
470 previousPage: function(dontPause, bypassHistory) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
471 var page = this.getCurrentPage();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
472 if (page > 0) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
473 var startIndex = page * this.numThumbs;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
474 var prevPage = startIndex - this.numThumbs;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
475 this.gotoIndex(prevPage, dontPause, bypassHistory);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
476 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
477
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
478 return this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
479 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
480
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
481 // Navigates to the image at the specified index in the gallery
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
482 // @param {Integer} index The index of the image in the gallery to display.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
483 // @param {Boolean} dontPause Specifies whether to pause the slideshow.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
484 // @param {Boolean} bypassHistory Specifies whether to delegate navigation to the history plugin when history is enabled.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
485 gotoIndex: function(index, dontPause, bypassHistory) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
486 if (!dontPause)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
487 this.pause();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
488
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
489 if (index < 0) index = 0;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
490 else if (index >= this.data.length) index = this.data.length-1;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
491
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
492 var imageData = this.data[index];
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
493
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
494 if (!bypassHistory && this.enableHistory)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
495 $.historyLoad(String(imageData.hash)); // At the moment, historyLoad only accepts string arguments
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
496 else
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
497 this.gotoImage(imageData);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
498
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
499 return this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
500 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
501
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
502 // This function is garaunteed to be called anytime a gallery slide changes.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
503 // @param {Object} imageData An object holding the image metadata of the image to navigate to.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
504 gotoImage: function(imageData) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
505 var index = imageData.index;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
506
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
507 if (this.onSlideChange)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
508 this.onSlideChange(this.currentImage.index, index);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
509
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
510 this.currentImage = imageData;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
511 this.preloadRelocate(index);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
512
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
513 this.refresh();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
514
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
515 return this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
516 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
517
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
518 // Returns the default transition duration value. The value is halved when not
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
519 // performing a synchronized transition.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
520 // @param {Boolean} isSync Specifies whether the transitions are synchronized.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
521 getDefaultTransitionDuration: function(isSync) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
522 if (isSync)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
523 return this.defaultTransitionDuration;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
524 return this.defaultTransitionDuration / 2;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
525 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
526
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
527 // Rebuilds the slideshow image and controls and performs transitions
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
528 refresh: function() {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
529 var imageData = this.currentImage;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
530 if (!imageData)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
531 return this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
532
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
533 var index = imageData.index;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
534
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
535 // Update Controls
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
536 if (this.$controlsContainer) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
537 this.$controlsContainer
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
538 .find('div.nav-controls a.prev').attr('href', '#'+this.data[this.getPrevIndex(index)].hash).end()
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
539 .find('div.nav-controls a.next').attr('href', '#'+this.data[this.getNextIndex(index)].hash);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
540 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
541
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
542 var previousSlide = this.$imageContainer.find('span.current').addClass('previous').removeClass('current');
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
543 var previousCaption = 0;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
544
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
545 if (this.$captionContainer) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
546 previousCaption = this.$captionContainer.find('span.current').addClass('previous').removeClass('current');
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
547 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
548
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
549 // Perform transitions simultaneously if syncTransitions is true and the next image is already preloaded
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
550 var isSync = this.syncTransitions && imageData.image;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
551
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
552 // Flag we are transitioning
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
553 var isTransitioning = true;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
554 var gallery = this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
555
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
556 var transitionOutCallback = function() {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
557 // Flag that the transition has completed
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
558 isTransitioning = false;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
559
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
560 // Remove the old slide
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
561 previousSlide.remove();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
562
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
563 // Remove old caption
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
564 if (previousCaption)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
565 previousCaption.remove();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
566
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
567 if (!isSync) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
568 if (imageData.image && imageData.hash == gallery.data[gallery.currentImage.index].hash) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
569 gallery.buildImage(imageData, isSync);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
570 } else {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
571 // Show loading container
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
572 if (gallery.$loadingContainer) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
573 gallery.$loadingContainer.show();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
574 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
575 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
576 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
577 };
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
578
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
579 if (previousSlide.length == 0) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
580 // For the first slide, the previous slide will be empty, so we will call the callback immediately
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
581 transitionOutCallback();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
582 } else {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
583 if (this.onTransitionOut) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
584 this.onTransitionOut(previousSlide, previousCaption, isSync, transitionOutCallback);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
585 } else {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
586 previousSlide.fadeTo(this.getDefaultTransitionDuration(isSync), 0.0, transitionOutCallback);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
587 if (previousCaption)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
588 previousCaption.fadeTo(this.getDefaultTransitionDuration(isSync), 0.0);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
589 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
590 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
591
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
592 // Go ahead and begin transitioning in of next image
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
593 if (isSync)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
594 this.buildImage(imageData, isSync);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
595
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
596 if (!imageData.image) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
597 var image = new Image();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
598
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
599 // Wire up mainImage onload event
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
600 image.onload = function() {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
601 imageData.image = this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
602
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
603 // Only build image if the out transition has completed and we are still on the same image hash
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
604 if (!isTransitioning && imageData.hash == gallery.data[gallery.currentImage.index].hash) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
605 gallery.buildImage(imageData, isSync);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
606 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
607 };
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
608
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
609 // set alt and src
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
610 image.alt = imageData.title;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
611 image.src = imageData.slideUrl;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
612 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
613
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
614 // This causes the preloader (if still running) to relocate out from the currentIndex
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
615 this.relocatePreload = true;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
616
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
617 return this.syncThumbs();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
618 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
619
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
620 // Called by the refresh method after the previous image has been transitioned out or at the same time
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
621 // as the out transition when performing a synchronous transition.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
622 // @param {Object} imageData An object holding the image metadata of the image to build.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
623 // @param {Boolean} isSync Specifies whether the transitions are synchronized.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
624 buildImage: function(imageData, isSync) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
625 var gallery = this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
626 var nextIndex = this.getNextIndex(imageData.index);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
627
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
628 // Construct new hidden span for the image
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
629 var newSlide = this.$imageContainer
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
630 .append('<span class="image-wrapper current"><a class="advance-link" rel="history" href="#'+this.data[nextIndex].hash+'" title="'+imageData.title+'">&nbsp;</a></span>')
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
631 .find('span.current').css('opacity', '0');
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
632
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
633 newSlide.find('a')
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
634 .append(imageData.image)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
635 .click(function(e) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
636 gallery.clickHandler(e, this);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
637 });
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
638
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
639 var newCaption = 0;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
640 if (this.$captionContainer) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
641 // Construct new hidden caption for the image
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
642 newCaption = this.$captionContainer
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
643 .append('<span class="image-caption current"></span>')
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
644 .find('span.current').css('opacity', '0')
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
645 .append(imageData.caption);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
646 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
647
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
648 // Hide the loading conatiner
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
649 if (this.$loadingContainer) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
650 this.$loadingContainer.hide();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
651 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
652
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
653 // Transition in the new image
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
654 if (this.onTransitionIn) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
655 this.onTransitionIn(newSlide, newCaption, isSync);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
656 } else {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
657 newSlide.fadeTo(this.getDefaultTransitionDuration(isSync), 1.0);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
658 if (newCaption)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
659 newCaption.fadeTo(this.getDefaultTransitionDuration(isSync), 1.0);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
660 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
661
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
662 if (this.isSlideshowRunning) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
663 if (this.slideshowTimeout)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
664 clearTimeout(this.slideshowTimeout);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
665
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
666 this.slideshowTimeout = setTimeout(function() { gallery.ssAdvance(); }, this.delay);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
667 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
668
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
669 return this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
670 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
671
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
672 // Returns the current page index that should be shown for the currentImage
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
673 getCurrentPage: function() {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
674 return Math.floor(this.currentImage.index / this.numThumbs);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
675 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
676
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
677 // Applies the selected class to the current image's corresponding thumbnail.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
678 // Also checks if the current page has changed and updates the displayed page of thumbnails if necessary.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
679 syncThumbs: function() {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
680 var page = this.getCurrentPage();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
681 if (page != this.displayedPage)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
682 this.updateThumbs();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
683
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
684 // Remove existing selected class and add selected class to new thumb
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
685 var $thumbs = this.find('ul.thumbs').children();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
686 $thumbs.filter('.selected').removeClass('selected');
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
687 $thumbs.eq(this.currentImage.index).addClass('selected');
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
688
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
689 return this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
690 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
691
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
692 // Performs transitions on the thumbnails container and updates the set of
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
693 // thumbnails that are to be displayed and the navigation controls.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
694 // @param {Delegate} postTransitionOutHandler An optional delegate that is called after
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
695 // the thumbnails container has transitioned out and before the thumbnails are rebuilt.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
696 updateThumbs: function(postTransitionOutHandler) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
697 var gallery = this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
698 var transitionOutCallback = function() {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
699 // Call the Post-transition Out Handler
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
700 if (postTransitionOutHandler)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
701 postTransitionOutHandler();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
702
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
703 gallery.rebuildThumbs();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
704
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
705 // Transition In the thumbsContainer
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
706 if (gallery.onPageTransitionIn)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
707 gallery.onPageTransitionIn();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
708 else
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
709 gallery.show();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
710 };
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
711
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
712 // Transition Out the thumbsContainer
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
713 if (this.onPageTransitionOut) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
714 this.onPageTransitionOut(transitionOutCallback);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
715 } else {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
716 this.hide();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
717 transitionOutCallback();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
718 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
719
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
720 return this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
721 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
722
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
723 // Updates the set of thumbnails that are to be displayed and the navigation controls.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
724 rebuildThumbs: function() {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
725 var needsPagination = this.data.length > this.numThumbs;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
726
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
727 // Rebuild top pager
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
728 if (this.enableTopPager) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
729 var $topPager = this.find('div.top');
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
730 if ($topPager.length == 0)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
731 $topPager = this.prepend('<div class="top pagination"></div>').find('div.top');
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
732 else
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
733 $topPager.empty();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
734
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
735 if (needsPagination)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
736 this.buildPager($topPager);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
737 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
738
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
739 // Rebuild bottom pager
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
740 if (this.enableBottomPager) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
741 var $bottomPager = this.find('div.bottom');
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
742 if ($bottomPager.length == 0)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
743 $bottomPager = this.append('<div class="bottom pagination"></div>').find('div.bottom');
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
744 else
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
745 $bottomPager.empty();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
746
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
747 if (needsPagination)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
748 this.buildPager($bottomPager);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
749 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
750
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
751 var page = this.getCurrentPage();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
752 var startIndex = page*this.numThumbs;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
753 var stopIndex = startIndex+this.numThumbs-1;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
754 if (stopIndex >= this.data.length)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
755 stopIndex = this.data.length-1;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
756
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
757 // Show/Hide thumbs
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
758 var $thumbsUl = this.find('ul.thumbs');
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
759 $thumbsUl.find('li').each(function(i) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
760 var $li = $(this);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
761 if (i >= startIndex && i <= stopIndex) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
762 $li.show();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
763 } else {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
764 $li.hide();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
765 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
766 });
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
767
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
768 this.displayedPage = page;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
769
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
770 // Remove the noscript class from the thumbs container ul
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
771 $thumbsUl.removeClass('noscript');
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
772
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
773 return this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
774 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
775
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
776 // Returns the total number of pages required to display all the thumbnails.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
777 getNumPages: function() {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
778 return Math.ceil(this.data.length/this.numThumbs);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
779 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
780
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
781 // Rebuilds the pager control in the specified matched element.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
782 // @param {jQuery} pager A jQuery element set matching the particular pager to be rebuilt.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
783 buildPager: function(pager) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
784 var gallery = this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
785 var numPages = this.getNumPages();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
786 var page = this.getCurrentPage();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
787 var startIndex = page * this.numThumbs;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
788 var pagesRemaining = this.maxPagesToShow - 1;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
789
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
790 var pageNum = page - Math.floor((this.maxPagesToShow - 1) / 2) + 1;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
791 if (pageNum > 0) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
792 var remainingPageCount = numPages - pageNum;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
793 if (remainingPageCount < pagesRemaining) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
794 pageNum = pageNum - (pagesRemaining - remainingPageCount);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
795 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
796 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
797
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
798 if (pageNum < 0) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
799 pageNum = 0;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
800 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
801
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
802 // Prev Page Link
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
803 if (page > 0) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
804 var prevPage = startIndex - this.numThumbs;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
805 pager.append('<a rel="history" href="#'+this.data[prevPage].hash+'" title="'+this.prevPageLinkText+'">'+this.prevPageLinkText+'</a>');
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
806 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
807
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
808 // Create First Page link if needed
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
809 if (pageNum > 0) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
810 this.buildPageLink(pager, 0, numPages);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
811 if (pageNum > 1)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
812 pager.append('<span class="ellipsis">&hellip;</span>');
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
813
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
814 pagesRemaining--;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
815 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
816
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
817 // Page Index Links
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
818 while (pagesRemaining > 0) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
819 this.buildPageLink(pager, pageNum, numPages);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
820 pagesRemaining--;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
821 pageNum++;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
822 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
823
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
824 // Create Last Page link if needed
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
825 if (pageNum < numPages) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
826 var lastPageNum = numPages - 1;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
827 if (pageNum < lastPageNum)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
828 pager.append('<span class="ellipsis">&hellip;</span>');
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
829
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
830 this.buildPageLink(pager, lastPageNum, numPages);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
831 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
832
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
833 // Next Page Link
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
834 var nextPage = startIndex + this.numThumbs;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
835 if (nextPage < this.data.length) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
836 pager.append('<a rel="history" href="#'+this.data[nextPage].hash+'" title="'+this.nextPageLinkText+'">'+this.nextPageLinkText+'</a>');
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
837 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
838
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
839 pager.find('a').click(function(e) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
840 gallery.clickHandler(e, this);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
841 });
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
842
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
843 return this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
844 },
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
845
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
846 // Builds a single page link within a pager. This function is called by buildPager
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
847 // @param {jQuery} pager A jQuery element set matching the particular pager to be rebuilt.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
848 // @param {Integer} pageNum The page number of the page link to build.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
849 // @param {Integer} numPages The total number of pages required to display all thumbnails.
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
850 buildPageLink: function(pager, pageNum, numPages) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
851 var pageLabel = pageNum + 1;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
852 var currentPage = this.getCurrentPage();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
853 if (pageNum == currentPage)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
854 pager.append('<span class="current">'+pageLabel+'</span>');
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
855 else if (pageNum < numPages) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
856 var imageIndex = pageNum*this.numThumbs;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
857 pager.append('<a rel="history" href="#'+this.data[imageIndex].hash+'" title="'+pageLabel+'">'+pageLabel+'</a>');
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
858 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
859
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
860 return this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
861 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
862 });
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
863
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
864 // Now initialize the gallery
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
865 $.extend(this, defaults, settings);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
866
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
867 // Verify the history plugin is available
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
868 if (this.enableHistory && !$.historyInit)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
869 this.enableHistory = false;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
870
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
871 // Select containers
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
872 if (this.imageContainerSel) this.$imageContainer = $(this.imageContainerSel);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
873 if (this.captionContainerSel) this.$captionContainer = $(this.captionContainerSel);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
874 if (this.loadingContainerSel) this.$loadingContainer = $(this.loadingContainerSel);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
875
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
876 // Initialize the thumbails
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
877 this.initializeThumbs();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
878
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
879 if (this.maxPagesToShow < 3)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
880 this.maxPagesToShow = 3;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
881
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
882 this.displayedPage = -1;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
883 this.currentImage = this.data[0];
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
884 var gallery = this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
885
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
886 // Hide the loadingContainer
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
887 if (this.$loadingContainer)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
888 this.$loadingContainer.hide();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
889
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
890 // Setup controls
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
891 if (this.controlsContainerSel) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
892 this.$controlsContainer = $(this.controlsContainerSel).empty();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
893
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
894 if (this.renderSSControls) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
895 if (this.autoStart) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
896 this.$controlsContainer
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
897 .append('<div class="ss-controls"><a href="#pause" class="pause" title="'+this.pauseLinkText+'">'+this.pauseLinkText+'</a></div>');
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
898 } else {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
899 this.$controlsContainer
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
900 .append('<div class="ss-controls"><a href="#play" class="play" title="'+this.playLinkText+'">'+this.playLinkText+'</a></div>');
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
901 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
902
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
903 this.$controlsContainer.find('div.ss-controls a')
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
904 .click(function(e) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
905 gallery.toggleSlideshow();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
906 e.preventDefault();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
907 return false;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
908 });
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
909 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
910
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
911 if (this.renderNavControls) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
912 this.$controlsContainer
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
913 .append('<div class="nav-controls"><a class="prev" rel="history" title="'+this.prevLinkText+'">'+this.prevLinkText+'</a><a class="next" rel="history" title="'+this.nextLinkText+'">'+this.nextLinkText+'</a></div>')
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
914 .find('div.nav-controls a')
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
915 .click(function(e) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
916 gallery.clickHandler(e, this);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
917 });
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
918 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
919 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
920
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
921 var initFirstImage = !this.enableHistory || !location.hash;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
922 if (this.enableHistory && location.hash) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
923 var hash = $.galleriffic.normalizeHash(location.hash);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
924 var imageData = allImages[hash];
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
925 if (!imageData)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
926 initFirstImage = true;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
927 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
928
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
929 // Setup gallery to show the first image
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
930 if (initFirstImage)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
931 this.gotoIndex(0, false, true);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
932
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
933 // Setup Keyboard Navigation
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
934 if (this.enableKeyboardNavigation) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
935 $(document).keydown(function(e) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
936 var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
937 switch(key) {
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
938 case 32: // space
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
939 gallery.next();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
940 e.preventDefault();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
941 break;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
942 case 33: // Page Up
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
943 gallery.previousPage();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
944 e.preventDefault();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
945 break;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
946 case 34: // Page Down
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
947 gallery.nextPage();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
948 e.preventDefault();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
949 break;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
950 case 35: // End
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
951 gallery.gotoIndex(gallery.data.length-1);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
952 e.preventDefault();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
953 break;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
954 case 36: // Home
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
955 gallery.gotoIndex(0);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
956 e.preventDefault();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
957 break;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
958 case 37: // left arrow
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
959 gallery.previous();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
960 e.preventDefault();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
961 break;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
962 case 39: // right arrow
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
963 gallery.next();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
964 e.preventDefault();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
965 break;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
966 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
967 });
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
968 }
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
969
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
970 // Auto start the slideshow
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
971 if (this.autoStart)
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
972 this.play();
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
973
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
974 // Kickoff Image Preloader after 1 second
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
975 setTimeout(function() { gallery.preloadInit(); }, 1000);
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
976
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
977 return this;
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
978 };
9185ca0a7b43 Updated package according to recommendations.
pierre.pouchin
parents:
diff changeset
979 })(jQuery);