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

📄 prototype.js

📁 针对wav格式转换为mp3一些相关说明
💻 JS
📖 第 1 页 / 共 5 页
字号:
var Prototype={Version:"1.6.0",Browser:{IE:!!(window.attachEvent&&!window.opera),Opera:!!window.opera,WebKit:navigator.userAgent.indexOf("AppleWebKit/")>-1,Gecko:navigator.userAgent.indexOf("Gecko")>-1&&navigator.userAgent.indexOf("KHTML")==-1,MobileSafari:!!navigator.userAgent.match(/Apple.*Mobile.*Safari/)},BrowserFeatures:{XPath:!!document.evaluate,ElementExtensions:!!window.HTMLElement,SpecificElementExtensions:document.createElement("div").__proto__&&document.createElement("div").__proto__!==document.createElement("form").__proto__},ScriptFragment:"<script[^>]*>([\\S\\s]*?)</script>",JSONFilter:/^\/\*-secure-([\s\S]*)\*\/\s*$/,emptyFunction:function(){
  },K:function(x){
    return x;
  }};
if(Prototype.Browser.MobileSafari){
  Prototype.BrowserFeatures.SpecificElementExtensions=false;
}
if(Prototype.Browser.WebKit){
  Prototype.BrowserFeatures.XPath=false;
}
var Class={create:function(){
    var parent=null,properties=$A(arguments);
    if(Object.isFunction(properties[0])){
      parent=properties.shift();
    }
    function klass(){
      this.initialize.apply(this,arguments);
    }
    Object.extend(klass,Class.Methods);
    klass.superclass=parent;
    klass.subclasses=[];
    if(parent){
      var subclass=function(){
      };
      subclass.prototype=parent.prototype;
      klass.prototype=new subclass;
      parent.subclasses.push(klass);
    }
    for(var i=0;i<properties.length;i++){
      klass.addMethods(properties[i]);
    }
    if(!klass.prototype.initialize){
      klass.prototype.initialize=Prototype.emptyFunction;
    }
    klass.prototype.constructor=klass;
    return klass;
  }};
Class.Methods={addMethods:function(source){
    var ancestor=this.superclass&&this.superclass.prototype;
    var properties=Object.keys(source);
    if(!Object.keys({toString:true}).length){
      properties.push("toString","valueOf");
    }
    for(var i=0,length=properties.length;i<length;i++){
      var property=properties[i],value=source[property];
      if(ancestor&&Object.isFunction(value)&&value.argumentNames().first()=="$super"){
        var method=value,value=Object.extend((function(m){
          return function(){
            return ancestor[m].apply(this,arguments);
          };
        })(property).wrap(method),{valueOf:function(){
            return method;
          },toString:function(){
            return method.toString();
          }});
      }
      this.prototype[property]=value;
    }
    return this;
  }};
var Abstract={};
Object.extend=function(destination,source){
  for(var property in source){
    destination[property]=source[property];
  }
  return destination;
};
Object.extend(Object,{inspect:function(object){
    try{
      if(object===undefined){
        return "undefined";
      }
      if(object===null){
        return "null";
      }
      return object.inspect?object.inspect():object.toString();
    }
    catch(e){
      if(e instanceof RangeError){
        return "...";
      }
      throw e;
    }
  },toJSON:function(object){
    var type=typeof object;
    switch(type){
    case "undefined":
    case "function":
    case "unknown":
      return ;
    case "boolean":
      return object.toString();
    }
    if(object===null){
      return "null";
    }
    if(object.toJSON){
      return object.toJSON();
    }
    if(Object.isElement(object)){
      return ;
    }
    var results=[];
    for(var property in object){
      var value=Object.toJSON(object[property]);
      if(value!==undefined){
        results.push(property.toJSON()+": "+value);
      }
    }
    return "{"+results.join(", ")+"}";
  },toQueryString:function(object){
    return $H(object).toQueryString();
  },toHTML:function(object){
    return object&&object.toHTML?object.toHTML():String.interpret(object);
  },keys:function(object){
    var keys=[];
    for(var property in object){
      keys.push(property);
    }
    return keys;
  },values:function(object){
    var values=[];
    for(var property in object){
      values.push(object[property]);
    }
    return values;
  },clone:function(object){
    return Object.extend({},object);
  },isElement:function(object){
    return object&&object.nodeType==1;
  },isArray:function(object){
    return object&&object.constructor===Array;
  },isHash:function(object){
    return object instanceof Hash;
  },isFunction:function(object){
    return typeof object=="function";
  },isString:function(object){
    return typeof object=="string";
  },isNumber:function(object){
    return typeof object=="number";
  },isUndefined:function(object){
    return typeof object=="undefined";
  }});
