OSDN Git Service

Version 0.6.49, fix for xnode.attr(name).
[pettanr/clientJs.git] / 0.6.x / js / core / 00_builtin.js
index ebf6e79..3f8f676 100644 (file)
@@ -9,15 +9,13 @@ Function.prototype.apply || (Function.prototype.apply = function (x, y) {
        y = y || [];\r
        \r
        // apply 内で apply を呼んだ場合に備える\r
-       if( x.__apply ){\r
-               if( x === window ){\r
-                       x.__apply = void 0;\r
-               } else {\r
-                       delete x.__apply;\r
-               };\r
-       };\r
-       if( x.constructor && x.constructor.prototype.__apply ){\r
-               delete x.constructor.prototype.__apply;\r
+       if( x === window ){\r
+               x.__apply = void 0;\r
+       } else {\r
+               if( x.constructor && x.constructor.prototype.__apply ){\r
+                       delete x.constructor.prototype.__apply;\r
+               } else\r
+               if( x.__apply ) delete x.__apply;\r
        };\r
        \r
        x.__apply = this;\r
@@ -38,27 +36,26 @@ Function.prototype.apply || (Function.prototype.apply = function (x, y) {
                        a = [];\r
                        for (i = 0; i < j; ++i)\r
                                a[i] = 'y[' + i + ']';\r
-                       r = eval('x.__apply(' + a.join(',') + ')');\r
+                       //r = eval('x.__apply(' + a.join(',') + ')');\r
+                       // closuer compiler 対策\r
+                       r = (new Function( 'x,y', 'return x.__apply(' + a.join(',') + ')' ))( x, y );\r
                        break;\r
        };\r
-       // delete x.__apply ? x.__apply : x.constructor.prototype.__apply ;\r
        // ie5\r
-       if( x.__apply ){\r
-               if( x === window ){\r
-                       x.__apply = void 0;\r
-               } else {\r
-                       delete x.__apply;\r
-               };\r
-       };\r
-       if( x.constructor && x.constructor.prototype.__apply ){\r
-               delete x.constructor.prototype.__apply;\r
+       if( x === window ){\r
+               x.__apply = void 0;\r
+       } else {\r
+               if( x.constructor && x.constructor.prototype.__apply ){\r
+                       delete x.constructor.prototype.__apply;\r
+               } else\r
+               if( x.__apply ) delete x.__apply;\r
        };\r
        return r;\r
 });\r
 Function.prototype.call || (Function.prototype.call = function () {\r
        var a = arguments, x = a[0], y = [], i = 1, j;\r
        for (j = a.length; i < j; ++i)\r
-               y[i - 1] = a[i]\r
+               y[i - 1] = a[i];\r
        return this.apply(x, y);\r
 });\r
 \r
@@ -105,36 +102,165 @@ Array.prototype.splice || (Array.prototype.splice = function (x, y) {
 });\r
 \r
 /*\r
+ * original\r
  * JavaScript 1.6, Array.indexOfを下位互換実装する\r
  * http://www.inazumatv.com/contents/archives/7965\r
  */\r
 \r
-Array.prototype.indexOf || (Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {\r
-        if( this == null ){\r
-            //throw new TypeError();\r
-        };\r
-        var t = Object(this);\r
-        var len = t.length >>> 0;\r
-        if (len === 0) return -1;\r
+Array.prototype.indexOf || (Array.prototype.indexOf = function( searchElement, fromIndex ){\r
+        var l = this.length >>> 0,\r
+               i = 0;\r
+        if( l === 0 ) return -1;\r
         \r
-        var n = 0;\r
-        if (arguments.length > 1) {\r
-            n = Number(arguments[1]);\r
-            if (n != n) { // shortcut for verifying if it's NaN\r
-                n = 0;\r
-            } else if (n != 0 && n != Infinity && n != -Infinity) {\r
-                n = (n > 0 || -1) * Math.floor(Math.abs(n));\r
-            }\r
-        }\r
-        if (n >= len) {\r
-            return -1;\r
-        }\r
-        var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);\r
-        for (; k < len; k++) {\r
-            if (t[k] === searchElement) {\r
-                return k;\r
-            }\r
-        }\r
+        if( fromIndex ){\r
+            i = fromIndex || 0;\r
+            i = i === -Infinity ? 0 : Math.floor( i < 0 ? -i : i );\r
+            if( l <= i ) return -1;\r
+        };\r
+\r
+        for( i = 0 <= i ? i : 0 < l + i ? l + i : 0; i < l; ++i ){\r
+            if( this[ i ] === searchElement ) return i;\r
+        };\r
         return -1;\r
        });\r
 \r
+\r
+/*\r
+ * Window\r
+ * by http://nurucom-archives.hp.infoseek.co.jp/digital/trans-uri.html\r
+ */\r
+\r
+/* 正規表現が使われているため、まだ投入しない itozyun\r
+window.encodeURI || (window.encodeURI = function (x) {\r
+       return ("" + x).replace(/[^!#$&-;=?-Z_a-z~]/g, function (s) {\r
+               var c = s.charCodeAt(0), p = "%";\r
+               return (\r
+                       c < 16 ? "%0" + c.toString(16) :\r
+                       c < 128 ? p + c.toString(16) :\r
+                       c < 2048 ? p + (c >> 6 | 192).toString(16) + p + (c & 63 | 128).toString(16) :\r
+                       p + (c >> 12 | 224).toString(16) + p + (c >> 6 & 63 | 128).toString(16) + p + (c & 63 | 128).toString(16)\r
+               ).toUpperCase();\r
+       });\r
+});\r
+\r
+window.encodeURIComponent || (window.encodeURIComponent = function (x) {\r
+       return ("" + x).replace(/[^!'-*.0-9A-Z_a-z~-]/g, function (s) {\r
+               var c = s.charCodeAt(0), p = "%";\r
+               return (\r
+                       c < 16 ? "%0" + c.toString(16) :\r
+                       c < 128 ? p + c.toString(16) :\r
+                       c < 2048 ? p + (c >> 6 | 192).toString(16) + p + (c & 63 | 128).toString(16) :\r
+                       p + (c >> 12 | 224).toString(16) + p + (c >> 6 & 63 | 128).toString(16) + p + (c & 63 | 128).toString(16)\r
+               ).toUpperCase();\r
+       });\r
+});\r
+\r
+// 手抜き\r
+window.decodeURI || (window.decodeURI = function (x) {\r
+       return ("" + x).replace(/%(E(0%[AB]|[1-CEF]%[89AB]|D%[89])[0-9A-F]|C[2-9A-F]|D[0-9A-F])%[89AB][0-9A-F]|%[0-7][0-9A-F]/ig, function (s) {\r
+               var c = parseInt(s.substring(1), 16);\r
+               return String.fromCharCode(\r
+                       c < 128 ? c :\r
+                       c < 224 ? (c & 31) << 6 | parseInt(s.substring(4), 16) & 63 :\r
+                       ((c & 15) << 6 | parseInt(s.substring(4), 16) & 63) << 6 | parseInt(s.substring(7), 16) & 63\r
+               );\r
+       });\r
+});\r
+*/\r
+\r
+\r
+//window.decodeURIComponent || (window.decodeURIComponent = window.decodeURI);\r
+\r
+\r
+/*\r
+ * String\r
+ */\r
+\r
+// replace(RegExp, Function)対応\r
+/*\r
+if (window.ActiveXObject ? !Number.prototype.toFixed : (!navigator.taintEnabled && !document.createElement("input").setSelectionRange))\r
+       (function () {\r
+               var g = String.prototype.replace;\r
+               String.prototype.replace = function (x, y) {\r
+                       var s = this, z = y;\r
+                       // 第二引数が関数\r
+                       if (y instanceof Function) {\r
+                               // 第一引数が正規表現\r
+                               if (x instanceof RegExp) {\r
+                                       // その上、グローバルマッチ\r
+                                       if (x.global || /^\/.*g$/.test(x)) {\r
+                                               var r = [], m;\r
+                                               while ((m = x.exec(s)) != null) {\r
+                                                       var i = m.index;\r
+                                                       r[r.length] = s.slice(0, i);\r
+                                                       s = s.slice(i + m[0].length);\r
+                                                       r[r.length] = y.apply(null, m.concat(i, this));\r
+                                               }\r
+                                               r[r.length] = s;\r
+                                               return r.join("");\r
+                                       }\r
+                                       var m = x.exec(s);\r
+                                       if (!m)\r
+                                               return s;\r
+                                       z = y.apply(null, m.concat(m.index, s));\r
+                               }\r
+                               else {\r
+                                       var i = s.indexOf(x);\r
+                                       if (i < 0)\r
+                                               return s;\r
+                                       z = y(x, i, s);\r
+                               }\r
+                       }\r
+                       return g.call(s, x, z);\r
+               };\r
+       })(); */\r
+       \r
+/*\r
+ * Safari の JavaScript の不備 \r
+ * http://nanto.asablo.jp/blog/2006/01/13/209495\r
+ * \r
+ * web.paulownia.jp - JavaScriptとクロージャ\r
+ * https://web.archive.org/web/20070526063400/http://web.paulownia.jp/script/oop/closure.html\r
+ * MacOSX 10.3のsafariにはhasOwnPropertyが実装されていないので、独自に追加する必要があります。\r
+ */\r
+/*\r
+Object.prototype.hasOwnProperty || (Object.prototype.hasOwnProperty = function( p ){\r
+               var proto = this.constructor && this.constructor.prototype,\r
+                       __p__ = proto && ( '__proto__' in proto ) && proto.__proto__,\r
+                       v     = this[ p ],\r
+                       nan   = v !== v, // isNaN\r
+                       r = false, save;\r
+               \r
+               if( __p__ ) proto.__proto__ = v === null ? undefined : null;\r
+               \r
+               if( nan ){\r
+                       if( proto[ p ] !== proto[ p ] ){ // proto is NaN\r
+                               proto[ p ] = 0; // different value\r
+                               r = this[ p ] !== this[ p ]; // isNaN\r
+                               proto[ p ] = NaN; // proto で定義されていた.\r
+                       } else {\r
+                               r = true;\r
+                       };\r
+               } else\r
+               if( p in this ){\r
+                       if( !proto || !( p in proto ) || ( proto[ p ] !== v ) ){\r
+                               r = true;\r
+                       } else {\r
+                               // this と proto に同名で同値が書かれている可能性あり\r
+                               save = proto[ p ];\r
+                               proto[ p ] = v + ' '; // different value\r
+                               r = v === this[ p ];\r
+                               \r
+                               delete proto[ p ];\r
+                       \r
+                               if( proto[ p ] !== v ){\r
+                                       // proto で定義されていた.\r
+                                       proto[ p ] = save;                              \r
+                               };\r
+                       };\r
+               };\r
+               \r
+               if( __p__ ) proto.__proto__ = __p__;\r
+               \r
+               return r;\r
+  });*/\r