1(function ($) { 2 // Monkey patch jQuery 1.3.1+ to add support for setting or animating CSS 3 // scale and rotation independently. 4 // 2009-2010 Zachary Johnson www.zachstronaut.com 5 // Updated 2010.11.06 6 var rotateUnits = 'deg'; 7 8 $.fn.rotate = function (val) 9 { 10 var style = $(this).css('transform') || 'none'; 11 12 if (typeof val == 'undefined') 13 { 14 if (style) 15 { 16 var m = style.match(/rotate\(([^)]+)\)/); 17 if (m && m[1]) 18 { 19 return m[1]; 20 } 21 } 22 23 return 0; 24 } 25 26 var m = val.toString().match(/^(-?\d+(\.\d+)?)(.+)?$/); 27 if (m) 28 { 29 if (m[3]) 30 { 31 rotateUnits = m[3]; 32 } 33 34 $(this).css( 35 'transform', 36 style.replace(/none|rotate\([^)]*\)/, '') + 'rotate(' + m[1] + rotateUnits + ')' 37 ); 38 } 39 40 return this; 41 } 42 43 // Note that scale is unitless. 44 $.fn.scale = function (val, duration, options) 45 { 46 var style = $(this).css('transform'); 47 48 if (typeof val == 'undefined') 49 { 50 if (style) 51 { 52 var m = style.match(/scale\(([^)]+)\)/); 53 if (m && m[1]) 54 { 55 return m[1]; 56 } 57 } 58 59 return 1; 60 } 61 62 $(this).css( 63 'transform', 64 style.replace(/none|scale\([^)]*\)/, '') + 'scale(' + val + ')' 65 ); 66 67 return this; 68 } 69 70 // fx.cur() must be monkey patched because otherwise it would always 71 // return 0 for current rotate and scale values 72 var curProxied = $.fx.prototype.cur; 73 $.fx.prototype.cur = function () 74 { 75 if (this.prop == 'rotate') 76 { 77 return parseFloat($(this.elem).rotate()); 78 } 79 else if (this.prop == 'scale') 80 { 81 return parseFloat($(this.elem).scale()); 82 } 83 84 return curProxied.apply(this, arguments); 85 } 86 87 $.fx.step.rotate = function (fx) 88 { 89 $(fx.elem).rotate(fx.now + rotateUnits); 90 } 91 92 $.fx.step.scale = function (fx) 93 { 94 $(fx.elem).scale(fx.now); 95 } 96 97 /* 98 99 Starting on line 3905 of jquery-1.3.2.js we have this code: 100 101 // We need to compute starting value 102 if ( unit != "px" ) { 103 self.style[ name ] = (end || 1) + unit; 104 start = ((end || 1) / e.cur(true)) * start; 105 self.style[ name ] = start + unit; 106 } 107 108 This creates a problem where we cannot give units to our custom animation 109 because if we do then this code will execute and because self.style[name] 110 does not exist where name is our custom animation's name then e.cur(true) 111 will likely return zero and create a divide by zero bug which will set 112 start to NaN. 113 114 The following monkey patch for animate() gets around this by storing the 115 units used in the rotation definition and then stripping the units off. 116 117 */ 118 119 var animateProxied = $.fn.animate; 120 $.fn.animate = function (prop) 121 { 122 if (typeof prop['rotate'] != 'undefined') 123 { 124 var m = prop['rotate'].toString().match(/^(([+-]=)?(-?\d+(\.\d+)?))(.+)?$/); 125 if (m && m[5]) 126 { 127 rotateUnits = m[5]; 128 } 129 130 prop['rotate'] = m[1]; 131 } 132 133 return animateProxied.apply(this, arguments); 134 } 135})(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.