Object.extend(Function.prototype,{argumentNames:function(){
    var names=this.toString().match(/^[\s\(]*function[^(]*\((.*?)\)/)[1].split(",").invoke("strip");
    return names.length==1&&!names[0]?[]:names;
  },bind:function(){
    if(arguments.length<2&&arguments[0]===undefined){
      return this;
    }
    var __method=this,args=$A(arguments),object=args.shift();
    return function(){
      return __method.apply(object,args.concat($A(arguments)));
    };
  },bindAsEventListener:function(){
    var __method=this,args=$A(arguments),object=args.shift();
    return function(event){
      return __method.apply(object,[event||window.event].concat(args));
    };
  },curry:function(){
    if(!arguments.length){
      return this;
    }
    var __method=this,args=$A(arguments);
    return function(){
      return __method.apply(this,args.concat($A(arguments)));
    };
  },delay:function(){
    var __method=this,args=$A(arguments),timeout=args.shift()*1000;
    return window.setTimeout(function(){
      return __method.apply(__method,args);
    },timeout);
  },wrap:function(wrapper){
    var __method=this;
    return function(){
      return wrapper.apply(this,[__method.bind(this)].concat($A(arguments)));
    };
  },methodize:function(){
    if(this._methodized){
      return this._methodized;
    }
    var __method=this;
    return this._methodized=function(){
      return __method.apply(null,[this].concat($A(arguments)));
    };
  }});
Function.prototype.defer=Function.prototype.delay.curry(0.01);
Date.prototype.toJSON=function(){
  return "\""+this.getUTCFullYear()+"-"+(this.getUTCMonth()+1).toPaddedString(2)+"-"+this.getUTCDate().toPaddedString(2)+"T"+this.getUTCHours().toPaddedString(2)+":"+this.getUTCMinutes().toPaddedString(2)+":"+this.getUTCSeconds().toPaddedString(2)+"Z\"";
};
var Try={these:function(){
    var returnValue;
    for(var i=0,length=arguments.length;i<length;i++){
      var lambda=arguments[i];
      try{
        returnValue=lambda();
        break ;
      }
      catch(e){
      }
    }
    return returnValue;
  }};
RegExp.prototype.match=RegExp.prototype.test;
RegExp.escape=function(str){
  return String(str).replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1");
};
var PeriodicalExecuter=Class.create({initialize:function(callback,frequency){
    this.callback=callback;
    this.frequency=frequency;
    this.currentlyExecuting=false;
    this.registerCallback();
  },registerCallback:function(){
    this.timer=setInterval(this.onTimerEvent.bind(this),this.frequency*1000);
  },execute:function(){
    this.callback(this);
  },stop:function(){
    if(!this.timer){
      return ;
    }
    clearInterval(this.timer);
    this.timer=null;
  },onTimerEvent:function(){
    if(!this.currentlyExecuting){
      try{
        this.currentlyExecuting=true;
        this.execute();
      }
      finally{
        this.currentlyExecuting=false;
      }
    }
  }});
Object.extend(String,{interpret:function(value){
    return value==null?"":String(value);
  },specialChar:{"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r","\\":"\\\\"}});
Object.extend(String.prototype,{gsub:function(pattern,replacement){
    var result="",source=this,match;
    replacement=arguments.callee.prepareReplacement(replacement);
    while(source.length>0){
      if(match=source.match(pattern)){
        result+=source.slice(0,match.index);
        result+=String.interpret(replacement(match));
        source=source.slice(match.index+match[0].length);
      }else {
        result+=source,source="";
      }
    }
    return result;
  },sub:function(pattern,replacement,count){
    replacement=this.gsub.prepareReplacement(replacement);
    count=count===undefined?1:count;
    return this.gsub(pattern,function(match){
      if(--count<0){
        return match[0];
      }
      return replacement(match);
    });
  },scan:function(pattern,iterator){
    this.gsub(pattern,iterator);
    return String(this);
  },truncate:function(length,truncation){
    length=length||30;
    truncation=truncation===undefined?"...":truncation;
    return this.length>length?this.slice(0,length-truncation.length)+truncation:String(this);
  },strip:function(){
    return this.replace(/^\s+/,"").replace(/\s+$/,"");
  },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(function(script){
      return eval(script);
    });
  },escapeHTML:function(){
    var self=arguments.callee;
    self.text.data=this;
    return self.div.innerHTML;
  },unescapeHTML:function(){
    var div=new Element("div");
    div.innerHTML=this.stripTags();
    return div.childNodes[0]?(div.childNodes.length>1?$A(div.childNodes).inject("",function(memo,node){
      return memo+node.nodeValue;
    }):div.childNodes[0].nodeValue):"";
  },toQueryParams:function(separator){
    var match=this.strip().match(/([^?#]*)(#.*)?$/);
    if(!match){
      return {};
    }
    return match[1].split(separator||"&").inject({},function(hash,pair){
      if((pair=pair.split("="))[0]){
        var key=decodeURIComponent(pair.shift());
        var value=pair.length>1?pair.join("="):pair[0];
        if(value!=undefined){
          value=decodeURIComponent(value);
        }
        if(key in hash){
          if(!Object.isArray(hash[key])){
            hash[key]=[hash[key]];
          }
          hash[key].push(value);
        }else {
          hash[key]=value;
        }
      }
      return hash;
    });
  },toArray:function(){
    return this.split("");
  },succ:function(){
    return this.slice(0,this.length-1)+String.fromCharCode(this.charCodeAt(this.length-1)+1);
  },times:function(count){
    return count<1?"":new Array(count+1).join(this);
  },camelize:function(){
    var parts=this.split("-"),len=parts.length;
    if(len==1){
      return parts[0];
    }
    var camelized=this.charAt(0)=="-"?parts[0].charAt(0).toUpperCase()+parts[0].substring(1):parts[0];
    for(var i=1;i<len;i++){
      camelized+=parts[i].charAt(0).toUpperCase()+parts[i].substring(1);
    }
    return camelized;
  },capitalize:function(){
    return this.charAt(0).toUpperCase()+this.substring(1).toLowerCase();
  },underscore:function(){
    return this.gsub(/::/,"/").gsub(/([A-Z]+)([A-Z][a-z])/,"#{1}_#{2}").gsub(/([a-z\d])([A-Z])/,"#{1}_#{2}").gsub(/-/,"_").toLowerCase();
  },dasherize:function(){
    return this.gsub(/_/,"-");
  },inspect:function(useDoubleQuotes){
    var escapedString=this.gsub(/[\x00-\x1f\\]/,function(match){
      var character=String.specialChar[match[0]];
      return character?character:"\\u00"+match[0].charCodeAt().toPaddedString(2,16);
    });
    if(useDoubleQuotes){
      return "\""+escapedString.replace(/"/g,"\\\"")+"\"";
    }
    return "'"+escapedString.replace(/'/g,"\\'")+"'";
  },toJSON:function(){
    return this.inspect(true);
  },unfilterJSON:function(filter){
    return this.sub(filter||Prototype.JSONFilter,"#{1}");
  },isJSON:function(){
    var str=this.replace(/\\./g,"@").replace(/"[^"\\\n\r]*"/g,"");
    return (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(str);
  },evalJSON:function(sanitize){
    var json=this.unfilterJSON();
    try{
      if(!sanitize||json.isJSON()){
        return eval("("+json+")");
      }
    }
    catch(e){
    }
    throw new SyntaxError("Badly formed JSON string: "+this.inspect());
  },include:function(pattern){
    return this.indexOf(pattern)>-1;
  },startsWith:function(pattern){
    return this.indexOf(pattern)===0;
  },endsWith:function(pattern){
    var d=this.length-pattern.length;
    return d>=0&&this.lastIndexOf(pattern)===d;
  },empty:function(){
    return this=="";
  },blank:function(){
    return /^\s*$/.test(this);
  },interpolate:function(object,pattern){
    return new Template(this,pattern).evaluate(object);
  }});
if(Prototype.Browser.WebKit||Prototype.Browser.IE){
  Object.extend(String.prototype,{escapeHTML:function(){
      return this.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
    },unescapeHTML:function(){
      return this.replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">");

⌨️ 快捷键说明

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