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

📄 controls.js

📁 Ajax最流行书籍
💻 JS
📖 第 1 页 / 共 2 页
字号:
      encodeURIComponent(this.getToken());    this.options.parameters = this.options.callback ?      this.options.callback(this.element, entry) : entry;    if(this.options.defaultParams)       this.options.parameters += '&' + this.options.defaultParams;    new Ajax.Request(this.url, this.options);  },  onComplete: function(request) {    this.updateChoices(request.responseText);  }});// The local array autocompleter. Used when you'd prefer to// inject an array of autocompletion options into the page, rather// than sending out Ajax queries, which can be quite slow sometimes.//// The constructor takes four parameters. The first two are, as usual,// the id of the monitored textbox, and id of the autocompletion menu.// The third is the array you want to autocomplete from, and the fourth// is the options block.//// Extra local autocompletion options:// - choices - How many autocompletion choices to offer//// - partialSearch - If false, the autocompleter will match entered//                    text only at the beginning of strings in the //                    autocomplete array. Defaults to true, which will//                    match text at the beginning of any *word* in the//                    strings in the autocomplete array. If you want to//                    search anywhere in the string, additionally set//                    the option fullSearch to true (default: off).//// - fullSsearch - Search anywhere in autocomplete array strings.//// - partialChars - How many characters to enter before triggering//                   a partial match (unlike minChars, which defines//                   how many characters are required to do any match//                   at all). Defaults to 2.//// - ignoreCase - Whether to ignore case when autocompleting.//                 Defaults to true.//// It's possible to pass in a custom function as the 'selector' // option, if you prefer to write your own autocompletion logic.// In that case, the other options above will not apply unless// you support them.Autocompleter.Local = Class.create();Autocompleter.Local.prototype = Object.extend(new Autocompleter.Base(), {  initialize: function(element, update, array, options) {    this.baseInitialize(element, update, options);    this.options.array = array;  },  getUpdatedChoices: function() {    this.updateChoices(this.options.selector(this));  },  setOptions: function(options) {    this.options = Object.extend({      choices: 10,      partialSearch: true,      partialChars: 2,      ignoreCase: true,      fullSearch: false,      selector: function(instance) {        var ret       = []; // Beginning matches        var partial   = []; // Inside matches        var entry     = instance.getToken();        var count     = 0;        for (var i = 0; i < instance.options.array.length &&            ret.length < instance.options.choices ; i++) {           var elem = instance.options.array[i];          var foundPos = instance.options.ignoreCase ?             elem.toLowerCase().indexOf(entry.toLowerCase()) :             elem.indexOf(entry);          while (foundPos != -1) {            if (foundPos == 0 && elem.length != entry.length) {               ret.push("<li><strong>" + elem.substr(0, entry.length) + "</strong>" +                 elem.substr(entry.length) + "</li>");              break;            } else if (entry.length >= instance.options.partialChars &&               instance.options.partialSearch && foundPos != -1) {              if (instance.options.fullSearch || /\s/.test(elem.substr(foundPos-1,1))) {                partial.push("<li>" + elem.substr(0, foundPos) + "<strong>" +                  elem.substr(foundPos, entry.length) + "</strong>" + elem.substr(                  foundPos + entry.length) + "</li>");                break;              }            }            foundPos = instance.options.ignoreCase ?               elem.toLowerCase().indexOf(entry.toLowerCase(), foundPos + 1) :               elem.indexOf(entry, foundPos + 1);          }        }        if (partial.length)          ret = ret.concat(partial.slice(0, instance.options.choices - ret.length))        return "<ul>" + ret.join('') + "</ul>";      }    }, options || {});  }});// AJAX in-place editor//// The constructor takes three parameters. The first is the element// that should support in-place editing. The second is the url to submit// the changed value to. The server should respond with the updated// value (the server might have post-processed it or validation might// have prevented it from changing). The third is a hash of options.//// Supported options are (all are optional and have sensible defaults):// - okText - The text of the submit button that submits the changed value//            to the server (default: "ok")// - cancelText - The text of the link that cancels editing (default: "cancel")// - savingText - The text being displayed as the AJAX engine communicates//                with the server (default: "Saving...")// - formId - The id given to the <form> element//            (default: the id of the element to edit plus '-inplaceeditor')Ajax.InPlaceEditor = Class.create();Ajax.InPlaceEditor.prototype = {  initialize: function(element, url, options) {    this.url = url;    this.element = $(element);    this.options = Object.extend({      okText: "ok",      cancelText: "cancel",      savingText: "Saving...",      okText: "ok",      rows: 1,      onFailure: function(transport) {        alert("Error communicating with the server: " + transport.responseText);      },      callback: function(form) {        return Form.serialize(form);      },      hoverClassName: 'inplaceeditor-hover',      externalControl:	null    }, options || {});    if(!this.options.formId && this.element.id) {      this.options.formId = this.element.id + "-inplaceeditor";      if ($(this.options.formId)) {        // there's already a form with that name, don't specify an id        this.options.formId = null;      }    }        if (this.options.externalControl) {      this.options.externalControl = $(this.options.externalControl);    }        this.onclickListener = this.enterEditMode.bindAsEventListener(this);    this.mouseoverListener = this.enterHover.bindAsEventListener(this);    this.mouseoutListener = this.leaveHover.bindAsEventListener(this);    Event.observe(this.element, 'click', this.onclickListener);    Event.observe(this.element, 'mouseover', this.mouseoverListener);    Event.observe(this.element, 'mouseout', this.mouseoutListener);    if (this.options.externalControl) {      Event.observe(this.options.externalControl, 'click', this.onclickListener);    }  },  enterEditMode: function() {    if (this.saving) return;    if (this.editing) return;    this.editing = true;    this.onEnterEditMode();    if (this.options.externalControl) {      Element.hide(this.options.externalControl);    }    Element.hide(this.element);    this.form = this.getForm();    this.element.parentNode.insertBefore(this.form, this.element);  },  getForm: function() {    form = document.createElement("form");    form.id = this.options.formId;    form.onsubmit = this.onSubmit.bind(this);    this.createEditField(form);    if (this.options.textarea) {      var br = document.createElement("br");      form.appendChild(br);    }    okButton = document.createElement("input");    okButton.type = "submit";    okButton.value = this.options.okText;    form.appendChild(okButton);    cancelLink = document.createElement("a");    cancelLink.href = "#";    cancelLink.appendChild(document.createTextNode(this.options.cancelText));    cancelLink.onclick = this.onclickCancel.bind(this);    form.appendChild(cancelLink);    return form;  },  createEditField: function(form) {    if (this.options.rows == 1) {      this.options.textarea = false;      var textField = document.createElement("input");      textField.type = "text";      textField.name = "value";      textField.value = this.getText();      var size = this.options.size || this.options.cols || 0;      if (size != 0)        textField.size = size;      form.appendChild(textField);    } else {      this.options.textarea = true;      var textArea = document.createElement("textarea");      textArea.name = "value";      textArea.value = this.getText();      textArea.rows = this.options.rows;      textArea.cols = this.options.cols || 40;      form.appendChild(textArea);    }  },  getText: function() {    return this.element.innerHTML;  },  onclickCancel: function() {    this.onComplete();  },  onFailure: function(transport) {    this.options.onFailure(transport);    if (this.oldInnerHTML) {      this.element.innerHTML = this.oldInnerHTML;      this.oldInnerHTML = null;    }    return false;    if (this.oldInnerHTML) {      this.element.innerHTML = this.oldInnerHTML;      this.oldInnerHTML = null;    }  },  onSubmit: function() {    this.saving = true;    new Ajax.Updater(      {         success: this.element,         // don't update on failure (this could be an option)        failure: null      },      this.url,      {        parameters: this.options.callback(this.form, this.form.value.value),        onComplete: this.onComplete.bind(this),        onFailure: this.onFailure.bind(this)      }    );    this.onLoading();    return false;  },  onLoading: function() {    this.saving = true;    this.removeForm();    this.leaveHover();    this.showSaving();  },  showSaving: function() {    this.oldInnerHTML = this.element.innerHTML;    this.element.innerHTML = this.options.savingText;    Element.show(this.element);  },  removeForm: function() {    if(this.form) {      Element.remove(this.form);      this.form = null;    }  },  enterHover: function() {    if (this.saving) return;    if (this.options.backgroundColor) {      this.oldBackground = this.element.style.backgroundColor;      this.element.style.backgroundColor = this.options.backgroundColor;    }    Element.addClassName(this.element, this.options.hoverClassName)  },  leaveHover: function() {    if (this.options.backgroundColor) {      this.element.style.backgroundColor = this.oldBackground;    }    Element.removeClassName(this.element, this.options.hoverClassName)  },  leaveEditMode: function() {    if(this.savingText) {      Element.remove(this.savingText);      this.savingText = null;    }    this.removeForm();    this.leaveHover();    Element.show(this.element);    if (this.options.externalControl) {      Element.show(this.options.externalControl);    }    this.editing = false;    this.onLeaveEditMode();  },  onComplete: function() {    this.leaveEditMode();    this.oldInnerHTML = null;    this.saving = false;  },  onEnterEditMode: function() {},  onLeaveEditMode: function() {},  dispose: function() {    if (this.oldInnerHTML) {      this.element.innerHTML = this.oldInnerHTML;    }    this.leaveEditMode();    Event.stopObserving(this.element, 'click', this.onclickListener);    Event.stopObserving(this.element, 'mouseover', this.mouseoverListener);    Event.stopObserving(this.element, 'mouseout', this.mouseoutListener);    if (this.options.externalControl) {      Event.stopObserving(this.options.externalControl, 'click', this.onclickListener);    }  }};

⌨️ 快捷键说明

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