📄 highslide-full.js
字号:
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';
if (p.target && p.target.match(/ /)) {
tgt = p.target.split(' ');
p.target = tgt[0];
}
if (p.target && hs.$(p.target)) {
p.min = hs.position(hs.$(p.target))[dim];
if (tgt && tgt[1] && tgt[1].match(/^[-]?[0-9]+px$/)) p.min += parseInt(tgt[1]);
} else 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;
},
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);
}
},
reflow : function () {
hs.setStyles(this.scrollerDiv, { height: 'auto', width: 'auto' });
this.x.span = this.innerContent.offsetWidth;
this.y.span = this.innerContent.offsetHeight;
var size = { width: this.x.span +'px', height: this.y.span +'px' };
hs.setStyles(this.content, size);
if (this.objOutline)
this.objOutline.setPosition(this, this.x.min, this.y.min, this.x.span, this.y.span);
},
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';
hs.fireEvent(this, 'onBeforeExpand');
// 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) {
// transition
var trans = this.transitions,
t = (trans[1] && hs.upcoming
&& hs.getParam(hs.upcoming, 'transitions')[1] == trans[1]) ?
trans[1] : trans[0];
if (this[t]) {
this[t](up, from, to);
return;
}
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);
},
fade : function(up, from, to) {
this.outlineWhileAnimating = false;
var exp = this, t = up ? 250 : 0;
if (up) {
hs.setStyles(this.wrapper, { opacity: 0 });
this.setSize(to);
if (this.caption) {
var ss = hs.captionSlideSpeed;
hs.captionSlideSpeed = 0;
this.writeCaption();
hs.captionSlideSpeed = ss;
}
this.content.style.visibility = 'visible';
hs.fade (this.wrapper, 0, 1);
}
if (this.objOutline) {
this.objOutline.table.style.zIndex = this.wrapper.style.zIndex;
var dir = up || -1;
for (var i = from.o; dir * i <= dir * to.o; i += dir, t += 25) {
(function() {
var o = up ? to.o - i : from.o - i;
setTimeout(function() {
exp.objOutline.setPosition(exp, (exp.x.min + o), (exp.y.min + o),
(exp.x.span - 2 * o), (exp.y.span - 2 * o), 1, t);
}, t);
})();
}
}
if (up) setTimeout(function() { exp.afterExpand(); }, t+50);
else {
setTimeout( function() {
if (exp.objOutline) exp.objOutline.destroy(exp.preserveContent);
hs.fade (exp.wrapper, 1, 0);
setTimeout( function() {
exp.afterClose();
}, 250);
}, 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.dimmingOpacity) hs.dim(this);
if (hs.upcoming == this.a) hs.upcoming = null;
if (!this.caption) this.prepareNextOutline();
if (!this.caption) hs.fireEvent(this, 'onAfterExpand');
},
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;
if (hs.upcoming == this.a) hs.upcoming = null;
hs.unDim();
this.a.style.cursor = this.originalCursor;
if (this.loading) hs.loading.style.left = '-9999px';
hs.fireEvent(this, 'onHideLoading');
},
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 (!hs.fireEvent(this, 'onBeforeGetCaption')) return;
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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -