1/*! 2/** 3 * Monkey patch jQuery 1.3.1+ to add support for setting or animating CSS 4 * scale and rotation independently. 5 * https://github.com/zachstronaut/jquery-animate-css-rotate-scale 6 * Released under dual MIT/GPL license just like jQuery. 7 * 2009-2012 Zachary Johnson www.zachstronaut.com 8 */ 9(function ($) { 10 // Updated 2010.11.06 11 // Updated 2012.10.13 - Firefox 16 transform style returns a matrix rather than a string of transform functions. This broke the features of this jQuery patch in Firefox 16. It should be possible to parse the matrix for both scale and rotate (especially when scale is the same for both the X and Y axis), however the matrix does have disadvantages such as using its own units and also 45deg being indistinguishable from 45+360deg. To get around these issues, this patch tracks internally the scale, rotation, and rotation units for any elements that are .scale()'ed, .rotate()'ed, or animated. The major consequences of this are that 1. the scaled/rotated element will blow away any other transform rules applied to the same element (such as skew or translate), and 2. the scaled/rotated element is unaware of any preset scale or rotation initally set by page CSS rules. You will have to explicitly set the starting scale/rotation value. 12 13 function initData($el) { 14 var _ARS_data = $el.data('_ARS_data'); 15 if (!_ARS_data) { 16 _ARS_data = { 17 rotateUnits: 'deg', 18 scale: 1, 19 rotate: 0 20 }; 21 22 $el.data('_ARS_data', _ARS_data); 23 } 24 25 return _ARS_data; 26 } 27 28 function setTransform($el, data) { 29 $el.css('transform', 'rotate(' + data.rotate + data.rotateUnits + ') scale(' + data.scale + ',' + data.scale + ')'); 30 } 31 32 $.fn.rotate = function (val) { 33 var $self = $(this), m, data = initData($self); 34 35 if (typeof val == 'undefined') { 36 return data.rotate + data.rotateUnits; 37 } 38 39 m = val.toString().match(/^(-?\d+(\.\d+)?)(.+)?$/); 40 if (m) { 41 if (m[3]) { 42 data.rotateUnits = m[3]; 43 } 44 45 data.rotate = m[1]; 46 47 setTransform($self, data); 48 } 49 50 return this; 51 }; 52 53 // Note that scale is unitless. 54 $.fn.scale = function (val) { 55 var $self = $(this), data = initData($self); 56 57 if (typeof val == 'undefined') { 58 return data.scale; 59 } 60 61 data.scale = val; 62 63 setTransform($self, data); 64 65 return this; 66 }; 67 68 // fx.cur() must be monkey patched because otherwise it would always 69 // return 0 for current rotate and scale values 70 var curProxied = $.fx.prototype.cur; 71 $.fx.prototype.cur = function () { 72 if (this.prop == 'rotate') { 73 return parseFloat($(this.elem).rotate()); 74 75 } else if (this.prop == 'scale') { 76 return parseFloat($(this.elem).scale()); 77 } 78 79 return curProxied.apply(this, arguments); 80 }; 81 82 $.fx.step.rotate = function (fx) { 83 var data = initData($(fx.elem)); 84 $(fx.elem).rotate(fx.now + data.rotateUnits); 85 }; 86 87 $.fx.step.scale = function (fx) { 88 $(fx.elem).scale(fx.now); 89 }; 90 91 /* 92 93 Starting on line 3905 of jquery-1.3.2.js we have this code: 94 95 // We need to compute starting value 96 if ( unit != "px" ) { 97 self.style[ name ] = (end || 1) + unit; 98 start = ((end || 1) / e.cur(true)) * start; 99 self.style[ name ] = start + unit; 100 } 101 102 This creates a problem where we cannot give units to our custom animation 103 because if we do then this code will execute and because self.style[name] 104 does not exist where name is our custom animation's name then e.cur(true) 105 will likely return zero and create a divide by zero bug which will set 106 start to NaN. 107 108 The following monkey patch for animate() gets around this by storing the 109 units used in the rotation definition and then stripping the units off. 110 111 */ 112 113 var animateProxied = $.fn.animate; 114 $.fn.animate = function (prop) { 115 if (typeof prop['rotate'] != 'undefined') { 116 var $self, data, m = prop['rotate'].toString().match(/^(([+-]=)?(-?\d+(\.\d+)?))(.+)?$/); 117 if (m && m[5]) { 118 $self = $(this); 119 data = initData($self); 120 data.rotateUnits = m[5]; 121 } 122 123 prop['rotate'] = m[1]; 124 } 125 126 return animateProxied.apply(this, arguments); 127 }; 128})(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.