2
header('Content-type: text/javascript');
3
require_once(dirname(__FILE__).'/../../../config.php');
5
// -----------------------------------------------------------------------------------
8
// by Lokesh Dhakar - http://www.lokeshdhakar.com
9
// Last Modification: 2/9/08
11
// For more information, visit:
12
// http://lokeshdhakar.com/projects/lightbox2/
14
// Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
15
// - Free for use in both personal and commercial projects
16
// - Attribution requires leaving author name, author link, and the license info intact.
18
// Thanks: Scott Upton(uptonic.com), Peter-Paul Koch(quirksmode.com), and Thomas Fuchs(mir.aculo.us) for ideas, libs, and snippets.
19
// Artemy Tregubenko (arty.name) for cleanup and help in updating to latest ver of proto-aculous.
21
// -----------------------------------------------------------------------------------
28
Lightbox Class Declaration
33
- resizeImageContainer()
38
- disableKeyboardNav()
40
- preloadNeighborImages()
47
// -----------------------------------------------------------------------------------
52
LightboxOptions = Object.extend({
53
fileLoadingImage: '<?php echo KAG_BASE_URL.'/packs/plugins/lightbox/loading.gif'; ?>',
54
fileBottomNavCloseImage: '<?php echo KAG_BASE_URL.'/packs/plugins/lightbox/closelabel.gif'; ?>',
56
overlayOpacity: 0.8, // controls transparency of shadow overlay
58
animate: true, // toggles resizing animations
59
resizeSpeed: 7, // controls the speed of the image resizing animations (1=slowest and 10=fastest)
61
borderSize: 10, //if you adjust the padding in the CSS, you will need to update this variable
63
// When grouping images this is used to write: Image # of #.
64
// Change it for non-english localization
67
}, window.LightboxOptions || {});
69
// -----------------------------------------------------------------------------------
71
var Lightbox = Class.create();
73
Lightbox.prototype = {
75
activeImage: undefined,
78
// Constructor runs on completion of the DOM loading. Calls updateImageList and then
79
// the function inserts html at the bottom of the page which is used to display the shadow
80
// overlay and the image container.
82
initialize: function() {
84
this.updateImageList();
86
this.keyboardAction = this.keyboardAction.bindAsEventListener(this);
88
if (LightboxOptions.resizeSpeed > 10) LightboxOptions.resizeSpeed = 10;
89
if (LightboxOptions.resizeSpeed < 1) LightboxOptions.resizeSpeed = 1;
91
this.resizeDuration = LightboxOptions.animate ? ((11 - LightboxOptions.resizeSpeed) * 0.15) : 0;
92
this.overlayDuration = LightboxOptions.animate ? 0.2 : 0; // shadow fade in/out duration
94
// When Lightbox starts it will resize itself from 250 by 250 to the current image dimension.
95
// If animations are turned off, it will be hidden as to prevent a flicker of a
96
// white 250 by 250 box.
97
var size = (LightboxOptions.animate ? 250 : 1) + 'px';
100
// Code inserts html at the bottom of the page that looks similar to this:
102
// <div id="overlay"></div>
103
// <div id="lightbox">
104
// <div id="outerImageContainer">
105
// <div id="imageContainer">
106
// <img id="lightboxImage">
107
// <div style="" id="hoverNav">
108
// <a href="#" id="prevLink"></a>
109
// <a href="#" id="nextLink"></a>
111
// <div id="loading">
112
// <a href="#" id="loadingLink">
113
// <img src="images/loading.gif">
118
// <div id="imageDataContainer">
119
// <div id="imageData">
120
// <div id="imageDetails">
121
// <span id="caption"></span>
122
// <span id="numberDisplay"></span>
124
// <div id="bottomNav">
125
// <a href="#" id="bottomNavClose">
126
// <img src="images/close.gif">
134
var objBody = $$('body')[0];
136
objBody.appendChild(Builder.node('div',{id:'overlay'}));
138
objBody.appendChild(Builder.node('div',{id:'lightbox'}, [
139
Builder.node('div',{id:'outerImageContainer'},
140
Builder.node('div',{id:'imageContainer'}, [
141
Builder.node('img',{id:'lightboxImage'}),
142
Builder.node('div',{id:'hoverNav'}, [
143
Builder.node('a',{id:'prevLink', href: '#' }),
144
Builder.node('a',{id:'nextLink', href: '#' })
146
Builder.node('div',{id:'loading'},
147
Builder.node('a',{id:'loadingLink', href: '#' },
148
Builder.node('img', {src: LightboxOptions.fileLoadingImage})
153
Builder.node('div', {id:'imageDataContainer'},
154
Builder.node('div',{id:'imageData'}, [
155
Builder.node('div',{id:'imageDetails'}, [
156
Builder.node('span',{id:'caption'}),
157
Builder.node('span',{id:'numberDisplay'})
159
Builder.node('div',{id:'bottomNav'},
160
Builder.node('a',{id:'bottomNavClose', href: '#' },
161
Builder.node('img', { src: LightboxOptions.fileBottomNavCloseImage })
169
$('overlay').hide().observe('click', (function() { this.end(); }).bind(this));
170
$('lightbox').hide().observe('click', (function(event) { if (event.element().id == 'lightbox') this.end(); }).bind(this));
171
$('outerImageContainer').setStyle({ width: size, height: size });
172
$('prevLink').observe('click', (function(event) { event.stop(); this.changeImage(this.activeImage - 1); }).bindAsEventListener(this));
173
$('nextLink').observe('click', (function(event) { event.stop(); this.changeImage(this.activeImage + 1); }).bindAsEventListener(this));
174
$('loadingLink').observe('click', (function(event) { event.stop(); this.end(); }).bind(this));
175
$('bottomNavClose').observe('click', (function(event) { event.stop(); this.end(); }).bind(this));
180
'overlay lightbox outerImageContainer imageContainer lightboxImage hoverNav prevLink nextLink loading loadingLink ' +
181
'imageDataContainer imageData imageDetails caption numberDisplay bottomNav bottomNavClose';
182
$w(ids).each(function(id){ th[id] = $(id); });
188
// Loops through anchor tags looking for 'lightbox' references and applies onclick
189
// events to appropriate links. You can rerun after dynamically adding images w/ajax.
191
updateImageList: function() {
192
this.updateImageList = Prototype.emptyFunction;
194
document.observe('click', (function(event){
195
var target = event.findElement('a[rel^=lightbox]') || event.findElement('area[rel^=lightbox]');
205
// Display overlay and lightbox. If image is part of a set, add siblings to imageArray.
207
start: function(imageLink) {
209
$$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'hidden' });
211
// stretch overlay to fill page and fade in
212
var arrayPageSize = this.getPageSize();
213
$('overlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' });
215
new Effect.Appear(this.overlay, { duration: this.overlayDuration, from: 0.0, to: LightboxOptions.overlayOpacity });
217
this.imageArray = [];
220
if ((imageLink.rel == 'lightbox')){
221
// if image is NOT part of a set, add single image to imageArray
222
this.imageArray.push([imageLink.href, imageLink.title]);
224
// if image is part of a set..
226
$$(imageLink.tagName + '[href][rel="' + imageLink.rel + '"]').
227
collect(function(anchor){ return [anchor.href, anchor.title]; }).
230
while (this.imageArray[imageNum][0] != imageLink.href) { imageNum++; }
233
// calculate top and left offset for the lightbox
234
var arrayPageScroll = document.viewport.getScrollOffsets();
235
var lightboxTop = arrayPageScroll[1] + (document.viewport.getHeight() / 10);
236
var lightboxLeft = arrayPageScroll[0];
237
this.lightbox.setStyle({ top: lightboxTop + 'px', left: lightboxLeft + 'px' }).show();
239
this.changeImage(imageNum);
244
// Hide most elements and preload image in preparation for resizing image container.
246
changeImage: function(imageNum) {
248
this.activeImage = imageNum; // update global var
250
// hide elements during transition
251
if (LightboxOptions.animate) this.loading.show();
252
this.lightboxImage.hide();
253
this.hoverNav.hide();
254
this.prevLink.hide();
255
this.nextLink.hide();
256
// HACK: Opera9 does not currently support scriptaculous opacity and appear fx
257
this.imageDataContainer.setStyle({opacity: .0001});
258
this.numberDisplay.hide();
260
var imgPreloader = new Image();
262
// once image is preloaded, resize image container
265
imgPreloader.onload = (function(){
266
this.lightboxImage.src = this.imageArray[this.activeImage][0];
267
this.resizeImageContainer(imgPreloader.width, imgPreloader.height);
269
imgPreloader.src = this.imageArray[this.activeImage][0];
273
// resizeImageContainer()
275
resizeImageContainer: function(imgWidth, imgHeight) {
277
// get current width and height
278
var widthCurrent = this.outerImageContainer.getWidth();
279
var heightCurrent = this.outerImageContainer.getHeight();
281
// get new width and height
282
var widthNew = (imgWidth + LightboxOptions.borderSize * 2);
283
var heightNew = (imgHeight + LightboxOptions.borderSize * 2);
285
// scalars based on change from old to new
286
var xScale = (widthNew / widthCurrent) * 100;
287
var yScale = (heightNew / heightCurrent) * 100;
289
// calculate size difference between new and old image, and resize if necessary
290
var wDiff = widthCurrent - widthNew;
291
var hDiff = heightCurrent - heightNew;
293
if (hDiff != 0) new Effect.Scale(this.outerImageContainer, yScale, {scaleX: false, duration: this.resizeDuration, queue: 'front'});
294
if (wDiff != 0) new Effect.Scale(this.outerImageContainer, xScale, {scaleY: false, duration: this.resizeDuration, delay: this.resizeDuration});
296
// if new and old image are same size and no scaling transition is necessary,
297
// do a quick pause to prevent image flicker.
299
if ((hDiff == 0) && (wDiff == 0)){
301
if (Prototype.Browser.IE) timeout = 250;
305
this.prevLink.setStyle({ height: imgHeight + 'px' });
306
this.nextLink.setStyle({ height: imgHeight + 'px' });
307
this.imageDataContainer.setStyle({ width: widthNew + 'px' });
310
}).bind(this).delay(timeout / 1000);
315
// Display image and begin preloading neighbors.
317
showImage: function(){
319
new Effect.Appear(this.lightboxImage, {
320
duration: this.resizeDuration,
322
afterFinish: (function(){ this.updateDetails(); }).bind(this)
324
this.preloadNeighborImages();
329
// Display caption, image number, and bottom nav.
331
updateDetails: function() {
333
// if caption is not null
334
if (this.imageArray[this.activeImage][1] != ""){
335
this.caption.update(this.imageArray[this.activeImage][1]).show();
338
// if image is part of set display 'Image x of x'
339
if (this.imageArray.length > 1){
340
this.numberDisplay.update( LightboxOptions.labelImage + ' ' + (this.activeImage + 1) + ' ' + LightboxOptions.labelOf + ' ' + this.imageArray.length).show();
345
new Effect.SlideDown(this.imageDataContainer, { sync: true, duration: this.resizeDuration, from: 0.0, to: 1.0 }),
346
new Effect.Appear(this.imageDataContainer, { sync: true, duration: this.resizeDuration })
349
duration: this.resizeDuration,
350
afterFinish: (function() {
351
// update overlay size and update nav
352
var arrayPageSize = this.getPageSize();
353
this.overlay.setStyle({ height: arrayPageSize[1] + 'px' });
362
// Display appropriate previous and next hover navigation.
364
updateNav: function() {
366
this.hoverNav.show();
368
// if not first image in set, display prev image button
369
if (this.activeImage > 0) this.prevLink.show();
371
// if not last image in set, display next image button
372
if (this.activeImage < (this.imageArray.length - 1)) this.nextLink.show();
374
this.enableKeyboardNav();
378
// enableKeyboardNav()
380
enableKeyboardNav: function() {
381
document.observe('keydown', this.keyboardAction);
385
// disableKeyboardNav()
387
disableKeyboardNav: function() {
388
document.stopObserving('keydown', this.keyboardAction);
394
keyboardAction: function(event) {
395
var keycode = event.keyCode;
398
if (event.DOM_VK_ESCAPE) { // mozilla
399
escapeKey = event.DOM_VK_ESCAPE;
404
var key = String.fromCharCode(keycode).toLowerCase();
406
if (key.match(/x|o|c/) || (keycode == escapeKey)){ // close lightbox
408
} else if ((key == 'p') || (keycode == 37)){ // display previous image
409
if (this.activeImage != 0){
410
this.disableKeyboardNav();
411
this.changeImage(this.activeImage - 1);
413
} else if ((key == 'n') || (keycode == 39)){ // display next image
414
if (this.activeImage != (this.imageArray.length - 1)){
415
this.disableKeyboardNav();
416
this.changeImage(this.activeImage + 1);
422
// preloadNeighborImages()
423
// Preload previous and next images.
425
preloadNeighborImages: function(){
426
var preloadNextImage, preloadPrevImage;
427
if (this.imageArray.length > this.activeImage + 1){
428
preloadNextImage = new Image();
429
preloadNextImage.src = this.imageArray[this.activeImage + 1][0];
431
if (this.activeImage > 0){
432
preloadPrevImage = new Image();
433
preloadPrevImage.src = this.imageArray[this.activeImage - 1][0];
442
this.disableKeyboardNav();
443
this.lightbox.hide();
444
new Effect.Fade(this.overlay, { duration: this.overlayDuration });
445
$$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'visible' });
451
getPageSize: function() {
453
var xScroll, yScroll;
455
if (window.innerHeight && window.scrollMaxY) {
456
xScroll = window.innerWidth + window.scrollMaxX;
457
yScroll = window.innerHeight + window.scrollMaxY;
458
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
459
xScroll = document.body.scrollWidth;
460
yScroll = document.body.scrollHeight;
461
} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
462
xScroll = document.body.offsetWidth;
463
yScroll = document.body.offsetHeight;
466
var windowWidth, windowHeight;
468
if (self.innerHeight) { // all except Explorer
469
if(document.documentElement.clientWidth){
470
windowWidth = document.documentElement.clientWidth;
472
windowWidth = self.innerWidth;
474
windowHeight = self.innerHeight;
475
} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
476
windowWidth = document.documentElement.clientWidth;
477
windowHeight = document.documentElement.clientHeight;
478
} else if (document.body) { // other Explorers
479
windowWidth = document.body.clientWidth;
480
windowHeight = document.body.clientHeight;
483
// for small pages with total height less then height of the viewport
484
if(yScroll < windowHeight){
485
pageHeight = windowHeight;
487
pageHeight = yScroll;
490
// for small pages with total width less then width of the viewport
491
if(xScroll < windowWidth){
494
pageWidth = windowWidth;
497
return [pageWidth,pageHeight];
501
document.observe('dom:loaded', function () { new Lightbox(); });