📄 slide.js
字号:
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);
}
}
}
if (this.fadeInOut) {
from.op = up ? 0 : 1;
to.op = up;
}
var t,
exp = this,
easing = Math[this.easing] || Math.easeInQuad;
if (!up) easing = Math[this.easingClose] || easing;
for (var i = 1; i <= steps; i++) {
t = Math.round(i * (dur / steps));
(function(){
var pI = i, size = {};
for (var x in from)
size[x] = easing(t, from[x], to[x] - from[x], dur);
setTimeout ( function() {
if (up && pI == 1) {
exp.content.style.visibility = 'visible';
exp.a.className += ' highslide-active-anchor';
}
exp.setSize(size);
}, 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 && !isNaN(to.imgW)) ? to.imgW : to.w) +'px'; if (hs.safari) this.content.style.maxWidth = this.content.style.width;
this.content.style.height = to.h +'px';
}
if (to.op) hs.setStyles(this.wrapper, { opacity: to.op });
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.isImage && 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 || null)) {
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';
var height, exp = this;
if (hs.ie && (hs.ieVersion() < 6 || document.compatMode == 'BackCompat')) {
height = this.caption.offsetHeight;
} else {
var temp = hs.createElement('div', {innerHTML: this.caption.innerHTML},
null, null, true); // to get height
this.caption.innerHTML = '';
this.caption.appendChild(temp);
height = this.caption.childNodes[0].offsetHeight;
this.caption.innerHTML = this.caption.childNodes[0].innerHTML;
}
hs.setStyles(this.caption, { overflow: 'hidden', height: 0, zIndex: 2, marginTop: 0 });
this.wrapper.style.height = 'auto';
if (hs.captionSlideSpeed) {
var step = (Math.round(height/50) || 1) * hs.captionSlideSpeed;
} else {
this.placeCaption(height, 1);
return;
}
for (var h = height % step, t = 0; h <= height; h += step, t += 10) {
(function(){
var pH = h, end = (h == height) ? 1 : 0;
setTimeout( function() {
exp.placeCaption(pH, end);
}, t);
})();
}
} catch (e) {}
},
placeCaption : function(height, end) {
if (!this.caption) return;
this.caption.style.height = height +'px';
this.caption.style.visibility = 'visible';
this.y.span = this.wrapper.offsetHeight - 2 * this.offsetBorderH;
var o = this.objOutline;
if (o) {
o.td[4].style.height = (this.wrapper.offsetHeight - 2 * this.objOutline.offset) +'px';
if (o.hasAlphaImageLoader) o.td[3].style.height = o.td[5].style.height = o.td[4].style.height;
}
if (end) this.prepareNextOutline();
},
showHideElements : function (tagName, visibility, imgPos) {
var els = document.getElementsByTagName(tagName);
var prop = tagName == '*' ? 'overflow' : 'visibility';
for (var i = 0; i < els.length; i++) {
if (prop == 'visibility' || (document.defaultView.getComputedStyle(
els[i], "").getPropertyValue('overflow') == 'auto'
|| els[i].getAttribute('hidden-by') != null)) {
var hiddenBy = els[i].getAttribute('hidden-by');
if (visibility == 'visible' && hiddenBy) {
hiddenBy = hiddenBy.replace('['+ this.key +']', '');
els[i].setAttribute('hidden-by', hiddenBy);
if (!hiddenBy) els[i].style[prop] = els[i].origProp;
} else if (visibility == 'hidden') { // hide if behind
var elPos = hs.position(els[i]);
elPos.w = els[i].offsetWidth;
elPos.h = els[i].offsetHeight;
var clearsX = (elPos.x + elPos.w < imgPos.x || elPos.x > imgPos.x + imgPos.w);
var clearsY = (elPos.y + elPos.h < imgPos.y || elPos.y > imgPos.y + imgPos.h);
var wrapperKey = hs.getWrapperKey(els[i]);
if (!clearsX && !clearsY && wrapperKey != this.key) { // element falls behind image
if (!hiddenBy) {
els[i].setAttribute('hidden-by', '['+ this.key +']');
els[i].origProp = els[i].style[prop];
els[i].style[prop] = 'hidden';
} else if (!hiddenBy.match('['+ this.key +']')) {
els[i].setAttribute('hidden-by', hiddenBy + '['+ this.key +']');
}
} else if (hiddenBy == '['+ this.key +']' || hs.focusKey == wrapperKey) { // on move
els[i].setAttribute('hidden-by', '');
els[i].style[prop] = els[i].origProp || '';
} else if (hiddenBy && hiddenBy.match('['+ this.key +']')) {
els[i].setAttribute('hidden-by', hiddenBy.replace('['+ this.key +']', ''));
}
}
}
}
},
focus : function() {
this.wrapper.style.zIndex = hs.zIndexCounter++;
// blur others
for (var i = 0; i < hs.expanders.length; i++) {
if (hs.expanders[i] && i == hs.focusKey) {
var blurExp = hs.expanders[i];
blurExp.content.className += ' highslide-'+ blurExp.contentType +'-blur';
if (blurExp.caption) {
blurExp.caption.className += ' highslide-caption-blur';
}
if (blurExp.isImage) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -