compat.js - jscancer - Javascript crap (relatively small)
 (HTM) git clone git://git.codemadness.org/jscancer
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
       compat.js (1922B)
       ---
            1 if (typeof(Array) != "undefined" && typeof(Element) != "undefined" &&
            2     typeof(Event) != "undefined" && typeof(String) != "undefined") {
            3         if (!Array.prototype.indexOf)
            4                 Array.prototype.indexOf = function(s) {
            5                         if (!(s in this))
            6                                 return -1;
            7                         for (var i = 0; i < this.length; i++)
            8                                 if (this[i] === s)
            9                                         return i;
           10                         return -1;
           11                 };
           12         if (!Array.prototype.map)
           13                 Array.prototype.map = function(fn) {
           14                         var l = [];
           15                         for (var i = 0; i < this.length; i++)
           16                                 l.push(fn(this[i]));
           17                         return l;
           18                 };
           19         if (!document.getElementsByClassName)
           20                 Element.prototype.getElementsByClassName = document.getElementsByClassName = function(classname) {
           21                         var els = this.getElementsByTagName("*"), l = [],
           22                                 p = new RegExp("(^|\\s)" + classname + "(\\s|$)");
           23                         for (var i = 0; i < els.length; i++)
           24                                 if (p.test(els[i].className))
           25                                         l.push(els[i]);
           26                         return l;
           27                 };
           28         if (!document.addEventListener)
           29                 // NOTE: capture is ignored if addEventListener is not supported.
           30                 if (this.attachEvent) // IE DOM
           31                         Element.prototype.addEventListener = document.addEventListener = function(ev, fn, capture) {
           32                                 this.attachEvent("on" + ev, function(e) {
           33                                         // fixup some standard event properties.
           34                                         if (typeof(e) == "undefined")
           35                                                 e = window.event;
           36                                         e.target = typeof(e.target) != "undefined" ? e.target : e.srcElement;
           37                                         e.which = typeof(e.which) != "undefined" ? e.which : e.keyCode;
           38                                         return fn.apply(this, arguments);
           39                                 });
           40                         };
           41         if (!document.removeEventListener)
           42                 if (this.detachEvent) // IE DOM
           43                         Element.prototype.removeEventListener = document.removeEventListener = function(ev, fn, capture) {
           44                                 this.detachEvent("on" + ev, fn);
           45                         };
           46         if (!Event.prototype.stopPropagation)
           47                 Event.prototype.stopPropagation = function() {
           48                          window.event.cancelBubble = true;
           49                          return false;
           50                 };
           51         if (!String.trim)
           52                 String.prototype.trim = function() {
           53                         return this.replace(/^\s+|\s+$/g, "");
           54                 };
           55 }