<commit_before>/**
 * DOM Element events handling methods
 *
 * Copyright (C) 2008-2010 <NAME>ka St. <nemshilov#gma-il>
 */
Element.include((function() {
  var observer = Observer.create({}, 
    $w('click rightclick contextmenu mousedown mouseup mouseover mouseout mousemove keypress keydown keyup')
  );
  
  //
  // HACK HACK HACK
  //
  // I'm kinda patching the observer methods manually in here
  // the reason is in building flat and fast functions
  //
  observer.observe = observer.on = eval('['+
    observer.observe.toString().replace(/(\$listeners\.push\((\w+?)\);)/, '$1'+
      '$2.e=Event.cleanName($2.e);$2.n=Event.realName($2.e);'+
      
      '$2.w=function(){var a=$A(arguments),e=($2.r&&$2.r!=="stopEvent")?a.shift():Event.ext(a[0],this);'+
        'return $2.f.apply(this,a.concat($2.a))};'+(
      
      self.attachEvent ?
        '$2.w=$2.w.bind(this);this.attachEvent("on"+$2.n,$2.w);' :
        'this.addEventListener($2.n,$2.w,false);'
      )
    )+
  ']')[0];
  
  observer.stopObserving = eval('['+
    observer.stopObserving.toString().replace(/(function\s*\((\w+)\)\s*\{\s*)(return\s*)([^}]+)/m, 
      '$1var r=$4;'+
      'if(!r)' + (self.attachEvent ? 
        'this.detachEvent("on"+$2.n,$2.w);' :
        'this.removeEventListener($2.n,$2.w,false);'
      )+'$3 r')+
  ']')[0];
  
  
  observer.fire = eval('['+
    observer.fire.toString().replace(/(\w+)\.f\.apply.*?\.concat\((\w+)\)[^}]/,
      '$1.f.apply(this,[new Event($1.e,$2.shift())].concat($1.a).concat($2))'
    )+
  ']')[0];
  
  // a simple events terminator method to be hooked like
  // this.onClick('stopEvent');
  observer.stopEvent = function(e) { e.stop(); };
  
  $ext(window,   observer);
  $ext(document, observer);
  
  Observer.createShortcuts(window, $w('blur focus scroll'));
  
  return observer;
})());<commit_msg>Cleaner and compacter element-events hack<commit_after>/**
 * DOM Element events handling methods
 *
 * Copyright (C) 2008-2010 <NAME> aka St. <nemshilov#gma-il>
 */
Element.include((function() {
  var observer = Observer.create({}, 
    $w('click rightclick contextmenu mousedown mouseup mouseover mouseout mousemove keypress keydown keyup')
  ),
  
  //
  // HACK HACK HACK
  //
  // I'm kinda patching the observer methods manually in here
  // the reason is in building flat and fast functions
  //
  hack = function(name, re, text) {
    observer[name] = eval('['+ observer[name].toString().replace(re, text) +']')[0];
  };
  
  hack('on', 
    /(\$listeners\.push\((\w+?)\);)/,
    
    '$1$2.e=Event.cleanName($2.e);$2.n=Event.realName($2.e);'+
    
    '$2.w=function(){'+
      'var a=$A(arguments),e=($2.r&&$2.r!=="stopEvent")?a.shift():Event.ext(a[0],this);'+
      'return $2.f.apply(this,a.concat($2.a))};' + (
        self.attachEvent ?
          '$2.w=$2.w.bind(this);this.attachEvent("on"+$2.n,$2.w);' :
          'this.addEventListener($2.n,$2.w,false);'
        )
  );
  observer.observe = observer.on;
  
  hack('stopObserving',
    /(function\s*\((\w+)\)\s*\{\s*)(return\s*)([^}]+)/m, 
    '$1var r=$4;'+
    'if(!r)' + (self.attachEvent ? 
      'this.detachEvent("on"+$2.n,$2.w);' :
      'this.removeEventListener($2.n,$2.w,false);'
    )+'$3 r'
  );
  
  hack('fire',
    /(\w+)\.f\.apply.*?\.concat\((\w+)\)\)/,
    '$1.f.apply(this,[new Event($1.e,$2.shift())].concat($1.a).concat($2))'
  );
  
  // a simple events terminator method to be hooked like this.onClick('stopEvent');
  observer.stopEvent = function(e) { e.stop(); };
  
  $ext(window,   observer);
  $ext(document, observer);
  
  Observer.createShortcuts(window, $w('blur focus scroll'));
  
  return observer;
})());
{'fraction_non_alphanumeric': 0.24030794610943085, 'fraction_numerical': 0.02144624690679131, 'mean_word_length': 3.1107344632768363, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6783163', 'n_tokens_mistral': 1420, 'n_tokens_neox': 1367, 'n_words': 215}