﻿(function ($) { function CloudZoom(a, b) { var c = $("img", a); var d; var e; var f = null; var g = null; var h = null; var i = null; var j = null; var k = null; var l; var m = 0; var n, o; var p = 0; var q = 0; var r = 0; var s = 0; var t = 0; var u, v; var w = this, x; setTimeout(function () { if (g === null) { var b = a.width(); a.parent().append(format('<div style="width:%0px;position:absolute;top:75%;left:%1px;text-align:center" class="cloud-zoom-loading" >Loading...</div>', b / 3, b / 2 - b / 6)).find(":last").css("opacity", .5) } }, 200); var y = function () { if (k !== null) { k.remove(); k = null } }; this.removeBits = function () { if (h) { h.remove(); h = null } if (i) { i.remove(); i = null } if (j) { j.remove(); j = null } y(); $(".cloud-zoom-loading", a.parent()).remove() }; this.destroy = function () { a.data("zoom", null); if (g) { g.unbind(); g.remove(); g = null } if (f) { f.remove(); f = null } this.removeBits() }; this.fadedOut = function () { if (f) { f.remove(); f = null } this.removeBits() }; this.controlLoop = function () { if (h) { var a = u - c.offset().left - n * .5 >> 0; var d = v - c.offset().top - o * .5 >> 0; if (a < 0) { a = 0 } else if (a > c.outerWidth() - n) { a = c.outerWidth() - n } if (d < 0) { d = 0 } else if (d > c.outerHeight() - o) { d = c.outerHeight() - o } h.css({ left: a, top: d }); h.css("background-position", -a + "px " + -d + "px"); p = a / c.outerWidth() * l.width >> 0; q = d / c.outerHeight() * l.height >> 0; s += (p - s) / b.smoothMove; r += (q - r) / b.smoothMove; f.css("background-position", -(s >> 0) + "px " + (-(r >> 0) + "px")) } m = setTimeout(function () { w.controlLoop() }, 30) }; this.init2 = function (a, b) { t++; if (b === 1) { l = a } if (t === 2) { this.init() } }; this.init = function () { $(".cloud-zoom-loading", a.parent()).remove(); g = a.parent().append(format("<div class='mousetrap' style='background-image:url(\".\");z-index:999;position:absolute;width:370px;height:660px;left:%2px;top:%3px;'></div>", c.outerWidth(), c.outerHeight(), 0, 0)).find(":last"); g.bind("mousemove", this, function (a) { u = a.pageX; v = a.pageY }); g.bind("mouseleave", this, function (a) { clearTimeout(m); if (h) { h.fadeOut(299) } if (i) { i.fadeOut(299) } if (j) { j.fadeOut(299) } f.fadeOut(300, function () { w.fadedOut() }); return false }); g.bind("mouseenter", this, function (d) { u = d.pageX; v = d.pageY; x = d.data; if (f) { f.stop(true, false); f.remove() } var e = b.adjustX, m = b.adjustY; var p = c.outerWidth(); var q = c.outerHeight(); var r = b.zoomWidth; var s = b.zoomHeight; if (b.zoomWidth == "auto") { r = p } if (b.zoomHeight == "auto") { s = q } var t = a.parent(); switch (b.position) { case "top": m -= s; break; case "right": e += p; break; case "bottom": m += q; break; case "left": e -= r; break; case "inside": r = p; s = q; break; default: t = $("#" + b.position); if (!t.length) { t = a; e += p; m += q } else { r = t.innerWidth(); s = t.innerHeight() } } f = t.append(format('<div id="cloud-zoom-big" class="cloud-zoom-big" style="display:none;position:absolute;left:%0px;top:%1px;width:%2px;height:%3px;background-image:url(\'%4\');z-index:99;"></div>', e, m, r, s, l.src)).find(":last"); if (c.attr("title") && b.showTitle) { f.append(format('<div class="cloud-zoom-title">%0</div>', c.attr("title"))).find(":last").css("opacity", b.titleOpacity) } if ($.browser.msie && $.browser.version < 7) { k = $('<iframe frameborder="0" src="#"></iframe>').css({ position: "absolute", left: e, top: m, zIndex: 99, width: r, height: s }).insertBefore(f) } f.fadeIn(500); if (h) { h.remove(); h = null } n = c.outerWidth() / l.width * f.width(); o = c.outerHeight() / l.height * f.height(); h = a.append(format("<div class = 'cloud-zoom-lens' style='display:none;z-index:98;position:absolute;width:%0px;height:%1px;'></div>", n, o)).find(":last"); g.css("cursor", h.css("cursor")); var w = false; if (b.tint) { h.css("background", 'url("' + c.attr("src") + '")'); i = a.append(format('<div style="display:none;position:absolute; left:0px; top:0px; width:%0px; height:%1px; background-color:%2;" />', c.outerWidth(), c.outerHeight(), b.tint)).find(":last"); i.css("opacity", b.tintOpacity); w = true; i.fadeIn(500) } if (b.softFocus) { h.css("background", 'url("' + c.attr("src") + '")'); j = a.append(format('<div style="position:absolute;display:none;top:2px; left:2px; width:%0px; height:%1px;" />', c.outerWidth() - 2, c.outerHeight() - 2, b.tint)).find(":last"); j.css("background", 'url("' + c.attr("src") + '")'); j.css("opacity", .5); w = true; j.fadeIn(500) } if (!w) { h.css("opacity", b.lensOpacity) } if (b.position !== "inside") { h.fadeIn(500) } x.controlLoop(); return }) }; d = new Image; $(d).load(function () { w.init2(this, 0) }); d.src = c.attr("src"); e = new Image; $(e).load(function () { w.init2(this, 1) }); e.src = a.attr("href") } function format(a) { for (var b = 1; b < arguments.length; b++) { a = a.replace("%" + (b - 1), arguments[b]) } return a } $(document).ready(function () { $(".cloud-zoom, .cloud-zoom-gallery").CloudZoom() }); $.fn.CloudZoom = function (options) { try { document.execCommand("BackgroundImageCache", false, true) } catch (e) { } this.each(function () { var relOpts, opts; eval("var\ta = {" + $(this).attr("rel") + "}"); relOpts = a; if ($(this).is(".cloud-zoom")) { $(this).css({ position: "relative", display: "block" }); $("img", $(this)).css({ display: "block" }); if ($(this).parent().attr("id") != "wrap") { $(this).wrap('<div id="wrap" style="top:0px;z-index:3000;position:relative;"></div>') } opts = $.extend({}, $.fn.CloudZoom.defaults, options); opts = $.extend({}, opts, relOpts); $(this).data("zoom", new CloudZoom($(this), opts)) } else if ($(this).is(".cloud-zoom-gallery")) { opts = $.extend({}, relOpts, options); $(this).data("relOpts", opts); $(this).bind("click", $(this), function (a) { var b = a.data.data("relOpts"); $("#" + b.useZoom).data("zoom").destroy(); $("#" + b.useZoom).attr("href", a.data.attr("href")); $("#" + b.useZoom + " img").attr("src", a.data.data("relOpts").smallImage); $("#" + a.data.data("relOpts").useZoom).CloudZoom(); return false }) } }); return this }; $.fn.CloudZoom.defaults = { zoomWidth: "auto", zoomHeight: "auto", position: "right", tint: false, tintOpacity: .5, lensOpacity: .5, softFocus: false, smoothMove: 3, showTitle: true, titleOpacity: .5, adjustX: 0, adjustY: 0} })(jQuery)
