⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 base.js

📁 .NET 网页编辑器
💻 JS
📖 第 1 页 / 共 2 页
字号:
      map:     Enumerable.collect,
      find:    Enumerable.detect,
      select:  Enumerable.findAll,
      member:  Enumerable.include,
      entries: Enumerable.toArray
    });

/*
    Enumerable End here
*/




/*
    Hash Start here
*/
    var Hash = {
      _each: function(iterator) {
        for (key in this) {
          var value = this[key];
          if (typeof value == 'function') continue;

          var pair = [key, value];
          pair.key = key;
          pair.value = value;
          iterator(pair);
        }
      },

      keys: function() {
        return this.pluck('key');
      },

      values: function() {
        return this.pluck('value');
      },

      merge: function(hash) {
        return $H(hash).inject($H(this), function(mergedHash, pair) {
          mergedHash[pair.key] = pair.value;
          return mergedHash;
        });
      },

      toQueryString: function() {
        return this.map(function(pair) {
          return pair.map(encodeURIComponent).join('=');
        }).join('&');
      },

      inspect: function() {
        return '#<Hash:{' + this.map(function(pair) {
          return pair.map(Object.inspect).join(': ');
        }).join(', ') + '}>';
      }
    }

    function $H(object) {
      var hash = Object.extend({}, object || {});
      Object.extend(hash, Enumerable);
      Object.extend(hash, Hash);
      return hash;
    }

/*
    Hash End here
*/




/*
    String Start here
*/

    Object.extend(String.prototype, {
      stripTags: function() {
        return this.replace(/<\/?[^>]+>/gi, '');
      },

      stripScripts: function() {
        return this.replace(new RegExp(Prototype.ScriptFragment, 'img'), '');
      },

      extractScripts: function() {
        var matchAll = new RegExp(Prototype.ScriptFragment, 'img');
        var matchOne = new RegExp(Prototype.ScriptFragment, 'im');
        return (this.match(matchAll) || []).map(function(scriptTag) {
          return (scriptTag.match(matchOne) || ['', ''])[1];
        });
      },

      evalScripts: function() {
        return this.extractScripts().map(eval);
      },

      escapeHTML: function() {
        var div = document.createElement('div');
        var text = document.createTextNode(this);
        div.appendChild(text);
        return div.innerHTML;
      },

      unescapeHTML: function() {
        var div = document.createElement('div');
        div.innerHTML = this.stripTags();
        return div.childNodes[0] ? div.childNodes[0].nodeValue : '';
      },

      toQueryParams: function() {
        var pairs = this.match(/^\??(.*)$/)[1].split('&');
        return pairs.inject({}, function(params, pairString) {
          var pair = pairString.split('=');
          params[pair[0]] = pair[1];
          return params;
        });
      },

      toArray: function() {
        return this.split('');
      },

      camelize: function() {
        var oStringList = this.split('-');
        if (oStringList.length == 1) return oStringList[0];

        var camelizedString = this.indexOf('-') == 0
          ? oStringList[0].charAt(0).toUpperCase() + oStringList[0].substring(1)
          : oStringList[0];

        for (var i = 1, len = oStringList.length; i < len; i++) {
          var s = oStringList[i];
          camelizedString += s.charAt(0).toUpperCase() + s.substring(1);
        }

        return camelizedString;
      },

      inspect: function() {
        return "'" + this.replace('\\', '\\\\').replace("'", '\\\'') + "'";
      }
    });

    String.prototype.parseQuery = String.prototype.toQueryParams;



    //此处为string类添加三个成员 
    String.prototype.Trim = function(){ return Trim(this);} 
    String.prototype.LTrim = function(){return LTrim(this);} 
    String.prototype.RTrim = function(){return RTrim(this);} 

    //此处为独立函数 
    function LTrim(str) 
    { 
    var i; 
    for(i=0;i<str.length;i++) 
    { 
    if(str.charAt(i)!=" "&&str.charAt(i)!=" ")break; 
    } 
    str=str.substring(i,str.length); 
    return str; 
    } 
    function RTrim(str) 
    { 
    var i; 
    for(i=str.length-1;i>=0;i--) 
    { 
    if(str.charAt(i)!=" "&&str.charAt(i)!=" ")break; 
    } 
    str=str.substring(0,i+1); 
    return str; 
    } 
    function Trim(str) 
    { 
    return LTrim(RTrim(str)); 
    } 
    
/*
    String End here
*/


/*
    Number Start here
*/
    Object.extend(Number.prototype, {
      toColorPart: function() {
        var digits = this.toString(16);
        if (this < 16) return '0' + digits;
        return digits;
      },

      succ: function() {
        return this + 1;
      },

      times: function(iterator) {
        $R(0, this, true).each(iterator);
        return this;
      }
    });
/*
    Number End here
*/



