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

📄 editor_toolbar.js

📁 简单的记事本
💻 JS
📖 第 1 页 / 共 2 页
字号:
function fHideTBMenu() {
	for(var i = gTBCmds.length - 1; i >= 0; i--)
		fDisp(S("mutb_" + gTBCmds[i]), 0);
}

function StringReplaceAll(Str, Src, NewStr) {
	if(!Str || Str.length == 0) return "";
	return Str.split(Src).join(NewStr);
}
function URLFieldEncode(str) {
	var arr = [
	   "%","%25"
	  ,' ',"%20"
	  ,"&","%26"
	  ,"#","%23"
	  ,"+","%2b"
	  ,"-","%2d"
	];
	for(var i=0,len=arr.length;i<len;i+=2)
		str = StringReplaceAll(str, arr[i], arr[i+1]);
	return str;
}

//do process
function fTBPInsertPic(para) {
	fLoadPos();
	var doc = F(gHtmlId).document;
	var r = doc.selection ? doc.selection.createRange() : null;
	fSetEditorFocus();
	doc.execCommand("InsertImage", false, para != null ? para : false);
	if (r != null) {
		try {
			r.move("character");
			r.select();
		}catch(e){}
	}
}
function fTBExecCmd(type, para) {
	fSetEditorFocus();
	F(gHtmlId).document.execCommand(type, false, para != null ? para : false);
}
function fCreateLink() {
	var u = S("mutb_"+gTBCmds[10]+"_url").value;
	if(u) {
		u= !(( u.indexOf("://") > 1 ) || (u.indexOf(":\\") > 1)) ? "http://" + u : u;
		fTBExecCmd(gTBCmds[10], u);
	}
}
function fTrimCR(str, bNn) {
	return bNn ? str.replace(/\r/ig, "") : str.replace(/\n|\r/ig, "");
}
function fRandomFontColor(mode) {
	var f = F(gHtmlId);
	try{
		if(!(f.getSelection != null ? !f.getSelection().getRangeAt(0).collapsed : f.document.selection.createRange().htmlText.length > 0)) return;
	}catch(e){}
	var html = fTrimCR(GetContent());
	if (f.getSelection != null) {
		var r = f.getSelection().getRangeAt(0);
		var code = f.document.createElement("div");
		code.appendChild(r.cloneContents());
		code = code.innerHTML;
		r.deleteContents();
		f.getSelection().getRangeAt(0).insertNode(f.document.createTextNode("/*=qqmail_selection=*/"));
	}
	else {
		var r = 	f.document.selection.createRange();
		var aSavePoint = [r.offsetLeft, r.offsetTop, fTrimCR(r.text, 1).length, f.document.body.scrollTop];
		var code = r.htmlText;
		r.pasteHTML("/*=qqmail_selection=*/"); 
	}
	code = fTrimCR(code);
	//code = code.substring(fContinuousTagPos(code), fContinuousTagPos(code, 1) + 1);
	var c = fTrimCR(GetContent());
	gIsIE ? fTBExecCmd("undo") : PutContent(html);
	c = c.split("/*=qqmail_selection=*/");
	c[0] = c[0].substring(0, fContinuousTagPos(c[0], 1) + 1);
//	fDebug("\n-----------code---------\n" + code + "\n----------c--------------\n" + c[0], 1);
	var p = html.indexOf(code, c[0].length);
	if (p == -1) {
		var len = c[0].length;
		var ap = [fContinuousTagPos(code), fContinuousTagPos(code, 1) + 1];
		var tmp = code.substring(ap[0], code.length);
		p = html.indexOf(tmp, len);
		if (p == -1) {
			tmp = code.substring(0, ap[1]);
			p = html.indexOf(tmp, len);
			if (p == -1) {
				tmp = code.substring(ap[0], ap[1]);
				p = html.indexOf(tmp, len);
				if (p == -1) return;
			}
		}
		code = tmp;
	}
	c[0] = html.substring(0, p);
	c[1] = html.substring(p + code.length, html.length);
	html = code;
	code = null;
/*
	c[1] = c[1].substring(fContinuousTagPos(c[1]), c[1].length);
	var p1 = c[0].length;
	var p2 = html.lastIndexOf(c[1]);
	c[0] = html.substring(0, p1);
	c[1] = html.substring(p2, html.length);
	html = html.substring(p1, p2);
*/
//	fDebug("\n-----------c[0]---------\n" + c[0] + "\n----------c[1]---------\n" + c[1] + "\n-----------html-----------\n" + html);
	RandomFontColor(html, mode, function(result) {
//		fDebug("\n\n---------resutl---------\n" + result);
		var p = [c[0].length, result.length];
		f.focus();
		PutContent(c.join(result));
		setTimeout(function() {
			if (gIsIE) {
				f.document.body.scrollTop = aSavePoint[3];
				r = f.document.selection.createRange();
				r.moveToPoint(aSavePoint[0], aSavePoint[1]);
				r.moveEnd("character", aSavePoint[2]);
				r.select();
			}
		}, 0);
	});

}

