📄 lightwindow.js
字号:
// Fire off our transition handler
//
_handleTransition : function() {
if (this.options.transitionHandler) {
this.options.transitionHandler().bind(this);
} else {
this._defaultTransitionHandler();
}
},
//
// Handle the finish of the window animation
//
_handleFinalWindowAnimation : function(delay) {
if (this.options.finalAnimationHandler) {
this.options.finalAnimationHandler().bind(this, delay);
} else {
this._defaultfinalWindowAnimationHandler(delay);
}
},
//
// Handle the gallery Animation
//
_handleGalleryAnimation : function(list) {
if (this.options.galleryAnimationHandler) {
this.options.galleryAnimationHandler().bind(this, list);
} else {
this._defaultGalleryAnimationHandler(list);
}
},
//
// Display the navigation
//
_defaultDisplayNavigation : function(display) {
if (display) {
$('lightwindow_navigation').setStyle({
display: 'block',
height: $('lightwindow_contents').getHeight()+'px',
width: '100%',
marginTop: this.options.dimensions.titleHeight+'px'
});
} else {
$('lightwindow_navigation').setStyle({
display: 'none',
height: 'auto',
width: 'auto'
});
}
},
//
// This is the default animation handler for LightWindow
//
_defaultAnimationHandler : function() {
// Now that we have figures out the cruft lets make the caption go away and add its effects
if (this.element.caption || this.element.author || (this.activeGallery && this.options.showGalleryCount)) {
$('lightwindow_data_slide').setStyle({
display: 'none',
width: 'auto'
});
this.dimensions.dataEffects.push(
new Effect.SlideDown('lightwindow_data_slide', {sync: true}),
new Effect.Appear('lightwindow_data_slide', {sync: true, from: 0.0, to: 1.0})
);
}
// Set up the Title if we have one
$('lightwindow_title_bar_inner').setStyle({
height: '0px',
marginTop: this.options.dimensions.titleHeight+'px'
});
// We always want the title bar as well
this.dimensions.dataEffects.push(
new Effect.Morph('lightwindow_title_bar_inner', {sync: true, style: {height: this.options.dimensions.titleHeight+'px', marginTop: '0px'}}),
new Effect.Appear('lightwindow_title_bar_inner', {sync: true, from: 0.0, to: 1.0})
);
if (!this.options.hideGalleryTab) {
this._handleGalleryAnimation(false);
if ($('lightwindow_galleries_tab_container').getHeight() == 0) {
this.dimensions.dataEffects.push(
new Effect.Morph('lightwindow_galleries_tab_container', {sync: true, style: {height: '20px', marginTop: '0px'}})
);
$('lightwindow_galleries').setStyle({
width: '0px'
});
}
}
var resized = false;
var ratio = this.dimensions.container.width-$('lightwindow_contents').getWidth()+this.resizeTo.width+this.options.contentOffset.width;
if (ratio != $('lightwindow_container').getWidth()) {
new Effect.Parallel([
new Effect.Scale('lightwindow_contents', 100*(this.resizeTo.width/$('lightwindow_contents').getWidth()), {scaleFrom: 100*($('lightwindow_contents').getWidth()/($('lightwindow_contents').getWidth()+(this.options.contentOffset.width))), sync: true, scaleY: false, scaleContent: false}),
new Effect.Scale('lightwindow_container', 100*(ratio/(this.dimensions.container.width)), {sync: true, scaleY: false, scaleFromCenter: true, scaleContent: false})
], {
duration: this.duration,
delay: 0.25,
queue: {position: 'end', scope: 'lightwindowAnimation'}
}
);
}
ratio = this.dimensions.container.height-$('lightwindow_contents').getHeight()+this.resizeTo.height+this.options.contentOffset.height;
if (ratio != $('lightwindow_container').getHeight()) {
new Effect.Parallel([
new Effect.Scale('lightwindow_contents', 100*(this.resizeTo.height/$('lightwindow_contents').getHeight()), {scaleFrom: 100*($('lightwindow_contents').getHeight()/($('lightwindow_contents').getHeight()+(this.options.contentOffset.height))), sync: true, scaleX: false, scaleContent: false}),
new Effect.Scale('lightwindow_container', 100*(ratio/(this.dimensions.container.height)), {sync: true, scaleX: false, scaleFromCenter: true, scaleContent: false})
], {
duration: this.duration,
afterFinish: function() {
if (this.dimensions.dataEffects.length > 0) {
if (!this.options.hideGalleryTab) {
$('lightwindow_galleries').setStyle({
width: this.resizeTo.width+'px'
});
}
new Effect.Parallel(this.dimensions.dataEffects, {
duration: this.duration,
afterFinish: function() {
this._finishWindow();
}.bind(this),
queue: {position: 'end', scope: 'lightwindowAnimation'}
}
);
}
}.bind(this),
queue: {position: 'end', scope: 'lightwindowAnimation'}
}
);
resized = true;
}
// We need to do our data effect since there was no resizing
if (!resized && this.dimensions.dataEffects.length > 0) {
new Effect.Parallel(this.dimensions.dataEffects, {
duration: this.duration,
beforeStart: function() {
if (!this.options.hideGalleryTab) {
$('lightwindow_galleries').setStyle({
width: this.resizeTo.width+'px'
});
}
if (this.containerChange.height != 0 || this.containerChange.width != 0) {
new Effect.MoveBy('lightwindow_container', this.containerChange.height, this.containerChange.width, {transition: Effect.Transitions.sinoidal});
}
}.bind(this),
afterFinish: function() {
this._finishWindow();
}.bind(this),
queue: {position: 'end', scope: 'lightwindowAnimation'}
}
);
}
},
//
// Finish up Window Animation
//
_defaultfinalWindowAnimationHandler : function(delay) {
if (this.windowType == 'media' || this._getParameter('lightwindow_loading_animation')) {
// Because of major flickering with the overlay we just hide it in this case
Element.hide('lightwindow_loading');
this._handleNavigation(this.activeGallery);
this._setStatus(false);
} else {
Effect.Fade('lightwindow_loading', {
duration: 0.75,
delay: 1.0,
afterFinish: function() {
// Just in case we need some scroll goodness (this also avoids the swiss cheese effect)
if (this.windowType != 'image' && this.windowType != 'media' && this.windowType != 'external') {
$('lightwindow_contents').setStyle({
overflow: 'auto'
});
}
this._handleNavigation(this.activeGallery);
this._defaultGalleryAnimationHandler();
this._setStatus(false);
}.bind(this),
queue: {position: 'end', scope: 'lightwindowAnimation'}
});
}
},
//
// Handle the gallery Animation
//
_defaultGalleryAnimationHandler : function(list) {
if (this.activeGallery) {
$('lightwindow_galleries').setStyle({
display: 'block',
marginBottom: $('lightwindow_data_slide').getHeight()+this.options.contentOffset.height/2+'px'
});
$('lightwindow_navigation').setStyle({
height: $('lightwindow_contents').getHeight()-20+'px'
});
} else {
$('lightwindow_galleries').setStyle({
display: 'none'
});
$('lightwindow_galleries_tab_container').setStyle({
height: '0px',
marginTop: '20px'
});
$('lightwindow_galleries_list').setStyle({
height: '0px'
});
return false;
}
if (list) {
if ($('lightwindow_galleries_list').getHeight() == 0) {
var height = $('lightwindow_contents').getHeight()*0.80;
$('lightwindow_galleries_tab_span').className = 'down';
} else {
var height = 0;
$('lightwindow_galleries_tab_span').className = 'up';
}
new Effect.Morph('lightwindow_galleries_list', {
duration: this.duration,
transition: Effect.Transitions.sinoidal,
style: {height: height+'px'},
beforeStart: function() {
$('lightwindow_galleries_list').setStyle({
overflow: 'hidden'
});
},
afterFinish: function() {
$('lightwindow_galleries_list').setStyle({
overflow: 'auto'
});
},
queue: {position: 'end', scope: 'lightwindowAnimation'}
});
}
},
//
// Default Transition Handler
//
_defaultTransitionHandler : function() {
// Clean out our effects
this.dimensions.dataEffects = [];
// Now that we have figures out the cruft lets make the caption go away and add its effects
if ($('lightwindow_data_slide').getStyle('display') != 'none') {
this.dimensions.dataEffects.push(
new Effect.SlideUp('lightwindow_data_slide', {sync: true}),
new Effect.Fade('lightwindow_data_slide', {sync: true, from: 1.0, to: 0.0})
);
}
if (!this.options.hideGalleryTab) {
if ($('lightwindow_galleries').getHeight() != 0 && !this.options.hideGalleryTab) {
this.dimensions.dataEffects.push(
new Effect.Morph('lightwindow_galleries_tab_container', {sync: true, style: {height: '0px', marginTop: '20px'}})
);
}
if ($('lightwindow_galleries_list').getHeight() != 0) {
$('lightwindow_galleries_tab_span').className = 'up';
this.dimensions.dataEffects.push(
new Effect.Morph('lightwindow_galleries_list', {
sync: true,
style: {height: '0px'},
transition: Effect.Transitions.sinoidal,
beforeStart: function() {
$('lightwindow_galleries_list').setStyle({
overflow: 'hidden'
});
},
afterFinish: function() {
$('lightwindow_galleries_list').setStyle({
overflow: 'auto'
});
}
})
);
}
}
// We always want the title bar as well
this.dimensions.dataEffects.push(
new Effect.Morph('lightwindow_title_bar_inner', {sync: true, style: {height: '0px', marginTop: this.options.dimensions.titleHeight+'px'}}),
new Effect.Fade('lightwindow_title_bar_inner', {sync: true, from: 1.0, to: 0.0})
);
new Effect.Parallel(this.dimensions.dataEffects, {
duration: this.duration,
afterFinish: function() {
this._loadWindow();
}.bind(this),
queue: {position: 'end', scope: 'lightwindowAnimation'}
}
);
},
//
// Default Form handler for LightWindow
//
_defaultFormHandler : function(e) {
var element = Event.element(e).parentNode;
var parameterString = Form.serialize(this._getParameter('lightwindow_form', element.getAttribute('params')));
if (this.options.formMethod == 'post') {
var newAJAX = new Ajax.Request(element.href, {
method: 'post',
postBody: parameterString,
onComplete: this.openWindow.bind(this, element)
});
} else if (this.options.formMethod == 'get') {
var newAJAX = new Ajax.Request(element.href, {
method: 'get',
parameters: parameterString,
onComplete: this.openWindow.bind(this, element)
});
}
},
//
// Wrap everything up
//
_finishWindow : function() {
if (this.windowType == 'external') {
// We set the externals source here because it allows for a much smoother animation
$('lightwindow_iframe').setAttribute('src', this.element.href);
this._handleFinalWindowAnimation(1);
} else if (this.windowType == 'media') {
var outerObject = document.createElement('object');
outerObject.setAttribute('classid', this.options.classids[this._fileExtension(this.contentToFetch)]);
outerObject.setAttribute('codebase', this.options.codebases[this._fileExtension(this.contentToFetch)]);
outerObject.setAttribute('id', 'lightwindow_media_primary');
outerObject.setAttribute('name', 'lightwindow_media_primary');
outerObject.setAttribute('width', this.resizeTo.width);
outerObject.setAttribute('height', this.resizeTo.height);
outerObject = this._addParamToObject('movie', this.contentToFetch, outerObject);
outerObject = this._addParamToObject('src', this.contentToFetch, outerObject);
outerObject = this._addParamToObject('controller', 'true', outerObject);
outerObject = this._addParamToObject('wmode', 'transparent', outerObject);
outerObject = this._addParamToObject('cache', 'false', outerObject);
outerObject = this._addParamToObject('quality', 'high', outerObject);
if (!Prototype.Browser.IE) {
var innerObject = document.createElement('object');
innerObject.setAttribute('type', this.options.mimeTypes[this._fileExtension(this.contentToFetch)]);
innerObject.setAttribute('data', this.contentToFetch);
innerObject.setAttribute('id', 'lightwindow_media_secondary');
innerObject.setAttribute('name', 'lightwindow_media_secondary');
innerObject.setAttribute('width', this.resizeTo.width);
innerObject.setAttribute('height', this.resizeTo.height);
innerObject = this._addParamToObject('controller', 'true', innerObject);
innerObject = this._addParamToObject('wmode', 'transparent', innerObject);
innerObject = this._addParamToObject('cache', 'false', innerObject);
innerObject = this._addParamToObject('quality', 'high', innerObject);
outerObject.appendChild(innerObject);
}
if (this._getParameter('lightwindow_iframe_embed')) {
this._appendIframe('no');
this._writeToIframe(this._convertToMarkup(outerObject, 'object'));
} else {
this._appendObject(outerObject, 'object', $('lightwindow_contents'));
}
this._handleFinalWindowAnimation(0);
} else {
this._handleFinalWindowAnimation(0);
}
// Initialize any actions
this._setupActions();
}
}
/*-----------------------------------------------------------------------------------------------*/
Event.observe(window, 'load', lightwindowInit, false);
//
// Set up all of our links
//
var myLightWindow = null;
function lightwindowInit() {
myLightWindow = new lightwindow();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -