门面(外观)模式

DED.util.Event = {
  getEvent: function(e) {
    return e || window.event;
  },
  getTarget: function(e) {
    return e.target || e.srcElement;
  },
  stopPropagation: function(e) {
    if (e.stopPropagation) {
      e.stopPropagation();
    } 
    else {
      e.cancelBubble = true;
    }
  },
  preventDefault: function(e) {
    if (e.preventDefault) {
      e.preventDefault();
    } 
    else {
      e.returnValue = false;
    }
  },
  stopEvent: function(e) {
    this.stopPropagation(e);
    this.preventDefault(e);
  }
};

addEvent($('example'), 'click', function(e) {
  // Who clicked me.
  console.log(DED.util.Event.getTarget(e));
  // Stop propgating and prevent the default action.
  DED.util.Event.stopEvent(e);
});
posted @ 2013-02-22 10:45  瓦尔登湖的秋天  阅读(153)  评论(0编辑  收藏  举报