X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.6.x%2Fjs%2F01_core%2F00_builtin.js;h=e483e4e06669b8301bc0326d007d94d5b1664c63;hb=a205577d1e16a34301f1199dcf9c699aa2c37fb9;hp=d98e43a3208205d02d34ecb98bd6ec95515d0b64;hpb=36e3d975f201a804af90f1a21ff352d14a438f6c;p=pettanr%2FclientJs.git diff --git a/0.6.x/js/01_core/00_builtin.js b/0.6.x/js/01_core/00_builtin.js index d98e43a..e483e4e 100644 --- a/0.6.x/js/01_core/00_builtin.js +++ b/0.6.x/js/01_core/00_builtin.js @@ -10,34 +10,36 @@ */ Function.prototype.apply || (Function.prototype.apply = function (x, y) { - var a, i, r, j; + var apply = '__apply', + a, i, r, j; + x = x || window; y = y || []; // apply 内で apply を呼んだ場合に備える if( x === window ){ - x.__apply = void 0; + x[ apply ] = void 0; } else { - if( x.constructor && x.constructor.prototype.__apply ){ - delete x.constructor.prototype.__apply; + if( x.constructor && x.constructor.prototype[ apply ] ){ + delete x.constructor.prototype[ apply ]; } else - if( x.__apply ) delete x.__apply; + if( x[ apply ] ) delete x[ apply ]; }; - x.__apply = this; - if (!x.__apply) x.constructor.prototype.__apply = this; + x[ apply ] = this; + if (!x[ apply ]) x.constructor.prototype[ apply ] = this; j = y.length; switch (j) { - case 0: r = x.__apply(); break; - case 1: r = x.__apply(y[0]); break; - case 2: r = x.__apply(y[0], y[1]); break; - case 3: r = x.__apply(y[0], y[1], y[2]); break; - case 4: r = x.__apply(y[0], y[1], y[2], y[3]); break; - case 5: r = x.__apply(y[0], y[1], y[2], y[3], y[4]); break; - case 6: r = x.__apply(y[0], y[1], y[2], y[3], y[4], y[5]); break; - case 7: r = x.__apply(y[0], y[1], y[2], y[3], y[4], y[5], y[6]); break; - case 8: r = x.__apply(y[0], y[1], y[2], y[3], y[4], y[5], y[6], y[7]); break; - case 9: r = x.__apply(y[0], y[1], y[2], y[3], y[4], y[5], y[6], y[7], y[8]); break; + case 0: r = x[ apply ](); break; + case 1: r = x[ apply ](y[0]); break; + case 2: r = x[ apply ](y[0], y[1]); break; + case 3: r = x[ apply ](y[0], y[1], y[2]); break; + case 4: r = x[ apply ](y[0], y[1], y[2], y[3]); break; + case 5: r = x[ apply ](y[0], y[1], y[2], y[3], y[4]); break; + case 6: r = x[ apply ](y[0], y[1], y[2], y[3], y[4], y[5]); break; + case 7: r = x[ apply ](y[0], y[1], y[2], y[3], y[4], y[5], y[6]); break; + case 8: r = x[ apply ](y[0], y[1], y[2], y[3], y[4], y[5], y[6], y[7]); break; + case 9: r = x[ apply ](y[0], y[1], y[2], y[3], y[4], y[5], y[6], y[7], y[8]); break; default: a = []; for (i = 0; i < j; ++i) @@ -49,13 +51,13 @@ Function.prototype.apply || (Function.prototype.apply = function (x, y) { }; // ie5 if( x === window ){ - x.__apply = void 0; + x[ apply ] = void 0; } else { //alert( typeof x ); - if( x.constructor && x.constructor.prototype.__apply ){ - delete x.constructor.prototype.__apply; + if( x.constructor && x.constructor.prototype[ apply ] ){ + delete x.constructor.prototype[ apply ]; } else - if( x.__apply ) delete x.__apply; + if( x[ apply ] ) delete x[ apply ]; }; return r; }); @@ -133,50 +135,100 @@ Array.prototype.indexOf || (Array.prototype.indexOf = function( searchElement, f /* - * Window - * by http://nurucom-archives.hp.infoseek.co.jp/digital/trans-uri.html + * JavaScript split Bugs: Fixed! + * http://blog.stevenlevithan.com/archives/cross-browser-split */ -/* 正規表現が使われているため、まだ投入しない itozyun -window.encodeURI || (window.encodeURI = function (x) { - return ("" + x).replace(/[^!#$&-;=?-Z_a-z~]/g, function (s) { - var c = s.charCodeAt(0), p = "%"; - return ( - c < 16 ? "%0" + c.toString(16) : - c < 128 ? p + c.toString(16) : - c < 2048 ? p + (c >> 6 | 192).toString(16) + p + (c & 63 | 128).toString(16) : - p + (c >> 12 | 224).toString(16) + p + (c >> 6 & 63 | 128).toString(16) + p + (c & 63 | 128).toString(16) - ).toUpperCase(); - }); -}); +/* + * original: + * by https://web.archive.org/web/20100413085309/http://nurucom-archives.hp.infoseek.co.jp/digital/trans-uri.html + */ +var _builtin_skipEncodeURI = (function(){ + var encodeURIComponentTarget = '!\'()*-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~', + encodeURITarget = '#$&+,-/:;=?@', + obj = {}, i; + for( i = encodeURIComponentTarget.length; i; ){ + obj[ encodeURIComponentTarget.charCodeAt( --i ) ] = 2; + }; + for( i = encodeURITarget.length; i; ){ + obj[ encodeURITarget.charCodeAt( --i ) ] = 1; + }; + return obj; +})(); -window.encodeURIComponent || (window.encodeURIComponent = function (x) { - return ("" + x).replace(/[^!'-*.0-9A-Z_a-z~-]/g, function (s) { - var c = s.charCodeAt(0), p = "%"; - return ( - c < 16 ? "%0" + c.toString(16) : - c < 128 ? p + c.toString(16) : - c < 2048 ? p + (c >> 6 | 192).toString(16) + p + (c & 63 | 128).toString(16) : - p + (c >> 12 | 224).toString(16) + p + (c >> 6 & 63 | 128).toString(16) + p + (c & 63 | 128).toString(16) - ).toUpperCase(); - }); -}); +// /[^!#$&-;=?-Z_a-z~]/g +window[ 'encodeURI' ] || (window[ 'encodeURI' ] = function( x ){ return _builtin_encodeURI( x, 0 ); }); +// /[^!'-*.0-9A-Z_a-z~-]/g +window[ 'encodeURIComponent' ] || (window[ 'encodeURIComponent' ] = function( x ){ return _builtin_encodeURI( x, 1 ); }); + +function _builtin_encodeURI( x, kind ){ + var result = [], + skip = _builtin_skipEncodeURI, + p = '%', + i = 0, l, chr, c; + + x += ''; + + for( l = x.length; i < l; ++i ){ + if( !( kind < skip[ c = x.charCodeAt( i ) ] ) ){ + chr = ( + c < 16 ? '%0' + c.toString(16) : + c < 128 ? p + c.toString(16) : + c < 2048 ? p + (c >> 6 | 192).toString(16) + p + (c & 63 | 128).toString(16) : + p + (c >> 12 | 224).toString(16) + p + (c >> 6 & 63 | 128).toString(16) + p + (c & 63 | 128).toString(16) + ).toUpperCase(); + } else { + chr = x.charAt( i ); + }; + result[ i ] = chr; + }; + + return result.join( '' ); +}; -// 手抜き -window.decodeURI || (window.decodeURI = function (x) { - 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) { - var c = parseInt(s.substring(1), 16); - return String.fromCharCode( - c < 128 ? c : - c < 224 ? (c & 31) << 6 | parseInt(s.substring(4), 16) & 63 : - ((c & 15) << 6 | parseInt(s.substring(4), 16) & 63) << 6 | parseInt(s.substring(7), 16) & 63 - ); - }); -}); -*/ +function _builtin_decodeURI( x ){ + var result = [], + toInt = parseInt, + toChrCode = String.fromCharCode, + n = -1, i = 0, l, chr, decode, code, memory; + + x += ''; + + for( l = x.length; i < l; ++i ){ + if( decode ){ + code = toInt( x.substr( i, 2 ), 16 ); + ++i; + if( 127 < code ){ + if( 223 < code ){ + memory = ( code & 15 ) << 12; + code = toInt( x.substr( i + 2, 2 ), 16 ) & 63; // 00%00%00 + i += 3; + memory += code << 6; + } else { + memory = ( code & 63 ) << 6; + }; + code = toInt( x.substr( i + 2, 2 ), 16 ) & 63; + i += 3; + code += memory; + }; + // if( code !== code ) error + //console.log( code ); + result[ ++n ] = toChrCode( code ); + decode = false; + } else { + chr = x.charAt( i ); + if( !( decode = chr === '%' ) ){ + result[ ++n ] = chr; + }; + }; + }; + + return result.join( '' ); +}; -//window.decodeURIComponent || (window.decodeURIComponent = window.decodeURI); +window[ 'decodeURI' ] || (window[ 'decodeURI' ] = _builtin_decodeURI); +window[ 'decodeURIComponent' ] || (window[ 'decodeURIComponent' ] = window.decodeURI); /* @@ -222,82 +274,3 @@ if (window.ActiveXObject ? !Number.prototype.toFixed : (!navigator.taintEnabled }; })(); */ -/* - * Safari の JavaScript の不備 - * http://nanto.asablo.jp/blog/2006/01/13/209495 - * - * web.paulownia.jp - JavaScriptとクロージャ - * https://web.archive.org/web/20070526063400/http://web.paulownia.jp/script/oop/closure.html - * MacOSX 10.3のsafariにはhasOwnPropertyが実装されていないので、独自に追加する必要があります。 - * - * prototype汚染問題でhasOwnPropertyを使わないクロスブラウザな方法 - * http://os0x.hatenablog.com/entry/20080901/1220272509 - */ -/* -Object.prototype.hasOwnProperty || (Object.prototype.hasOwnProperty = function( p ){ - var proto = this.constructor && this.constructor.prototype, - __p__ = proto && proto.__proto__, - v = this[ p ], - r = false; - - if( __p__ ) proto.__proto__ = null; - - if( p in this ){ - if( v !== v ){ - if( proto && ( p in proto ) && proto[ p ] !== proto[ p ] ){ // proto[ p ] is NaN - proto[ p ] = 0; // different value - r = this[ p ] !== this[ p ]; // isNaN? - proto[ p ] = v; // set NaN - } else { - r = true; - }; - } else - if( proto && p in proto && proto[ p ] === v ){ - // this と proto に同名で同値が書かれている可能性あり - proto[ p ] = v + ' '; // different value - r = v === this[ p ]; - proto[ p ] = v; - } else { - r = true; - }; - }; - - if( __p__ ) proto.__proto__ = __p__; - - return r; - }); */ -/* -Object.prototype.hasOwnProperty || (Object.prototype.hasOwnProperty = function( p ){ - var proto = this.constructor && this.constructor.prototype, - __p__ = proto && proto.__proto__, - r = false,//!!( __p__ && ( proto.__proto__ = null ) ) - _pro_, v, isNaN; - - if( __p__ ) proto.__proto__ = null; - if( this.__proto__ ){ - _pro_ = this.__proto__; - this.__proto__ = null; - }; - - if( p === '__proto__' ){ - r = !!_pro_; - } else { - v = this[ p ]; - isNaN = v !== v; - - if( p in this ){ - if( proto && p in proto && ( proto[ p ] === v ) ^ isNaN ){ //true + false, false + true - // this と proto に同名で同値が書かれている可能性あり - proto[ p ] = v + ' '; // different value - r = ( v === this[ p ] ) ^ isNaN; // true + false, false + true - proto[ p ] = v; - } else { - r = true; - }; - }; - }; - - if( __p__ ) proto.__proto__ = __p__; - if( _p_ ) this.__proto__ = _pro_; - return r; - }); */ \ No newline at end of file