查看文章 |
lite tools
2008-07-01 00:34
(function(bootstrap){ if( window.$__loaded ) return ; window.$__loaded = true; var temp = document.createElement('div'); (function(){ try{ temp.doScroll('left'); document.body.appendChild(temp); temp.innerHTML = 'temp'; document.body.removeChild(temp); }catch(e){ return setTimeout(arguments.callee, 50); } bootstrap(); try{setTimeout(window.$domready, 1);}catch(e){} })(); })(function(){ function $impl( obj ){ if(this instanceof Array){ for (var i = 0, l = this.length; i < l; i++){ arguments.callee.call(this[i], obj); } return ; }else{ for(var key in obj ){ if( !this.prototype[key] ){ this.prototype[key] = obj[key]; } } } } if( !window.$ ){ window.$ = function(id){ return document.getElementById(id); } } $impl.call(Array, { forEach: function(fn, bind){ for (var i = 0, l = this.length; i < l; i++) fn.call(bind, this[i], i, this); }, filter: function(fn, bind){ var results = []; for (var i = 0, l = this.length; i < l; i++){ if (fn.call(bind, this[i], i, this)) results.push(this[i]); } return results; }, map: function(fn, bind){ var results = []; for (var i = 0, l = this.length; i < l; i++) results[i] = fn.call(bind, this[i], i, this); return results; } }); Array.prototype.each = Array.prototype.forEach; $impl.call(String, { test: function(regex, params){ return ((typeof regex == 'string') ? new RegExp(regex, params) : regex).test(this); }, trim: function(){ return this.replace(/^\s+|\s+$/g, ''); } }); // JSON if( !window.JSON ){ window.JSON = (function(){ var useHasOwn = !!{}.hasOwnProperty; var pad = function(n) { return n < 10 ? "0" + n : n; }; var m = { "\b": '\\b', "\t": '\\t', "\n": '\\n', "\f": '\\f', "\r": '\\r', '"' : '\\"', "\\": '\\\\' }; var encodeString = function(s){ if (/["\\\x00-\x1f]/.test(s)) { return '"' + s.replace(/([\x00-\x1f\\"])/g, function(a, b) { var c = m[b]; if(c){ return c; } c = b.charCodeAt(); return "\\u00" + Math.floor(c / 16).toString(16) + (c % 16).toString(16); }) + '"'; } return '"' + s + '"'; }; var encodeArray = function(o){ var a = ["["], b, i, l = o.length, v; for (i = 0; i < l; i += 1) { v = o[i]; switch (typeof v) { case "undefined": case "function": case "unknown": break; default: if (b) { a.push(','); } a.push(v === null ? "null" : encode(v)); b = true; } } a.push("]"); return a.join(""); }; var encode = function(o){ if(typeof o == "undefined" || o === null){ return "null"; }else if(o instanceof Array){ return encodeArray(o); }else if(typeof o == "string"){ return encodeString(o); }else if(typeof o == "number"){ return isFinite(o) ? String(o) : "null"; }else if(typeof o == "boolean"){ return String(o); }else { var a = ["{"], b, i, v; for (i in o) { if(!useHasOwn || o.hasOwnProperty(i)) { v = o[i]; switch (typeof v) { case "undefined": case "function": case "unknown": break; default: if(b){ a.push(','); } a.push(this.encode(i), ":", v === null ? "null" : this.encode(v)); b = true; } } } a.push("}"); return a.join(""); } }; var decode = function(json){ return eval("(" + json + ')'); }; return {encode: encode , decode : decode} })(); } }); |
最近读者: