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

📄 prototype.js

📁 这是一款js组建
💻 JS
📖 第 1 页 / 共 5 页
字号:
/*  Prototype JavaScript framework, version 1.5.0 *  (c) 2005-2007 Sam Stephenson * *  Prototype is freely distributable under the terms of an MIT-style license. *  For details, see the Prototype web site: http://prototype.conio.net/ */*--------------------------------------------------------------------------*/var Prototype = {  Version: '1.5.0',  BrowserFeatures: {    XPath: !!document.evaluate  },  ScriptFragment: '(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)',  emptyFunction: function() {},  K: function(x) { return x }}var Class = {  create: function() {    return function() {      this.initialize.apply(this, arguments);    }  }}var Abstract = new Object();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;    }  },  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);  }});Function.prototype.bind = function() {  var __method = this, args = $A(arguments), object = args.shift();  return function() {    return __method.apply(object, args.concat($A(arguments)));  }}Function.prototype.bindAsEventListener = function(object) {  var __method = this, args = $A(arguments), object = args.shift();  return function(event) {    return __method.apply(object, [( event || window.event)].concat(args).concat($A(arguments)));  }}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;  }});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;  }}/*--------------------------------------------------------------------------*/var PeriodicalExecuter = Class.create();PeriodicalExecuter.prototype = {  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);  },  stop: function() {    if (!this.timer) return;    clearInterval(this.timer);    this.timer = null;  },  onTimerEvent: function() {    if (!this.currentlyExecuting) {      try {        this.currentlyExecuting = true;        this.callback(this);      } finally {        this.currentlyExecuting = false;      }    }  }}String.interpret = function(value){  return value == null ? '' : String(value);}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 this;  },  truncate: function(length, truncation) {    length = length || 30;    truncation = truncation === undefined ? '...' : truncation;    return this.length > length ?      this.slice(0, length - truncation.length) + truncation : 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 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.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 name = decodeURIComponent(pair[0]);        var value = pair[1] ? decodeURIComponent(pair[1]) : undefined;        if (hash[name] !== undefined) {          if (hash[name].constructor != Array)            hash[name] = [hash[name]];          if (value) hash[name].push(value);        }        else hash[name] = 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);  },  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.replace(/\\/g, '\\\\');    if (useDoubleQuotes)      return '"' + escapedString.replace(/"/g, '\\"') + '"';    else      return "'" + escapedString.replace(/'/g, '\\\'') + "'";  }});String.prototype.gsub.prepareReplacement = function(replacement) {  if (typeof replacement == 'function') return replacement;  var template = new Template(replacement);  return function(match) { return template.evaluate(match) };}String.prototype.parseQuery = String.prototype.toQueryParams;var Template = Class.create();Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/;Template.prototype = {  initialize: function(template, pattern) {    this.template = template.toString();    this.pattern  = pattern || Template.Pattern;  },  evaluate: function(object) {    return this.template.gsub(this.pattern, function(match) {      var before = match[1];      if (before == '\\') return match[2];      return before + String.interpret(object[match[3]]);    });  }}var $break    = new Object();var $continue = new Object();var Enumerable = {  each: function(iterator) {    var index = 0;    try {      this._each(function(value) {        try {          iterator(value, index++);        } catch (e) {          if (e != $continue) throw e;        }      });    } catch (e) {      if (e != $break) throw e;    }    return this;  },  eachSlice: function(number, iterator) {    var index = -number, slices = [], array = this.toArray();    while ((index += number) < array.length)      slices.push(array.slice(index, index+number));    return slices.map(iterator);  },  all: function(iterator) {    var result = true;    this.each(function(value, index) {      result = result && !!(iterator || Prototype.K)(value, index);      if (!result) throw $break;    });    return result;  },  any: function(iterator) {    var result = false;    this.each(function(value, index) {      if (result = !!(iterator || Prototype.K)(value, index))        throw $break;    });    return result;  },  collect: function(iterator) {    var results = [];    this.each(function(value, index) {      results.push((iterator || Prototype.K)(value, index));    });    return results;  },  detect: function(iterator) {    var result;    this.each(function(value, index) {      if (iterator(value, index)) {        result = value;        throw $break;      }    });    return result;  },  findAll: function(iterator) {    var results = [];    this.each(function(value, index) {      if (iterator(value, index))        results.push(value);    });    return results;  },  grep: function(pattern, iterator) {    var results = [];    this.each(function(value, index) {      var stringValue = value.toString();      if (stringValue.match(pattern))        results.push((iterator || Prototype.K)(value, index));    })    return results;  },  include: function(object) {    var found = false;    this.each(function(value) {      if (value == object) {        found = true;        throw $break;      }    });    return found;  },  inGroupsOf: function(number, fillWith) {    fillWith = fillWith === undefined ? null : fillWith;    return this.eachSlice(number, function(slice) {      while(slice.length < number) slice.push(fillWith);      return slice;    });  },  inject: function(memo, iterator) {    this.each(function(value, index) {      memo = iterator(memo, value, index);    });    return memo;  },  invoke: function(method) {    var args = $A(arguments).slice(1);    return this.map(function(value) {      return value[method].apply(value, args);    });  },  max: function(iterator) {    var result;    this.each(function(value, index) {      value = (iterator || Prototype.K)(value, index);      if (result == undefined || value >= result)        result = value;    });    return result;  },  min: function(iterator) {    var result;    this.each(function(value, index) {      value = (iterator || Prototype.K)(value, index);      if (result == undefined || value < result)        result = value;    });    return result;  },  partition: function(iterator) {    var trues = [], falses = [];    this.each(function(value, index) {      ((iterator || Prototype.K)(value, index) ?        trues : falses).push(value);    });    return [trues, falses];  },  pluck: function(property) {    var results = [];    this.each(function(value, index) {      results.push(value[property]);    });

⌨️ 快捷键说明

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