📄 lightwindow.js
字号:
var current = 0;
var images = [];
this.checkImage = [];
this.resizeTo.height = this.resizeTo.width = 0;
this.imageCount = this._getParameter('lightwindow_show_images') ? parseInt(this._getParameter('lightwindow_show_images')) : 1;
// If there is a gallery get it
if (gallery = this._getGalleryInfo(this.element.rel)) {
for (current = 0; current < this.galleries[gallery[0]][gallery[1]].length; current++) {
if (this.contentToFetch.indexOf(this.galleries[gallery[0]][gallery[1]][current].href) > -1) {
break;
}
}
if (this.galleries[gallery[0]][gallery[1]][current-this.imageCount]) {
this.navigationObservers.previous = this.galleries[gallery[0]][gallery[1]][current-this.imageCount];
} else {
this.navigationObservers.previous = false;
}
if (this.galleries[gallery[0]][gallery[1]][current+this.imageCount]) {
this.navigationObservers.next = this.galleries[gallery[0]][gallery[1]][current+this.imageCount];
} else {
this.navigationObservers.next = false;
}
this.activeGallery = true;
} else {
this.navigationObservers.previous = false;
this.navigationObservers.next = false;
this.activeGallery = false;
}
for (var i = current; i < (current+this.imageCount); i++) {
if (gallery && this.galleries[gallery[0]][gallery[1]][i]) {
this.contentToFetch = this.galleries[gallery[0]][gallery[1]][i].href;
this.galleryLocation = {current: (i+1)/this.imageCount, total: (this.galleries[gallery[0]][gallery[1]].length)/this.imageCount};
if (!this.galleries[gallery[0]][gallery[1]][i+this.imageCount]) {
$('lightwindow_next').setStyle({
display: 'none'
});
} else {
$('lightwindow_next').setStyle({
display: 'block'
});
$('lightwindow_next_title').innerHTML = this.galleries[gallery[0]][gallery[1]][i+this.imageCount].title;
}
if (!this.galleries[gallery[0]][gallery[1]][i-this.imageCount]) {
$('lightwindow_previous').setStyle({
display: 'none'
});
} else {
$('lightwindow_previous').setStyle({
display: 'block'
});
$('lightwindow_previous_title').innerHTML = this.galleries[gallery[0]][gallery[1]][i-this.imageCount].title;
}
}
images[i] = document.createElement('img');
images[i].setAttribute('id', 'lightwindow_image_'+i);
images[i].setAttribute('border', '0');
images[i].setAttribute('src', this.contentToFetch);
$('lightwindow_contents').appendChild(images[i]);
// We have to do this instead of .onload
this.checkImage[i] = new PeriodicalExecuter(function(i) {
if (!(typeof $('lightwindow_image_'+i).naturalWidth != "undefined" && $('lightwindow_image_'+i).naturalWidth == 0)) {
this.checkImage[i].stop();
var imageHeight = $('lightwindow_image_'+i).getHeight();
if (imageHeight > this.resizeTo.height) {
this.resizeTo.height = imageHeight;
}
this.resizeTo.width += $('lightwindow_image_'+i).getWidth();
this.imageCount--;
$('lightwindow_image_'+i).setStyle({
height: '100%'
});
if (this.imageCount == 0) {
this._processWindow();
}
}
}.bind(this, i), 1);
}
break;
case 'media' :
var current = 0;
this.resizeTo.height = this.resizeTo.width = 0;
// If there is a gallery get it
if (gallery = this._getGalleryInfo(this.element.rel)) {
for (current = 0; current < this.galleries[gallery[0]][gallery[1]].length; current++) {
if (this.contentToFetch.indexOf(this.galleries[gallery[0]][gallery[1]][current].href) > -1) {
break;
}
}
if (this.galleries[gallery[0]][gallery[1]][current-1]) {
this.navigationObservers.previous = this.galleries[gallery[0]][gallery[1]][current-1];
} else {
this.navigationObservers.previous = false;
}
if (this.galleries[gallery[0]][gallery[1]][current+1]) {
this.navigationObservers.next = this.galleries[gallery[0]][gallery[1]][current+1];
} else {
this.navigationObservers.next = false;
}
this.activeGallery = true;
} else {
this.navigationObservers.previous = false;
this.navigationObservers.next = false;
this.activeGallery = false;
}
if (gallery && this.galleries[gallery[0]][gallery[1]][current]) {
this.contentToFetch = this.galleries[gallery[0]][gallery[1]][current].href;
this.galleryLocation = {current: current+1, total: this.galleries[gallery[0]][gallery[1]].length};
if (!this.galleries[gallery[0]][gallery[1]][current+1]) {
$('lightwindow_next').setStyle({
display: 'none'
});
} else {
$('lightwindow_next').setStyle({
display: 'block'
});
$('lightwindow_next_title').innerHTML = this.galleries[gallery[0]][gallery[1]][current+1].title;
}
if (!this.galleries[gallery[0]][gallery[1]][current-1]) {
$('lightwindow_previous').setStyle({
display: 'none'
});
} else {
$('lightwindow_previous').setStyle({
display: 'block'
});
$('lightwindow_previous_title').innerHTML = this.galleries[gallery[0]][gallery[1]][current-1].title;
}
}
if (this._getParameter('lightwindow_iframe_embed')) {
this.resizeTo.height = this.dimensions.viewport.height;
this.resizeTo.width = this.dimensions.viewport.width;
} else {
this.resizeTo.height = this._getParameter('lightwindow_height');
this.resizeTo.width = this._getParameter('lightwindow_width');
}
this._processWindow();
break;
case 'external' :
this._appendIframe('auto');
this.resizeTo.height = this.dimensions.viewport.height;
this.resizeTo.width = this.dimensions.viewport.width;
this._processWindow();
break;
case 'page' :
var newAJAX = new Ajax.Request(
this.contentToFetch, {
method: 'get',
parameters: '',
onComplete: function(response) {
$('lightwindow_contents').innerHTML += response.responseText;
this.resizeTo.height = $('lightwindow_contents').scrollHeight+(this.options.contentOffset.height);
this.resizeTo.width = $('lightwindow_contents').scrollWidth+(this.options.contentOffset.width);
this._processWindow();
}.bind(this)
}
);
break;
case 'inline' :
var content = this.contentToFetch;
if (content.indexOf('?') > -1) {
content = content.substring(0, content.indexOf('?'));
}
content = content.substring(content.indexOf('#')+1);
new Insertion.Top($('lightwindow_contents'), $(content).innerHTML);
this.resizeTo.height = $('lightwindow_contents').scrollHeight+(this.options.contentOffset.height);
this.resizeTo.width = $('lightwindow_contents').scrollWidth+(this.options.contentOffset.width);
this._toggleTroubleElements('hidden', true);
this._processWindow();
break;
default :
throw("Page Type could not be determined, please amend this lightwindow URL "+this.contentToFetch);
break;
}
},
//
// Resize the Window to fit the viewport if necessary
//
_resizeWindowToFit : function() {
if (this.resizeTo.height+this.dimensions.cruft.height > this.dimensions.viewport.height) {
var heightRatio = this.resizeTo.height/this.resizeTo.width;
this.resizeTo.height = this.dimensions.viewport.height-this.dimensions.cruft.height-(2*this.options.viewportPadding);
// We only care about ratio's with this window type
if (this.windowType == 'image' || (this.windowType == 'media' && !this._getParameter('lightwindow_iframe_embed'))) {
this.resizeTo.width = this.resizeTo.height/heightRatio;
$('lightwindow_data_slide_inner').setStyle({
width: this.resizeTo.width+'px'
});
}
}
if (this.resizeTo.width+this.dimensions.cruft.width > this.dimensions.viewport.width) {
var widthRatio = this.resizeTo.width/this.resizeTo.height;
this.resizeTo.width = this.dimensions.viewport.width-2*this.dimensions.cruft.width-(2*this.options.viewportPadding);
// We only care about ratio's with this window type
if (this.windowType == 'image' || (this.windowType == 'media' && !this._getParameter('lightwindow_iframe_embed'))) {
this.resizeTo.height = this.resizeTo.width/widthRatio;
$('lightwindow_data_slide_inner').setStyle({
height: this.resizeTo.height+'px'
});
}
}
},
//
// Set the Window to a preset size
//
_presetWindowSize : function() {
if (this._getParameter('lightwindow_height')) {
this.resizeTo.height = parseFloat(this._getParameter('lightwindow_height'));
}
if (this._getParameter('lightwindow_width')) {
this.resizeTo.width = parseFloat(this._getParameter('lightwindow_width'));
}
},
//
// Process the Window
//
_processWindow : function() {
// Clean out our effects
this.dimensions.dataEffects = [];
// Set up the data-slide if we have caption information
if (this.element.caption || this.element.author || (this.activeGallery && this.options.showGalleryCount)) {
if (this.element.caption) {
$('lightwindow_data_caption').innerHTML = this.element.caption;
$('lightwindow_data_caption').setStyle({
display: 'block'
});
} else {
$('lightwindow_data_caption').setStyle({
display: 'none'
});
}
if (this.element.author) {
$('lightwindow_data_author').innerHTML = this.element.author;
$('lightwindow_data_author_container').setStyle({
display: 'block'
});
} else {
$('lightwindow_data_author_container').setStyle({
display: 'none'
});
}
if (this.activeGallery && this.options.showGalleryCount) {
$('lightwindow_data_gallery_current').innerHTML = this.galleryLocation.current;
$('lightwindow_data_gallery_total').innerHTML = this.galleryLocation.total;
$('lightwindow_data_gallery_container').setStyle({
display: 'block'
});
} else {
$('lightwindow_data_gallery_container').setStyle({
display: 'none'
});
}
$('lightwindow_data_slide_inner').setStyle({
width: this.resizeTo.width+'px',
height: 'auto',
visibility: 'visible',
display: 'block'
});
$('lightwindow_data_slide').setStyle({
height: $('lightwindow_data_slide').getHeight()+'px',
width: '1px',
overflow: 'hidden',
display: 'block'
});
} else {
$('lightwindow_data_slide').setStyle({
display: 'none',
width: 'auto'
});
$('lightwindow_data_slide_inner').setStyle({
display: 'none',
visibility: 'hidden',
width: this.resizeTo.width+'px',
height: '0px'
});
}
if (this.element.title != 'null') {
$('lightwindow_title_bar_title').innerHTML = this.element.title;
} else {
$('lightwindow_title_bar_title').innerHTML = '';
}
var originalContainerDimensions = {height: $('lightwindow_container').getHeight(), width: $('lightwindow_container').getWidth()};
// Position the window
$('lightwindow_container').setStyle({
height: 'auto',
// We need to set the width to a px not auto as opera has problems with it
width: $('lightwindow_container').getWidth()+this.options.contentOffset.width-(this.windowActive ? this.options.contentOffset.width : 0)+'px'
});
var newContainerDimensions = {height: $('lightwindow_container').getHeight(), width: $('lightwindow_container').getWidth()};
// We need to record the container dimension changes
this.containerChange = {height: originalContainerDimensions.height-newContainerDimensions.height, width: originalContainerDimensions.width-newContainerDimensions.width};
// Get out general dimensions
this.dimensions.container = {height: $('lightwindow_container').getHeight(), width: $('lightwindow_container').getWidth()};
this.dimensions.cruft = {height: this.dimensions.container.height-$('lightwindow_contents').getHeight()+this.options.contentOffset.height, width: this.dimensions.container.width-$('lightwindow_contents').getWidth()+this.options.contentOffset.width};
// Set Sizes if we need too
this._presetWindowSize();
this._resizeWindowToFit(); // Even if the window is preset we still don't want it to go outside of the viewport
if (!this.windowActive) {
// Position the window
$('lightwindow_container').setStyle({
left: -(this.dimensions.container.width/2)+'px',
top: -(this.dimensions.container.height/2)+'px'
});
}
$('lightwindow_container').setStyle({
height: this.dimensions.container.height+'px',
width: this.dimensions.container.width+'px'
});
// We are ready, lets show this puppy off!
this._displayLightWindow('block', 'visible');
this._animateLightWindow();
},
//
// Fire off our animation handler
//
_animateLightWindow : function() {
if (this.options.animationHandler) {
this.options.animationHandler().bind(this);
} else {
this._defaultAnimationHandler();
}
},
//
// Fire off our transition handler
//
_handleNavigation : function(display) {
if (this.options.navigationHandler) {
this.options.navigationHandler().bind(this, display);
} else {
this._defaultDisplayNavigation(display);
}
},
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -