123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. export function getCss(docEle) {
  2. const css = {};
  3. // transform
  4. var i;
  5. var keys = ['webkitTransform', '-webkit-transform', 'webkit-transform', 'transform'];
  6. for (i = 0; i < keys.length; i++) {
  7. if (docEle.style[keys[i]] !== undefined) {
  8. css.transform = keys[i];
  9. break;
  10. }
  11. }
  12. // transition
  13. keys = ['webkitTransition', 'transition'];
  14. for (i = 0; i < keys.length; i++) {
  15. if (docEle.style[keys[i]] !== undefined) {
  16. css.transition = keys[i];
  17. break;
  18. }
  19. }
  20. // The only prefix we care about is webkit for transitions.
  21. var isWebkit = css.transition.indexOf('webkit') > -1;
  22. // transition duration
  23. css.transitionDuration = (isWebkit ? '-webkit-' : '') + 'transition-duration';
  24. // transition timing function
  25. css.transitionTimingFn = (isWebkit ? '-webkit-' : '') + 'transition-timing-function';
  26. // transition delay
  27. css.transitionDelay = (isWebkit ? '-webkit-' : '') + 'transition-delay';
  28. // To be sure transitionend works everywhere, include *both* the webkit and non-webkit events
  29. css.transitionEnd = (isWebkit ? 'webkitTransitionEnd ' : '') + 'transitionend';
  30. // transform origin
  31. css.transformOrigin = (isWebkit ? '-webkit-' : '') + 'transform-origin';
  32. // animation delay
  33. css.animationDelay = (isWebkit ? 'webkitAnimationDelay' : 'animationDelay');
  34. return css;
  35. }
  36. export function pointerCoord(ev) {
  37. // get coordinates for either a mouse click
  38. // or a touch depending on the given event
  39. if (ev) {
  40. var changedTouches = ev.changedTouches;
  41. if (changedTouches && changedTouches.length > 0) {
  42. var touch = changedTouches[0];
  43. return { x: touch.clientX, y: touch.clientY };
  44. }
  45. var pageX = ev.pageX;
  46. if (pageX !== undefined) {
  47. return { x: pageX, y: ev.pageY };
  48. }
  49. }
  50. return { x: 0, y: 0 };
  51. }
  52. export function hasPointerMoved(threshold, startCoord, endCoord) {
  53. if (startCoord && endCoord) {
  54. const deltaX = (startCoord.x - endCoord.x);
  55. const deltaY = (startCoord.y - endCoord.y);
  56. const distance = deltaX * deltaX + deltaY * deltaY;
  57. return distance > (threshold * threshold);
  58. }
  59. return false;
  60. }
  61. export function isTextInput(ele) {
  62. return !!ele &&
  63. (ele.tagName === 'TEXTAREA' ||
  64. ele.contentEditable === 'true' ||
  65. (ele.tagName === 'INPUT' && !(NON_TEXT_INPUT_REGEX.test(ele.type))));
  66. }
  67. export const NON_TEXT_INPUT_REGEX = /^(radio|checkbox|range|file|submit|reset|color|image|button)$/i;
  68. const SKIP_INPUT_ATTR = ['value', 'checked', 'disabled', 'readonly', 'placeholder', 'type', 'class', 'style', 'id', 'autofocus', 'autocomplete', 'autocorrect'];
  69. export function copyInputAttributes(srcElement, destElement) {
  70. // copy attributes from one element to another
  71. // however, skip over a few of them as they're already
  72. // handled in the angular world
  73. const attrs = srcElement.attributes;
  74. for (var i = 0; i < attrs.length; i++) {
  75. var attr = attrs[i];
  76. if (SKIP_INPUT_ATTR.indexOf(attr.name) === -1) {
  77. destElement.setAttribute(attr.name, attr.value);
  78. }
  79. }
  80. }
  81. //# sourceMappingURL=dom.js.map