//callback after load this script
try{fLoadEditorToolBarCallBack();}catch(e){}


//-------------------rand fore color
var g_rfc_rgb = [
	 ["cc6633","cc0000","663399","0066cc","00ade5","00b085"]
	,["124d7e","295caa","0071bc","0089cf","0099d1","00a9eb","00abbc","00a9a4"]
	,["7e4312","aa7729","bc4b00","d13800","eb4200","a90005"]
	,["00bcb2","00cfb7","00d1aa","00ebc3","00bc78","00a957"]
];
var g_rfc_color_arr = ["<font color=#", "", " qq>", "", "</font>"];
function GenColorCode(str, m) {
	m = m ? m : 0;
	g_rfc_color_arr[1] = g_rfc_rgb[m][parseInt(Math.random() * 1000) %  g_rfc_rgb[m].length];
	g_rfc_color_arr[3] = str;
	return g_rfc_color_arr.join("");
}

var g_tmCharColor = ["lt","gt","amp","quot","reg","copy","trade"]
var g_tmCharNoColor = ["ensp","emsp","nbsp"];
var g_tmCharMaxLen = 5;
function IsTmChar(str, color) {
	var a = color ? g_tmCharColor : g_tmCharNoColor;
	for (var i = a.length - 1; i >= 0; i--) {
		if (str == a[i]) return true;
	}
	return false;
}

