annotate bin/js/jquery.galleriffic.js @ 18:9f6ece278d09 draft

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