📄 highslide.js
字号:
} else { // first img within anchor
for (i = 0; i < a.childNodes.length; i++) {
if (a.childNodes[i].tagName && a.childNodes[i].tagName == 'IMG') {
var el = a.childNodes[i];
break;
}
}
}
if (!el) el = a;
// cancel other instances
for (i = 0; i < hs.expanders.length; i++) {
if (hs.expanders[i] && hs.expanders[i].thumb != el && !hs.expanders[i].onLoadStarted) {
hs.expanders[i].cancelLoading();
}
}
// check if already open
for (i = 0; i < hs.expanders.length; i++) {
if (hs.expanders[i] && hs.expanders[i].thumb == el) {
hs.expanders[i].focus();
return false;
}
}
this.key = hs.expandedImagesCounter++;
hs.expanders[this.key] = this;
if (contentType == 'html') {
this.isHtml = true;
this.contentType = 'html';
} else {
this.isImage = true;
this.contentType = 'image';
}
this.a = a;
// override inline parameters
for (i = 0; i < hs.overrides.length; i++) {
var name = hs.overrides[i];
if (params && params[name] != undefined) this[name] = params[name];
else this[name] = hs[name];
}
// check slideshowGroup
if (hs.toggleImagesGroup != null && hs.toggleImagesGroup != this.slideshowGroup) {
hs.toggleImagesGroup = null;
hs.expanders[this.key] = null;
return;
}
this.thumbsUserSetId = el.id || a.id;
this.thumb = el;
this.overlays = new Array();
var pos = hs.position(el);
// instanciate the wrapper
this.wrapper = hs.createElement(
'div',
{
id: 'highslide-wrapper-'+ this.key,
className: this.wrapperClassName
},
{
visibility: 'hidden',
position: 'absolute',
zIndex: hs.zIndexCounter++
}
);
// store properties of the thumbnail
this.thumbWidth = el.width ? el.width : el.offsetWidth;
this.thumbHeight = el.height ? el.height : el.offsetHeight;
this.thumbLeft = pos.x;
this.thumbTop = pos.y;
this.thumbClass = el.className;
// thumb borders
this.thumbOffsetBorderW = (this.thumb.offsetWidth - this.thumbWidth) / 2;
this.thumbOffsetBorderH = (this.thumb.offsetHeight - this.thumbHeight) / 2;
if (this.isImage) this.imageCreate();
return false;
} catch(e) {
return true;
}
};
HsExpander.prototype.displayLoading = function() {
if (this.onLoadStarted) return;
this.originalCursor = this.a.style.cursor;
this.a.style.cursor = 'wait';
this.loading = hs.createElement('a',
{
className: 'highslide-loading',
title: hs.loadingTitle,
href: 'javascript:hs.expanders['+ this.key +'].cancelLoading()',
innerHTML: hs.loadingText
},
{
position: 'absolute',
visibility: 'hidden'
}, hs.container);
if (hs.ie) this.loading.style.filter = 'alpha(opacity='+ (100*hs.loadingOpacity) +')';
else this.loading.style.opacity = hs.loadingOpacity;
this.loading.style.left = (this.thumbLeft + this.thumbOffsetBorderW
+ (this.thumbWidth - this.loading.offsetWidth) / 2) +'px';
this.loading.style.top = (this.thumbTop
+ (this.thumbHeight - this.loading.offsetHeight) / 2) +'px';
setTimeout(
"if (hs.expanders["+ this.key +"] && hs.expanders["+ this.key +"].loading) "
+ "hs.expanders["+ this.key +"].loading.style.visibility = 'visible';",
100
);
};
HsExpander.prototype.imageCreate = function() {
var img = document.createElement('img');
var key = this.key;
var img = document.createElement('img');
this.content = img;
img.onload = function () { if (hs.expanders[key]) hs.expanders[key].onLoad(); };
img.className = 'highslide-image '+ this.thumbClass;
img.style.visibility = 'hidden'; // prevent flickering in IE
img.style.display = 'block';
img.style.position = 'absolute';
img.style.zIndex = 3;
img.title = hs.restoreTitle;
img.onmouseover = function () {
if (hs.expanders[key]) hs.expanders[key].onMouseOver();
};
img.onmouseout = function (e) {
var rel = e ? e.relatedTarget : event.toElement;
if (hs.expanders[key]) hs.expanders[key].onMouseOut(rel);
};
if (hs.safari) hs.container.appendChild(img);
img.src = unescape(hs.getSrc(this.a));//获得图片的URL地址并对编码后的中文进行解码。将中文解码后JS可以正常的访问中文文件。
this.displayLoading();
};
HsExpander.prototype.onLoad = function() {
try {
if (!this.content) return;
// prevent looping on certain Gecko engines:
if (this.onLoadStarted) return;
else this.onLoadStarted = true;
if (this.loading) {
hs.container.removeChild(this.loading);
this.loading = null;
this.a.style.cursor = this.originalCursor || '';
}
if (this.isImage) {
this.newWidth = this.content.width;
this.newHeight = this.content.height;
this.fullExpandWidth = this.newWidth;
this.fullExpandHeight = this.newHeight;
this.content.width = this.thumbWidth;
this.content.height = this.thumbHeight;
}
// identify caption div
var modMarginBottom = hs.marginBottom;
if (this.captionId && hs.$(this.captionId)) {
this.caption = hs.$(this.captionId).cloneNode(true);
} else if (this.thumbsUserSetId && hs.$('caption-for-'+ this.thumbsUserSetId)) {
this.caption = hs.$('caption-for-'+ this.thumbsUserSetId).cloneNode(true);
}
if (this.caption) {
modMarginBottom += this.spaceForCaption;
this.caption.id = null;
}
this.wrapper.appendChild(this.content);
this.content.style.position = 'relative'; // Saf
if (this.caption) this.wrapper.appendChild(this.caption);
this.wrapper.style.left = this.thumbLeft +'px';
this.wrapper.style.top = this.thumbTop +'px';
hs.container.appendChild(this.wrapper);
if (this.swfObject) this.swfObject.write(this.flashContainerId);
// correct for borders
this.offsetBorderW = (this.wrapper.offsetWidth - this.thumbWidth) / 2;
this.offsetBorderH = (this.wrapper.offsetHeight - this.thumbHeight) / 2;
var modMarginRight = hs.marginRight + 2 * this.offsetBorderW;
modMarginBottom += 2 * this.offsetBorderH;
var ratio = this.newWidth / this.newHeight;
var minWidth = this.allowSizeReduction ? this.minWidth : this.newWidth;
var minHeight = this.allowSizeReduction ? this.minHeight : this.newHeight;
var justify = { x: 'auto', y: 'auto' };
if (this.align == 'center') {
justify.x = 'center';
justify.y = 'center';
} else {
if (this.anchor.match(/^top/)) justify.y = null;
if (this.anchor.match(/right$/)) justify.x = 'max';
if (this.anchor.match(/^bottom/)) justify.y = 'max';
if (this.anchor.match(/left$/)) justify.x = null;
}
client = new hs.clientInfo();
// justify
this.x = {
min: parseInt(this.thumbLeft) - this.offsetBorderW + this.thumbOffsetBorderW,
span: this.newWidth,
minSpan: this.newWidth < minWidth ? this.newWidth : minWidth,
justify: justify.x,
marginMin: hs.marginLeft,
marginMax: modMarginRight,
scroll: client.scrollLeft,
clientSpan: client.width,
thumbSpan: this.thumbWidth
};
var oldRight = this.x.min + parseInt(this.thumbWidth);
this.x = this.justify(this.x);
this.y = {
min: parseInt(this.thumbTop) - this.offsetBorderH + this.thumbOffsetBorderH,
span: this.newHeight,
minSpan: this.newHeight < minHeight ? this.newHeight : minHeight,
justify: justify.y,
marginMin: hs.marginTop,
marginMax: modMarginBottom,
scroll: client.scrollTop,
clientSpan: client.height,
thumbSpan: this.thumbHeight
};
var oldBottom = this.y.min + parseInt(this.thumbHeight);
this.y = this.justify(this.y);
if (this.isHtml) this.htmlSizeOperations();
// correct ratio
if (this.isImage) this.correctRatio(ratio);
var x = this.x;
var y = this.y;
// Selectbox bug
var imgPos = {x: x.min - 20, y: y.min - 20, w: x.span + 40, h: y.span + 40 + this.spaceForCaption};
hs.hideSelects = (hs.ie && hs.ieVersion() < 7);
if (hs.hideSelects) this.showHideElements('SELECT', 'hidden', imgPos);
// Iframes bug
hs.hideIframes = (window.opera || navigator.vendor == 'KDE' || (hs.ie && hs.ieVersion() < 5.5));
if (hs.hideIframes) this.showHideElements('IFRAME', 'hidden', imgPos);
// Apply size change
this.changeSize(
this.thumbLeft + this.thumbOffsetBorderW - this.offsetBorderW,
this.thumbTop + this.thumbOffsetBorderH - this.offsetBorderH,
this.thumbWidth,
this.thumbHeight,
x.min,
y.min,
x.span,
y.span,
hs.expandDuration,
hs.expandSteps
);
setTimeout(
"if (hs.expanders["+ this.key +"])"
+ "hs.expanders["+ this.key +"].onExpanded()",
hs.expandDuration
);
} catch(e) {
if (hs.expanders[this.key] && hs.expanders[this.key].a)
window.location.href = hs.getSrc(hs.expanders[this.key].a);
}
};
HsExpander.prototype.changeSize = function(x1, y1, w1, h1, x2, y2, w2, h2, dur, steps) {
dW = (w2 - w1) / steps;
dH = (h2 - h1) / steps;
dX = (x2 - x1) / steps;
dY = (y2 - y1) / steps;
for (i = 1; i < hs.expandSteps; i++) {
w1 += dW;
h1 += dH;
x1 += dX;
y1 += dY;
setTimeout(
"if (hs.expanders["+ this.key +"]) "
+ "hs.expanders["+ this.key +"]."+ this.contentType +"SetSize("
+ w1 +", "+ h1 +", "+ x1 +", "+ y1 +")",
Math.round(i * (dur / steps))
);
}
};
HsExpander.prototype.imageSetSize = function (width, height, left, top) {
try {
this.content.width = width;
this.content.height = height;
hs.setStyles ( this.wrapper,
{
'visibility': 'visible',
'left': left +'px',
'top': top +'px'
}
);
this.content.style.visibility = 'visible';
if (this.thumb.tagName == 'IMG') this.thumb.style.visibility = 'hidden';
} catch(e) {
window.location.href = hs.getSrc(hs.expanders[this.key].a);
}
};
HsExpander.prototype.onExpanded = function() {
this[this.contentType +'SetSize'](this.x.span, this.y.span, this.x.min, this.y.min);
this.isExpanded = true;
this.focus();
this.createCustomOverlays();
if (hs.showCredits) this.writeCredits();
if (this.caption) this.writeCaption();
//else if (this.outlineType) this.writeOutline();
if (!this.caption || !hs.slideInOutline && this.outlineType) this.writeOutline();
if (this.fullExpandWidth > this.x.span) this.createFullExpand();
if (!this.caption && !this.outlineType) this.onDisplayFinished();
};
HsExpander.prototype.onDisplayFinished = function() {
// preload next
var nextA = hs.getAdjacentAnchor(this.key, 1);
if (nextA) {
var img = document.createElement('img');
img.src = hs.getSrc(nextA);
}
};
HsExpander.prototype.justify = function (p) {
if (p.justify == 'auto' || p.justify == 'center') {
var hasMovedMin = false;
var allowReduce = true;
// calculate p.min
if (p.justify == 'center') p.min = Math.round(p.scroll + (p.clientSpan - p.span - p.marginMax) / 2);
else p.min = Math.round(p.min - ((p.span - p.thumbSpan) / 2)); // auto
if (p.min < p.scroll + p.marginMin) {
p.min = p.scroll + p.marginMin;
hasMovedMin = true;
}
if (p.span < p.minSpan) {
p.span = p.minSpan;
allowReduce = false;
}
// calculate right/newWidth
if (p.min + p.span > p.scroll + p.clientSpan - p.marginMax) {
if (hasMovedMin && allowReduce) p.span = p.clientSpan - p.marginMin - p.marginMax; // can't expand more
else if (p.span < p.clientSpan - p.marginMin - p.marginMax) { // move newTop up
p.min = p.scroll + p.clientSpan - p.span - p.marginMin - p.marginMax;
} else { // image larger than client
p.min = p.scroll + p.marginMin;
if (allowReduce) p.span = p.clientSpan - p.marginMin - p.marginMax;
}
}
if (p.span < p.minSpan) {
p.span = p.minSpan;
allowReduce = false;
}
} else if (p.justify == 'max') {
p.min = Math.floor(p.min - p.span + p.thumbSpan);
}
if (p.min < p.marginMin) {
tmpMin = p.min;
p.min = p.marginMin;
if (allowReduce) p.span = p.span - (p.min - tmpMin);
}
return p;
};
HsExpander.prototype.correctRatio = function(ratio) {
var x = this.x;
var y = this.y;
var changed = false;
if (x.span / y.span > ratio) { // width greater
var tmpWidth = x.span;
x.span = y.span * ratio;
if (x.span < x.minSpan) { // below minWidth
x.span = x.minSpan;
y.span = x.span / ratio;
}
changed = true;
} else if (x.span / y.span < ratio) { // height greater
var tmpHeight = y.span;
y.span = x.span / ratio;
changed = true;
}
if (changed) {
x.min = parseInt(this.thumbLeft) - this.offsetBorderW + this.thumbOffsetBorderW;
x.minSpan = x.span;
this.x = this.justify(x);
y.min = parseInt(this.thumbTop) - this.offsetBorderH + this.thumbOffsetBorderH;
y.minSpan = y.span;
this.y = this.justify(y);
}
};
HsExpander.prototype.cancelLoading = function() {
this.a.style.cursor = this.originalCursor;
if (this.loading) {
hs.container.removeChild(this.loading);
this.loading = null;
}
hs.expanders[this.key] = null;
};
HsExpander.prototype.writeCredits = function () {
var credits = hs.createElement('a',
{
href: hs.creditsHref,
className: 'highslide-credits',
innerHTML: hs.creditsText,
title: hs.creditsTitle
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -