Advertisement
Guest User

jquery-css-transform.js

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