﻿/**
* jquery.Jcrop.min.js v0.9.9 (build:20110607)
* jQuery Image Cropping Plugin
* @author Kelly Hallman <khallman@gmail.com>
* Copyright (c) 2008-2011 Kelly Hallman - released under MIT License
* https://github.com/tapmodo/Jcrop
*/
(function (a) { a.Jcrop = function (b, c) { function br(a) { if (d.allowResize) { if (a) { bc.enableOnly() } else { bc.enableHandles() } } else { bc.disableHandles() } bd.setCursor(d.allowSelect ? "crosshair" : "default"); bc.setCursor(d.allowMove ? "move" : "default"); if (d.hasOwnProperty("setSelect")) { bh(d.setSelect); bc.done(); delete d.setSelect } if (d.hasOwnProperty("trueSize")) { V = d.trueSize[0] / H; W = d.trueSize[1] / I } if (d.hasOwnProperty("bgColor")) { if (l() && d.fadeTime) { J.animate({ backgroundColor: d.bgColor }, { queue: false, duration: d.fadeTime }) } else { J.css("backgroundColor", d.bgColor) } delete d.bgColor } if (d.hasOwnProperty("bgOpacity")) { Q = d.bgOpacity; if (bc.isAwake()) { if (d.fadeTime) { G.fadeTo(d.fadeTime, Q) } else { J.css("opacity", d.opacity) } } delete d.bgOpacity } R = d.maxSize[0] || 0; S = d.maxSize[1] || 0; T = d.minSize[0] || 0; U = d.minSize[1] || 0; if (d.hasOwnProperty("outerImage")) { G.attr("src", d.outerImage); delete d.outerImage } bc.refresh() } function bq(a, b) { bc.release(); bm(); var c = new Image; c.onload = function () { var e = c.width; var f = c.height; var g = d.boxWidth; var h = d.boxHeight; G.width(e).height(f); G.attr("src", a); K.attr("src", a); v(G, g, h); H = G.width(); I = G.height(); K.width(H).height(I); P.width(H + O * 2).height(I + O * 2); J.width(H).height(I); bn(); if (typeof b === "function") { b.call(bs) } }; c.src = a } function bp() { J.remove(); F.show(); a(b).removeData("Jcrop") } function bo() { bc.done(); bd.activateHandlers(null, null) } function bn() { d.disabled = false; br() } function bm() { d.disabled = true; bc.disableHandles(); bc.setCursor("default"); bd.setCursor("default") } function bl(a) { o(a); br() } function bk() { return bb.getFixed() } function bj() { return z(bb.getFixed()) } function bi(a) { bb.setPressed([a[0], a[1]]); bb.setCurrent([a[2], a[3]]); bc.update() } function bh(a) { bi([parseInt(a[0], 10) / V, parseInt(a[1], 10) / W, parseInt(a[2], 10) / V, parseInt(a[3], 10) / W]) } function bg(a, b) { function t() { window.setTimeout(u, l) } var c = parseInt(a[0], 10) / V, e = parseInt(a[1], 10) / W, f = parseInt(a[2], 10) / V, g = parseInt(a[3], 10) / W; if (Z) { return } var h = bb.flipCoords(c, e, f, g), i = bb.getFixed(), j = [i.x, i.y, i.x2, i.y2], k = j, l = d.animationDelay, m = h[0] - j[0], n = h[1] - j[1], o = h[2] - j[2], p = h[3] - j[3], q = 0, r = d.swingSpeed; x = k[0]; y = k[1]; f = k[2]; g = k[3]; bc.animMode(true); var s; var u = function () { return function () { q += (100 - q) / r; k[0] = x + q / 100 * m; k[1] = y + q / 100 * n; k[2] = f + q / 100 * o; k[3] = g + q / 100 * p; if (q >= 99.8) { q = 100 } if (q < 100) { bi(k); t() } else { bc.done(); if (typeof b === "function") { b.call(bs) } } } } (); t() } function bf(a) { J.removeClass().addClass(k("holder")).addClass(a) } function D() { var b = a("<div></div>").addClass(k("tracker")); if (a.browser.msie) { b.css({ opacity: 0, backgroundColor: "white" }) } return b } function C(a) { bb.setCurrent(a); bc.update() } function B(a) { if (d.disabled) { return false } if (!d.allowSelect) { return false } Y = true; e = m(G); bc.disableHandles(); p("crosshair"); var b = n(a); bb.setPressed(b); bc.update(); bd.activateHandlers(C, A); be.watchKeys(); a.stopPropagation(); a.preventDefault(); return false } function A(a) { var b = bb.getFixed(); if (b.w > d.minSelect[0] && b.h > d.minSelect[1]) { bc.enableHandles(); bc.done() } else { bc.release() } bd.setCursor(d.allowSelect ? "crosshair" : "default") } function z(a) { return { x: parseInt(a.x * V, 10), y: parseInt(a.y * W, 10), x2: parseInt(a.x2 * V, 10), y2: parseInt(a.y2 * W, 10), w: parseInt(a.w * V, 10), h: parseInt(a.h * W, 10)} } function v(a, b, c) { var d = a.width(), e = a.height(); if (d > b && b > 0) { d = b; e = b / a.width() * a.height() } if (e > c && c > 0) { e = c; d = c / a.height() * a.width() } V = a.width() / d; W = a.height() / e; a.width(d); a.height(e) } function u(a) { return function (b) { if (d.disabled) { return false } if (a === "move" && !d.allowMove) { return false } Y = true; q(a, n(b)); b.stopPropagation(); b.preventDefault(); return false } } function t(a) { switch (a) { case "n": return "sw"; case "s": return "nw"; case "e": return "nw"; case "w": return "ne"; case "ne": return "sw"; case "nw": return "se"; case "se": return "nw"; case "sw": return "ne" } } function s(a) { var b = a; be.watchKeys(); return function (a) { bb.moveOffset([a[0] - b[0], a[1] - b[1]]); b = a; bc.update() } } function r(a, b) { return function (c) { if (!d.aspectRatio) { switch (a) { case "e": c[1] = b.y2; break; case "w": c[1] = b.y2; break; case "n": c[0] = b.x2; break; case "s": c[0] = b.x2; break } } else { switch (a) { case "e": c[1] = b.y + 1; break; case "w": c[1] = b.y + 1; break; case "n": c[0] = b.x + 1; break; case "s": c[0] = b.x + 1; break } } bb.setCurrent(c); bc.update() } } function q(a, b) { e = m(G); bd.setCursor(a === "move" ? a : a + "-resize"); if (a === "move") { return bd.activateHandlers(s(b), A) } var c = bb.getFixed(); var d = t(a); var f = bb.getCorner(t(d)); bb.setPressed(bb.getCorner(d)); bb.setCurrent(f); bd.activateHandlers(r(a, c), A) } function p(a) { if (a !== f) { bd.setCursor(a); f = a } } function o(b) { if (typeof b !== "object") { b = {} } d = a.extend(d, b); if (typeof d.onChange !== "function") { d.onChange = function () { } } if (typeof d.onSelect !== "function") { d.onSelect = function () { } } if (typeof d.onRelease !== "function") { d.onRelease = function () { } } } function n(a) { return [a.pageX - e[0], a.pageY - e[1]] } function m(b) { var c = a(b).offset(); return [c.left, c.top] } function l() { return a.fx.step.hasOwnProperty("backgroundColor") } function k(a) { return d.baseClass + "-" + a } function j(a) { return parseInt(a, 10) + "%" } function i(a) { return parseInt(a, 10) + "px" } var d = a.extend({}, a.Jcrop.defaults), e, f, g = false; if (a.browser.msie && a.browser.version.split(".")[0] === "6") { g = true } if (typeof b !== "object") { b = a(b)[0] } if (typeof c !== "object") { c = {} } o(c); var E = { border: "none", margin: 0, padding: 0, position: "absolute" }; var F = a(b); var G = F.clone().removeAttr("id").css(E); G.width(F.width()); G.height(F.height()); F.after(G).hide(); v(G, d.boxWidth, d.boxHeight); var H = G.width(), I = G.height(), J = a("<div />").width(H).height(I).addClass(k("holder")).css({ position: "relative", backgroundColor: d.bgColor }).insertAfter(F).append(G); delete d.bgColor; if (d.addClass) { J.addClass(d.addClass) } var K = a("<img />").attr("src", G.attr("src")).css(E).width(H).height(I), L = a("<div />").width(j(100)).height(j(100)).css({ zIndex: 310, position: "absolute", overflow: "hidden" }).append(K), M = a("<div />").width(j(100)).height(j(100)).css("zIndex", 320), N = a("<div />").css({ position: "absolute", zIndex: 300 }).insertBefore(G).append(L, M); if (g) { N.css({ overflowY: "hidden" }) } var O = d.boundary; var P = D().width(H + O * 2).height(I + O * 2).css({ position: "absolute", top: i(-O), left: i(-O), zIndex: 290 }).mousedown(B); var Q = d.bgOpacity, R, S, T, U, V, W, X = true, Y, Z, _; e = m(G); var ba = function () { function b() { if (d.touchSupport === true || d.touchSupport === false) return d.touchSupport; else return a() } function a() { var a = {}, b = ["touchstart", "touchmove", "touchend"], c = document.createElement("div"), d; try { for (d = 0; d < b.length; d++) { var e = b[d]; e = "on" + e; var f = e in c; if (!f) { c.setAttribute(e, "return;"); f = typeof c[e] == "function" } a[b[d]] = f } return a.touchstart && a.touchend && a.touchmove } catch (g) { return false } } return { createDragger: function (a) { return function (b) { b.pageX = b.originalEvent.changedTouches[0].pageX; b.pageY = b.originalEvent.changedTouches[0].pageY; if (d.disabled) { return false } if (a === "move" && !d.allowMove) { return false } Y = true; q(a, n(b)); b.stopPropagation(); b.preventDefault(); return false } }, newSelection: function (a) { a.pageX = a.originalEvent.changedTouches[0].pageX; a.pageY = a.originalEvent.changedTouches[0].pageY; return B(a) }, isSupported: a, support: b()} } (); var bb = function () { function r(a) { return { x: a[0], y: a[1], x2: a[2], y2: a[3], w: a[2] - a[0], h: a[3] - a[1]} } function q() { var d = c - a, f = e - b, g; if (R && Math.abs(d) > R) { c = d > 0 ? a + R : a - R } if (S && Math.abs(f) > S) { e = f > 0 ? b + S : b - S } if (U / W && Math.abs(f) < U / W) { e = f > 0 ? b + U / W : b - U / W } if (T / V && Math.abs(d) < T / V) { c = d > 0 ? a + T / V : a - T / V } if (a < 0) { c -= a; a -= a } if (b < 0) { e -= b; b -= b } if (c < 0) { a -= c; c -= c } if (e < 0) { b -= e; e -= e } if (c > H) { g = c - H; a -= g; c -= g } if (e > I) { g = e - I; b -= g; e -= g } if (a > H) { g = a - I; e -= g; b -= g } if (b > I) { g = b - I; e -= g; b -= g } return r(p(a, b, c, e)) } function p(a, b, c, d) { var e = a, f = c, g = b, h = d; if (c < a) { e = c; f = a } if (d < b) { g = d; h = b } return [Math.round(e), Math.round(g), Math.round(f), Math.round(h)] } function o(a) { if (a[0] < 0) { a[0] = 0 } if (a[1] < 0) { a[1] = 0 } if (a[0] > H) { a[0] = H } if (a[1] > I) { a[1] = I } return [a[0], a[1]] } function n() { if (!d.aspectRatio) { return q() } var f = d.aspectRatio, g = d.minSize[0] / V, i = d.maxSize[0] / V, j = d.maxSize[1] / W, k = c - a, l = e - b, m = Math.abs(k), n = Math.abs(l), o = m / n, s, t; if (i === 0) { i = H * 10 } if (j === 0) { j = I * 10 } if (o < f) { t = e; w = n * f; s = k < 0 ? a - w : w + a; if (s < 0) { s = 0; h = Math.abs((s - a) / f); t = l < 0 ? b - h : h + b } else if (s > H) { s = H; h = Math.abs((s - a) / f); t = l < 0 ? b - h : h + b } } else { s = c; h = m / f; t = l < 0 ? b - h : b + h; if (t < 0) { t = 0; w = Math.abs((t - b) * f); s = k < 0 ? a - w : w + a } else if (t > I) { t = I; w = Math.abs(t - b) * f; s = k < 0 ? a - w : w + a } } if (s > a) { if (s - a < g) { s = a + g } else if (s - a > i) { s = a + i } if (t > b) { t = b + (s - a) / f } else { t = b - (s - a) / f } } else if (s < a) { if (a - s < g) { s = a - g } else if (a - s > i) { s = a - i } if (t > b) { t = b + (a - s) / f } else { t = b - (a - s) / f } } if (s < 0) { a -= s; s = 0 } else if (s > H) { a -= s - H; s = H } if (t < 0) { b -= t; t = 0 } else if (t > I) { b -= t - I; t = I } return r(p(a, b, s, t)) } function m(a) { var b = n(); switch (a) { case "ne": return [b.x2, b.y]; case "nw": return [b.x, b.y]; case "se": return [b.x2, b.y2]; case "sw": return [b.x, b.y2] } } function l(d) { var f = d[0], g = d[1]; if (0 > a + f) { f -= f + a } if (0 > b + g) { g -= g + b } if (I < e + g) { g += I - (e + g) } if (H < c + f) { f += H - (c + f) } a += f; c += f; b += g; e += g } function k() { return [f, g] } function j(a) { a = o(a); f = a[0] - c; g = a[1] - e; c = a[0]; e = a[1] } function i(d) { d = o(d); c = a = d[0]; e = b = d[1] } var a = 0, b = 0, c = 0, e = 0, f, g; return { flipCoords: p, setPressed: i, setCurrent: j, getOffset: k, moveOffset: l, getCorner: m, getFixed: n} } (); var bc = function () { function F() { E(false); t() } function E(a) { if (Z === a) { C() } else { B() } } function C() { g = false; M.hide() } function B() { g = true; if (d.allowResize) { q(bb.getFixed()); M.show(); return true } } function A() { if (g) { q(bb.getFixed()); M.show() } } function y() { C(); N.hide(); if (d.bgFade) { G.fadeTo(d.fadeTime, 1) } else { G.css("opacity", 1) } b = false; d.onRelease.call(bs) } function x() { N.show(); if (d.bgFade) { G.fadeTo(d.fadeTime, Q) } else { G.css("opacity", Q) } b = true } function w() { var a = bb.getFixed(); s(a.w, a.h); r(a.x, a.y); if (g) { q(a) } if (!b) { x() } d.onChange.call(bs, z(a)) } function v() { if (b) { return w() } } function t() { var a = bb.getFixed(); bb.setPressed([a.x, a.y]); bb.setCurrent([a.x2, a.y2]); v() } function s(a, b) { N.width(a).height(b) } function r(a, b) { K.css({ top: i(-b), left: i(-a) }); N.css({ top: i(b), left: i(a) }) } function q(a) { var b = Math.round(a.h / 2 - h), c = Math.round(a.w / 2 - h), d = -h + 1, e = -h + 1, g = a.w - h, j = a.h - h, k, l; if (f.e) { f.e.css({ top: i(b), left: i(g) }); f.w.css({ top: i(b) }); f.s.css({ top: i(j), left: i(c) }); f.n.css({ left: i(c) }) } if (f.ne) { f.ne.css({ left: i(g) }); f.se.css({ top: i(j), left: i(g) }); f.sw.css({ top: i(j) }) } if (f.b) { f.b.css({ top: i(j) }); f.r.css({ left: i(g) }) } } function p(a) { var b; for (b = 0; b < a.length; b++) { f[a[b]] = n(a[b]) } } function o(a) { var b = d.handleSize, e = b, f = b, g = h, k = h; switch (a) { case "n": case "s": f = j(100); break; case "e": case "w": e = j(100); break } return m(a, c++).width(f).height(e).css({ top: i(-g + 1), left: i(-k + 1) }) } function n(a) { return m(a, c++).css({ top: i(-h + 1), left: i(-h + 1), opacity: d.handleOpacity }).addClass(k("handle")) } function m(b, c) { var d = a("<div />").mousedown(u(b)).css({ cursor: b + "-resize", position: "absolute", zIndex: c }); if (ba.support) { d.bind("touchstart", ba.createDragger(b)) } M.append(d); return d } function l(b) { var c = a("<div />").css({ position: "absolute", opacity: d.borderOpacity }).addClass(k(b)); L.append(c); return c } var b, c = 370; var e = {}; var f = {}; var g = false; var h = d.handleOffset; if (d.drawBorders) { e = { top: l("hline"), bottom: l("hline bottom"), left: l("vline"), right: l("vline right")} } if (d.dragEdges) { f.t = o("n"); f.b = o("s"); f.r = o("e"); f.l = o("w") } if (d.sideHandles) { p(["n", "s", "e", "w"]) } if (d.cornerHandles) { p(["sw", "nw", "ne", "se"]) } var H = D().mousedown(u("move")).css({ cursor: "move", position: "absolute", zIndex: 360 }); if (ba.support) { H.bind("touchstart.jcrop", ba.createDragger("move")) } L.append(H); C(); return { updateVisible: v, update: w, release: y, refresh: t, isAwake: function () { return b }, setCursor: function (a) { H.css("cursor", a) }, enableHandles: B, enableOnly: function () { g = true }, showHandles: A, disableHandles: C, animMode: E, done: F} } (); var bd = function () { function m(a) { P.css("cursor", a) } function l(a) { a.pageX = a.originalEvent.changedTouches[0].pageX; a.pageY = a.originalEvent.changedTouches[0].pageY; return i(a) } function k(a) { a.pageX = a.originalEvent.changedTouches[0].pageX; a.pageY = a.originalEvent.changedTouches[0].pageY; return h(a) } function j(a, d) { Y = true; b = a; c = d; f(); return false } function i(a) { a.preventDefault(); a.stopPropagation(); if (Y) { Y = false; c(n(a)); if (bc.isAwake()) { d.onSelect.call(bs, z(bb.getFixed())) } g(); b = function () { }; c = function () { } } return false } function h(a) { b(n(a)); return false } function g() { P.css({ zIndex: 290 }); if (e) { a(document).unbind("mousemove", h).unbind("mouseup", i) } } function f() { P.css({ zIndex: 450 }); if (e) { a(document).bind("mousemove", h).bind("mouseup", i) } } var b = function () { }, c = function () { }, e = d.trackDocument; if (ba.support) { a(document).bind("touchmove", k).bind("touchend", l) } if (!e) { P.mousemove(h).mouseup(i).mouseout(i) } G.before(P); return { activateHandlers: j, setCursor: m} } (); var be = function () { function i(a) { if (a.ctrlKey) { return true } _ = a.shiftKey ? true : false; var b = _ ? 10 : 1; switch (a.keyCode) { case 37: h(a, -b, 0); break; case 39: h(a, b, 0); break; case 38: h(a, 0, -b); break; case 40: h(a, 0, b); break; case 27: bc.release(); break; case 9: return true } return false } function h(a, b, c) { if (d.allowMove) { bb.moveOffset([b, c]); bc.updateVisible() } a.preventDefault(); a.stopPropagation() } function f(a) { b.hide() } function e() { if (d.keySupport) { b.show(); b.focus() } } var b = a('<input type="radio" />').css({ position: "fixed", left: "-120px", width: "12px" }), c = a("<div />").css({ position: "absolute", overflow: "hidden" }).append(b); if (d.keySupport) { b.keydown(i).blur(f); if (g || !d.fixedSupport) { b.css({ position: "absolute", left: "-20px" }); c.append(b).insertBefore(G) } else { b.insertBefore(G) } } return { watchKeys: e} } (); if (ba.support) { P.bind("touchstart", ba.newSelection) } M.hide(); br(true); var bs = { setImage: bq, animateTo: bg, setSelect: bh, setOptions: bl, tellSelect: bj, tellScaled: bk, setClass: bf, disable: bm, enable: bn, cancel: bo, release: bc.release, destroy: bp, focus: be.watchKeys, getBounds: function () { return [H * V, I * W] }, getWidgetSize: function () { return [H, I] }, getScaleFactor: function () { return [V, W] }, ui: { holder: J, selection: N} }; if (a.browser.msie) { J.bind("selectstart", function () { return false }) } F.data("Jcrop", bs); return bs }; a.fn.Jcrop = function (b, c) { function d(d) { var e = typeof b === "object" ? b : {}; var f = e.useImg || d.src; var g = new Image; g.onload = function () { function f() { if (!g.width || !g.height) { window.setTimeout(f, 50) } else { b() } } function b() { var b = a.Jcrop(d, e); if (typeof c === "function") { c.call(b) } } window.setTimeout(f, 50) }; g.src = f } this.each(function () { if (a(this).data("Jcrop")) { if (b === "api") { return a(this).data("Jcrop") } else { a(this).data("Jcrop").setOptions(b) } } else { d(this) } }); return this }; a.Jcrop.defaults = { allowSelect: true, allowMove: true, allowResize: true, trackDocument: true, baseClass: "jcrop", addClass: null, bgColor: "black", bgOpacity: .6, bgFade: false, borderOpacity: .4, handleOpacity: .5, handleSize: 9, handleOffset: 5, aspectRatio: 0, keySupport: true, cornerHandles: true, sideHandles: true, drawBorders: true, dragEdges: true, fixedSupport: true, touchSupport: null, boxWidth: 0, boxHeight: 0, boundary: 2, fadeTime: 400, animationDelay: 20, swingSpeed: 3, minSelect: [0, 0], maxSize: [0, 0], minSize: [0, 0], onChange: function () { }, onSelect: function () { }, onRelease: function () { } } })(jQuery)
