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

📄 prototype.js

📁 用来在地图上做操作GIS,在地图上做标记
💻 JS
📖 第 1 页 / 共 5 页
字号:
      if (this.options.asynchronous)        setTimeout(function() { this.respondToReadyState(1) }.bind(this), 10);      this.transport.onreadystatechange = this.onStateChange.bind(this);      this.setRequestHeaders();      this.body = this.method == 'post' ? (this.options.postBody || params) : null;      this.transport.send(this.body);      /* Force Firefox to handle ready state 4 for synchronous requests */      if (!this.options.asynchronous && this.transport.overrideMimeType)        this.onStateChange();    }    catch (e) {      this.dispatchException(e);    }  },  onStateChange: function() {    var readyState = this.transport.readyState;    if (readyState > 1 && !((readyState == 4) && this._complete))      this.respondToReadyState(this.transport.readyState);  },  setRequestHeaders: function() {    var headers = {      'X-Requested-With': 'XMLHttpRequest',      'X-Prototype-Version': Prototype.Version,      'Accept': 'text/javascript, text/html, application/xml, text/xml, */*'    };    if (this.method == 'post') {      headers['Content-type'] = this.options.contentType +        (this.options.encoding ? '; charset=' + this.options.encoding : '');      /* Force "Connection: close" for older Mozilla browsers to work       * around a bug where XMLHttpRequest sends an incorrect       * Content-length header. See Mozilla Bugzilla #246651.       */      if (this.transport.overrideMimeType &&          (navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005)            headers['Connection'] = 'close';    }    // user-defined headers    if (typeof this.options.requestHeaders == 'object') {      var extras = this.options.requestHeaders;      if (typeof extras.push == 'function')        for (var i = 0, length = extras.length; i < length; i += 2)          headers[extras[i]] = extras[i+1];      else        $H(extras).each(function(pair) { headers[pair.key] = pair.value });    }    for (var name in headers)      this.transport.setRequestHeader(name, headers[name]);  },  success: function() {    return !this.transport.status        || (this.transport.status >= 200 && this.transport.status < 300);  },  respondToReadyState: function(readyState) {    var state = Ajax.Request.Events[readyState];    var transport = this.transport, json = this.evalJSON();    if (state == 'Complete') {      try {        this._complete = true;        (this.options['on' + this.transport.status]         || this.options['on' + (this.success() ? 'Success' : 'Failure')]         || Prototype.emptyFunction)(transport, json);      } catch (e) {        this.dispatchException(e);      }      var contentType = this.getHeader('Content-type');      if (contentType && contentType.strip().        match(/^(text|application)\/(x-)?(java|ecma)script(;.*)?$/i))          this.evalResponse();    }    try {      (this.options['on' + state] || Prototype.emptyFunction)(transport, json);      Ajax.Responders.dispatch('on' + state, this, transport, json);    } catch (e) {      this.dispatchException(e);    }    if (state == 'Complete') {      // avoid memory leak in MSIE: clean up      this.transport.onreadystatechange = Prototype.emptyFunction;    }  },  getHeader: function(name) {    try {      return this.transport.getResponseHeader(name);    } catch (e) { return null }  },  evalJSON: function() {    try {      var json = this.getHeader('X-JSON');      return json ? json.evalJSON() : null;    } catch (e) { return null }  },  evalResponse: function() {    try {      return eval((this.transport.responseText || '').unfilterJSON());    } catch (e) {      this.dispatchException(e);    }  },  dispatchException: function(exception) {    (this.options.onException || Prototype.emptyFunction)(this, exception);    Ajax.Responders.dispatch('onException', this, exception);  }});/** * @classDescription	Contains properties and methods to update an HTML element with content from the server. * @constructor * @alias Ajax.Updater */Ajax.Updater = Class.create();Object.extend(Object.extend(Ajax.Updater.prototype, Ajax.Request.prototype), {  initialize: function(container, url, options) {    this.container = {      success: (container.success || container),      failure: (container.failure || (container.success ? null : container))    }    this.transport = Ajax.getTransport();    this.setOptions(options);    var onComplete = this.options.onComplete || Prototype.emptyFunction;    this.options.onComplete = (function(transport, param) {      this.updateContent();      onComplete(transport, param);    }).bind(this);    this.request(url);  },  updateContent: function() {    var receiver = this.container[this.success() ? 'success' : 'failure'];    var response = this.transport.responseText;    if (!this.options.evalScripts) response = response.stripScripts();    if (receiver = $(receiver)) {      if (this.options.insertion)        new this.options.insertion(receiver, response);      else        receiver.update(response);    }    if (this.success()) {      if (this.onComplete)        setTimeout(this.onComplete.bind(this), 10);    }  }});/** * @classDescription Periodically performs an AJAX request and updates a container�s contents based on the response text. Offers a mechanism for �decay,� which lets it trigger at widening intervals while the response is unchanged. * @alias Ajax.PeriodicalUpdater */Ajax.PeriodicalUpdater = Class.create();Ajax.PeriodicalUpdater.prototype = Object.extend(new Ajax.Base(), {  initialize: function(container, url, options) {    this.setOptions(options);    this.onComplete = this.options.onComplete;    this.frequency = (this.options.frequency || 2);    this.decay = (this.options.decay || 1);    this.updater = {};    this.container = container;    this.url = url;    this.start();  },  start: function() {    this.options.onComplete = this.updateComplete.bind(this);    this.onTimerEvent();  },  stop: function() {    this.updater.options.onComplete = undefined;    clearTimeout(this.timer);    (this.onComplete || Prototype.emptyFunction).apply(this, arguments);  },  updateComplete: function(request) {    if (this.options.decay) {      this.decay = (request.responseText == this.lastText ?        this.decay * this.options.decay : 1);      this.lastText = request.responseText;    }    this.timer = setTimeout(this.onTimerEvent.bind(this),      this.decay * this.frequency * 1000);  },  onTimerEvent: function() {    this.updater = new Ajax.Updater(this.container, this.url, this.options);  }});/** * If provided with a string, returns the element in the document with matching ID; otherwise returns the passed element. Takes in an arbitrary number of arguments. All elements returned by the function are extended with Prototype DOM extensions. * @alias $ * @param {String} element	ID of the element to return * @return {HTMLElement} Returns the matching element. */function $(element) {  if (arguments.length > 1) {    for (var i = 0, elements = [], length = arguments.length; i < length; i++)      elements.push($(arguments[i]));    return elements;  }  if (typeof element == 'string')    element = document.getElementById(element);  return Element.extend(element);}if (Prototype.BrowserFeatures.XPath) {  document._getElementsByXPath = function(expression, parentElement) {    var results = [];    var query = document.evaluate(expression, $(parentElement) || document,      null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);    for (var i = 0, length = query.snapshotLength; i < length; i++)      results.push(query.snapshotItem(i));    return results;  };  /**  * Returns any elements with the specified CSS class name.  * @alias document.getElementsByClassName()  * @param {String} className	CSS className corresponding to the elements to retrieve.  * @param {String} parentElement	id of the parent element that contains the elements to retrieve.  * @return {Array, Object}	Returns the elements matching the className.  * @extends {document}  */  document.getElementsByClassName = function(className, parentElement) {    var q = ".//*[contains(concat(' ', @class, ' '), ' " + className + " ')]";    return document._getElementsByXPath(q, parentElement);  }} else document.getElementsByClassName = function(className, parentElement) {  var children = ($(parentElement) || document.body).getElementsByTagName('*');  var elements = [], child, pattern = new RegExp("(^|\\s)" + className + "(\\s|$)");  for (var i = 0, length = children.length; i < length; i++) {    child = children[i];    var elementClassName = child.className;    if (elementClassName.length == 0) continue;    if (elementClassName == className || elementClassName.match(pattern))      elements.push(Element.extend(child));  }  return elements;};/*--------------------------------------------------------------------------*/if (!window.Element) var Element = {};Element.extend = function(element) {  var F = Prototype.BrowserFeatures;  if (!element || !element.tagName || element.nodeType == 3 ||   element._extended || F.SpecificElementExtensions || element == window)    return element;  var methods = {}, tagName = element.tagName, cache = Element.extend.cache,   T = Element.Methods.ByTag;  // extend methods for all tags (Safari doesn't need this)  if (!F.ElementExtensions) {    Object.extend(methods, Element.Methods),    Object.extend(methods, Element.Methods.Simulated);  }  // extend methods for specific tags  if (T[tagName]) Object.extend(methods, T[tagName]);  for (var property in methods) {    var value = methods[property];    if (typeof value == 'function' && !(property in element))      element[property] = cache.findOrStore(value);  }  element._extended = Prototype.emptyFunction;  return element;};Element.extend.cache = {  findOrStore: function(value) {    return this[value] = this[value] || function() {      return value.apply(null, [this].concat($A(arguments)));    }  }};Element.Methods = {    /**  * Returns true if the element is visible.  * @alias Element.Methods.visible  * @param {Object} element Element to check.  * @return {Boolean}	Returns true if the element is visible.  */  visible: function(element) {    return $(element).style.display != 'none';  },  /**  * Toggles the visibility of the specified element(s).  * @alias Element.Methods.toggle  * @param {Object, String} One or more elements (or ids) to toggle the visibility of.  */  toggle: function(element) {    element = $(element);    Element[Element.visible(element) ? 'hide' : 'show'](element);    return element;  },  /**  * Hides the specified element(s) by setting the style.display attribute to "none".  * @alias Element.hide  * @param {Object} ... One or more elements to hide.  */  hide: function(element) {    $(element).style.display = 'none';    return element;  },  /**  * Displays the specified element(s) by setting the style.display attribute to "".  * @alias Element.show  * @param {Object} ... One or more elements to display.  */  show: function(element) {    $(element).style.display = '';    return element;  },  /**  * Removes the element from the document.  * @alias Element.remove  * @param {Object} element	Element to remove.  */  remove: function(element) {    element = $(element);    element.parentNode.removeChild(element);    return element;  },  /**  * Updates the inner HTML of the element with the specified HTML.  * @alias Element.update  * @param {Element} element	Element to update.  * @param {String} html	HTML to replace the current inner HTMl with.  */  update: function(element, html) {    html = typeof html == 'undefined' ? '' : html.toString();    $(element).innerHTML = html.stripScripts();    setTimeout(function() {html.evalScripts()}, 10);    return element;  },  /**   * Replaces element by the content of the html argument and returns the removed element.   * @alias Element.replace   * @param {Element} element	Element to replace   * @param {String} html	HTML to replace the content with.   * @return {Element} Returns the replaced element.   */  replace: function(element, html) {    element = $(element);    html = typeof html == 'undefined' ? '' : html.toString();    if (element.outerHTML) {      element.outerHTML = html.stripScripts();    } else {      var range = element.ownerDocument.createRange();      range.selectNodeContents(element);      element.parentNode.replaceChild(        range.createContextualFragment(html.stripScripts()), element);    }    setTimeout(function() {html.evalScripts()}, 10);    return element;  },  /**   * Returns the debug-oriented string representation of element.   * @alias Element.inspect   * @param {Element} element Element to inspect.   * @return {String} Returns the debug-oriented string representation of element.   */  inspect: function(element) {    element = $(element);    var result = '<' + element.tagName.toLowerCase();    $H({'id': 'id', 'className': 'class'}).each(function(pair) {      var property = pair.first(), attribute = pair.last();      var value = (element[property] || '').toString();      if (value) result += ' ' + attribute + '=' + value.inspect(true);    });    return result + '>';  },  /**   * Recursivel

⌨️ 快捷键说明

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