support.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. var Support = (function() {
  2. var style = $('<support>').get(0).style,
  3. prefixes = ['webkit', 'Moz', 'O', 'ms'],
  4. events = {
  5. transition: {
  6. end: {
  7. WebkitTransition: 'webkitTransitionEnd',
  8. MozTransition: 'transitionend',
  9. OTransition: 'oTransitionEnd',
  10. transition: 'transitionend'
  11. }
  12. }
  13. },
  14. tests = {
  15. csstransitions: function() {
  16. return !!test('transition');
  17. }
  18. };
  19. function test(property, prefixed) {
  20. var result = false,
  21. upper = property.charAt(0).toUpperCase() + property.slice(1);
  22. if (style[property] !== undefined) {
  23. result = property;
  24. }
  25. if (!result) {
  26. $.each(prefixes, function(i, prefix) {
  27. if (style[prefix + upper] !== undefined) {
  28. result = '-' + prefix.toLowerCase() + '-' + upper;
  29. return false;
  30. }
  31. });
  32. }
  33. if (prefixed) {
  34. return result;
  35. }
  36. if (result) {
  37. return true;
  38. } else {
  39. return false;
  40. }
  41. }
  42. function prefixed(property) {
  43. return test(property, true);
  44. }
  45. var support = {};
  46. if (tests.csstransitions()) {
  47. /* jshint -W053 */
  48. support.transition = new String(prefixed('transition'))
  49. support.transition.end = events.transition.end[support.transition];
  50. }
  51. return support;
  52. })();