📄 highslide.js
字号:
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();
}
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 {
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();
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';
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';
}
blurExp.content.style.cursor = hs.ie ? 'hand' : 'pointer';
blurExp.content.title = hs.focusTitle;
}
}
// focus this
if (this.objOutline) this.objOutline.table.style.zIndex
= this.wrapper.style.zIndex;
this.content.className = 'highslide-'+ this.contentType;
if (this.caption) {
this.caption.className = this.caption.className.replace(' highslide-caption-blur', '');
}
this.content.title = hs.restoreTitle;
hs.styleRestoreCursor = window.opera ? 'pointer' : 'url('+ hs.graphicsDir + hs.restoreCursor +'), pointer';
if (hs.ie && hs.ieVersion() < 6) hs.styleRestoreCursor = 'hand';
this.content.style.cursor = hs.styleRestoreCursor;
hs.focusKey = this.key;
hs.addEventListener(document, 'keydown', hs.keyHandler);
},
move : function (e) {
this.x.min = e.left + e.dX;
this.y.min = e.top + e.dY;
hs.setStyles(this.wrapper, { left: this.x.min +'px', top: this.y.min +'px' });
if (this.objOutline)
this.objOutline.setPosition(this, this.x.min, this.y.min, this.x.span, this.y.span);
},
close : function() {
if (this.isClosing || !this.isExpanded) return;
this.isClosing = true;
hs.removeEventListener(document, 'keydown', hs.keyHandler);
try {
this.content.style.cursor = 'default';
this.changeSize(
0,
{
x: this.x.min,
y: this.y.min,
w: this.x.span,
h: parseInt(this.content.style.height),
imgW: this.x.imgSpan,
o: this.objOutline ? this.objOutline.offset : 0
},
{
x: this.thumbLeft - this.offsetBorderW + this.thumbOffsetBorderW,
y: this.thumbTop - this.offsetBorderH + this.thumbOffsetBorderH,
w: this.thumbWidth,
h: this.thumbHeight,
imgW: this.thumbWidth,
o: hs.outlineStartOffset
},
hs.restoreDuration,
hs.restoreSteps
);
} catch (e) { this.afterClose(); }
},
createOverlay : function (o) {
var el = o.overlayId;
if (typeof el == 'string') el = hs.getNode(el);
if (!el || typeof el == 'string') return;
var overlay = hs.createElement(
'div',
null,
{
'left' : 0,
'top' : 0,
'position' : 'absolute',
'zIndex' : 3,
'visibility' : 'hidden'
},
this.wrapper,
true
);
if (o.opacity) hs.setStyles(el, { opacity: o.opacity });
el.className += ' highslide-display-block';
overlay.appendChild(el);
overlay.hsPos = o.position;
this.positionOverlay(overlay);
if (o.hideOnMouseOut) overlay.setAttribute('hideOnMouseOut', true);
if (!o.opacity) o.opacity = 1;
overlay.setAttribute('opacity', o.opacity);
hs.fade(overlay, 0, o.opacity);
hs.push(this.overlays, overlay);
},
positionOverlay : function(overlay) {
var left = this.offsetBorderW;
var dLeft = this.x.span - overlay.offsetWidth;
var top = this.offsetBorderH;
var dTop = parseInt(this.content.style.height) - overlay.offsetHeight;
var p = overlay.hsPos || 'center center';
if (/^bottom/.test(p)) top += dTop;
if (/^center/.test(p)) top += dTop / 2;
if (/right$/.test(p)) left += dLeft;
if (/center$/.test(p)) left += dLeft / 2;
overlay.style.left = left +'px';
overlay.style.top = top +'px';
},
createOverlays : function() {
for (var i = 0; i < hs.overlays.length; i++) {
var o = hs.overlays[i];
if ((!o.thumbnailId && !o.slideshowGroup) || o.thumbnailId == this.thumbsUserSetId
|| o.slideshowGroup === this.slideshowGroup) {
this.createOverlay(o);
}
}
},
createFullExpand : function () {
var a = hs.createElement(
'a',
{
href: 'javascript:hs.expanders['+ this.key +'].doFullExpand();',
title: hs.fullExpandTitle,
className: 'highslide-full-expand'
}
);
this.fullExpandLabel = a;
this.createOverlay({ overlayId: a, position: hs.fullExpandPosition,
hideOnMouseOut: true, opacity: hs.fullExpandOpacity });
},
doFullExpand : function () {
try {
hs.purge(this.fullExpandLabel);
this.fullExpandLabel.parentNode.removeChild(this.fullExpandLabel);
this.focus();
this.x.min = parseInt(this.wrapper.style.left) - (this.fullExpandWidth - this.content.width) / 2;
if (this.x.min < hs.marginLeft) this.x.min = hs.marginLeft;
this.wrapper.style.left = this.x.min +'px';
hs.setStyles(this.content, { width: this.fullExpandWidth +'px',
height: this.fullExpandHeight +'px'});
this.x.span = this.fullExpandWidth;
this.wrapper.style.width = (this.x.span + 2*this.offsetBorderW) +'px';
this.y.span = this.wrapper.offsetHeight - 2 * this.offsetBorderH;
if (this.objOutline)
this.objOutline.setPosition(this, this.x.min, this.y.min, this.x.span, this.y.span);
for (var i = 0; i < this.overlays.length; i++)
this.positionOverlay(this.overlays[i]);
this.redoShowHide();
} catch (e) {
window.location.href = this.content.src;
}
},
// on end move and resize
redoShowHide : function() {
var imgPos = {
x: parseInt(this.wrapper.style.left) - 20,
y: parseInt(this.wrapper.style.top) - 20,
w: this.content.offsetWidth + 40,
h: this.content.offsetHeight + 40
+ this.spaceForCaption
};
if (hs.hideSelects) this.showHideElements('SELECT', 'hidden', imgPos);
if (hs.hideIframes) this.showHideElements('IFRAME', 'hidden', imgPos);
if (hs.geckoMac) this.showHideElements('*', 'hidden', imgPos);
},
wrapperMouseHandler : function (e) {
if (!e) e = window.event;
var over = /mouseover/i.test(e.type);
if (!e.target) e.target = e.srcElement; // ie
if (!e.relatedTarget) e.relatedTarget =
over ? e.fromElement : e.toElement; // ie
if (hs.getExpander(e.relatedTarget) == this || hs.dragArgs) return;
for (var i = 0; i < this.overlays.length; i++) {
var o = this.overlays[i];
if (o.getAttribute('hideOnMouseOut')) {
var from = over ? 0 : o.getAttribute('opacity'),
to = over ? o.getAttribute('opacity') : 0;
hs.fade(o, from, to);
}
}
},
afterClose : function () {
this.a.className = this.a.className.replace('highslide-active-anchor', '');
if (hs.hideSelects) this.showHideElements('SELECT', 'visible');
if (hs.hideIframes) this.showHideElements('IFRAME', 'visible');
if (hs.geckoMac) this.showHideElements('*', 'visible');
if (this.objOutline && this.outlineWhileAnimating) this.objOutline.destroy();
hs.purge(this.wrapper);
if (hs.ie && hs.ieVersion() < 5.5) this.wrapper.innerHTML = ''; // crash
else this.wrapper.parentNode.removeChild(this.wrapper);
hs.expanders[this.key] = null;
hs.cleanUp();
}
};
// history
var HsExpander = hs.Expander;
// set handlers
hs.addEventListener(document, 'mousedown', hs.mouseClickHandler);
hs.addEventListener(document, 'mouseup', hs.mouseClickHandler);
hs.addEventListener(window, 'load', hs.preloadImages);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -