block-quotation.js

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

JS
111
字号
// BlockQuotation plugin for HTMLArea
// Implementation by Dejan Lilkic
// Original Author - Dejan Lilkic
//
// (c) Dejan Lilkic & Levi9 Global Sourcing
// Distributed under the same terms as Apache 2.0.
// This notice MUST stay intact for use (see license.txt).

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

	// register the toolbar buttons provided by this plugin
	cfg.registerButton({
	id       : "block-quotation",
	tooltip  : this._lc("BlockQuotation"),
	image    : editor.imgURL("blockquotation.gif", "BlockQuotation"),
	textMode : false,
	action   : function(editor) {
			self.buttonPress(editor);
		}
	})
	cfg.addToolbarElement("block-quotation", ["abbreviation","citation","inserthorizontalrule"], 1);	
}

BlockQuotation._pluginInfo = {
	name          : "BlockQuotation",
	origin        : "version: 1.0, by Levi9, http://www.levi9.com",
	version       : "1.0",
	developer     : "Dejan Lilkic",
	developer_url : "http://www.levi9.com",
	license       : "Apache 2.0"
};

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

BlockQuotation.prototype.onGenerate = function() {
};

BlockQuotation.prototype.buttonPress = function(editor, context, updatecontextclass) {
	var outparam = null;
	var html = editor.getSelectedHTML();
	var sel  = editor._getSelection();
	var range  = editor._createRange(sel);
	var quot = editor._activeElement(sel);
	  if(!(quot != null && quot.tagName.toLowerCase() == "blockquote")) {
	  	if(!editor._getFirstAncestor(sel, 'blockquote')){
		  //check range length
	      var compare = 0;
	      if (HTMLArea.is_ie) {
	        if(sel.type == "Control") {
	          compare = range.length;
	        } else {
	          compare = range.compareEndPoints("StartToEnd", range);
	        }
	      } else {
	        compare = range.compareBoundaryPoints(range.START_TO_END, range);
	      }	      
	      if (compare == 0) {
	        alert(HTMLArea._lc("You need to select some text before creating a block quotation"));
	        return;
	      }
	  	}	  	
	    quot = editor._getFirstAncestor(sel, 'blockquote'); 
      }
      
      if (quot != null && quot.tagName.toLowerCase() == "blockquote") {
        outparam = { cite : quot.getAttribute("cite"),
                 text : quot.innerHTML};
      } else {	
	  outparam = { cite : '',
	               text : html};
      }
  
	editor._popupDialog( "plugin://BlockQuotation/block_quotation", function( param )	{
		if ( param ) {
		  var cite = param["cite"];
          if (cite == "" || cite == null) {
            if (quot) {
              var child = quot.innerHTML;
              quot.parentNode.removeChild(quot);
              editor.insertHTML(child);
            }
            //return;
          } 
          try {
            var doc = editor._doc;
            if (!quot) {
              quot = doc.createElement("blockquote");
              if (cite != "" && cite != null) {
                quot.cite = cite;
              }
              quot.innerHTML = html;
              if (HTMLArea.is_ie) {
                range.pasteHTML(quot.outerHTML);
              } else {
                editor.insertNodeAtSelection(quot);
              }
            } else {
              if (cite != "" && cite != null) {
                quot.cite = cite;
              }
            }
          } catch (e) {           	
          }
       }
    }, outparam);
};

⌨️ 快捷键说明

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