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

📄 controls.js

📁 WordPress是一个Blog程序,用它你可以架设完全属于你自己的Blog. 而WordPress现在的应用又不仅仅只是在Blog方面,因为其强大的扩展性,部分网站甚至已经开始使用WordPress
💻 JS
📖 第 1 页 / 共 3 页
字号:
    var diff = arguments.callee.getFirstDifferencePos(value, this.oldElementValue);    var offset = (diff == this.oldElementValue.length ? 1 : 0);    var prevTokenPos = -1, nextTokenPos = value.length;    var tp;    for (var index = 0, l = this.options.tokens.length; index < l; ++index) {      tp = value.lastIndexOf(this.options.tokens[index], diff + offset - 1);      if (tp > prevTokenPos) prevTokenPos = tp;      tp = value.indexOf(this.options.tokens[index], diff + offset);      if (-1 != tp && tp < nextTokenPos) nextTokenPos = tp;    }    return (this.tokenBounds = [prevTokenPos + 1, nextTokenPos]);  }});Autocompleter.Base.prototype.getTokenBounds.getFirstDifferencePos = function(newS, oldS) {  var boundary = Math.min(newS.length, oldS.length);  for (var index = 0; index < boundary; ++index)    if (newS[index] != oldS[index])      return index;  return boundary;};Ajax.Autocompleter = Class.create(Autocompleter.Base, {  initialize: function(element, update, url, options) {    this.baseInitialize(element, update, options);    this.options.asynchronous  = true;    this.options.onComplete    = this.onComplete.bind(this);    this.options.defaultParams = this.options.parameters || null;    this.url                   = url;  },  getUpdatedChoices: function() {    this.startIndicator();        var entry = encodeURIComponent(this.options.paramName) + '=' +       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.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 and collection editor// Full rewrite by Christophe Porteneuve <tdd@tddsworld.com> (April 2007).// Use this if you notice weird scrolling problems on some browsers,// the DOM might be a bit confused when this gets called so do this// waits 1 ms (with setTimeout) until it does the activationField.scrollFreeActivate = function(field) {  setTimeout(function() {    Field.activate(field);  }, 1);}Ajax.InPlaceEditor = Class.create({  initialize: function(element, url, options) {    this.url = url;    this.element = element = $(element);    this.prepareOptions();    this._controls = { };    arguments.callee.dealWithDeprecatedOptions(options); // DEPRECATION LAYER!!!    Object.extend(this.options, options || { });    if (!this.options.formId && this.element.id) {      this.options.formId = this.element.id + '-inplaceeditor';      if ($(this.options.formId))        this.options.formId = '';    }    if (this.options.externalControl)      this.options.externalControl = $(this.options.externalControl);    if (!this.options.externalControl)      this.options.externalControlOnly = false;    this._originalBackground = this.element.getStyle('background-color') || 'transparent';    this.element.title = this.options.clickToEditText;    this._boundCancelHandler = this.handleFormCancellation.bind(this);    this._boundComplete = (this.options.onComplete || Prototype.emptyFunction).bind(this);    this._boundFailureHandler = this.handleAJAXFailure.bind(this);    this._boundSubmitHandler = this.handleFormSubmission.bind(this);    this._boundWrapperHandler = this.wrapUp.bind(this);    this.registerListeners();  },  checkForEscapeOrReturn: function(e) {    if (!this._editing || e.ctrlKey || e.altKey || e.shiftKey) return;    if (Event.KEY_ESC == e.keyCode)      this.handleFormCancellation(e);    else if (Event.KEY_RETURN == e.keyCode)      this.handleFormSubmission(e);  },  createControl: function(mode, handler, extraClasses) {    var control = this.options[mode + 'Control'];    var text = this.options[mode + 'Text'];    if ('button' == control) {      var btn = document.createElement('input');      btn.type = 'submit';      btn.value = text;      btn.className = 'editor_' + mode + '_button';      if ('cancel' == mode)        btn.onclick = this._boundCancelHandler;      this._form.appendChild(btn);      this._controls[mode] = btn;    } else if ('link' == control) {      var link = document.createElement('a');      link.href = '#';      link.appendChild(document.createTextNode(text));      link.onclick = 'cancel' == mode ? this._boundCancelHandler : this._boundSubmitHandler;      link.className = 'editor_' + mode + '_link';      if (extraClasses)        link.className += ' ' + extraClasses;      this._form.appendChild(link);      this._controls[mode] = link;    }  },  createEditField: function() {    var text = (this.options.loadTextURL ? this.options.loadingText : this.getText());    var fld;    if (1 >= this.options.rows && !/\r|\n/.test(this.getText())) {      fld = document.createElement('input');      fld.type = 'text';      var size = this.options.size || this.options.cols || 0;      if (0 < size) fld.size = size;    } else {      fld = document.createElement('textarea');      fld.rows = (1 >= this.options.rows ? this.options.autoRows : this.options.rows);      fld.cols = this.options.cols || 40;    }    fld.name = this.options.paramName;    fld.value = text; // No HTML breaks conversion anymore    fld.className = 'editor_field';    if (this.options.submitOnBlur)      fld.onblur = this._boundSubmitHandler;    this._controls.editor = fld;    if (this.options.loadTextURL)      this.loadExternalText();    this._form.appendChild(this._controls.editor);  },  createForm: function() {    var ipe = this;    function addText(mode, condition) {      var text = ipe.options['text' + mode + 'Controls'];      if (!text || condition === false) return;      ipe._form.appendChild(document.createTextNode(text));    };    this._form = $(document.createElement('form'));    this._form.id = this.options.formId;    this._form.addClassName(this.options.formClassName);    this._form.onsubmit = this._boundSubmitHandler;    this.createEditField();    if ('textarea' == this._controls.editor.tagName.toLowerCase())      this._form.appendChild(document.createElement('br'));    if (this.options.onFormCustomization)      this.options.onFormCustomization(this, this._form);    addText('Before', this.options.okControl || this.options.cancelControl);    this.createControl('ok', this._boundSubmitHandler);    addText('Between', this.options.okControl && this.options.cancelControl);    this.createControl('cancel', this._boundCancelHandler, 'editor_cancel');    addText('After', this.options.okControl || this.options.cancelControl);  },  destroy: function() {    if (this._oldInnerHTML)      this.element.innerHTML = this._oldInnerHTML;    this.leaveEditMode();    this.unregisterListeners();  },  enterEditMode: function(e) {    if (this._saving || this._editing) return;    this._editing = true;    this.triggerCallback('onEnterEditMode');    if (this.options.externalControl)      this.options.externalControl.hide();    this.element.hide();    this.createForm();    this.element.parentNode.insertBefore(this._form, this.element);    if (!this.options.loadTextURL)      this.postProcessEditField();    if (e) Event.stop(e);  },  enterHover: function(e) {    if (this.options.hoverClassName)      this.element.addClassName(this.options.hoverClassName);    if (this._saving) return;    this.triggerCallback('onEnterHover');  },  getText: function() {    return this.element.innerHTML;  },  handleAJAXFailure: function(transport) {    this.triggerCallback('onFailure', transport);    if (this._oldInnerHTML) {      this.element.innerHTML = this._oldInnerHTML;      this._oldInnerHTML = null;    }  },  handleFormCancellation: function(e) {    this.wrapUp();    if (e) Event.stop(e);  },  handleFormSubmission: function(e) {    var form = this._form;    var value = $F(this._controls.editor);    this.prepareSubmission();    var params = this.options.callback(form, value) || '';    if (Object.isString(params))      params = params.toQueryParams();    params.editorId = this.element.id;    if (this.options.htmlResponse) {      var options = Object.extend({ evalScripts: true }, this.options.ajaxOptions);      Object.extend(options, {        parameters: params,        onComplete: this._boundWrapperHandler,        onFailure: this._boundFailureHandler      });      new Ajax.Updater({ success: this.element }, this.url, options);    } else {      var options = Object.extend({ method: 'get' }, this.options.ajaxOptions);      Object.extend(options, {        parameters: params,        onComplete: this._boundWrapperHandler,        onFailure: this._boundFailureHandler      });

⌨️ 快捷键说明

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