2 * @preserve Copyright 2012-2014 pettanR team.
\r
3 * https://sourceforge.jp/projects/pettanr/
\r
4 * BSD 3-Clause License
\r
8 * ビルトインオブジェクトに拡張したい10のメソッド
\r
9 * http://d.hatena.ne.jp/ofk/20080922/1222047483
\r
12 Function.prototype.apply || (Function.prototype.apply = function (x, y) {
\r
13 var apply = '__apply',
\r
19 // apply 内で apply を呼んだ場合に備える
\r
21 x[ apply ] = void 0;
\r
23 if( x.constructor && x.constructor.prototype[ apply ] ){
\r
24 delete x.constructor.prototype[ apply ];
\r
26 if( x[ apply ] ) delete x[ apply ];
\r
30 if (!x[ apply ]) x.constructor.prototype[ apply ] = this;
\r
33 case 0: r = x[ apply ](); break;
\r
34 case 1: r = x[ apply ](y[0]); break;
\r
35 case 2: r = x[ apply ](y[0], y[1]); break;
\r
36 case 3: r = x[ apply ](y[0], y[1], y[2]); break;
\r
37 case 4: r = x[ apply ](y[0], y[1], y[2], y[3]); break;
\r
38 case 5: r = x[ apply ](y[0], y[1], y[2], y[3], y[4]); break;
\r
39 case 6: r = x[ apply ](y[0], y[1], y[2], y[3], y[4], y[5]); break;
\r
40 case 7: r = x[ apply ](y[0], y[1], y[2], y[3], y[4], y[5], y[6]); break;
\r
41 case 8: r = x[ apply ](y[0], y[1], y[2], y[3], y[4], y[5], y[6], y[7]); break;
\r
42 case 9: r = x[ apply ](y[0], y[1], y[2], y[3], y[4], y[5], y[6], y[7], y[8]); break;
\r
45 for (i = 0; i < j; ++i)
\r
46 a[i] = 'y[' + i + ']';
\r
47 //r = eval('x.__apply(' + a.join(',') + ')');
\r
48 // closuer compiler 対策
\r
49 r = (new Function( 'x,y', 'return x.__apply(' + a.join(',') + ')' ))( x, y );
\r
54 x[ apply ] = void 0;
\r
56 //alert( typeof x );
\r
57 if( x.constructor && x.constructor.prototype[ apply ] ){
\r
58 delete x.constructor.prototype[ apply ];
\r
60 if( x[ apply ] ) delete x[ apply ];
\r
64 Function.prototype.call || (Function.prototype.call = function () {
\r
65 var a = arguments, x = a[0], y = [], i = 1, j = a.length;
\r
68 return this.apply(x, y);
\r
71 Array.prototype.pop || (Array.prototype.pop = function () {
\r
72 var r = this[this.length - 1];
\r
76 Array.prototype.push || (Array.prototype.push = function () {
\r
77 var a = arguments, i = 0, j = a.length, l = this.length;
\r
82 Array.prototype.shift || (Array.prototype.shift = function () {
\r
83 var r = this[0], i = 1, j = this.length;
\r
85 this[i - 1] = this[i];
\r
89 Array.prototype.unshift || (Array.prototype.unshift = function () {
\r
90 var a = arguments, l = a.length, j = this.length += l - 1, i = j;
\r
92 this[i] = this[i - l];
\r
93 for (i = 0; i < l; ++i)
\r
97 Array.prototype.splice || (Array.prototype.splice = function (x, y) {
\r
98 var a = arguments, s = a.length - 2 - y, r = this.slice(x, x + y),i,j;
\r
100 for (i = this.length - 1, j = x + y; i >= j; --i)
\r
101 this[i + s] = this[i];
\r
104 for (i = x + y, j = this.length; i < j; ++i)
\r
105 this[i + s] = this[i];
\r
108 for (i = 2, j = a.length; i < j; ++i)
\r
109 this[i - 2 + x] = a[i];
\r
115 * JavaScript 1.6, Array.indexOfを下位互換実装する
\r
116 * http://www.inazumatv.com/contents/archives/7965
\r
119 Array.prototype.indexOf || (Array.prototype.indexOf = function( searchElement, fromIndex ){
\r
120 var l = this.length >>> 0, i;
\r
122 if( l === 0 ) return -1;
\r
125 i = fromIndex || 0;
\r
126 i = i === -Infinity ? 0 : ( i < 0 ? -i : i ) | 0; // Math.floor
\r
127 if( l <= i ) return -1;
\r
130 for( i = 0 <= i ? i : 0 < l + i ? l + i : 0; i < l; ++i ){
\r
131 if( this[ i ] === searchElement ) return i;
\r
138 * JavaScript split Bugs: Fixed!
\r
139 * http://blog.stevenlevithan.com/archives/cross-browser-split
\r
144 * by https://web.archive.org/web/20100413085309/http://nurucom-archives.hp.infoseek.co.jp/digital/trans-uri.html
\r
149 // TransURI (UTF-8): transURI.js (Ver.041211)
\r
151 // Copyright (C) http://nurucom-archives.hp.infoseek.co.jp/digital/
\r
154 EncodeURI=function(str){
\r
155 return str.replace(/[^!#$&-;=?-Z_a-z~]/g,function(s){
\r
156 var c=s.charCodeAt(0);
\r
157 return (c<16?"%0"+c.toString(16):c<128?"%"+c.toString(16):c<2048?"%"+(c>>6|192).toString(16)+"%"+(c&63|128).toString(16):"%"+(c>>12|224).toString(16)+"%"+(c>>6&63|128).toString(16)+"%"+(c&63|128).toString(16)).toUpperCase()
\r
161 EncodeURIComponent=function(str){
\r
162 return str.replace(/[^!'-*.0-9A-Z_a-z~-]/g,function(s){
\r
163 var c=s.charCodeAt(0);
\r
164 return (c<16?'%0'+c.toString(16):c<128?'%'+c.toString(16):c<2048?'%'+(c>>6|192).toString(16)+'%'+(c&63|128).toString(16):'%'+(c>>12|224).toString(16)+'%'+(c>>6&63|128).toString(16)+'%'+(c&63|128).toString(16)).toUpperCase()
\r
168 DecodeURI=function(str){
\r
169 return str.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
170 var c=parseInt(s.substring(1),16);
\r
171 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)
\r
176 /* 正規表現が使われているため、まだ投入しない itozyun*/
\r
177 window.encodeURI || (window.encodeURI = function (x) {
\r
178 return ("" + x).replace(/[^!#$&-;=?-Z_a-z~]/g, function (s) {
\r
179 var c = s.charCodeAt(0), p = "%";
\r
181 c < 16 ? "%0" + c.toString(16) :
\r
182 c < 128 ? p + c.toString(16) :
\r
183 c < 2048 ? p + (c >> 6 | 192).toString(16) + p + (c & 63 | 128).toString(16) :
\r
184 p + (c >> 12 | 224).toString(16) + p + (c >> 6 & 63 | 128).toString(16) + p + (c & 63 | 128).toString(16)
\r
189 window.encodeURIComponent || (window.encodeURIComponent = function (x) {
\r
190 return ("" + x).replace(/[^!'-*.0-9A-Z_a-z~-]/g, function (s) {
\r
191 var c = s.charCodeAt(0), p = "%";
\r
193 c < 16 ? "%0" + c.toString(16) :
\r
194 c < 128 ? p + c.toString(16) :
\r
195 c < 2048 ? p + (c >> 6 | 192).toString(16) + p + (c & 63 | 128).toString(16) :
\r
196 p + (c >> 12 | 224).toString(16) + p + (c >> 6 & 63 | 128).toString(16) + p + (c & 63 | 128).toString(16)
\r
202 window.decodeURI || (window.decodeURI = function (x) {
\r
203 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
204 var c = parseInt(s.substring(1), 16);
\r
205 return String.fromCharCode(
\r
207 c < 224 ? (c & 31) << 6 | parseInt(s.substring(4), 16) & 63 :
\r
208 ((c & 15) << 6 | parseInt(s.substring(4), 16) & 63) << 6 | parseInt(s.substring(7), 16) & 63
\r
215 //window.decodeURIComponent || (window.decodeURIComponent = window.decodeURI);
\r
222 // replace(RegExp, Function)対応
\r
224 if (window.ActiveXObject ? !Number.prototype.toFixed : (!navigator.taintEnabled && !document.createElement("input").setSelectionRange))
\r
226 var g = String.prototype.replace;
\r
227 String.prototype.replace = function (x, y) {
\r
228 var s = this, z = y;
\r
230 if (y instanceof Function) {
\r
232 if (x instanceof RegExp) {
\r
234 if (x.global || /^\/.*g$/.test(x)) {
\r
236 while ((m = x.exec(s)) != null) {
\r
238 r[r.length] = s.slice(0, i);
\r
239 s = s.slice(i + m[0].length);
\r
240 r[r.length] = y.apply(null, m.concat(i, this));
\r
248 z = y.apply(null, m.concat(m.index, s));
\r
251 var i = s.indexOf(x);
\r
257 return g.call(s, x, z);
\r
262 * Safari の JavaScript の不備
\r
263 * http://nanto.asablo.jp/blog/2006/01/13/209495
\r
265 * web.paulownia.jp - JavaScriptとクロージャ
\r
266 * https://web.archive.org/web/20070526063400/http://web.paulownia.jp/script/oop/closure.html
\r
267 * MacOSX 10.3のsafariにはhasOwnPropertyが実装されていないので、独自に追加する必要があります。
\r
269 * prototype汚染問題でhasOwnPropertyを使わないクロスブラウザな方法
\r
270 * http://os0x.hatenablog.com/entry/20080901/1220272509
\r
273 Object.prototype.hasOwnProperty || (Object.prototype.hasOwnProperty = function( p ){
\r
274 var proto = this.constructor && this.constructor.prototype,
\r
275 __p__ = proto && proto.__proto__,
\r
279 if( __p__ ) proto.__proto__ = null;
\r
283 if( proto && ( p in proto ) && proto[ p ] !== proto[ p ] ){ // proto[ p ] is NaN
\r
284 proto[ p ] = 0; // different value
\r
285 r = this[ p ] !== this[ p ]; // isNaN?
\r
286 proto[ p ] = v; // set NaN
\r
291 if( proto && p in proto && proto[ p ] === v ){
\r
292 // this と proto に同名で同値が書かれている可能性あり
\r
293 proto[ p ] = v + ' '; // different value
\r
294 r = v === this[ p ];
\r
301 if( __p__ ) proto.__proto__ = __p__;
\r
306 Object.prototype.hasOwnProperty || (Object.prototype.hasOwnProperty = function( p ){
\r
307 var proto = this.constructor && this.constructor.prototype,
\r
308 __p__ = proto && proto.__proto__,
\r
309 r = false,//!!( __p__ && ( proto.__proto__ = null ) )
\r
312 if( __p__ ) proto.__proto__ = null;
\r
313 if( this.__proto__ ){
\r
314 _pro_ = this.__proto__;
\r
315 this.__proto__ = null;
\r
318 if( p === '__proto__' ){
\r
325 if( proto && p in proto && ( proto[ p ] === v ) ^ isNaN ){ //true + false, false + true
\r
326 // this と proto に同名で同値が書かれている可能性あり
\r
327 proto[ p ] = v + ' '; // different value
\r
328 r = ( v === this[ p ] ) ^ isNaN; // true + false, false + true
\r
336 if( __p__ ) proto.__proto__ = __p__;
\r
337 if( _p_ ) this.__proto__ = _pro_;
\r