var g_rfc_max_once = 600;
var g_rfc_content = null;
var g_rfc_content_l = 0;
var g_rfc_result = null;
var g_rfc_status = 0;
var g_rfc_font_num = 0;
//var g_rfc_font_pos = -1;
var g_rfc_font_pos = null;
var g_rfc_tag_pos = 0;
var g_rfc_del_font = null;
var g_rfc_stop = 0;
var g_rfc_fcallback = null;
function RandomFontColor(content, mode, fcallback) {
	if (fcallback == null || content == null) return;
	fChangeEditor(0);
	g_rfc_content = content;
	g_rfc_content_l = content.length;
	g_rfc_result = new Array();
	g_rfc_status = 0;
	g_rfc_font_num = 0;
	g_rfc_font_pos = new Array();
	g_rfc_del_font = new Array();
	g_rfc_tag_pos = 0;
	g_rfc_stop = 0;
	g_rfc_fcallback = fcallback;
	mode = mode ? mode : 0;
	setTimeout("RandomFontColorPercent("+mode+")", 0);
}
function RandomFontColorPercent(mode, pos) {
	if (pos == null) {
		if (g_rfc_content_l >= g_rfc_max_once) {
			ModelDialog(1, "随机前景色处理进度", "<div style='padding:20px 0 10px 0;'><div style='width:260px;border:1px solid #969696;position:relative;height:12px;background:#fff;'><div id='randcolor_pencent_bar' style='width:0%;border:1px solid #84EE57;background:#C5EDB4;position:absolute;left:-1;top:-1px;font:8px;height:12px;'></div></div></div><div style='align:left;width:260px;'>正在对字体进行随机颜色渲染中...<span id='randcolor_pencent' style='color:#00A2A2;'></span></div>");
		}
		setTimeout("RandomFontColorPercent("+mode+",0)", 0);
		return ;
	}

	//让完成先行
	if (pos >= g_rfc_content_l) {
		//补完不完整标签删除的
		//alert(g_rfc_font_num + " pos:" + g_rfc_font_pos);
		for (var i = 0; i < g_rfc_font_pos.length; i ++) g_rfc_result.push(g_rfc_del_font[i]);
		if (g_rfc_fcallback) {
			g_rfc_fcallback(g_rfc_result.join(""));
		}
		g_rfc_content = null;
		g_rfc_result = null;
		g_rfc_fcallback = null;
		g_rfc_font_pos = null;
		g_rfc_del_font = null;
		return HideModelDialog();
	}

	if (g_rfc_stop == 1) {
		g_rfc_content = null;
		g_rfc_result = null;
		g_rfc_fcallback = null;
		g_rfc_font_pos = null;
		g_rfc_del_font = null;
		return HideModelDialog();
	}

	var i = pos;
	for (; i < (g_rfc_max_once + pos) && i < g_rfc_content_l; i++) {
		var v = g_rfc_content.charAt(i);
		switch(v) {
			case " ":
			case " ":
			case "	":
			case "\n":
			case "\r":
			case "\t":
				break;
			case "&":
				if (g_rfc_status != 0) break;
				var _a = new Array();
				var j = i + 1;
				var _l = j + g_tmCharMaxLen + 1;
				_l = _l < g_rfc_content_l ? _l : g_rfc_content_l;
				var _v;
				//预读:只有在标签外情况下才会判断转义
				for (; j < _l; j++)	{
					_v = g_rfc_content.charAt(j);
					if (_v == ";") break;
					_a.push(_v);
				}
				if (_v == ";") {
					//这里简化了,不判断是否转义号,有分号都整体变色
					i = j;
					_a = _a.join("");
					v = "&" + _a + ";";
					if (IsTmChar(_a, 0)) break;
				}
				v = mode == -1 ? v : GenColorCode(v, mode);
				break;
			case "<":
				if (g_rfc_status != 0) break;
				g_rfc_tag_pos = i;
				g_rfc_status = 1;
				//预读标签
				var tag = g_rfc_content.substr(i + 1, 5).toUpperCase();
				if (tag == "FONT " || tag == "FONT>") {
					g_rfc_font_num++;
					g_rfc_status = 2;
				}
				else if (tag == "/FONT") {
					if (g_rfc_font_num != 0 && g_rfc_font_num == g_rfc_font_pos.slice(-1)) {
						//alert("kill /font font_num:" + g_rfc_font_num + " pos:" + g_rfc_font_pos.length + " num:" + g_rfc_font_num);
						//必须去掉</font>
						g_rfc_font_pos.pop();
						g_rfc_del_font.pop();
						i = i + 6;
						g_rfc_font_num--;
						g_rfc_status = 0;
						continue;
					}
					if (g_rfc_font_num > 0) g_rfc_font_num--;
				}
				break;
			case ">":
				if (g_rfc_status == 0) {
					v = mode == -1 ? v : GenColorCode(v, mode);
				}
				else {
					//带有 qq标记,必须删除<font>标签
					if (g_rfc_status == 2 && g_rfc_font_pos.slice(-1) == g_rfc_font_num) {
						g_rfc_del_font.push(g_rfc_result.slice(g_rfc_tag_pos - i).join("") + ">");
//						alert("kill <font qq> " + g_rfc_del_font);
						g_rfc_result = g_rfc_result.slice(0, g_rfc_tag_pos - i);
						g_rfc_status = 0;
						continue;
					}
					g_rfc_status = 0;
				}
				break;
			default:
				if (g_rfc_status == 0)	v = mode == -1 ? v : GenColorCode(v, mode);
				//判断是否是随机颜色, 带有 qq标记
				if (g_rfc_status == 2 && v == "q" && g_rfc_content.charAt(i - 1) == " " && g_rfc_content.charAt(i + 1) == "q") g_rfc_font_pos.push(g_rfc_font_num);
				break;
		}
		g_rfc_result.push(v);
	}

	g_rfc_stop = 1;
	/*
	var p = GetDialogObj("randcolor_pencent");
	if (p) {
		var per = parseInt((i / g_rfc_content_l) * 100);
		p.innerHTML = per + "%";
		p = GetDialogObj("randcolor_pencent_bar");
		p.style.width = per * parseInt(p.parentNode.style.width) / 100;
	}
	else {
		g_rfc_stop = 1;
	}
	*/

	setTimeout("RandomFontColorPercent("+mode+","+i+")", 0);
}


⌨️ 快捷键说明

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