📄 lightwindow.js
字号:
this._handleNavigation(false);
if (direction == 'previous') {
this.openWindow(this.navigationObservers.previous);
} else if (direction == 'next'){
this.openWindow(this.navigationObservers.next);
}
},
//
// Build the Gallery List and Load it
//
buildGalleryList : function() {
var output = '';
var galleryLink;
for (i in this.galleries) {
if (typeof this.galleries[i] == 'object') {
output += (this.options.skin.gallery.top).replace('{gallery_title_replace}', unescape(i));
for (j in this.galleries[i]) {
if (typeof this.galleries[i][j] == 'object') {
galleryLink = '<a href="#" id="lightwindow_gallery_'+i+'_'+j+'" >'+unescape(j)+'</a>';
output += (this.options.skin.gallery.middle).replace('{gallery_link_replace}', galleryLink);
}
}
output += this.options.skin.gallery.bottom;
}
}
new Insertion.Top('lightwindow_galleries_list', output);
// Attach Events
for (i in this.galleries) {
if (typeof this.galleries[i] == 'object') {
for (j in this.galleries[i]) {
if (typeof this.galleries[i][j] == 'object') {
Event.observe($('lightwindow_gallery_'+i+'_'+j), 'click', this.openWindow.bind(this, this.galleries[i][j][0]), false);
$('lightwindow_gallery_'+i+'_'+j).onclick = function() {return false;};
}
}
}
}
},
//
// Set Links Up
//
_setupLinks : function() {
var links = $$('.'+this.options.classNames.standard);
links.each(function(link) {
this._processLink(link);
}.bind(this));
},
//
// Process a Link
//
_processLink : function(link) {
if ((this._fileType(link.getAttribute('href')) == 'image' || this._fileType(link.getAttribute('href')) == 'media')) {
if (gallery = this._getGalleryInfo(link.rel)) {
if (!this.galleries[gallery[0]]) {
this.galleries[gallery[0]] = new Array();
}
if (!this.galleries[gallery[0]][gallery[1]]) {
this.galleries[gallery[0]][gallery[1]] = new Array();
}
this.galleries[gallery[0]][gallery[1]].push(link);
}
}
// Take care of our inline content
var url = link.getAttribute('href');
if (url.indexOf('?') > -1) {
url = url.substring(0, url.indexOf('?'));
}
var container = url.substring(url.indexOf('#')+1);
if($(container)) {
$(container).setStyle({
display : 'none'
});
}
Event.observe(link, 'click', this.activate.bindAsEventListener(this, link), false);
link.onclick = function() {return false;};
},
//
// Setup our actions
//
_setupActions : function() {
var links = $$('#lightwindow_container .'+this.options.classNames.action);
links.each(function(link) {
Event.observe(link, 'click', this[link.getAttribute('rel')].bindAsEventListener(this, link), false);
link.onclick = function() {return false;};
}.bind(this));
},
//
// Add the markup to the page.
//
_addLightWindowMarkup : function(rebuild) {
var overlay = Element.extend(document.createElement('div'));
overlay.setAttribute('id', 'lightwindow_overlay');
// FF Mac has a problem with putting Flash above a layer without a 100% opacity background, so we need to use a pre-made
if (Prototype.Browser.Gecko) {
overlay.setStyle({
backgroundImage: 'url('+this.options.overlay.presetImage+')',
backgroundRepeat: 'repeat',
height: this.pageDimensions.height+'px'
});
} else {
overlay.setStyle({
opacity: this.options.overlay.opacity,
backgroundImage: 'url('+this.options.overlay.image+')',
backgroundRepeat: 'repeat',
height: this.pageDimensions.height+'px'
});
}
var lw = document.createElement('div');
lw.setAttribute('id', 'lightwindow');
lw.innerHTML = this.options.skin.main;
var body = document.getElementsByTagName('body')[0];
body.appendChild(overlay);
body.appendChild(lw);
if ($('lightwindow_title_bar_close_link')) {
Event.observe('lightwindow_title_bar_close_link', 'click', this.deactivate.bindAsEventListener(this));
$('lightwindow_title_bar_close_link').onclick = function() {return false;};
}
Event.observe($('lightwindow_previous'), 'click', this.navigateWindow.bind(this, 'previous'), false);
$('lightwindow_previous').onclick = function() {return false;};
Event.observe($('lightwindow_next'), 'click', this.navigateWindow.bind(this, 'next'), false);
$('lightwindow_next').onclick = function() {return false;};
if (!this.options.hideGalleryTab) {
Event.observe($('lightwindow_galleries_tab'), 'click', this._handleGalleryAnimation.bind(this, true), false);
$('lightwindow_galleries_tab').onclick = function() {return false;};
}
// Because we use position absolute, kill the scroll Wheel on animations
if (Prototype.Browser.IE) {
Event.observe(document, 'mousewheel', this._stopScrolling.bindAsEventListener(this), false);
} else {
Event.observe(window, 'DOMMouseScroll', this._stopScrolling.bindAsEventListener(this), false);
}
Event.observe(overlay, 'click', this.deactivate.bindAsEventListener(this), false);
overlay.onclick = function() {return false;};
},
//
// Add loading window markup
//
_addLoadingWindowMarkup : function() {
$('lightwindow_contents').innerHTML += this.options.skin.loading;
},
//
// Setup the window elements
//
_setupWindowElements : function(link) {
this.element = link;
this.element.title = null ? '' : link.getAttribute('title');
this.element.author = null ? '' : link.getAttribute('author');
this.element.caption = null ? '' : link.getAttribute('caption');
this.element.rel = null ? '' : link.getAttribute('rel');
this.element.params = null ? '' : link.getAttribute('params');
// Set the window type
this.contentToFetch = this.element.href;
this.windowType = this._getParameter('lightwindow_type') ? this._getParameter('lightwindow_type') : this._fileType(this.contentToFetch);
},
//
// Clear the window contents out
//
_clearWindowContents : function(contents) {
// If there is an iframe, its got to go
if ($('lightwindow_iframe')) {
Element.remove($('lightwindow_iframe'));
}
// Stop playing an object if its still around
if ($('lightwindow_media_primary')) {
try {
$('lightwindow_media_primary').Stop();
} catch(e) {}
Element.remove($('lightwindow_media_primary'));
}
// Stop playing an object if its still around
if ($('lightwindow_media_secondary')) {
try {
$('lightwindow_media_secondary').Stop();
} catch(e) {}
Element.remove($('lightwindow_media_secondary'));
}
this.activeGallery = false;
this._handleNavigation(this.activeGallery);
if (contents) {
// Empty the contents
$('lightwindow_contents').innerHTML = '';
// Reset the scroll bars
$('lightwindow_contents').setStyle({
overflow: 'hidden'
});
if (!this.windowActive) {
$('lightwindow_data_slide_inner').setStyle({
display: 'none'
});
$('lightwindow_title_bar_title').innerHTML = '';
}
// Because of browser differences and to maintain flexible captions we need to reset this height at close
$('lightwindow_data_slide').setStyle({
height: 'auto'
});
}
this.resizeTo.height = null;
this.resizeTo.width = null;
},
//
// Set the status of our animation to keep things from getting clunky
//
_setStatus : function(status) {
this.animating = status;
if (status) {
Element.show('lightwindow_loading');
}
if (!(/MSIE 6./i.test(navigator.userAgent))) {
this._fixedWindow(status);
}
},
//
// Make this window Fixed
//
_fixedWindow : function(status) {
if (status) {
if (this.windowActive) {
this._getScroll();
$('lightwindow').setStyle({
position: 'absolute',
top: parseFloat($('lightwindow').getStyle('top'))+this.pagePosition.y+'px',
left: parseFloat($('lightwindow').getStyle('left'))+this.pagePosition.x+'px'
});
} else {
$('lightwindow').setStyle({
position: 'absolute'
});
}
} else {
if (this.windowActive) {
this._getScroll();
$('lightwindow').setStyle({
position: 'fixed',
top: parseFloat($('lightwindow').getStyle('top'))-this.pagePosition.y+'px',
left: parseFloat($('lightwindow').getStyle('left'))-this.pagePosition.x+'px'
});
} else {
if ($('lightwindow_iframe')) {
// Ideally here we would set a 50% value for top and left, but Safari rears it ugly head again and we need to do it by pixels
this._browserDimensions();
}
$('lightwindow').setStyle({
position: 'fixed',
top: (parseFloat(this._getParameter('lightwindow_top')) ? parseFloat(this._getParameter('lightwindow_top'))+'px' : this.dimensions.viewport.height/2+'px'),
left: (parseFloat(this._getParameter('lightwindow_left')) ? parseFloat(this._getParameter('lightwindow_left'))+'px' : this.dimensions.viewport.width/2+'px')
});
}
}
},
//
// Prepare the window for IE.
//
_prepareIE : function(setup) {
if (Prototype.Browser.IE) {
var height, overflowX, overflowY;
if (setup) {
var height = '100%';
} else {
var height = 'auto';
}
var body = document.getElementsByTagName('body')[0];
var html = document.getElementsByTagName('html')[0];
html.style.height = body.style.height = height;
}
},
_stopScrolling : function(e) {
if (this.animating) {
if (e.preventDefault) {
e.preventDefault();
}
e.returnValue = false;
}
},
//
// Get the scroll for the page.
//
_getScroll : function(){
if(typeof(window.pageYOffset) == 'number') {
this.pagePosition.x = window.pageXOffset;
this.pagePosition.y = window.pageYOffset;
} else if(document.body && (document.body.scrollLeft || document.body.scrollTop)) {
this.pagePosition.x = document.body.scrollLeft;
this.pagePosition.y = document.body.scrollTop;
} else if(document.documentElement) {
this.pagePosition.x = document.documentElement.scrollLeft;
this.pagePosition.y = document.documentElement.scrollTop;
}
},
//
// Reset the scroll.
//
_setScroll : function(x, y) {
document.documentElement.scrollLeft = x;
document.documentElement.scrollTop = y;
},
//
// Hide Selects from the page because of IE.
// We could use iframe shims instead here but why add all the extra markup for one browser when this is much easier and cleaner
//
_toggleTroubleElements : function(visibility, content){
if (content) {
var selects = $('lightwindow_contents').getElementsByTagName('select');
} else {
var selects = document.getElementsByTagName('select');
}
for(var i = 0; i < selects.length; i++) {
selects[i].style.visibility = visibility;
}
if (!content) {
if (this.options.hideFlash){
var objects = document.getElementsByTagName('object');
for (i = 0; i != objects.length; i++) {
objects[i].style.visibility = visibility;
}
var embeds = document.getElementsByTagName('embed');
for (i = 0; i != embeds.length; i++) {
embeds[i].style.visibility = visibility;
}
}
var iframes = document.getElementsByTagName('iframe');
for (i = 0; i != iframes.length; i++) {
iframes[i].style.visibility = visibility;
}
}
},
//
// Get the actual page size
//
_getPageDimensions : function() {
var xScroll, yScroll;
if (window.innerHeight && window.scrollMaxY) {
xScroll = document.body.scrollWidth;
yScroll = window.innerHeight + window.scrollMaxY;
} else if (document.body.scrollHeight > document.body.offsetHeight){
xScroll = document.body.scrollWidth;
yScroll = document.body.scrollHeight;
} else {
xScroll = document.body.offsetWidth;
yScroll = document.body.offsetHeight;
}
var windowWidth, windowHeight;
if (self.innerHeight) {
windowWidth = self.innerWidth;
windowHeight = self.innerHeight;
} else if (document.documentElement && document.documentElement.clientHeight) {
windowWidth = document.documentElement.clientWidth;
windowHeight = document.documentElement.clientHeight;
} else if (document.body) {
windowWidth = document.body.clientWidth;
windowHeight = document.body.clientHeight;
}
if(yScroll < windowHeight){
this.pageDimensions.height = windowHeight;
} else {
this.pageDimensions.height = yScroll;
}
if(xScroll < windowWidth){
this.pageDimensions.width = windowWidth;
} else {
this.pageDimensions.width = xScroll;
}
},
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -