zoukankan      html  css  js  c++  java
  • event related object in javascript

      1 var EventUtil = {
      2 
      3         addHandler: function (element, type, handler) {
      4             if (element.addEventListener) {
      5                 element.addEventListener(type, handler, false);
      6             } else if (element.attachEvent) {
      7                 element.attachEvent("on" + type, handler);
      8             } else {
      9                 element["on" + type] = handler;
     10             }
     11         },
     12 
     13         removeHandler: function (element, type, handler) {
     14             if (element.removeEventListener) {
     15                 element.removeEventListener(type, handler, false);
     16             } else if (element.detachEvent) {
     17                 element.detachEvent("on" + type, handler);
     18             } else {
     19                 element["on" + type] = null;
     20             }
     21         },
     22 
     23         getEvent: function (event) {
     24             return event ? event : window.event;
     25         },
     26 
     27         getTarget: function (event) {
     28             return event.target || event.srcElement;
     29         },
     30 
     31         preventDefault: function (event) {
     32             if (event.preventDefault) {
     33                 event.preventDefault();
     34             } else {
     35                 event.returnValue = false;
     36             }
     37         },
     38 
     39         stopPropagation: function (event) {
     40             if (event.stopPropagation) {
     41                 event.stopPropagation();
     42             } else {
     43                 event.cancelBubble = true;
     44             }
     45         },
     46 
     47         getRelatedTarget: function (event) {
     48             if (event.relatedTarget) {
     49                 return event.relatedTarget;
     50             } else if (event.toElement) {
     51                 return event.toElement;
     52             } else if (event.fromElement) {
     53                 return event.fromElement;
     54             } else {
     55                 return null;
     56             }
     57         },
     58 
     59         getButton: function (event) {
     60             if (document.implementation.hasFeature("MouseEvents", "2.0")) {
     61                 return event.button;
     62             } else {
     63                 switch (event.button) {
     64                     case 0:
     65                     case 1:
     66                     case 3:
     67                     case 5:
     68                     case 7:
     69                         return 0;
     70                     case 2:
     71                     case 6:
     72                         return 2;
     73                     case 4:
     74                         return 1;
     75                 }
     76             }
     77         },
     78 
     79         getCharCode: function (event) {
     80             if (typeof event.charCode == "number") {
     81                 return event.charCode;
     82             } else {
     83                 return event.keyCode;
     84             }
     85         },
     86 
     87         getWheelDelta: function (event) {
     88             if (event.wheelDelta) {
     89                 return (client.engine.opera && client.engine.opera < 9.5 ? -event.wheelDelta : event.wheelDelta);
     90             } else {
     91                 return -event.detail * 40;
     92             }
     93         },
     94 
     95         getClipboardText: function (event) {
     96             var clipboardDate = (event.clipboardDate || window.clipboardDate);
     97             return clipboardDate.getDate("text");
     98         },
     99 
    100         setClipboardText: function (event, value) {
    101             if (event.clipboardDate) {
    102                 return event.clipboardDate.setDate("text/plain", value);
    103             } else if (window.clipboardDate) {
    104                 return window.clipboardDate.setDate("text", value);
    105             }
    106         }
    107     };
  • 相关阅读:
    saiku导出excel单元格格式与中文列宽自动适应
    saiku中过滤窗口优化及隐藏异常报错
    saiku之固定维度(必选维度)
    saiku中多cube排序问题
    saiku中默认级别all的国际化
    Nginx基本配置、性能优化指南
    Nginx安装部署
    64位虚拟机中安装CentOS_6.7
    memcached全面剖析–5. memcached的应用和兼容程序
    memcached全面剖析–4. memcached的分布式算法
  • 原文地址:https://www.cnblogs.com/ongoing/p/3082229.html
Copyright © 2011-2022 走看看