📄 highslide-with-html.js
字号:
var page = hs.getPageSize();
// justify
this.x = {
min: parseInt(this.thumbLeft) - this.offsetBorderW + this.thumbOffsetBorderW,
span: this.newWidth,
minSpan: (this.newWidth < minWidth && !hs.padToMinWidth)
? this.newWidth : minWidth,
marginMin: hs.marginLeft,
marginMax: modMarginRight,
scroll: page.scrollLeft,
clientSpan: page.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,
marginMin: hs.marginTop,
marginMax: this.marginBottom,
scroll: page.scrollTop,
clientSpan: page.height,
thumbSpan: this.thumbHeight
};
var oldBottom = this.y.min + parseInt(this.thumbHeight);
this.y = this.justify(this.y);
if (this.isHtml) this.htmlSizeOperations();
if (this.isImage)
this.correctRatio(ratio);
var x = this.x;
var y = this.y;
this.show();
} catch (e) {
window.location.href = hs.getSrc(this.a);
}
},
setObjContainerSize : function(parent, auto) {
var c = hs.getElementByClass(parent, 'DIV', 'highslide-body');
if (this.objectType == 'iframe') {
if (this.objectWidth) c.style.width = this.objectWidth +'px';
if (this.objectHeight) c.style.height = this.objectHeight +'px';
}
if (this.swfObject) {
c.style.width = this.swfObject.attributes.width +'px';
c.style.height = this.swfObject.attributes.height +'px';
}
},
writeExtendedContent : function (loadTime) {
if (this.hasExtendedContent) return;
var exp = this;
this.body = hs.getElementByClass(this.innerContent, 'DIV', 'highslide-body');
if (this.objectType == 'iframe') {
this.displayLoading();
this.ruler = hs.clearing.cloneNode(1);
this.body.appendChild(this.ruler);
this.newWidth = this.innerContent.offsetWidth;
if (!this.objectWidth) this.objectWidth = this.ruler.offsetWidth;
var hDiff = this.innerContent.offsetHeight - this.body.offsetHeight;
var h = this.objectHeight || (hs.getPageSize()).height - hDiff - hs.marginTop - hs.marginBottom;
var onload = (hs.ie && this.objectLoadTime == 'before') ?
'onload="try {hs.expanders['+ this.key +'].contentLoaded()} catch(e){}"' : '';
var tag = hs.ie ? '<iframe name="hsIframe'+ this.key+ '" '+ onload +'/>' : 'iframe';
this.iframe = hs.createElement(tag,
{ name: 'hsIframe'+ this.key, frameBorder: 0, allowTransparency: true },
{ width: this.objectWidth +'px', height: h +'px' },
this.body);
if (this.objectLoadTime == 'before') {
if (!hs.ie) this.iframe.onload = function () { try { exp.contentLoaded(); } catch (e) {}};
}
if (hs.safari) this.iframe.src = null;
this.iframe.src = hs.getSrc(this.a);
if (this.objectLoadTime == 'after') this.correctIframeSize();
} else if (this.swfObject) {
this.body.id = this.body.id || 'hs-flash-id-' + this.key;
this.swfObject.write(this.body.id);
}
this.hasExtendedContent = true;
},
htmlGetSize : function() {
if (this.iframe && !this.objectHeight) { // loadtime before
try {
var doc = this.iframe.contentDocument || this.iframe.contentWindow.document;
var clearing = doc.createElement('div');
clearing.style.clear = 'both';
doc.body.appendChild(clearing);
var h = clearing.offsetTop;
if (hs.ie) h += parseInt(doc.body.currentStyle.marginTop)
+ parseInt(doc.body.currentStyle.marginBottom) - 1;
this.iframe.style.height = this.body.style.height = h +'px';
} catch (e) { // other domain
this.iframe.style.height = '300px';
}
}
this.innerContent.appendChild(hs.clearing);
if (!this.newWidth) this.newWidth = this.innerContent.offsetWidth;
this.newHeight = this.innerContent.offsetHeight;
this.innerContent.removeChild(hs.clearing);
if (hs.ie && this.newHeight > parseInt(this.innerContent.currentStyle.height)) { // ie css bug
this.newHeight = parseInt(this.innerContent.currentStyle.height);
}
},
correctIframeSize : function () {
var wDiff = this.innerContent.offsetWidth - this.ruler.offsetWidth;
if (wDiff < 0) wDiff = 0;
var hDiff = this.innerContent.offsetHeight - this.body.offsetHeight;
hs.setStyles(this.iframe, { width: (this.x.span - wDiff) +'px',
height: (this.y.span - hDiff) +'px' });
hs.setStyles(this.body, { width: this.iframe.style.width,
height: this.iframe.style.height });
this.scrollingContent = this.iframe;
this.scrollerDiv = this.scrollingContent;
},
htmlSizeOperations : function () {
this.setObjContainerSize(this.innerContent);
if (this.swfObject && this.objectLoadTime == 'before') this.writeExtendedContent();
// handle minimum size
if (this.x.span < this.newWidth && !this.allowWidthReduction) this.x.span = this.newWidth;
if (this.y.span < this.newHeight && !this.allowHeightReduction) this.y.span = this.newHeight;
this.scrollerDiv = this.innerContent;
this.mediumContent = hs.createElement('div', null,
{
width: this.x.span +'px',
position: 'relative',
left: (this.x.min - this.thumbLeft) +'px',
top: (this.y.min - this.thumbTop) +'px'
}, this.content, true);
this.mediumContent.appendChild(this.innerContent);
hs.container.removeChild(this.tempContainer);
hs.setStyles(this.innerContent, { border: 'none', width: 'auto', height: 'auto' });
var node = hs.getElementByClass(this.innerContent, 'DIV', 'highslide-body');
if (node && !this.swfObject && this.objectType != 'iframe') {
var cNode = node; // wrap to get true size
node = hs.createElement(cNode.nodeName, null, {overflow: 'hidden'}, null, true);
cNode.parentNode.insertBefore(node, cNode);
node.appendChild(hs.clearing); // IE6
node.appendChild(cNode);
var wDiff = this.innerContent.offsetWidth - node.offsetWidth;
var hDiff = this.innerContent.offsetHeight - node.offsetHeight;
node.removeChild(hs.clearing);
var kdeBugCorr = hs.safari || navigator.vendor == 'KDE' ? 1 : 0; // KDE repainting bug
hs.setStyles(node, {
width: (this.x.span - wDiff - kdeBugCorr) +'px',
height: (this.y.span - hDiff) +'px',
overflow: 'auto',
position: 'relative'
}
);
if (kdeBugCorr && cNode.offsetHeight > node.offsetHeight) {
node.style.width = (parseInt(node.style.width) + kdeBugCorr) + 'px';
}
this.scrollingContent = node;
this.scrollerDiv = this.scrollingContent;
}
if (this.iframe && this.objectLoadTime == 'before') this.correctIframeSize();
if (!this.scrollingContent && this.y.span < this.mediumContent.offsetHeight) this.scrollerDiv = this.content;
if (this.scrollerDiv == this.content && !this.allowWidthReduction && this.objectType != 'iframe') {
this.x.span += 17; // room for scrollbars
}
if (this.scrollerDiv && this.scrollerDiv.offsetHeight > this.scrollerDiv.parentNode.offsetHeight) {
setTimeout("try { hs.expanders["+ this.key +"].scrollerDiv.style.overflow = 'auto'; } catch(e) {}",
hs.expandDuration);
}
},
justify : function (p) {
var tgt, dim = p == this.x ? 'x' : 'y';
var hasMovedMin = false;
var allowReduce = true;
// calculate p.min
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;
}
if (p.min < p.marginMin) {
tmpMin = p.min;
p.min = p.marginMin;
if (allowReduce) p.span = p.span - (p.min - tmpMin);
}
return p;
},
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
if (hs.padToMinWidth) x.imgSpan = x.span;
x.span = x.minSpan;
if (!x.imgSpan)
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);
}
},
show : function () {
// Selectbox bug
var imgPos = {x: this.x.min - 20, y: this.y.min - 20, w: this.x.span + 40,
h: this.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.appVersion < 9) || navigator.vendor == 'KDE'
|| (hs.ie && hs.ieVersion() < 5.5));
if (hs.hideIframes) this.showHideElements('IFRAME', 'hidden', imgPos);
// Scrollbars bug
if (hs.geckoMac) this.showHideElements('*', 'hidden', imgPos);
if (this.x.imgSpan) this.content.style.margin = '0 auto';
// Apply size change
this.changeSize(
1,
{
x: this.thumbLeft + this.thumbOffsetBorderW - this.offsetBorderW,
y: this.thumbTop + this.thumbOffsetBorderH - this.offsetBorderH,
w: this.thumbWidth,
h: this.thumbHeight,
imgW: this.thumbWidth,
o: hs.outlineStartOffset
},
{
x: this.x.min,
y: this.y.min,
w: this.x.span,
h: this.y.span,
imgW: this.x.imgSpan,
o: this.objOutline ? this.objOutline.offset : 0
},
hs.expandDuration,
hs.expandSteps
);
},
changeSize : function(up, from, to, dur, steps) {
if (up && this.objOutline && !this.outlineWhileAnimating)
this.objOutline.setPosition(this, this.x.min, this.y.min, this.x.span, this.y.span);
else if (!up && this.objOutline) {
if (this.outlineWhileAnimating) this.objOutline.setPosition(this, from.x, from.y, from.w, from.h);
else this.objOutline.destroy(
(this.isHtml && this.preserveContent));
}
if (!up) { // remove children
var n = this.wrapper.childNodes.length;
for (var i = n - 1; i >= 0 ; i--) {
var child = this.wrapper.childNodes[i];
if (child != this.content) {
hs.purge(child);
this.wrapper.removeChild(child);
}
}
}
var dW = (to.w - from.w) / steps,
dImgW = (to.imgW - from.imgW) / steps,
dH = (to.h - from.h) / steps,
dX = (to.x - from.x) / steps,
dY = (to.y - from.y) / steps,
dO = (to.o - from.o) /steps,
t,
exp = this;
for (var i = 1; i <= steps; i++) {
from.w += dW;
from.imgW += dImgW;
from.h += dH;
from.x += dX;
from.y += dY;
from.o += dO;
t = Math.round(i * (dur / steps));
(function(){
var size = i < steps ? from : to, param = {}, pI = i;
for (var x in size) param[x] = size[x];
setTimeout ( function() {
if (up && pI == 1) {
exp.content.style.visibility = 'visible';
exp.a.className += ' highslide-active-anchor';
}
exp.setSize(param);
}, t);
})();
}
if (up) {
setTimeout(function() {
if (exp.objOutline) exp.objOutline.table.style.visibility = "visible";
}, t);
setTimeout(function() {
if (exp.caption) exp.writeCaption();
exp.afterExpand();
}, t +50);
}
else setTimeout(function() { exp.afterClose(); }, t);
},
setSize : function (to) {
try {
if (this.isHtml) {
hs.setStyles(this.content, { width: to.w +'px', height: to.h +'px' });
hs.setStyles(this.mediumContent, { left: (this.x.min - to.x) +'px',
top: (this.y.min - to.y) +'px' });
this.innerContent.style.visibility = 'visible';
} else {
this.wrapper.style.width = (to.w + 2*this.offsetBorderW) +'px';
this.content.style.width = (to.imgW || to.w) +'px';
this.content.style.height = to.h +'px';
}
if (this.objOutline && this.outlineWhileAnimating) {
var o = this.objOutline.offset - to.o;
this.objOutline.setPosition(this, to.x + o, to.y + o, to.w - 2 * o, to.h - 2 * o, 1);
}
hs.setStyles ( this.wrapper,
{
'visibility': 'visible',
'left': to.x +'px',
'top': to.y +'px'
}
);
} catch (e) { window.location.href = hs.getSrc(this.a); }
},
afterExpand : function() {
this.isExpanded = true;
this.focus();
if (this.isHtml && this.objectLoadTime == 'after') this.writeExtendedContent();
if (this.isHtml) {
if (this.iframe) {
try {
var exp = this,
doc = this.iframe.contentDocument || this.iframe.contentWindow.document;
hs.addEventListener(doc, 'mousedown', function () {
if (hs.focusKey != exp.key) exp.focus();
});
} catch(e) {}
if (hs.ie && typeof this.isClosing != 'boolean') // first open
this.iframe.style.width = (this.objectWidth - 1) +'px'; // hasLayout
}
}
this.createOverlays();
if (hs.showCredits) this.writeCredits();
if (this.fullExpandWidth > this.x.span) this.createFullExpand();
if (!this.caption) this.prepareNextOutline();
},
prepareNextOutline : function() {
var key = this.key;
var outlineType = this.outlineType;
new hs.Outline(outlineType,
function () { try { hs.expanders[key].preloadNext(); } catch (e) {} });
},
preloadNext : function() {
var next = hs.getAdjacentAnchor(this.key, 1);
if (next.onclick.toString().match(/hs\.expand/))
var img = hs.createElement('img', { src: hs.getSrc(next) });
},
cancelLoading : function() {
hs.expanders[this.key] = null;
this.a.style.cursor = this.originalCursor;
if (this.loading) hs.loading.style.left = '-9999px';
},
writeCredits : function () {
var credits = hs.createElement('a',
{
href: hs.creditsHref,
className: 'highslide-credits',
innerHTML: hs.creditsText,
title: hs.creditsTitle
}
);
this.createOverlay({ overlayId: credits, position: 'top left'});
},
getCaption : function() {
if (!this.captionId && this.thumbsUserSetId)
this.captionId = 'caption-for-'+ this.thumbsUserSetId;
if (this.captionId) this.caption = hs.getNode(this.captionId);
if (!this.caption && !this.captionText && this.captionEval) try {
this.captionText = eval(this.captionEval);
} catch (e) {}
if (!this.caption && this.captionText) this.caption = hs.createElement('div',
{ className: 'highslide-caption', innerHTML: this.captionText } );
if (!this.caption) {
var next = this.a.nextSibling;
while (next && !hs.isHsAnchor(next)) {
if (/highslide-caption/.test(next.className)) {
this.caption = next.cloneNode(1);
break;
}
next = next.nextSibling;
}
}
if (this.caption) {
this.marginBottom += this.spaceForCaption;
}
},
writeCaption : function() {
try {
hs.setStyles(this.wrapper, { width: this.wrapper.offsetWidth +'px',
height: this.wrapper.offsetHeight +'px' } );
hs.setStyles(this.caption, { visibility: 'hidden', marginTop: hs.safari ? 0 : '-'+ this.y.span +'px'});
this.caption.className += ' highslide-display-block';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -