acronym.js

来自「Hippo CMS是一个以信息为中心的开源内容管理系统。Hippo CMS目标是」· JavaScript 代码 · 共 96 行

JS
96
字号
// Acronym plugin for HTMLArea
// Implementation by Jeroen Reijn
//
// (c) Hippo 2007
// Distributed under the Apache License 2.0

function Acronym(editor) {
	this.editor = editor;
	var cfg = editor.config;
	var self = this;

	// register the toolbar buttons provided by this plugin
	cfg.registerButton({
	id       : "acronym",
	tooltip  : this._lc("Acronym"),
	image    : editor.imgURL("ed_acronym.gif", "Acronym"),
	textMode : false,
	action   : function(editor) {
			self.buttonPress(editor);
		}
	})
	cfg.addToolbarElement("acronym", "inserthorizontalrule", 1);
}

Acronym._pluginInfo = {
	name          : "Acronym",
	version       : "1.0",
	developer     : "Jeroen Reijn",
	developer_url : "",
	sponsor       : "Hippo",
	sponsor_url   : "http://www.hippo.nl",
	license       : "Apache 2.0"
};

Acronym.prototype._lc = function(string) {
    return HTMLArea._lc(string, 'Acronym');
};

Acronym.prototype.onGenerate = function() {
  var style_id = "Acr-style"
  var style = this.editor._doc.getElementById(style_id);
  if (style == null) {
    style = this.editor._doc.createElement("link");
    style.id = style_id;
    style.rel = 'stylesheet';
    style.href = _editor_url + 'plugins/Acronym/acronym.css';
    this.editor._doc.getElementsByTagName("HEAD")[0].appendChild(style);
  }
};

Acronym.prototype.buttonPress = function(editor, context, updatecontextclass) {
	var outparam = null;
	var html = editor.getSelectedHTML();
	var sel  = editor._getSelection();
	var range  = editor._createRange(sel);
	var acronym = editor._activeElement(sel);
	  if(!(acronym != null && acronym.tagName.toLowerCase() == "acronym")) {
	    acronym = editor._getFirstAncestor(sel, 'acronym'); 
  }
  if (acronym != null && acronym.tagName.toLowerCase() == "acronym")
    outparam = { title : acronym.title,
                 text : acronym.innerHTML};
	else	
	  outparam = { title : '',
	               text : html};
	  
	editor._popupDialog( "plugin://Acronym/acronym", function( param )	{
		if ( param ) {
			var title = param["title"];
      if (title == "" || title == null) {
        if (acronym) {
          var child = acronym.innerHTML;
          acronym.parentNode.removeChild(acronym);
          editor.insertHTML(child);
        }
        return;
      } 
      try {
        var doc = editor._doc;
        if (!acronym) {
          acronym = doc.createElement("acronym");
          acronym.title = title;
          acronym.innerHTML = html;
          if (HTMLArea.is_ie) {
            range.pasteHTML(acronym.outerHTML);
          } else {
            editor.insertNodeAtSelection(acronym);
          }
        } else {
          acronym.title = title;
        }
      }
      catch (e) { }
    }
  }, outparam);
};

⌨️ 快捷键说明

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