/*
    Event Start here
*/
    if (!window.Event) {
      var Event = new Object();
    }

    Object.extend(Event, {
      KEY_BACKSPACE: 8,
      KEY_TAB:       9,
      KEY_RETURN:   13,
      KEY_ESC:      27,
      KEY_LEFT:     37,
      KEY_UP:       38,
      KEY_RIGHT:    39,
      KEY_DOWN:     40,
      KEY_DELETE:   46,

      element: function(event) {
        return event.target || event.srcElement;
      },

      isLeftClick: function(event) {
        return (((event.which) && (event.which == 1)) ||
                ((event.button) && (event.button == 1)));
      },

      pointerX: function(event) {
        return event.pageX || (event.clientX +
          (document.documentElement.scrollLeft || document.body.scrollLeft));
      },

      pointerY: function(event) {
        return event.pageY || (event.clientY +
          (document.documentElement.scrollTop || document.body.scrollTop));
      },

      stop: function(event) {
        if (event.preventDefault) {
          event.preventDefault();
          event.stopPropagation();
        } else {
          event.returnValue = false;
          event.cancelBubble = true;
        }
      },

      // find the first node with the given tagName, starting from the
      // node the event was triggered on; traverses the DOM upwards
      findElement: function(event, tagName) {
        var element = Event.element(event);
        while (element.parentNode && (!element.tagName ||
            (element.tagName.toUpperCase() != tagName.toUpperCase())))
          element = element.parentNode;
        return element;
      },

      observers: false,

      _observeAndCache: function(element, name, observer, useCapture) {
        if (!this.observers) this.observers = [];
        if (element.addEventListener) {
          this.observers.push([element, name, observer, useCapture]);
          element.addEventListener(name, observer, useCapture);
        } else if (element.attachEvent) {
          this.observers.push([element, name, observer, useCapture]);
          element.attachEvent('on' + name, observer);
        }
      },

      unloadCache: function() {
        if (!Event.observers) return;
        for (var i = 0; i < Event.observers.length; i++) {
          Event.stopObserving.apply(this, Event.observers[i]);
          Event.observers[i][0] = null;
        }
        Event.observers = false;
      },

      observe: function(element, name, observer, useCapture) {
        var element = $(element);
        useCapture = useCapture || false;

        if (name == 'keypress' &&
            (navigator.appVersion.match(/Konqueror|Safari|KHTML/)
            || element.attachEvent))
          name = 'keydown';

        this._observeAndCache(element, name, observer, useCapture);
      },

      stopObserving: function(element, name, observer, useCapture) {
        var element = $(element);
        useCapture = useCapture || false;

        if (name == 'keypress' &&
            (navigator.appVersion.match(/Konqueror|Safari|KHTML/)
            || element.detachEvent))
          name = 'keydown';

        if (element.removeEventListener) {
          element.removeEventListener(name, observer, useCapture);
        } else if (element.detachEvent) {
          element.detachEvent('on' + name, observer);
        }
      }
    });


    /* prevent memory leaks in IE */
    Event.observe(window, 'unload', Event.unloadCache, false);

/*
    Event End here
*/


/*        
        FrameWork Start here                  
 */

    //addNamespace
    if(!window.addNamespace) {
	    window.addNamespace = function(ns) {
		    var nsParts = ns.split(".");
		    var root = window;

		    for(var i=0; i<nsParts.length; i++) {
			    if(typeof root[nsParts[i]] == "undefined")
				    root[nsParts[i]] = {};
			    root = root[nsParts[i]];
		    }
	    }
    }

    //getInstance
    window.getInstance = function(className, o) {
	    if(o == null) o = window;
	    var c = className.split(".");	
	    if(c.length > 1)
		    return window.getInstance(className.substr(className.indexOf(".") +1), o[c[0]]);
	    return o[className];
    }

    window.toJSON = function(o) {

	    if(o == null)
		    return "null";

	    switch(o.constructor) {
    		
		    case String:
			    var s = o; // .encodeURI();
			    s = '"' + s.replace(/(["\\])/g, '\\$1') + '"';
			    s = s.replace(/\n/g,"\\n");
			    s = s.replace(/\r/g,"\\r");
			    return s;
    		
		    case Array:
			    var v = [];
			    for(var i=0; i<o.length; i++)
				    v.push(window.toJSON(o[i])) ;
			    return "[" + v.join(", ") + "]";
    		
		    case Number:
			    return isFinite(o) ? o.toString() : window.toJSON(null);
    	
		    case Boolean:
			    return o.toString();
    			
		    case Date:
			    var d = new Object();
			    d.Year = o.getUTCFullYear();
			    d.Month = o.getUTCMonth() +1;
			    d.Day = o.getUTCDate();
			    d.Hour = o.getUTCHours();
			    d.Minute = o.getUTCMinutes();
			    d.Second = o.getUTCSeconds();
			    d.Millisecond = o.getUTCMilliseconds();
			    d.TimezoneOffset = o.getTimezoneOffset();
			    return window.toJSON(d);
    	
		    default:
			    if(o["toJSON"] != null && typeof o["toJSON"] == "function")
				    return o.toJSON();
    				
			    if(typeof o == "object") {
				    var v=[];
    				
				    for(attr in o) {
					    if(typeof o[attr] != "function")
						    v.push('"' + attr + '": ' + window.toJSON(o[attr]));
				    }

				    if(v.length>0)
					    return "{" + v.join(", ") + "}";
				    else
					    return "{}";		
			    }
			    return o.toString();
	    }
    }
/*        
        FrameWork End here                  
 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -