﻿(function ($) { var supportedCSS, styles = document.getElementsByTagName("head")[0].style, toCheck = "transformProperty WebkitTransform OTransform msTransform MozTransform".split(" "); for (var a = 0; a < toCheck.length; a++) if (styles[toCheck[a]] !== undefined) supportedCSS = toCheck[a]; var IE = eval('"v"==""'); jQuery.fn.extend({ ImageRotate: function (a) { if (this.Wilq32 && this.Wilq32.PhotoEffect) return; var b = $.extend(true, {}, a); return (new Wilq32.PhotoEffect(this.get(0), b))._rootObj }, rotate: function (a) { if (this.length === 0 || typeof a == "undefined") return; if (typeof a == "number") a = { angle: a }; var b = []; for (var c = 0, d = this.length; c < d; c++) { var e = this.get(c); if (typeof e.Wilq32 == "undefined") b.push($($(e).ImageRotate(a))); else e.Wilq32.PhotoEffect._handleRotation(a) } return b } }); Wilq32 = window.Wilq32 || {}; Wilq32.PhotoEffect = function () { if (supportedCSS) { return function (a, b) { a.Wilq32 = { PhotoEffect: this }; this._img = this._rootObj = this._eventObj = a; this._handleRotation(b) } } else { return function (a, b) { this._img = a; this._rootObj = document.createElement("span"); this._rootObj.style.display = "inline-block"; this._rootObj.Wilq32 = { PhotoEffect: this }; a.parentNode.insertBefore(this._rootObj, a); if (a.complete) { this._Loader(b) } else { var c = this; jQuery(this._img).bind("load", function () { c._Loader(b) }) } } } } (); Wilq32.PhotoEffect.prototype = { _setupParameters: function (a) { this._parameters = this._parameters || {}; if (typeof this._angle !== "number") this._angle = 0; if (typeof a.angle === "number") this._angle = a.angle; this._parameters.animateTo = typeof a.animateTo === "number" ? a.animateTo : this._angle; this._parameters.easing = a.easing || this._parameters.easing || function (a, b, c, d, e) { return -d * ((b = b / e - 1) * b * b * b - 1) + c }; this._parameters.duration = a.duration || this._parameters.duration || 1e3; this._parameters.callback = a.callback || this._parameters.callback || function () { }; if (a.bind && a.bind != this._parameters.bind) this._BindEvents(a.bind) }, _handleRotation: function (a) { this._setupParameters(a); if (this._angle == this._parameters.animateTo) { this._rotate(this._angle) } else { this._animateStart() } }, _BindEvents: function (a) { if (a && this._eventObj) { if (this._parameters.bind) { var b = this._parameters.bind; for (var c in b) if (b.hasOwnProperty(c)) jQuery(this._eventObj).unbind(c, b[c]) } this._parameters.bind = a; for (var c in a) if (a.hasOwnProperty(c)) jQuery(this._eventObj).bind(c, a[c]) } }, _Loader: function () { if (IE) return function (a) { var b = this._img.width; var c = this._img.height; this._img.parentNode.removeChild(this._img); this._vimage = this.createVMLNode("image"); this._vimage.src = this._img.src; this._vimage.style.height = c + "px"; this._vimage.style.width = b + "px"; this._vimage.style.position = "absolute"; this._vimage.style.top = "0px"; this._vimage.style.left = "0px"; this._container = this.createVMLNode("group"); this._container.style.width = b; this._container.style.height = c; this._container.style.position = "absolute"; this._container.setAttribute("coordsize", b - 1 + "," + (c - 1)); this._container.appendChild(this._vimage); this._rootObj.appendChild(this._container); this._rootObj.style.position = "relative"; this._rootObj.style.width = b + "px"; this._rootObj.style.height = c + "px"; this._rootObj.setAttribute("id", this._img.getAttribute("id")); this._rootObj.className = this._img.className; this._eventObj = this._rootObj; this._handleRotation(a) }; else return function (a) { this._rootObj.setAttribute("id", this._img.getAttribute("id")); this._rootObj.className = this._img.className; this._width = this._img.width; this._height = this._img.height; this._widthHalf = this._width / 2; this._heightHalf = this._height / 2; var b = Math.sqrt(this._height * this._height + this._width * this._width); this._widthAdd = b - this._width; this._heightAdd = b - this._height; this._widthAddHalf = this._widthAdd / 2; this._heightAddHalf = this._heightAdd / 2; this._img.parentNode.removeChild(this._img); this._aspectW = (parseInt(this._img.style.width, 10) || this._width) / this._img.width; this._aspectH = (parseInt(this._img.style.height, 10) || this._height) / this._img.height; this._canvas = document.createElement("canvas"); this._canvas.setAttribute("width", this._width); this._canvas.style.position = "relative"; this._canvas.style.left = -this._widthAddHalf + "px"; this._canvas.style.top = -this._heightAddHalf + "px"; this._canvas.Wilq32 = this._rootObj.Wilq32; this._rootObj.appendChild(this._canvas); this._rootObj.style.width = this._width + "px"; this._rootObj.style.height = this._height + "px"; this._eventObj = this._canvas; this._cnv = this._canvas.getContext("2d"); this._handleRotation(a) } } (), _animateStart: function () { if (this._timer) { clearTimeout(this._timer) } this._animateStartTime = +(new Date); this._animateStartAngle = this._angle; this._animate() }, _animate: function () { var a = +(new Date); var b = a - this._animateStartTime > this._parameters.duration; if (b && !this._parameters.animatedGif) { clearTimeout(this._timer) } else { if (this._canvas || this._vimage || this._img) { var c = this._parameters.easing(0, a - this._animateStartTime, this._animateStartAngle, this._parameters.animateTo - this._animateStartAngle, this._parameters.duration); this._rotate(~ ~(c * 10) / 10) } var d = this; this._timer = setTimeout(function () { d._animate.call(d) }, 10) } if (this._parameters.callback && b) { this._angle = this._parameters.animateTo; this._rotate(this._angle); this._parameters.callback.call(this._rootObj) } }, _rotate: function () { var a = Math.PI / 180; if (IE) return function (a) { this._angle = a; this._container.style.rotation = a % 360 + "deg" }; else if (supportedCSS) return function (a) { this._angle = a; this._img.style[supportedCSS] = "rotate(" + a % 360 + "deg)" }; else return function (b) { this._angle = b; b = b % 360 * a; this._canvas.width = this._width + this._widthAdd; this._canvas.height = this._height + this._heightAdd; this._cnv.translate(this._widthAddHalf, this._heightAddHalf); this._cnv.translate(this._widthHalf, this._heightHalf); this._cnv.rotate(b); this._cnv.translate(-this._widthHalf, -this._heightHalf); this._cnv.scale(this._aspectW, this._aspectH); this._cnv.drawImage(this._img, 0, 0) } } () }; if (IE) { Wilq32.PhotoEffect.prototype.createVMLNode = function () { document.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)"); try { !document.namespaces.rvml && document.namespaces.add("rvml", "urn:schemas-microsoft-com:vml"); return function (a) { return document.createElement("<rvml:" + a + ' class="rvml">') } } catch (a) { return function (a) { return document.createElement("<" + a + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">') } } } () } })(jQuery)
