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

📄 editor_plugin.js

📁 F2blog v1.1 beta 12.27更新说明 1、后台编辑器增加了文本粘贴与从WORD粘贴
💻 JS
📖 第 1 页 / 共 2 页
字号:
/* Import plugin specific language pack */
tinyMCE.importPluginLanguagePack('f2blog', 'en,zh_cn,zh_tw');

var TinyMCE_f2blogPlugin = {
	getInfo : function() {
		return {
			longname : 'F2Blog Plugin',
			author : 'Joesen',
			authorurl : 'http://joesen.f2blog.com',
			infourl : 'http://joesen.f2blog.com',
			version : '1.0'
		};
	},

	getControlHTML : function(control_name) {
		switch (control_name) {
			case "f2_hide":
				return tinyMCE.getButtonHTML(control_name, 'lang_f2blog_hide_button', '{$pluginurl}/images/hide.gif', 'f2Hide');
			case "f2_more":
				return tinyMCE.getButtonHTML(control_name, 'lang_f2blog_more_button', '{$pluginurl}/images/more.gif', 'f2More');
			case "f2_page":
				return tinyMCE.getButtonHTML(control_name, 'lang_f2blog_page_button', '{$pluginurl}/images/page.gif', 'f2Page');
			case "f2_quote":
				return tinyMCE.getButtonHTML(control_name, 'lang_f2blog_quote_button', '{$pluginurl}/images/quote.gif', 'f2Quote');
			case "f2_help":
				return tinyMCE.getButtonHTML(control_name, 'lang_help_button_title', '{$pluginurl}/images/help.gif', 'f2Help');
		}
		return '';
	},

	execCommand : function(editor_id, element, command, user_interface, value) {
		var inst = tinyMCE.getInstanceById(editor_id);
		var focusElm = inst.getFocusElement();
		var doc = inst.getDoc();

		function getAttrib(elm, name) {
			return elm.getAttribute(name) ? elm.getAttribute(name) : "";
		}

		// Handle commands
		switch (command) {
			case "f2Hide":
				var flag = "";
				var template = new Array();
				var altMore = tinyMCE.getLang('lang_f2blog_hide_alt');

				html = '<div id="MoreLess" class="mceItemMoreLess">' + inst.selection.getSelectedHTML() + '<!--hideEnd--></div>';
				tinyMCE.execInstanceCommand(editor_id, 'mceInsertContent', false, html);
				tinyMCE.selectedInstance.repaint();
				return true;
			case "f2Quote":
				var flag = "";
				var template = new Array();
				var altMore = tinyMCE.getLang('lang_f2blog_quote_alt');

				html = '<div style="background-color: #F9FBFC;border: 1px solid #C3CED9;margin: 0;margin-bottom: 5px;width: auto;height: auto;overflow : auto;text-align: left;font-family: "Courier New", Courier, monospace;font-size: 12px;">' + inst.selection.getSelectedHTML() + '</div>';
				//html = '<blockquote style="MARGIN-RIGHT: 0px">' + inst.selection.getSelectedHTML() + '</blockquote>'; 
				// blockquote {border-left:3px solid #BEDCFF;margin:20px;padding-left:10px;}

				tinyMCE.execInstanceCommand(editor_id, 'mceInsertContent', false, html);
				tinyMCE.selectedInstance.repaint();
				return true;
			case "f2More":
				var flag = "";
				var template = new Array();
				var altMore = tinyMCE.getLang('lang_f2blog_more_alt');

				// Is selection a image
				if (focusElm != null && focusElm.nodeName.toLowerCase() == "img") {
					flag = getAttrib(focusElm, 'class');

					if (flag != 'mce_plugin_f2blog_more') // Not a f2blog
						return true;

					action = "update";
				}

				html = ''
					+ '<img src="' + (tinyMCE.getParam("theme_href") + "/images/spacer.gif") + '" '
					+ ' width="100%" height="10px" '
					+ 'alt="'+altMore+'" title="'+altMore+'" class="mce_plugin_f2blog_more" name="mce_plugin_f2blog_more" />';
				tinyMCE.execInstanceCommand(editor_id, 'mceInsertContent', false, html);
				tinyMCE.selectedInstance.repaint();
				return true;

			case "f2Page":
				var flag = "";
				var template = new Array();
				var altPage = tinyMCE.getLang('lang_f2blog_more_alt');

				// Is selection a image
				if (focusElm != null && focusElm.nodeName.toLowerCase() == "img") {
					flag = getAttrib(focusElm, 'name');

					if (flag != 'mce_plugin_f2blog_page') // Not a f2blog
						return true;

					action = "update";
				}

				html = ''
					+ '<img src="' + (tinyMCE.getParam("theme_href") + "/images/spacer.gif") + '" '
					+ ' width="100%" height="10px" '
					+ 'alt="'+altPage+'" title="'+altPage+'" class="mce_plugin_f2blog_page" name="mce_plugin_f2blog_page" />';
				tinyMCE.execCommand("mceInsertContent",true,html);
				tinyMCE.selectedInstance.repaint();
				return true;
		}

		// Pass to next handler in chain
		return false;
	},

	cleanup : function(type, content) {
		switch (type) {
			case "insert_to_editor":
				var startPos = 0;
				var altMore = tinyMCE.getLang('lang_f2blog_more_alt');
				var altPage = tinyMCE.getLang('lang_f2blog_page_alt');
				var altHide = tinyMCE.getLang('lang_f2blog_hide_alt');

				var reg = new RegExp('<!--hideBegin-->', "ig");
				content = content.replace(reg,'<div id="MoreLess" class="mceItemMoreLess">');
				reg = new RegExp('<!--hideEnd-->', "ig");
				content = content.replace(reg,'<!--hideEnd--></div>');

				//Gallery
				var arrDesc=content.match(/(<!--galleryBegin-->.*?\<!--galleryEnd-->)/g);
				var curInfo='';
				var curDesc='';
				if (arrDesc!=null){
					for (var i=0;i<arrDesc.length;i++){
						curInfo=arrDesc[i];
						curInfo=curInfo.replace("<!--galleryEnd-->","");
						curInfo=curInfo.replace("<!--galleryBegin-->","");
							
						curDesc = '<img width="400" height="300"';
						curDesc += ' src="' + (tinyMCE.getParam("theme_href") + '/images/spacer.gif') + '" title="Gallery"';
						curDesc += ' alt="' + curInfo + '" class="mceItemGallery" />';
						content = content.replace('<!--galleryBegin-->'+curInfo+'<!--galleryEnd-->',curDesc);
					}
				}

				//File
				var arrDesc=content.match(/(<!--fileBegin-->.*?\<!--fileEnd-->)/g);
				var curInfo='';
				var curDesc='';
				if (arrDesc!=null){
					for (var i=0;i<arrDesc.length;i++){
						curInfo=arrDesc[i];
						curInfo=curInfo.replace("<!--fileEnd-->","");
						curInfo=curInfo.replace("<!--fileBegin-->","");
							
						curDesc = '<img width="80" height="25"';
						curDesc += ' src="' + (tinyMCE.getParam("theme_href") + '/images/spacer.gif') + '" title="File"';
						curDesc += ' alt="' + curInfo + '" class="mceItemFile" />';
						content = content.replace('<!--fileBegin-->'+curInfo+'<!--fileEnd-->',curDesc);
					}
				}

				//Member File
				var arrDesc=content.match(/(<!--mfileBegin-->.*?\<!--mfileEnd-->)/g);
				var curInfo='';
				var curDesc='';
				if (arrDesc!=null){
					for (var i=0;i<arrDesc.length;i++){
						curInfo=arrDesc[i];
						curInfo=curInfo.replace("<!--mfileEnd-->","");
						curInfo=curInfo.replace("<!--mfileBegin-->","");
							
						curDesc = '<img width="50" height="25"';
						curDesc += ' src="' + (tinyMCE.getParam("theme_href") + '/images/spacer.gif') + '" title="Member File"';
						curDesc += ' alt="' + curInfo + '" class="mceItemMFile" />';
						content = content.replace('<!--mfileBegin-->'+curInfo+'<!--mfileEnd-->',curDesc);
					}
				}

				var startPos = 0;
				// Parse all <!--more--> tags and replace them with images
				while ((startPos = content.indexOf('<!--more-->', startPos)) != -1) {
					// Insert image
					var contentAfter = content.substring(startPos + 11);
					content = content.substring(0, startPos);
					content += '<img src="' + (tinyMCE.getParam("theme_href") + "/images/spacer.gif") + '" ';
					content += ' width="100%" height="10px" ';
					content += 'alt="'+altMore+'" title="'+altMore+'" class="mce_plugin_f2blog_more" name="mce_plugin_f2blog_more" />';
					content += contentAfter;

					startPos++;
				}

				var startPos = 0;
				// Parse all <!--page--> tags and replace them with images
				while ((startPos = content.indexOf('<!--nextpage-->', startPos)) != -1) {
					// Insert image
					var contentAfter = content.substring(startPos + 15);
					content = content.substring(0, startPos);
					content += '<img src="' + (tinyMCE.getParam("theme_href") + "/images/spacer.gif") + '" ';
					content += ' width="100%" height="10px" ';
					content += 'alt="'+altPage+'" title="'+altPage+'" class="mce_plugin_f2blog_page" name="mce_plugin_f2blog_page" />';
					content += contentAfter;

					startPos++;
				}

				// Look for \n in <pre>, replace with <br>
				var startPos = -1;
				while ((startPos = content.indexOf('<pre', startPos+1)) != -1) {
					var endPos = content.indexOf('</pre>', startPos+1);
					var innerPos = content.indexOf('>', startPos+1);
					var chunkBefore = content.substring(0, innerPos);
					var chunkAfter = content.substring(endPos);
					
					var innards = content.substring(innerPos, endPos);
					innards = innards.replace(/\n/g, '<br />');
					content = chunkBefore + innards + chunkAfter;
				}

				break;

			case "get_from_editor":
				//Hide
				var reg = new RegExp('<div id="MoreLess" class="mceItemMoreLess">', "ig");
				content = content.replace(reg,'<!--hideBegin-->');
				reg = new RegExp('<!--hideEnd--></div>', "ig");
				content = content.replace(reg,'<!--hideEnd-->');

				// Parse all img tags and replace them with <!--more-->
				var startPos = -1;
				while ((startPos = content.indexOf('<img', startPos+1)) != -1) {
					var endPos = content.indexOf('/>', startPos);
					var attribs = this._parseAttributes(content.substring(startPos + 4, endPos));
					
					//Gallery

⌨️ 快捷键说明

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