forked from zachstronaut/jquery-css-transform
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjquery-css-transform.js
61 lines (57 loc) · 2.15 KB
/
jquery-css-transform.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
(function ($) {
// Monkey patch jQuery 1.3.1+ css() method to support CSS 'transform'
// property uniformly across Webkit/Safari/Chrome and Firefox 3.5.
// 2009 Zachary Johnson www.zachstronaut.com
function getTransformProperty(element)
{
// Try transform first for forward compatibility
var properties = ['transform', 'WebkitTransform', 'MozTransform'];
var p;
while (p = properties.shift())
{
if (typeof element.style[p] != 'undefined')
{
return p;
}
}
// Default to transform also
return 'transform';
}
var proxied = $.fn.css;
$.fn.css = function (arg)
{
// Find the correct browser specific property and setup the mapping using
// $.props which is used internally by jQuery.attr() when setting CSS
// properties via either the css(name, value) or css(properties) method.
// The problem with doing this once outside of css() method is that you
// need a DOM node to find the right CSS property, and there is some risk
// that somebody would call the css() method before body has loaded or any
// DOM-is-ready events have fired.
if
(
typeof $.props['transform'] == 'undefined'
&&
(
arg == 'transform'
||
(
typeof arg == 'object'
&& typeof arg['transform'] != 'undefined'
)
)
)
{
$.props['transform'] = getTransformProperty(this.get(0));
}
// We force the property mapping here because jQuery.attr() does
// property mapping with jQuery.props when setting a CSS property,
// but curCSS() does *not* do property mapping when *getting* a
// CSS property. (It probably should since it manually does it
// for 'float' now anyway... but that'd require more testing.)
if (arg == 'transform')
{
arg = $.props['transform'];
}
return proxied.apply(this, arguments);
};
})(jQuery);