get-style-property.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*!
  2. * getStyleProperty v1.0.4
  3. * original by kangax
  4. * http://perfectionkills.com/feature-testing-css-properties/
  5. * MIT license
  6. */
  7. /*jshint browser: true, strict: true, undef: true */
  8. /*global define: false, exports: false, module: false */
  9. ( function( window ) {
  10. 'use strict';
  11. var prefixes = 'Webkit Moz ms Ms O'.split(' ');
  12. var docElemStyle = document.documentElement.style;
  13. function getStyleProperty( propName ) {
  14. if ( !propName ) {
  15. return;
  16. }
  17. // test standard property first
  18. if ( typeof docElemStyle[ propName ] === 'string' ) {
  19. return propName;
  20. }
  21. // capitalize
  22. propName = propName.charAt(0).toUpperCase() + propName.slice(1);
  23. // test vendor specific properties
  24. var prefixed;
  25. for ( var i=0, len = prefixes.length; i < len; i++ ) {
  26. prefixed = prefixes[i] + propName;
  27. if ( typeof docElemStyle[ prefixed ] === 'string' ) {
  28. return prefixed;
  29. }
  30. }
  31. }
  32. // transport
  33. if ( typeof define === 'function' && define.amd ) {
  34. // AMD
  35. define( function() {
  36. return getStyleProperty;
  37. });
  38. } else if ( typeof exports === 'object' ) {
  39. // CommonJS for Component
  40. module.exports = getStyleProperty;
  41. } else {
  42. // browser global
  43. window.getStyleProperty = getStyleProperty;
  44. }
  45. })( window );