|
57 |
|
57 |
|
58 |
itemHeight: null, |
58 |
itemHeight: null, |
59 |
heighestImg: null, |
59 |
heighestImg: null, |
|
|
60 |
heighestImgRatio: null, |
61 |
_youtubeIframeRatio: null, |
62 |
onlyYoutubeVideos: null, |
60 |
|
63 |
|
61 |
// items: Array |
64 |
// items: Array |
62 |
// array of objects({src: <src-string>}) |
65 |
// array of objects({src: <src-string>}) |
|
66 |
|
69 |
|
67 |
allItemsLoaded: null, |
70 |
allItemsLoaded: null, |
68 |
|
71 |
|
69 |
bigThumbnails: null, |
72 |
isBigThumbnails: null, |
70 |
|
73 |
|
71 |
_resizeDeferred: null, |
74 |
_resizeDeferred: null, |
72 |
|
75 |
|
|
76 |
this.contentSliderOffset = 0; |
79 |
this.contentSliderOffset = 0; |
77 |
this.shownItemIndex = 0; |
80 |
this.shownItemIndex = 0; |
78 |
this.allItemsLoaded = false; |
81 |
this.allItemsLoaded = false; |
79 |
this.bigThumbnails = false; |
82 |
this.isBigThumbnails = false; |
|
|
83 |
this._youtubeIframeRatio = 16 / 9; |
84 |
this.heighestImgRatio = this._youtubeIframeRatio; |
85 |
this.heighestImg = this.heighestImg || {w: 1600, h: 900}; |
86 |
this.onlyYoutubeVideos = true; |
87 |
this.defaultSliderWidth = 0; |
80 |
}, |
88 |
}, |
81 |
|
89 |
|
82 |
buildRendering: function() { |
90 |
postCreate: function() { |
83 |
this.inherited(arguments); |
91 |
this._setDefaultThumbsHeight(); |
84 |
|
92 |
|
85 |
this.outerContainer = new ContainerWidget({ |
|
|
86 |
'class': 'carouselOuterContainer' |
87 |
}); |
88 |
|
89 |
this.addChild(this.outerContainer); |
90 |
this.own(this.outerContainer); |
91 |
|
92 |
this.renderContentSlider(); |
93 |
this.renderNavButtons(); |
94 |
this.renderScaleButton(); |
95 |
|
96 |
}, |
97 |
|
98 |
postCreate: function() { |
99 |
if (window.YT && window.YT.loaded) { |
93 |
if (window.YT && window.YT.loaded) { |
100 |
setTimeout(lang.hitch(this, function() { |
94 |
//stub |
101 |
this._renderYoutubeVideos(); |
|
|
102 |
}), 500); |
103 |
} else { |
95 |
} else { |
104 |
//load youtube api |
96 |
//load youtube api |
105 |
var tag = document.createElement('script'); |
97 |
var tag = document.createElement('script'); |
|
115 |
}); |
107 |
}); |
116 |
} |
108 |
} |
117 |
onPlayerReady = lang.hitch(this, function() { |
109 |
onPlayerReady = lang.hitch(this, function() { |
118 |
this.imagesLoaded(); |
110 |
this.thumbLoaded(); |
119 |
}); |
111 |
}); |
|
|
112 |
onPlayerError = lang.hitch(this, function() { |
113 |
this.thumbLoaded(); |
114 |
}); |
120 |
}, |
115 |
}, |
121 |
|
116 |
|
122 |
renderContentSlider: function() { |
117 |
buildRendering: function() { |
|
|
118 |
this.inherited(arguments); |
119 |
|
120 |
this.outerContainer = new ContainerWidget({ |
121 |
'class': 'carouselOuterContainer', |
122 |
style: { |
123 |
'height': this.itemHeight + 'px' |
124 |
} |
125 |
}); |
123 |
this.contentSliderWrapper = new ContainerWidget({ |
126 |
this.contentSliderWrapper = new ContainerWidget({ |
124 |
'class': 'contentSliderWrapper' |
127 |
'class': 'contentSliderWrapper' |
125 |
}); |
128 |
}); |
|
|
129 |
|
130 |
this.outerContainer.addChild(this.contentSliderWrapper); |
131 |
this.addChild(this.outerContainer); |
132 |
this.own(this.outerContainer); |
133 |
|
134 |
this.renderNavButtons(); |
135 |
this.renderScaleButton(); |
136 |
this.renderContentSlider(); |
137 |
|
138 |
}, |
139 |
|
140 |
renderNavButtons: function() { |
141 |
this.leftButton = domConstruct.create('div', { |
142 |
'class': 'carouselButton leftCarouselButton', |
143 |
onclick: lang.hitch(this, function() { |
144 |
this.showItem(this.shownItemIndex - 1); |
145 |
}) |
146 |
}, this.contentSliderWrapper.domNode, 'before'); |
147 |
domConstruct.create('div', { |
148 |
'class': 'carouselButtonImage' |
149 |
}, this.leftButton); |
150 |
|
151 |
this.rightButton = domConstruct.create('div', { |
152 |
'class': 'carouselButton rightCarouselButton', |
153 |
onclick: lang.hitch(this, function() { |
154 |
this.showItem(this.shownItemIndex + 1); |
155 |
}) |
156 |
}, this.contentSliderWrapper.domNode, 'after'); |
157 |
domConstruct.create('div', { |
158 |
'class': 'carouselButtonImage' |
159 |
}, this.rightButton); |
160 |
}, |
161 |
|
162 |
renderScaleButton: function() { |
163 |
this.scaleButton = domConstruct.create('div', { |
164 |
'class': 'scaleButton dijitHidden', |
165 |
onclick: lang.hitch(this, function() { |
166 |
this.togglePreviewSize(this.shownItemIndex); |
167 |
}) |
168 |
}, this.domNode); |
169 |
}, |
170 |
|
171 |
renderContentSlider: function() { |
126 |
this.contentSlider = new ContainerWidget({ |
172 |
this.contentSlider = new ContainerWidget({ |
127 |
'class': 'contentSlider' |
173 |
'class': 'contentSlider' |
128 |
}); |
174 |
}); |
129 |
this.contentSliderWrapper.addChild(this.contentSlider); |
175 |
this.contentSliderWrapper.addChild(this.contentSlider); |
130 |
this.outerContainer.addChild(this.contentSliderWrapper); |
|
|
131 |
|
176 |
|
132 |
this._renderThumbs(); |
177 |
this._renderThumbs(); |
133 |
}, |
178 |
}, |
134 |
|
179 |
|
135 |
_renderThumbs: function() { |
180 |
_renderThumbs: function() { |
136 |
this.loadedImagesCount = 0; |
181 |
this.loadedThumbsCount = 0; |
137 |
var index = 0; |
182 |
var index = 0; |
138 |
var uniqueYTVideoIds = []; |
183 |
var uniqueYTVideoIds = []; |
139 |
|
184 |
|
|
145 |
} |
190 |
} |
146 |
uniqueYTVideoIds.push(videoId); |
191 |
uniqueYTVideoIds.push(videoId); |
147 |
|
192 |
|
148 |
var videoWrapper = domConstruct.create('div', {'class': 'galleryVideo'}, this.contentSlider.domNode); |
193 |
var videoWrapper = domConstruct.create('div', { |
149 |
var div = domConstruct.create('div', { |
194 |
'class': 'galleryThumbWrapper galleryVideoWrapper' |
|
|
195 |
}, this.contentSlider.domNode); |
196 |
|
197 |
var galleryVideo = domConstruct.create('div', { |
198 |
'class': 'galleryThumb galleryVideo notLoadedBackground', |
199 |
style: { |
200 |
'width': this.itemHeight * this._youtubeIframeRatio + 'px' |
201 |
}, |
150 |
id: videoId |
202 |
id: videoId |
151 |
}, videoWrapper); |
203 |
}, videoWrapper); |
152 |
|
204 |
|
153 |
this.itemNodes.push(videoWrapper); |
205 |
this.itemNodes.push(videoWrapper); |
|
|
206 |
|
207 |
if (window.YT && window.YT.loaded) { |
208 |
setTimeout(lang.hitch(this, function() { |
209 |
this._renderYoutubeVideo(galleryVideo); |
210 |
}), 0); |
211 |
} |
154 |
} else { |
212 |
} else { |
155 |
var imgWrapper = domConstruct.create('div', {}, this.contentSlider.domNode); |
213 |
var imgWrapper = domConstruct.create('div', { |
|
|
214 |
'class': 'galleryThumbWrapper galleryImgWrapper' |
215 |
}, this.contentSlider.domNode); |
216 |
|
156 |
var img = domConstruct.create('img', { |
217 |
var img = domConstruct.create('img', { |
157 |
src: item.src, |
218 |
src: item.src, |
158 |
index: index, |
219 |
index: index, |
159 |
'class': 'carouselScreenshot', |
220 |
'class': 'galleryThumb galleryImg', |
160 |
onload: lang.hitch(this, function() { |
221 |
onload: lang.hitch(this, function() { |
161 |
this._updateHeighestImage(img); |
222 |
this._updateHeighestImage(img); |
162 |
this.imagesLoaded(); |
223 |
this.resizeCarousel(); |
|
|
224 |
this.thumbLoaded(); |
163 |
}), |
225 |
}), |
|
|
226 |
onerror: lang.hitch(this, function() { |
227 |
domClass.add(img.parentNode, 'brokenImg'); |
228 |
this.resizeCarousel(); |
229 |
this.thumbLoaded(); |
230 |
}), |
164 |
onclick: lang.hitch(this, function(evt) { |
231 |
onclick: lang.hitch(this, function(evt) { |
165 |
this.togglePreviewSize(parseInt(evt.target.getAttribute('index'))); |
232 |
this.togglePreviewSize(parseInt(evt.target.getAttribute('index'))); |
166 |
}) |
233 |
}) |
167 |
}, imgWrapper); |
234 |
}, imgWrapper); |
168 |
this.itemNodes.push(imgWrapper); |
235 |
this.itemNodes.push(imgWrapper); |
|
|
236 |
|
237 |
this.onlyYoutubeVideos = false; |
169 |
} |
238 |
} |
170 |
index++; |
239 |
index++; |
171 |
})); |
240 |
})); |
|
172 |
}, |
241 |
}, |
173 |
|
242 |
|
174 |
_renderYoutubeVideos: function() { |
243 |
_renderYoutubeVideos: function() { |
175 |
query('.galleryVideo', this.contentSlider.domNode).forEach(lang.hitch(this, function(videoWrapper) { |
244 |
query('.galleryVideo', this.contentSlider.domNode).forEach(lang.hitch(this, function(galleryVideo) { |
176 |
var player; |
245 |
this._renderYoutubeVideo(galleryVideo); |
177 |
var videoId = videoWrapper.firstChild.id; |
|
|
178 |
player = new YT.Player(videoId, { |
179 |
height: this.itemHeight.toString(), |
180 |
width: 'auto', |
181 |
videoId: videoId, |
182 |
events: { |
183 |
'onReady': onPlayerReady |
184 |
} |
185 |
}); |
186 |
this.own(player); |
187 |
})); |
246 |
})); |
188 |
}, |
247 |
}, |
189 |
|
248 |
|
|
|
249 |
_renderYoutubeVideo: function(galleryVideo) { |
250 |
//check if video already exists |
251 |
if (galleryVideo.tagName === 'IFRAME') { |
252 |
return; |
253 |
} |
254 |
//needed so the carousel gets resized and is visible |
255 |
if (this.onlyYoutubeVideos) { |
256 |
this.resizeCarousel(); |
257 |
} |
258 |
|
259 |
var player; |
260 |
var videoId = galleryVideo.id; |
261 |
player = new YT.Player(videoId, { |
262 |
height: this.itemHeight.toString(), |
263 |
width: this.itemHeight * this._youtubeIframeRatio + 'px', |
264 |
videoId: videoId, |
265 |
events: { |
266 |
'onReady': onPlayerReady, |
267 |
'onError': onPlayerError |
268 |
} |
269 |
}); |
270 |
this.own(player); |
271 |
}, |
272 |
|
190 |
_srcIsYoutubeVideo: function(src) { |
273 |
_srcIsYoutubeVideo: function(src) { |
191 |
//taken from http://stackoverflow.com/questions/28735459/how-to-validate-youtube-url-in-client-side-in-text-box |
274 |
//taken from http://stackoverflow.com/questions/28735459/how-to-validate-youtube-url-in-client-side-in-text-box |
192 |
var p = /^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/; |
275 |
var p = /^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/; |
|
203 |
|
286 |
|
204 |
_setDefaultThumbsHeight: function() { |
287 |
_setDefaultThumbsHeight: function() { |
205 |
if (!styles.getStyleSheet('defaultItemHeightImage')) { |
288 |
if (!styles.getStyleSheet('defaultItemHeightImage')) { |
206 |
styles.insertCssRule('.contentSlider .carouselScreenshot', lang.replace('max-height: {0}px', [this.itemHeight]), 'defaultItemHeightImage'); |
289 |
styles.insertCssRule('.contentSlider .galleryImg', lang.replace('max-height: {0}px', [this.itemHeight]), 'defaultItemHeightImage'); |
207 |
} |
290 |
} |
208 |
if (!styles.getStyleSheet('defaultItemHeightWrapper')) { |
291 |
if (!styles.getStyleSheet('defaultItemHeightWrapper')) { |
209 |
styles.insertCssRule('.contentSlider div', lang.replace('height: {0}px', [this.itemHeight]), 'defaultItemHeightWrapper'); |
292 |
styles.insertCssRule('.contentSlider .galleryThumbWrapper', lang.replace('height: {0}px', [this.itemHeight]), 'defaultItemHeightWrapper'); |
210 |
} |
293 |
} |
211 |
}, |
294 |
}, |
212 |
|
295 |
|
213 |
renderNavButtons: function() { |
296 |
//checks if all divs in the contentSlider are ready |
214 |
this.leftButton = domConstruct.create('div', { |
297 |
thumbLoaded: function() { |
215 |
'class': 'carouselButton leftCarouselButton', |
298 |
this.loadedThumbsCount++; |
216 |
onclick: lang.hitch(this, function() { |
299 |
if (this.loadedThumbsCount === this.itemNodes.length) { |
217 |
this.showItem(this.shownItemIndex - 1); |
|
|
218 |
}) |
219 |
}, this.contentSliderWrapper.domNode, 'before'); |
220 |
domConstruct.create('div', { |
221 |
'class': 'carouselButtonImage' |
222 |
}, this.leftButton); |
223 |
|
224 |
this.rightButton = domConstruct.create('div', { |
225 |
'class': 'carouselButton rightCarouselButton', |
226 |
onclick: lang.hitch(this, function() { |
227 |
this.showItem(this.shownItemIndex + 1); |
228 |
}) |
229 |
}, this.contentSliderWrapper.domNode, 'after'); |
230 |
domConstruct.create('div', { |
231 |
'class': 'carouselButtonImage' |
232 |
}, this.rightButton); |
233 |
}, |
234 |
|
235 |
renderScaleButton: function() { |
236 |
this.scaleButton = domConstruct.create('div', { |
237 |
'class': 'scaleButton dijitHidden', |
238 |
onclick: lang.hitch(this, function() { |
239 |
this.togglePreviewSize(this.shownItemIndex); |
240 |
}) |
241 |
}, this.domNode); |
242 |
}, |
243 |
|
244 |
imagesLoaded: function() { |
245 |
this.loadedImagesCount++; |
246 |
if (this.loadedImagesCount === this.itemNodes.length) { |
247 |
this.allItemsLoaded = true; |
300 |
this.allItemsLoaded = true; |
248 |
this.heighestImg = this.heighestImg.cloneNode(); |
|
|
249 |
domConstruct.place(this.heighestImg, this.domNode); |
250 |
domClass.add(this.heighestImg, 'dijitHidden'); |
251 |
domClass.remove(this.scaleButton, 'dijitHidden'); |
301 |
domClass.remove(this.scaleButton, 'dijitHidden'); |
252 |
|
302 |
|
253 |
this._setDefaultThumbsHeight(); |
|
|
254 |
this.resizeCarousel(); |
303 |
this.resizeCarousel(); |
255 |
this.calcDefaultSliderWidth(); |
304 |
this._calcDefaultValues(); |
256 |
this.calcOffsets(); |
|
|
257 |
} |
305 |
} |
258 |
}, |
306 |
}, |
259 |
|
307 |
|
260 |
_updateHeighestImage: function(img) { |
308 |
_updateHeighestImage: function(img) { |
261 |
if (!this.heighestImg) { |
309 |
if (img.naturalHeight > this.heighestImg.h) { |
262 |
this.heighestImg = img; |
310 |
this.heighestImg.w = img.naturalWidth; |
|
|
311 |
this.heighestImg.h = img.naturalHeight; |
312 |
this.heighestImgRatio = img.naturalWidth / img.naturalHeight; |
263 |
} |
313 |
} |
264 |
if ((img.height > img.width) && (img.height > this.heighestImg.height)) { |
314 |
}, |
265 |
this.heighestImg = img; |
315 |
|
|
|
316 |
_calcDefaultValues: function() { |
317 |
//check if carouselWidget is displayed |
318 |
if (domGeometry.getMarginBox(this.domNode).w === 0) { |
319 |
return; |
266 |
} |
320 |
} |
|
|
321 |
this._calcDefaultContentSliderWidth(); |
322 |
this._calcDefaultContentSliderOffsets(); |
267 |
}, |
323 |
}, |
268 |
|
324 |
|
269 |
calcDefaultSliderWidth: function() { |
325 |
_calcDefaultContentSliderWidth: function() { |
270 |
this.defaultSliderWidth = domGeometry.getMarginBox(this.contentSlider.domNode).w; |
326 |
this.defaultSliderWidth = domGeometry.getMarginBox(this.contentSlider.domNode).w; |
271 |
this.defaultItemWidths = []; |
327 |
this.defaultItemWidths = []; |
272 |
array.forEach(this.itemNodes, lang.hitch(this, function(itemNode) { |
328 |
array.forEach(this.itemNodes, lang.hitch(this, function(itemNode) { |
|
274 |
})); |
330 |
})); |
275 |
}, |
331 |
}, |
276 |
|
332 |
|
277 |
calcOffsets: function() { |
333 |
_calcDefaultContentSliderOffsets: function() { |
278 |
this.offsets = [0]; |
334 |
this.defaultContentSliderOffsets = [0]; |
279 |
var maxOffset = Math.max(0, this.defaultSliderWidth - domGeometry.getMarginBox(this.contentSliderWrapper.domNode).w); |
|
|
280 |
|
335 |
|
281 |
for (var i = 1; i < this.itemNodes.length; i++) { |
336 |
for (var i = 1; i < this.itemNodes.length; i++) { |
282 |
var offset = 0; |
337 |
var offset = 0; |
|
283 |
for (var c = 0; c < i; c++) { |
338 |
for (var c = 0; c < i; c++) { |
284 |
offset += this.defaultItemWidths[c]; |
339 |
offset += this.defaultItemWidths[c]; |
285 |
} |
340 |
} |
286 |
if (offset >= maxOffset) { |
341 |
this.defaultContentSliderOffsets.push(offset); |
287 |
this.offsets.push(maxOffset); |
|
|
288 |
} else { |
289 |
this.offsets.push(offset); |
290 |
} |
291 |
} |
342 |
} |
292 |
}, |
343 |
}, |
293 |
|
344 |
|
294 |
resizeCarousel: function() { |
345 |
resizeCarousel: function() { |
295 |
if (this.bigThumbnails) { |
346 |
if (this.isBigThumbnails) { |
296 |
this._resizeBigThumbnails(); |
347 |
this._resizeBigThumbnails(); |
|
|
348 |
this._toggleNavButtonsVisibility(); |
349 |
return; |
297 |
} |
350 |
} |
|
|
351 |
|
298 |
var totalItemsWidth = 0; |
352 |
var totalItemsWidth = 0; |
299 |
array.forEach(this.itemNodes, function(imgWrapper) { |
353 |
array.forEach(this.itemNodes, function(imgWrapper) { |
300 |
var imgWrapperWidth = domGeometry.getMarginBox(imgWrapper).w; |
354 |
var imgWrapperWidth = domGeometry.getMarginBox(imgWrapper).w; |
|
320 |
domStyle.set(this.outerContainer.domNode, 'width', availableWidth + 'px'); |
374 |
domStyle.set(this.outerContainer.domNode, 'width', availableWidth + 'px'); |
321 |
domStyle.set(this.contentSliderWrapper.domNode, 'width', widthForThumbs + 'px'); |
375 |
domStyle.set(this.contentSliderWrapper.domNode, 'width', widthForThumbs + 'px'); |
322 |
} |
376 |
} |
323 |
this._toggleNavButtonsVisibility(); |
377 |
setTimeout(lang.hitch(this, function() { |
|
|
378 |
this._toggleNavButtonsVisibility(); |
379 |
}), 0); |
324 |
}, |
380 |
}, |
325 |
|
381 |
|
326 |
_resizeBigThumbnails: function(newIndex) { |
382 |
_resizeBigThumbnails: function(newIndex) { |
|
332 |
domClass.remove(this.rightButton, 'dijitHidden'); |
388 |
domClass.remove(this.rightButton, 'dijitHidden'); |
333 |
var maxWidth = domGeometry.getMarginBox(this.domNode).w - (domGeometry.getMarginBox(this.leftButton).w * 2) - marginOfThumbs; |
389 |
var maxWidth = domGeometry.getMarginBox(this.domNode).w - (domGeometry.getMarginBox(this.leftButton).w * 2) - marginOfThumbs; |
334 |
domStyle.set(this.outerContainer.domNode, 'width', ''); |
390 |
domStyle.set(this.outerContainer.domNode, 'width', ''); |
335 |
domStyle.set(this.contentSliderWrapper.domNode, 'width', maxWidth + 'px'); |
391 |
domStyle.set(this.contentSliderWrapper.domNode, 'width', maxWidth + marginOfThumbs + 'px'); |
336 |
|
392 |
|
337 |
styles.disableStyleSheet('defaultItemHeightWrapper'); |
393 |
var heighestImgHeight = Math.min(maxWidth / this.heighestImgRatio, maxHeight, this.heighestImg.h); |
338 |
|
|
|
339 |
domStyle.set(this.heighestImg, 'position', 'absolute'); |
340 |
domStyle.set(this.heighestImg, 'right', '1000000px'); |
341 |
domClass.toggle(this.heighestImg, 'dijitHidden'); |
342 |
|
394 |
|
343 |
|
|
|
344 |
domStyle.set(this.heighestImg, 'max-height', maxHeight + 'px'); |
345 |
domStyle.set(this.heighestImg, 'max-width', maxWidth + 'px'); |
346 |
var heighestImgHeight = domGeometry.getMarginBox(this.heighestImg).h; |
347 |
domClass.toggle(this.heighestImg, 'dijitHidden'); |
348 |
|
349 |
array.forEach(this.itemNodes, lang.hitch(this, function(imgWrapper) { |
395 |
array.forEach(this.itemNodes, lang.hitch(this, function(imgWrapper) { |
350 |
domStyle.set(imgWrapper.firstChild, 'max-width', maxWidth + 'px'); |
396 |
domStyle.set(imgWrapper.firstChild, 'max-width', maxWidth + 'px'); |
351 |
domStyle.set(imgWrapper.firstChild, 'max-height', maxHeight + 'px'); |
397 |
domStyle.set(imgWrapper.firstChild, 'max-height', maxHeight + 'px'); |
|
352 |
domStyle.set(imgWrapper, 'height', heighestImgHeight + 'px'); |
398 |
domStyle.set(imgWrapper, 'height', heighestImgHeight + 'px'); |
353 |
domStyle.set(imgWrapper, 'width', maxWidth + 'px'); |
399 |
domStyle.set(imgWrapper, 'width', maxWidth + 'px'); |
354 |
})); |
400 |
})); |
355 |
query('.galleryVideo', this.contentSlider.domNode).forEach(lang.hitch(this, function(videoWrapper) { |
401 |
query('.galleryVideoWrapper', this.contentSlider.domNode).forEach(lang.hitch(this, function(videoWrapper) { |
356 |
domStyle.set(videoWrapper.firstChild, 'height', '100%'); |
402 |
var height = maxWidth / this._youtubeIframeRatio; |
|
|
403 |
domStyle.set(videoWrapper.firstChild, 'height', height + 'px'); |
357 |
domStyle.set(videoWrapper.firstChild, 'width', '100%'); |
404 |
domStyle.set(videoWrapper.firstChild, 'width', '100%'); |
358 |
})); |
405 |
})); |
359 |
domStyle.set(this.outerContainer.domNode, 'height', heighestImgHeight + 'px'); |
406 |
domStyle.set(this.outerContainer.domNode, 'height', heighestImgHeight + 'px'); |
360 |
|
407 |
|
|
|
408 |
newIndex = (newIndex === undefined) ? this.shownItemIndex : newIndex; |
361 |
var newOffset = newIndex * (maxWidth + marginOfThumbs); |
409 |
var newOffset = newIndex * (maxWidth + marginOfThumbs); |
362 |
domStyle.set(this.contentSlider.domNode, 'left', (newOffset * (-1)) + 'px'); |
410 |
domStyle.set(this.contentSlider.domNode, 'left', (newOffset * (-1)) + 'px'); |
|
|
411 |
this.contentSliderOffset = newOffset; |
412 |
|
413 |
var availableWidth = domGeometry.getMarginBox(this.domNode).w; |
414 |
var widthForThumbs = availableWidth - |
415 |
(domGeometry.getMarginBox(this.leftButton).w + domGeometry.getMarginBox(this.rightButton).w); |
416 |
domStyle.set(this.outerContainer.domNode, 'width', availableWidth + 'px'); |
417 |
domStyle.set(this.contentSliderWrapper.domNode, 'width', widthForThumbs + 'px'); |
363 |
}, |
418 |
}, |
364 |
|
419 |
|
365 |
_toggleNavButtonsVisibility: function(newOffset) { |
420 |
_toggleNavButtonsVisibility: function(newOffset) { |
|
377 |
}, |
432 |
}, |
378 |
|
433 |
|
379 |
togglePreviewSize: function(newIndex) { |
434 |
togglePreviewSize: function(newIndex) { |
380 |
if (this.bigThumbnails) { |
435 |
if (this.isBigThumbnails) { |
381 |
styles.enableStyleSheet('defaultItemHeightWrapper'); |
|
|
382 |
var availableWidth = domGeometry.getMarginBox(this.domNode).w; |
436 |
var availableWidth = domGeometry.getMarginBox(this.domNode).w; |
383 |
|
437 |
|
384 |
if (availableWidth >= this.defaultSliderWidth) { |
438 |
if (availableWidth >= this.defaultSliderWidth) { |
385 |
domClass.add(this.leftButton, 'dijitHidden'); |
439 |
domClass.add(this.leftButton, 'dijitHidden'); |
386 |
domClass.add(this.rightButton, 'dijitHidden'); |
440 |
domClass.add(this.rightButton, 'dijitHidden'); |
387 |
domStyle.set(this.outerContainer.domNode, 'transition', 'height 0.5s, width 0.5s'); |
|
|
388 |
domStyle.set(this.contentSliderWrapper.domNode, 'transition', 'height 0.5s, width 0.5s'); |
389 |
domStyle.set(this.outerContainer.domNode, 'width', this.defaultSliderWidth + 'px'); |
441 |
domStyle.set(this.outerContainer.domNode, 'width', this.defaultSliderWidth + 'px'); |
390 |
domStyle.set(this.contentSliderWrapper.domNode, 'width', this.defaultSliderWidth + 'px'); |
442 |
domStyle.set(this.contentSliderWrapper.domNode, 'width', this.defaultSliderWidth + 'px'); |
391 |
} |
443 |
} |
392 |
|
444 |
|
393 |
|
445 |
query('.galleryImg', this.contentSlider.domNode).forEach(lang.hitch(this, function(imgNode) { |
394 |
query('.carouselScreenshot', this.contentSlider.domNode).forEach(lang.hitch(this, function(imgNode) { |
|
|
395 |
domStyle.set(imgNode, 'max-height', ''); |
446 |
domStyle.set(imgNode, 'max-height', ''); |
396 |
domStyle.set(imgNode, 'max-width', ''); |
447 |
domStyle.set(imgNode, 'max-width', ''); |
397 |
domStyle.set(imgNode.parentNode, 'width', ''); |
448 |
domStyle.set(imgNode.parentNode, 'width', ''); |
398 |
domStyle.set(imgNode.parentNode, 'height', ''); |
449 |
domStyle.set(imgNode.parentNode, 'height', ''); |
399 |
})); |
450 |
})); |
400 |
query('.galleryVideo', this.contentSlider.domNode).forEach(lang.hitch(this, function(videoWrapper) { |
451 |
query('.galleryVideoWrapper', this.contentSlider.domNode).forEach(lang.hitch(this, function(videoWrapper) { |
401 |
domStyle.set(videoWrapper, 'height', ''); |
452 |
domStyle.set(videoWrapper, 'height', ''); |
402 |
domStyle.set(videoWrapper, 'width', ''); |
453 |
domStyle.set(videoWrapper, 'width', ''); |
403 |
domStyle.set(videoWrapper.firstChild, 'height', ''); |
454 |
domStyle.set(videoWrapper.firstChild, 'height', ''); |
|
404 |
domStyle.set(videoWrapper.firstChild, 'width', ''); |
455 |
domStyle.set(videoWrapper.firstChild, 'width', ''); |
405 |
})); |
456 |
})); |
406 |
domStyle.set(this.outerContainer.domNode, 'height', this.itemHeight + 'px'); |
457 |
domStyle.set(this.outerContainer.domNode, 'height', this.itemHeight + 'px'); |
407 |
domStyle.set(this.contentSlider.domNode, 'left', Math.abs(this.offsets[newIndex]) * (-1) + 'px'); |
458 |
|
|
|
459 |
//set offset for small thumbs |
460 |
var maxOffset = Math.max(0, this.defaultSliderWidth - domGeometry.getMarginBox(this.contentSliderWrapper.domNode).w); |
461 |
var newOffset = Math.min(this.defaultContentSliderOffsets[newIndex], maxOffset); |
462 |
domStyle.set(this.contentSlider.domNode, 'left', Math.abs(newOffset) * (-1) + 'px'); |
463 |
this.contentSliderOffset = newOffset; |
408 |
|
464 |
|
409 |
} else { |
465 |
} else { |
410 |
domStyle.set(this.outerContainer.domNode, 'transition', ''); |
466 |
//scroll to the top of the carouselWidget |
411 |
domStyle.set(this.contentSliderWrapper.domNode, 'transition', ''); |
467 |
var scrollTarget = domGeometry.position(this.domNode, true).y - 50; |
|
|
468 |
var scrollInterval = setInterval(lang.hitch(this, function() { |
469 |
window.scrollTo(0, scrollTarget); |
470 |
}), 5); |
471 |
//wait for the transition to finish |
472 |
setTimeout(function() { |
473 |
clearInterval(scrollInterval); |
474 |
}, 600); |
412 |
this._resizeBigThumbnails(newIndex); |
475 |
this._resizeBigThumbnails(newIndex); |
413 |
} |
476 |
} |
414 |
this.bigThumbnails = !this.bigThumbnails; |
477 |
this.isBigThumbnails = !this.isBigThumbnails; |
415 |
domClass.toggle(this.scaleButton, 'minimize'); |
478 |
domClass.toggle(this.scaleButton, 'minimize'); |
416 |
this.shownItemIndex = newIndex; |
479 |
this.shownItemIndex = newIndex; |
417 |
|
480 |
|
418 |
setTimeout(lang.hitch(this, function() { |
481 |
setTimeout(lang.hitch(this, function() { |
419 |
this.resizeCarousel(); |
482 |
this._toggleNavButtonsVisibility(); |
420 |
}), 600); |
483 |
}), 550); |
421 |
|
|
|
422 |
//scroll to the top of the image |
423 |
//var scrollTarget = domGeometry.position(this.domNode, true).y - 50; |
424 |
//window.scrollTo(0, scrollTarget); |
425 |
}, |
484 |
}, |
426 |
|
485 |
|
427 |
showItem: function(newIndex) { |
486 |
showItem: function(newIndex) { |
|
452 |
this.showItem(newIndex -1); |
511 |
this.showItem(newIndex -1); |
453 |
return; |
512 |
return; |
454 |
} |
513 |
} |
|
|
514 |
//take a higher or lower index if the offset would only change |
515 |
//by a few pixels |
516 |
if (newOffset < oldOffset && (oldOffset - newOffset) <= 70) { |
517 |
this.showItem(newIndex -1); |
518 |
return; |
519 |
} else if (maxOffset > newOffset && (maxOffset - newOffset) <= 70) { |
520 |
this.showItem(newIndex +1); |
521 |
return; |
522 |
} |
455 |
|
523 |
|
456 |
this.shownItemIndex = newIndex; |
524 |
this.shownItemIndex = newIndex; |
457 |
domStyle.set(this.contentSlider.domNode, 'left', (newOffset * (-1)) + 'px'); |
525 |
domStyle.set(this.contentSlider.domNode, 'left', (newOffset * (-1)) + 'px'); |
|
|
526 |
this.contentSliderOffset = newOffset; |
458 |
|
527 |
|
459 |
this._toggleNavButtonsVisibility(newOffset); |
528 |
this._toggleNavButtonsVisibility(newOffset); |
460 |
}, |
529 |
}, |
461 |
|
530 |
|
462 |
_handleResize: function() { |
531 |
_handleResize: function() { |
|
|
532 |
if (domGeometry.getMarginBox(this.domNode).w === 0) { |
533 |
return; |
534 |
} |
463 |
if (this._resizeDeferred && !this._resizeDeferred.isFulfilled()) { |
535 |
if (this._resizeDeferred && !this._resizeDeferred.isFulfilled()) { |
464 |
this._resizeDeferred.cancel(); |
536 |
this._resizeDeferred.cancel(); |
465 |
} |
537 |
} |
466 |
this._resizeDeferred = tools.defer(lang.hitch(this, function() { |
538 |
this._resizeDeferred = tools.defer(lang.hitch(this, function() { |
467 |
this.resizeCarousel(); |
539 |
this.resizeCarousel(); |
468 |
this.calcOffsets(); |
540 |
if (!this.isBigThumbnails) { |
469 |
this.showItem(this.shownItemIndex); |
541 |
setTimeout(lang.hitch(this, function() { |
|
|
542 |
this.showItem(this.shownItemIndex); |
543 |
}), 0); |
544 |
} |
545 |
this._toggleNavButtonsVisibility(); |
470 |
}), 200); |
546 |
}), 200); |
471 |
this._resizeDeferred.otherwise(function() { /* prevent logging of exception */ }); |
547 |
this._resizeDeferred.otherwise(function() { /* prevent logging of exception */ }); |
472 |
}, |
548 |
}, |
|
474 |
startup: function() { |
550 |
startup: function() { |
475 |
this.inherited(arguments); |
551 |
this.inherited(arguments); |
476 |
this._registerAtParentOnShowEvents(lang.hitch(this, function() { |
552 |
this._registerAtParentOnShowEvents(lang.hitch(this, function() { |
477 |
if (this.defaultSliderWidth === 0 && !this.bigThumbnails) { |
553 |
if (this.defaultSliderWidth === 0 && !this.isBigThumbnails) { |
478 |
this.calcDefaultSliderWidth(); |
554 |
this._calcDefaultValues(); |
479 |
} |
555 |
} |
480 |
if (this.allItemsLoaded) { |
556 |
if (this.allItemsLoaded) { |
481 |
this.resizeCarousel(); |
557 |
this.resizeCarousel(); |
482 |
this.showItem(this.shownItemIndex); |
558 |
|
|
|
559 |
if (!this.isBigThumbnails) { |
560 |
setTimeout(lang.hitch(this, function() { |
561 |
this.showItem(this.shownItemIndex); |
562 |
}), 0); |
563 |
} |
483 |
} |
564 |
} |
484 |
})); |
565 |
})); |
485 |
this.own(on(baseWin.doc, 'resize', lang.hitch(this, '_handleResize'))); |
566 |
this.own(on(baseWin.doc, 'resize', lang.hitch(this, '_handleResize'))); |
486 |
this.own(on(kernel.global, 'resize', lang.hitch(this, '_handleResize'))); |
567 |
this.own(on(kernel.global, 'resize', lang.hitch(this, '_handleResize'))); |
487 |
styles.enableStyleSheet('defaultItemHeightWrapper'); |
|
|
488 |
} |
568 |
} |
489 |
}); |
569 |
}); |
490 |
}); |
570 |
}); |