Guest User

Untitled

a guest
May 23rd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. addEvent: function(type, fn){
  2. var events = this.retrieve('events', {});
  3. events[type] = events[type] || {'keys': [], 'values': []};
  4. if (events[type].keys.contains(fn)) return this;
  5. events[type].keys.push(fn);
  6. var realType = type, custom = Element.Events.get(type), condition = fn, self = this;
  7. if (custom){
  8. if (custom.onAdd) custom.onAdd.call(this, fn);
  9. if (custom.condition){
  10. condition = function(event){
  11. if (custom.condition.call(this, event)) return fn.call(this, event);
  12. return true;
  13. };
  14. }
  15. realType = custom.base || realType;
  16. }
  17. var defn = function(){
  18. return fn.call(self);
  19. };
  20. var nativeEvent = Element.NativeEvents[realType];
  21. if (nativeEvent){
  22. if (nativeEvent == 2){
  23. defn = function(event){
  24. event = new Event(event, self.getWindow());
  25. if (condition.call(self, event) === false) event.stop();
  26. };
  27. }
  28. this.addListener(realType, defn);
  29. }
  30. events[type].values.push(defn);
  31. return this;
  32. },
Add Comment
Please, Sign In to add comment