(function ($) { $.fn.jqzoom = function (g) { var h = { zoomtype: 'standard', zoomwidth: 200, zoomheight: 200, xoffset: 10, yoffset: 0, position: "right", lens: true, lensreset: false, imageopacity: 0.3, title: true, alwayson: false, showeffect: 'show', hideeffect: 'hide', fadeinspeed: 'fast', fadeoutspeed: 'slow', preloadimages: false, showpreload: true, preloadtext: 'loading zoom', preloadposition: 'center' }; g = g || {}; $.extend(h, g); return this.each(function () { var a = $(this); var d = a.attr('title'); $(a).removeattr('title'); $(a).css('outline-style', 'none'); $(a).css('text-decoration', 'none'); var f = $(a).attr('rel'); var g = $("img", this); var j = g.attr('title'); g.removeattr('title'); var k = new smallimage(g); var l = {}; var m = 0; var n = 0; var p = null; p = new loader(); var q = (trim(d).length > 0) ? d : (trim(j).length > 0) ? j : null; var r = new zoomtitle(); var s = new largeimage(a[0].href); var t = new lens(); var u = {}; var v = false; var y = {}; var z = null; var a = false; var b = {}; var c = 0; var d = false; var e = false; var f = false; k.loadimage(); $(this).click(function () { return false }); $(this).hover(function (e) { b.x = e.pagex; b.y = e.pagey; k.setpos(); activate() }, function () { k.setpos(); deactivate() }); if (h.alwayson) { settimeout(function () { activate() }, 150) } function activate() { if (!a) { k.findborder(); a = true; j = g.attr('title'); g.removeattr('title'); d = a.attr('title'); $(a).removeattr('title'); s = new largeimage(a[0].href); if (!v || $.browser.safari) { s.loadimage() } else { if (h.zoomtype != 'innerzoom') { z = new stage(); z.activate() } t = new lens; t.activate() } a[0].blur(); return false } }; function deactivate() { if (h.zoomtype == 'reverse' && !h.alwayson) { g.css({ 'opacity': 1 }) } if (!h.alwayson) { a = false; v = false; $(t.node).unbind('mousemove'); t.remove(); if ($('div.jqzoomwindow').length > 0) { z.remove() } if ($('div.jqzoomtitle').length > 0) { r.remove() } g.attr('title', j); a.attr('title', d); $().unbind(); a.unbind('mousemove'); c = 0; if (jquery('.zoom_ieframe').length > 0) { jquery('.zoom_ieframe').remove() } } else { if (h.lensreset) { switch (h.zoomtype) { case 'innerzoom': s.setcenter(); break; default: t.center(); break } } } if (h.alwayson) { activate() } }; function smallimage(c) { this.node = c[0]; this.loadimage = function () { this.node.src = c[0].src }; this.findborder = function () { var a = ''; a = $(g).css('border-top-width'); m = ''; var b = ''; b = $(g).css('border-left-width'); n = ''; if (a) { for (i = 0; i < 3; i++) { var x = []; x = a.substr(i, 1); if (isnan(x) == false) { m = m + '' + a.substr(i, 1) } else { break } } } if (b) { for (i = 0; i < 3; i++) { if (!isnan(b.substr(i, 1))) { n = n + b.substr(i, 1) } else { break } } } m = (m.length > 0) ? eval(m) : 0; n = (n.length > 0) ? eval(n) : 0 }; this.node.onload = function () { a.css({ 'cursor': 'crosshair', 'display': 'block' }); if (a.css('position') != 'absolute' && a.parent().css('position')) { a.css({ 'cursor': 'crosshair', 'position': 'relative', 'display': 'block' }); } //�˴��ж�����с if ($(this).width() == $(this).height() || ($(this).width() == 300 && $(this).height() == 248)) { } else { var _width = math.abs(parseint((300 - parseint($(this).width())) / 2)); var _height = math.abs(parseint((248 - parseint($(this).height())) / 2)); var _pad = _height + "px 0 0 " + _width + "px"; // alert(_pad); a.parent().css('padding', _pad); a.parent().css('height', (248 - _height) + "px"); a.parent().css('width', (300 - _width) + "px"); } if (a.parent().css('position') != 'absolute') { a.parent().css('position', 'relative') } else { } if ($.browser.safari || $.browser.opera) { $(g).css({ position: 'absolute', top: '0px', left: '0px' }) } if ($.browser.msie && ($.browser.version == "6.0") && !$.support.style) { if ($(this).width() > $(this).height()) { a.children("img").css({ 'width': '300px' }) var _height = math.abs(parseint((248 - parseint($(this).height())) / 2)); var _pad = _height + "px 0 0 0"; a.parent().css('padding', _pad); a.parent().css('height', (300 - _height) + "px"); } else { a.children("img").css({ 'height': '248px' }) var _width = math.abs(parseint((300 - parseint($(this).width())) / 2)); var _pad = "0 0 0 " + _width + "px"; a.parent().css('padding', _pad); a.parent().css('height', (300 - _width) + "px"); } } l.w = $(this).width(); l.h = $(this).height(); l.pos = $(this).offset(); l.pos.l = $(this).offset().left; l.pos.t = $(this).offset().top; l.pos.r = l.w + l.pos.l; l.pos.b = l.h + l.pos.t; a.height(l.h); a.width(l.w); if (h.preloadimages) { k.setpos(); s.loadimage() } }; return this }; smallimage.prototype.setpos = function () { l.pos = $(g).offset(); l.pos.l = $(g).offset().left; l.pos.t = $(g).offset().top; l.pos.r = l.w + l.pos.l; l.pos.b = l.h + l.pos.t }; function lens() { this.node = document.createelement("div"); $(this.node).addclass('jqzoompup'); this.node.onerror = function () { $(t.node).remove(); t = new lens(); t.activate() }; this.loadlens = function () { switch (h.zoomtype) { case 'reverse': this.image = new image(); this.image.src = k.node.src; this.node.appendchild(this.image); $(this.node).css({ 'opacity': 1 }); break; case 'innerzoom': this.image = new image(); this.image.src = s.node.src; this.node.appendchild(this.image); $(this.node).css({ 'opacity': 1 }); break; default: break } switch (h.zoomtype) { case 'innerzoom': u.w = l.w; u.h = l.h; break; default: u.w = (h.zoomwidth) / y.x; u.h = (h.zoomheight) / y.y; break } $(this.node).css({ width: u.w + 'px', height: u.h + 'px', position: 'absolute', display: 'none', borderwidth: 1 + 'px' }); a.append(this.node) }; return this }; lens.prototype.activate = function () { this.loadlens(); switch (h.zoomtype) { case 'reverse': g.css({ 'opacity': h.imageopacity }); (h.alwayson) ? t.center() : t.setposition(null); a.bind('mousemove', function (e) { b.x = e.pagex; b.y = e.pagey; t.setposition(e) }); break; case 'innerzoom': $(this.node).css({ top: 0, left: 0 }); if (h.title) { r.loadtitle() } s.setcenter(); a.bind('mousemove', function (e) { b.x = e.pagex; b.y = e.pagey; s.setinner(e) }); break; default: (h.alwayson) ? t.center() : t.setposition(null); $(a).bind('mousemove', function (e) { b.x = e.pagex; b.y = e.pagey; t.setposition(e) }); break } return this }; lens.prototype.setposition = function (e) { if (e) { b.x = e.pagex; b.y = e.pagey } if (c == 0) { var b = (l.w) / 2 - (u.w) / 2; var c = (l.h) / 2 - (u.h) / 2; $('div.jqzoompup').show(); if (h.lens) { this.node.style.visibility = 'visible' } else { this.node.style.visibility = 'hidden'; $('div.jqzoompup').hide() } c = 1 } else { var b = b.x - l.pos.l - (u.w) / 2; var c = b.y - l.pos.t - (u.h) / 2 } if (overleft()) { b = 0 + n } else if (overright()) { if ($.browser.msie && $.browser.version < 7) { b = l.w - u.w + n - 1 } else { b = l.w - u.w + n - 1 } } if (overtop()) { c = 0 + m } else if (overbottom()) { if ($.browser.msie && $.browser.version < 7) { c = l.h - u.h + m - 1 } else { c = l.h - u.h - 1 + m } } b = parseint(b); c = parseint(c); $('div.jqzoompup', a).css({ top: c, left: b }); if (h.zoomtype == 'reverse') { $('div.jqzoompup img', a).css({ 'position': 'absolute', 'top': -(c - m + 1), 'left': -(b - n + 1) }) } this.node.style.left = b + 'px'; this.node.style.top = c + 'px'; s.setposition(); function overleft() { return b.x - (u.w + 2 * 1) / 2 - n < l.pos.l } function overright() { return b.x + (u.w + 2 * 1) / 2 > l.pos.r + n } function overtop() { return b.y - (u.h + 2 * 1) / 2 - m < l.pos.t } function overbottom() { return b.y + (u.h + 2 * 1) / 2 > l.pos.b + m } return this }; lens.prototype.center = function () { $('div.jqzoompup', a).css('display', 'none'); var b = (l.w) / 2 - (u.w) / 2; var c = (l.h) / 2 - (u.h) / 2; this.node.style.left = b + 'px'; this.node.style.top = c + 'px'; $('div.jqzoompup', a).css({ top: c, left: b }); if (h.zoomtype == 'reverse') { $('div.jqzoompup img', a).css({ 'position': 'absolute', 'top': -(c - m + 1), 'left': -(b - n + 1) }) } s.setposition(); if ($.browser.msie) { $('div.jqzoompup', a).show() } else { settimeout(function () { $('div.jqzoompup').fadein('fast') }, 10) } }; lens.prototype.getoffset = function () { var o = {}; o.left = parseint(this.node.style.left); o.top = parseint(this.node.style.top); return o }; lens.prototype.remove = function () { if (h.zoomtype == 'innerzoom') { $('div.jqzoompup', a).fadeout('fast', function () { $(this).remove() }) } else { $('div.jqzoompup', a).remove() } }; lens.prototype.findborder = function () { var a = ''; a = $('div.jqzoompup').css('bordertop'); lensbtop = ''; var b = ''; b = $('div.jqzoompup').css('borderleft'); lensbleft = ''; if ($.browser.msie) { var c = a.split(' '); a = c[1]; var c = b.split(' '); b = c[1] } if (a) { for (i = 0; i < 3; i++) { var x = []; x = a.substr(i, 1); if (isnan(x) == false) { lensbtop = lensbtop + '' + a.substr(i, 1) } else { break } } } if (b) { for (i = 0; i < 3; i++) { if (!isnan(b.substr(i, 1))) { lensbleft = lensbleft + b.substr(i, 1) } else { break } } } lensbtop = (lensbtop.length > 0) ? eval(lensbtop) : 0; lensbleft = (lensbleft.length > 0) ? eval(lensbleft) : 0 }; function largeimage(a) { this.url = a; this.node = new image(); this.loadimage = function () { if (!this.node) this.node = new image(); this.node.style.position = 'absolute'; this.node.style.display = 'none'; this.node.style.left = '-5000px'; this.node.style.top = '10px'; p = new loader(); if (h.showpreload && !d) { p.show(); d = true } document.body.appendchild(this.node); this.node.src = this.url }; this.node.onload = function () { this.style.display = 'block'; var w = math.round($(this).width()); var h = math.round($(this).height()); this.style.display = 'none'; y.x = (w / l.w); y.y = (h / l.h); if ($('div.preload').length > 0) { $('div.preload').remove() } v = true; if (h.zoomtype != 'innerzoom' && a) { z = new stage(); z.activate() } if (a) { t = new lens(); t.activate() } if ($('div.preload').length > 0) { $('div.preload').remove() } }; return this }; largeimage.prototype.setposition = function () { this.node.style.left = math.ceil(-y.x * parseint(t.getoffset().left) + n) + 'px'; this.node.style.top = math.ceil(-y.y * parseint(t.getoffset().top) + m) + 'px' }; largeimage.prototype.setinner = function (e) { this.node.style.left = math.ceil(-y.x * math.abs(e.pagex - l.pos.l)) + 'px'; this.node.style.top = math.ceil(-y.y * math.abs(e.pagey - l.pos.t)) + 'px'; $('div.jqzoompup img', a).css({ 'position': 'absolute', 'top': this.node.style.top, 'left': this.node.style.left }) }; largeimage.prototype.setcenter = function () { this.node.style.left = math.ceil(-y.x * math.abs((l.w) / 2)) + 'px'; this.node.style.top = math.ceil(-y.y * math.abs((l.h) / 2)) + 'px'; $('div.jqzoompup img', a).css({ 'position': 'absolute', 'top': this.node.style.top, 'left': this.node.style.left }) }; function stage() { var a = jquery(g).offset().left; var b = jquery(g).offset().top; this.node = document.createelement("div"); $(this.node).addclass('jqzoomwindow'); $(this.node).css({ position: 'absolute', width: math.round(h.zoomwidth) + 'px', height: math.round(h.zoomheight) + 'px', display: 'none', zindex: 10000, overflow: 'hidden' }); switch (h.position) { case "right": a = (a + $(g).width() + math.abs(h.xoffset) + h.zoomwidth < $(document).width()) ? (a + $(g).width() + math.abs(h.xoffset)) : (a - h.zoomwidth - 10); topwindow = b + h.yoffset + h.zoomheight; b = (topwindow < $(document).height() && topwindow > 0) ? b + h.yoffset : b; break; case "left": a = (l.pos.l - math.abs(h.xoffset) - h.zoomwidth > 0) ? (l.pos.l - math.abs(h.xoffset) - h.zoomwidth) : (l.pos.l + l.w + 10); topwindow = l.pos.t + h.yoffset + h.zoomheight; b = (topwindow < $(document).height() && topwindow > 0) ? l.pos.t + h.yoffset : l.pos.t; break; case "top": b = (l.pos.t - math.abs(h.yoffset) - h.zoomheight > 0) ? (l.pos.t - math.abs(h.yoffset) - h.zoomheight) : (l.pos.t + l.h + 10); leftwindow = l.pos.l + h.xoffset + h.zoomwidth; a = (leftwindow < $(document).width() && leftwindow > 0) ? l.pos.l + h.xoffset : l.pos.l; break; case "bottom": b = (l.pos.b + math.abs(h.yoffset) + h.zoomheight < $(document).height()) ? (l.pos.b + math.abs(h.yoffset)) : (l.pos.t - h.zoomheight - 10); leftwindow = l.pos.l + h.xoffset + h.zoomwidth; a = (leftwindow < $(document).width() && leftwindow > 0) ? l.pos.l + h.xoffset : l.pos.l; break; default: a = (l.pos.l + l.w + h.xoffset + h.zoomwidth < $(document).width()) ? (l.pos.l + l.w + math.abs(h.xoffset)) : (l.pos.l - h.zoomwidth - math.abs(h.xoffset)); b = (l.pos.b + math.abs(h.yoffset) + h.zoomheight < $(document).height()) ? (l.pos.b + math.abs(h.yoffset)) : (l.pos.t - h.zoomheight - math.abs(h.yoffset)); break } this.node.style.left = a + 'px'; this.node.style.top = b + 'px'; return this }; stage.prototype.activate = function () { if (!this.node.firstchild) this.node.appendchild(s.node); if (h.title) { r.loadtitle() } document.body.appendchild(this.node); switch (h.showeffect) { case 'show': $(this.node).show(); break; case 'fadein': $(this.node).fadein(h.fadeinspeed); break; default: $(this.node).show(); break } $(this.node).show(); if ($.browser.msie && $.browser.version < 7) { this.ieframe = $('').css({ position: "absolute", left: this.node.style.left, top: this.node.style.top, zindex: 99, width: (h.zoomwidth + 2), height: (h.zoomheight) }).insertbefore(this.node) }; s.node.style.display = 'block' }; stage.prototype.remove = function () { switch (h.hideeffect) { case 'hide': $('.jqzoomwindow').remove(); break; case 'fadeout': $('.jqzoomwindow').fadeout(h.fadeoutspeed); break; default: $('.jqzoomwindow').remove(); break } }; function zoomtitle() { this.node = jquery('
').addclass('jqzoomtitle').html('' + q + ''); this.loadtitle = function () { if (h.zoomtype == 'innerzoom') { $(this.node).css({ position: 'absolute', top: l.pos.b + 3, left: (l.pos.l + 1), width: l.w }).appendto('body') } else { $(this.node).appendto(z.node) } } }; zoomtitle.prototype.remove = function () { $('.jqzoomtitle').remove() }; function loader() { this.node = document.createelement("div"); $(this.node).addclass('preload'); $(this.node).html(h.preloadtext); $(this.node).appendto(a).css('visibility', 'hidden'); this.show = function () { switch (h.preloadposition) { case 'center': loadertop = (l.h - $(this.node).height()) / 2; loaderleft = (l.w - $(this.node).width()) / 2; $(this.node).css({ top: loadertop, left: loaderleft }); break; default: var a = this.getoffset(); break } $(this.node).css({ position: 'absolute', visibility: 'visible' }) }; return this }; loader.prototype.getoffset = function () { var o = null; o = $('div.preload').offset(); return o } }) } })(jquery); function trim(a) { while (a.substring(0, 1) == ' ') { a = a.substring(1, a.length) } while (a.substring(a.length - 1, a.length) == ' ') { a = a.substring(0, a.length - 1) } return a };