/**
 * 事件辅助类
 * @module zrender/tool/event
 * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
 */
module.exports = function (require) {
  'use strict';

  var Eventful = require('../mixin/Eventful');
  /**
  * 提取鼠标（手指）x坐标
  * @memberOf module:zrender/tool/event
  * @param  {Event} e 事件.
  * @return {number} 鼠标（手指）x坐标.
  */


  function getX(e) {
    return typeof e.zrenderX != 'undefined' && e.zrenderX || typeof e.offsetX != 'undefined' && e.offsetX || typeof e.layerX != 'undefined' && e.layerX || typeof e.clientX != 'undefined' && e.clientX;
  }
  /**
  * 提取鼠标y坐标
  * @memberOf module:zrender/tool/event
  * @param  {Event} e 事件.
  * @return {number} 鼠标（手指）y坐标.
  */


  function getY(e) {
    return typeof e.zrenderY != 'undefined' && e.zrenderY || typeof e.offsetY != 'undefined' && e.offsetY || typeof e.layerY != 'undefined' && e.layerY || typeof e.clientY != 'undefined' && e.clientY;
  }
  /**
  * 提取鼠标滚轮变化
  * @memberOf module:zrender/tool/event
  * @param  {Event} e 事件.
  * @return {number} 滚轮变化，正值说明滚轮是向上滚动，如果是负值说明滚轮是向下滚动
  */


  function getDelta(e) {
    return typeof e.zrenderDelta != 'undefined' && e.zrenderDelta || typeof e.wheelDelta != 'undefined' && e.wheelDelta || typeof e.detail != 'undefined' && -e.detail;
  }
  /**
   * 停止冒泡和阻止默认行为
   * @memberOf module:zrender/tool/event
   * @method
   * @param {Event} e : event对象
   */


  var stop = typeof window.addEventListener === 'function' ? function (e) {
    e.preventDefault();
    e.stopPropagation();
    e.cancelBubble = true;
  } : function (e) {
    e.returnValue = false;
    e.cancelBubble = true;
  };
  return {
    getX: getX,
    getY: getY,
    getDelta: getDelta,
    stop: stop,
    // 做向上兼容
    Dispatcher: Eventful
  };
}(require);