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

📄 prototype.js

📁 用来在地图上做操作GIS,在地图上做标记
💻 JS
📖 第 1 页 / 共 5 页
字号:
});Array.prototype.toArray = Array.prototype.clone;/** * Splits a string into an Array, treating all whitespace as delimiters. Equivalent to Ruby's %w{foo bar} or Perl's qw(foo bar). * @alias $w * @param {String} string	String to split into an array * @return {Array} Returns an array. */function $w(string) {  string = string.strip();  return string ? string.split(/\s+/) : [];}if (Prototype.Browser.Opera){  Array.prototype.concat = function() {    var array = [];    for (var i = 0, length = this.length; i < length; i++) array.push(this[i]);    for (var i = 0, length = arguments.length; i < length; i++) {      if (arguments[i].constructor == Array) {        for (var j = 0, arrayLength = arguments[i].length; j < arrayLength; j++)          array.push(arguments[i][j]);      } else {        array.push(arguments[i]);      }    }    return array;  }}/** * @classDescription Hash can be thought of as an associative array, binding unique keys to values (which are not necessarily unique), though it can not guarantee consistent order its elements when iterating. Because of the nature of JavaScript programming language, every object is in fact a hash; but Hash adds a number of methods that let you enumerate keys and values, iterate over key/value pairs, merge two hashes together, encode the hash into a query string representation, etc. */var Hash = function(object) {  if (object instanceof Hash) this.merge(object);  else Object.extend(this, object || {});};Object.extend(Hash, {  toQueryString: function(obj) {    var parts = [];    parts.add = arguments.callee.addPair;    this.prototype._each.call(obj, function(pair) {      if (!pair.key) return;      var value = pair.value;      if (value && typeof value == 'object') {        if (value.constructor == Array) value.each(function(value) {          parts.add(pair.key, value);        });        return;      }      parts.add(pair.key, value);    });    return parts.join('&');  },  /**   * Returns a JSON string.   * @alias Hash.toJSON   * @param {Object} object	Object to convert to JSON string.   * @return {Object} Returns a JSON string.   */  toJSON: function(object) {    var results = [];    this.prototype._each.call(object, function(pair) {      var value = Object.toJSON(pair.value);      if (value !== undefined) results.push(pair.key.toJSON() + ': ' + value);    });    return '{' + results.join(', ') + '}';  }});Hash.toQueryString.addPair = function(key, value, prefix) {  key = encodeURIComponent(key);  if (value === undefined) this.push(key);  else this.push(key + '=' + (value == null ? '' : encodeURIComponent(value)));}Object.extend(Hash.prototype, Enumerable);Object.extend(Hash.prototype, {  _each: function(iterator) {    for (var key in this) {      var value = this[key];      if (value && value == Hash.prototype[key]) continue;      var pair = [key, value];      pair.key = key;      pair.value = value;      iterator(pair);    }  },  /**   Creates an array of the keys in a hash.  * @alias Hash.keys  * @return {Array} Returns an array of keys.  */  keys: function() {    return this.pluck('key');  },  /**  * Creates an array of the values in a hash.  * @alias Hash.values  * @return {Array} Returns an array of values.  */  values: function() {    return this.pluck('value');  },  /**  * Merges this hash with the specified hash.  * @alias Hash.merge()  * @param {Object} hash	Hash to merge with.  * @return {Object} Returns the merged hash.  */  merge: function(hash) {    return $H(hash).inject(this, function(mergedHash, pair) {      mergedHash[pair.key] = pair.value;      return mergedHash;    });  },  /**   * Removes keys from a hash and returns their values.   * @alias Hash.remove   * @return {Array} Returns an array of values.   */  remove: function() {    var result;    for(var i = 0, length = arguments.length; i < length; i++) {      var value = this[arguments[i]];      if (value !== undefined){        if (result === undefined) result = value;        else {          if (result.constructor != Array) result = [result];          result.push(value)        }      }      delete this[arguments[i]];    }    return result;  },  /**  * Returns the keys and values of a hash formatted into a query string. (e.g. 'key1=value1&key2=value2')  * @alias Hash.toQueryString  * @return {String} Returns a query string version of the hash.  */  toQueryString: function() {    return Hash.toQueryString(this);  },  /**  * Formats the hash into a human-readable string of key:value pairs.  * @alias Hash.inspect  * @return {String} Returns a string version of the key:value pairs of the hash.  */  inspect: function() {    return '#<Hash:{' + this.map(function(pair) {      return pair.map(Object.inspect).join(': ');    }).join(', ') + '}>';  },  /**   * Returns a JSON string.   * @alias Hash.toJSON   * @return {String} Returns a JSON string.   */  toJSON: function() {    return Hash.toJSON(this);  }});/** * Converts the argument "object" into a hash. * @alias $H * @param {Object} object	Object to be converted to a hash. * @return {Object} Returns a hash object. */function $H(object) {  if (object instanceof Hash) return object;  return new Hash(object);};// Safari iterates over shadowed propertiesif (function() {  var i = 0, Test = function(value) { this.key = value };  Test.prototype.key = 'foo';  for (var property in new Test('bar')) i++;  return i > 1;}()) Hash.prototype._each = function(iterator) {  var cache = [];  for (var key in this) {    var value = this[key];    if ((value && value == Hash.prototype[key]) || cache.include(key)) continue;    cache.push(key);    var pair = [key, value];    pair.key = key;    pair.value = value;    iterator(pair);  }};ObjectRange = Class.create();Object.extend(ObjectRange.prototype, Enumerable);Object.extend(ObjectRange.prototype, {  initialize: function(start, end, exclusive) {    this.start = start;    this.end = end;    this.exclusive = exclusive;  },  _each: function(iterator) {    var value = this.start;    while (this.include(value)) {      iterator(value);      value = value.succ();    }  },  /**  * Checks if the specified value is included in the range.  * @alias ObjectRange.include  * @param {Object} value	Value to search for.  * @return {Boolean} Returns true if the value is included in the range.  */  include: function(value) {    if (value < this.start)      return false;    if (this.exclusive)      return value < this.end;    return value <= this.end;  }});/** * Creates a new ObjectRange using the specified bounds. * @alias $R * @param {Object} start	Start point of the range. * @param {Object} end	End point of the range. * @param {Boolean} exclusive	If true, indicates that the start and end points should be excluded from the ObjectRange. * @constructor * @return {ObjectRange} Returns a new ObjectRange. */var $R = function(start, end, exclusive) {  return new ObjectRange(start, end, exclusive);}/** * @classDescription Prototype offers several objects to deal with AJAX communication. With Prototype, going Ajaxy is downright simple! All objects share a common set of options, which are discussed separately. */var Ajax = {   /** * Creates a new XMLHttpRequest object. * @alias Ajax.getTransport * @return {XMLHttpRequest} Returns a new XMLHttpRequest object. */  getTransport: function() {    return Try.these(      function() {return new XMLHttpRequest()},      function() {return new ActiveXObject('Msxml2.XMLHTTP')},      function() {return new ActiveXObject('Microsoft.XMLHTTP')}    ) || false;  },  activeRequestCount: 0}Ajax.Responders = {  /**  * Array of objects that are registered for AJAX event notifications.  * @alias Ajax.responders  */  responders: [],  _each: function(iterator) {    this.responders._each(iterator);  },  /**  * Calls the methods associated with the responderToAdd object when the corresponding event occurs.  * @alias Ajax.Responders.register  * @param {Object} responderToAdd	Object containing the methods to call. Should be named the same as the appropriate AJAX event.  * @extends {Enumerable}  */  register: function(responder) {    if (!this.include(responder))      this.responders.push(responder);  },  /**  * Removes the responderToRemove object from the list of registered objects.  * @alias Ajax.Responders.unregister  * @param {Object} responderToRemove  * @extends {Enumerable}  */  unregister: function(responder) {    this.responders = this.responders.without(responder);  },  /**  * For each object in the list, calls the method specified in callback using request, transport, and json as arguments.  * @alias Ajax.Responders.dispatch  * @param {Object} callback	Name of the AJAX event.  * @param {Object} request	Ajax.Request object responsible for the event.  * @param {Object} transport	XMLHttpRequest object that carries the AJAX call.  * @param {Object} json	X-JSON header of the response.  * @extends {Enumerable}  */  dispatch: function(callback, request, transport, json) {    this.each(function(responder) {      if (typeof responder[callback] == 'function') {        try {          responder[callback].apply(responder, [request, transport, json]);        } catch (e) {}      }    });  }};Object.extend(Ajax.Responders, Enumerable);Ajax.Responders.register({  onCreate: function() {    Ajax.activeRequestCount++;  },  onComplete: function() {    Ajax.activeRequestCount--;  }});/** * @classDescription Base class for most other classes defined by the Ajax object. * @constructor */Ajax.Base = function() {};Ajax.Base.prototype = {    /**  * Sets the options for an AJAX operation.  * @alias Ajax.Base.setOptions  * @param {Object} options	Options to set for the operation.  */  setOptions: function(options) {    this.options = {      method:       'post',      asynchronous: true,      contentType:  'application/x-www-form-urlencoded',      encoding:     'UTF-8',      parameters:   ''    }    Object.extend(this.options, options || {});    this.options.method = this.options.method.toLowerCase();    if (typeof this.options.parameters == 'string')      this.options.parameters = this.options.parameters.toQueryParams();  }}/** * @classDescription Contains properties and methods to compose an AJAX request to send to the server. * @constructor * @alias Ajax.Request */Ajax.Request = Class.create();/** * List of possible events and statuses associated with an AJAX operation. * @extends {Ajax.Base} */Ajax.Request.Events =  ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'];Ajax.Request.prototype = Object.extend(new Ajax.Base(), {  _complete: false,  /**  * Inititializes a new Ajax request.  * @alias Ajax.Request.initialize  * @param {Object} url	URL target for the request.  * @param {Object} options	Options to set.  * @extends {Ajax.Base}  */  initialize: function(url, options) {    this.transport = Ajax.getTransport();    this.setOptions(options);    this.request(url);  },  request: function(url) {    this.url = url;    this.method = this.options.method;    var params = Object.clone(this.options.parameters);    if (!['get', 'post'].include(this.method)) {      // simulate other verbs over post      params['_method'] = this.method;      this.method = 'post';    }    this.parameters = params;    if (params = Hash.toQueryString(params)) {      // when GET, append parameters to URL      if (this.method == 'get')        this.url += (this.url.include('?') ? '&' : '?') + params;      else if (/Konqueror|Safari|KHTML/.test(navigator.userAgent))        params += '&_=';    }    try {      if (this.options.onCreate) this.options.onCreate(this.transport);      Ajax.Responders.dispatch('onCreate', this, this.transport);      this.transport.open(this.method.toUpperCase(), this.url,        this.options.asynchronous);

⌨️ 快捷键说明

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