PageSourceSearch

https://www.carmanmusic.ru/js/jquery.rotate.2.2.js

js carmanmusic.ru collected 2026-10-06 12:09:02 UTC 11,187 bytes, 313 lines download raw bytes

1// VERSION: 2.2 LAST UPDATE: 13.03.2012
2/* 
3 * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
4 * 
5 * Made by Wilq32, [email protected], Wroclaw, Poland, 01.2009
6 * Website: http://code.google.com/p/jqueryrotate/ 
7 */
8
9// Documentation removed from script file (was kinda useless and outdated)
10
11(function($) {
12var supportedCSS,styles=document.getElementsByTagName("head")[0].style,toCheck="transformProperty WebkitTransform OTransform msTransform MozTransform".split(" ");
13for (var a=0;a<toCheck.length;a++) if (styles[toCheck[a]] !== undefined) supportedCSS = toCheck[a];
14// Bad eval to preven google closure to remove it from code o_O
15// After compresion replace it back to var IE = 'v' == '\v'
16var IE = eval('"v"=="\v"');
17
18jQuery.fn.extend({
19    rotate:function(parameters)
20    {
21        if (this.length===0||typeof parameters=="undefined") return;
22            if (typeof parameters=="number") parameters={angle:parameters};
23        var returned=[];
24        for (var i=0,i0=this.length;i<i0;i++)
25            {
26                var element=this.get(i);	
27                if (!element.Wilq32 || !element.Wilq32.PhotoEffect) {
28
29                    var paramClone = $.extend(true, {}, parameters); 
30                    var newRotObject = new Wilq32.PhotoEffect(element,paramClone)._rootObj;
31
32                    returned.push($(newRotObject));
33                }
34                else {
35                    element.Wilq32.PhotoEffect._handleRotation(parameters);
36                }
37            }
38            return returned;
39    },
40    getRotateAngle: function(){
41        var ret = [];
42        for (var i=0,i0=this.length;i<i0;i++)
43            {
44                var element=this.get(i);	
45                if (element.Wilq32 && element.Wilq32.PhotoEffect) {
46                    ret[i] = element.Wilq32.PhotoEffect._angle;
47                }
48            }
49            return ret;
50    },
51    stopRotate: function(){
52        for (var i=0,i0=this.length;i<i0;i++)
53            {
54                var element=this.get(i);	
55                if (element.Wilq32 && element.Wilq32.PhotoEffect) {
56                    clearTimeout(element.Wilq32.PhotoEffect._timer);
57                }
58            }
59    }
60});
61
62// Library agnostic interface
63
64Wilq32=window.Wilq32||{};
65Wilq32.PhotoEffect=(function(){
66
67	if (supportedCSS) {
68		return function(img,parameters){
69			img.Wilq32 = {
70				PhotoEffect: this
71			};
72            
73            this._img = this._rootObj = this._eventObj = img;
74            this._handleRotation(parameters);
75		}
76	} else {
77		return function(img,parameters) {
78			// Make sure that class and id are also copied - just in case you would like to refeer to an newly created object
79            this._img = img;
80
81			this._rootObj=document.createElement('span');
82			this._rootObj.style.display="inline-block";
83			this._rootObj.Wilq32 = 
84				{
85					PhotoEffect: this
86				};
87			img.parentNode.insertBefore(this._rootObj,img);
88			
89			if (img.complete) {
90				this._Loader(parameters);
91			} else {
92				var self=this;
93				// TODO: Remove jQuery dependency
94				jQuery(this._img).bind("load", function()
95				{
96					self._Loader(parameters);
97				});
98			}
99		}
100	}
101})();
102
103Wilq32.PhotoEffect.prototype={
104    _setupParameters : function (parameters){
105		this._parameters = this._parameters || {};
106        if (typeof this._angle !== "number") this._angle = 0 ;
107        if (typeof parameters.angle==="number") this._angle = parameters.angle;
108        this._parameters.animateTo = (typeof parameters.animateTo==="number") ? (parameters.animateTo) : (this._angle); 
109
110        this._parameters.step = parameters.step || this._parameters.step || null;
111		this._parameters.easing = parameters.easing || this._parameters.easing || function (x, t, b, c, d) { return -c * ((t=t/d-1)*t*t*t - 1) + b; }
112		this._parameters.duration = parameters.duration || this._parameters.duration || 1000;
113        this._parameters.callback = parameters.callback || this._parameters.callback || function(){};
114        if (parameters.bind && parameters.bind != this._parameters.bind) this._BindEvents(parameters.bind); 
115	},
116	_handleRotation : function(parameters){
117          this._setupParameters(parameters);
118          if (this._angle==this._parameters.animateTo) {
119              this._rotate(this._angle);
120          }
121          else { 
122              this._animateStart();          
123          }
124	},
125
126	_BindEvents:function(events){
127		if (events && this._eventObj) 
128		{
129            // Unbinding previous Events
130            if (this._parameters.bind){
131                var oldEvents = this._parameters.bind;
132                for (var a in oldEvents) if (oldEvents.hasOwnProperty(a)) 
133                        // TODO: Remove jQuery dependency
134                        jQuery(this._eventObj).unbind(a,oldEvents[a]);
135            }
136
137            this._parameters.bind = events;
138			for (var a in events) if (events.hasOwnProperty(a)) 
139				// TODO: Remove jQuery dependency
140					jQuery(this._eventObj).bind(a,events[a]);
141		}
142	},
143
144	_Loader:(function()
145	{
146		if (IE)
147		return function(parameters)
148		{
149			var width=this._img.width;
150			var height=this._img.height;
151			this._img.parentNode.removeChild(this._img);
152							
153			this._vimage = this.createVMLNode('image');
154			this._vimage.src=this._img.src;
155			this._vimage.style.height=height+"px";
156			this._vimage.style.width=width+"px";
157			this._vimage.style.position="absolute"; // FIXES IE PROBLEM - its only rendered if its on absolute position!
158			this._vimage.style.top = "0px";
159			this._vimage.style.left = "0px";
160
161			/* Group minifying a small 1px precision problem when rotating object */
162			this._container =  this.createVMLNode('group');
163			this._container.style.width=width;
164			this._container.style.height=height;
165			this._container.style.position="absolute";
166			this._container.setAttribute('coordsize',width-1+','+(height-1)); // This -1, -1 trying to fix ugly problem with small displacement on IE
167			this._container.appendChild(this._vimage);
168			
169			this._rootObj.appendChild(this._container);
170			this._rootObj.style.position="relative"; // FIXES IE PROBLEM
171			this._rootObj.style.width=width+"px";
172			this._rootObj.style.height=height+"px";
173			this._rootObj.setAttribute('id',this._img.getAttribute('id'));
174			this._rootObj.className=this._img.className;			
175		    this._eventObj = this._rootObj;	
176		    this._handleRotation(parameters);	
177		}
178		else
179		return function (parameters)
180		{
181			this._rootObj.setAttribute('id',this._img.getAttribute('id'));
182			this._rootObj.className=this._img.className;
183			
184			this._width=this._img.width;
185			this._height=this._img.height;
186			this._widthHalf=this._width/2; // used for optimisation
187			this._heightHalf=this._height/2;// used for optimisation
188			
189			var _widthMax=Math.sqrt((this._height)*(this._height) + (this._width) * (this._width));
190
191			this._widthAdd = _widthMax - this._width;
192			this._heightAdd = _widthMax - this._height;	// widthMax because maxWidth=maxHeight
193			this._widthAddHalf=this._widthAdd/2; // used for optimisation
194			this._heightAddHalf=this._heightAdd/2;// used for optimisation
195			
196			this._img.parentNode.removeChild(this._img);	
197			
198			this._aspectW = ((parseInt(this._img.style.width,10)) || this._width)/this._img.width;
199			this._aspectH = ((parseInt(this._img.style.height,10)) || this._height)/this._img.height;
200			
201			this._canvas=document.createElement('canvas');
202			this._canvas.setAttribute('width',this._width);
203			this._canvas.style.position="relative";
204			this._canvas.style.left = -this._widthAddHalf + "px";
205			this._canvas.style.top = -this._heightAddHalf + "px";
206			this._canvas.Wilq32 = this._rootObj.Wilq32;
207			
208			this._rootObj.appendChild(this._canvas);
209			this._rootObj.style.width=this._width+"px";
210			this._rootObj.style.height=this._height+"px";
211            this._eventObj = this._canvas;
212			
213			this._cnv=this._canvas.getContext('2d');
214            this._handleRotation(parameters);
215		}
216	})(),
217
218	_animateStart:function()
219	{	
220		if (this._timer) {
221			clearTimeout(this._timer);
222		}
223		this._animateStartTime = +new Date;
224		this._animateStartAngle = this._angle;
225		this._animate();
226	},
227    _animate:function()
228    {
229         var actualTime = +new Date;
230         var checkEnd = actualTime - this._animateStartTime > this._parameters.duration;
231
232         // TODO: Bug for animatedGif for static rotation ? (to test)
233         if (checkEnd && !this._parameters.animatedGif) 
234         {
235             clearTimeout(this._timer);
236         }
237         else 
238         {
239             if (this._canvas||this._vimage||this._img) {
240                 var angle = this._parameters.easing(0, actualTime - this._animateStartTime, this._animateStartAngle, this._parameters.animateTo - this._animateStartAngle, this._parameters.duration);
241                 this._rotate((~~(angle*10))/10);
242             }
243             if (this._parameters.step) {
244                this._parameters.step(this._angle);
245             }
246             var self = this;
247             this._timer = setTimeout(function()
248                     {
249                     self._animate.call(self);
250                     }, 10);
251         }
252
253         // To fix Bug that prevents using recursive function in callback I moved this function to back
254         if (this._parameters.callback && checkEnd){
255             this._angle = this._parameters.animateTo;
256             this._rotate(this._angle);
257             this._parameters.callback.call(this._rootObj);
258         }
259     },
260
261	_rotate : (function()
262	{
263		var rad = Math.PI/180;
264		if (IE)
265		return function(angle)
266		{
267            this._angle = angle;
268			this._container.style.rotation=(angle%360)+"deg";
269		}
270		else if (supportedCSS)
271		return function(angle){
272            this._angle = angle;
273			this._img.style[supportedCSS]="rotate("+(angle%360)+"deg)";
274		}
275		else 
276		return function(angle)
277		{
278            this._angle = angle;
279			angle=(angle%360)* rad;
280			// clear canvas	
281			this._canvas.width = this._width+this._widthAdd;
282			this._canvas.height = this._height+this._heightAdd;
283						
284			// REMEMBER: all drawings are read from backwards.. so first function is translate, then rotate, then translate, translate..
285			this._cnv.translate(this._widthAddHalf,this._heightAddHalf);	// at least center image on screen
286			this._cnv.translate(this._widthHalf,this._heightHalf);			// we move image back to its orginal 
287			this._cnv.rotate(angle);										// rotate image
288			this._cnv.translate(-this._widthHalf,-this._heightHalf);		// move image to its center, so we can rotate around its center
289			this._cnv.scale(this._aspectW,this._aspectH); // SCALE - if needed ;)
290			this._cnv.drawImage(this._img, 0, 0);							// First - we draw image
291		}
292
293	})()
294}
295
296if (IE)
297{
298Wilq32.PhotoEffect.prototype.createVMLNode=(function(){
299document.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
300		try {
301			!document.namespaces.rvml && document.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
302			return function (tagName) {
303				return document.createElement('<rvml:' + tagName + ' class="rvml">');
304			};
305		} catch (e) {
306			return function (tagName) {
307				return document.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
308			};
309		}		
310})();
311}
312
313})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.