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

📄 csdnubbeditor.js

📁 关于断言的一篇小文章
💻 JS
📖 第 1 页 / 共 2 页
字号:
/*
Author:Meizz
Created:2007-02-28
Version:2008-07-07
Modify:ZswangY37
*/

var defaultLanguages = new Array
(
	{ forumIDs: 
		"F9FB995E-C93D-456A-8097-0B27CCB25C4E," +
		"6C6B2CF3-A601-4629-8EB9-466F34AAB011," +
		"B3552BF0-9B33-47B2-B067-57F9BE054A7F," +
		"A329B8A2-DF76-4C97-A779-63E19535209E," +
		"4269C85A-666C-44A6-84B0-8841DB1E7F68," +
		"0BC02486-646A-4A41-9F4E-8E0F36871768," +
		"29D9B8D4-82F5-4801-B736-914192A98F21," +
		"32DAECB5-5DB5-42B5-8DA4-BD03849E181D," +
		"A11DF1B2-DE12-4FDC-A65A-C5C21681F7AC," +
		"0B896AC3-294A-49F6-BECD-CEC492C787A9," +
		"9AA3F9C9-7481-448C-997B-48616819FE87," +
		"0CB5B416-3071-421F-B910-5A3392C5BD19," +
		"F7252002-6D2A-4DFA-B957-5F17B9B654B3," +
		"65ACDD61-4A3A-4131-8261-7C0AB1E8BEF5," +
		"2C6D6B6B-7D47-4FA3-B25F-B2960A1711B0," +
		"A43F0123-4D00-4F56-AD06-BF600E1A8062," +
		"AE925434-466E-42C8-B32F-C24BA1C73D6D," +
		"2C9ABD1C-1E3E-4E45-BFDB-31213B2AA736," +
		"17673F58-331A-4F41-A240-3AC1D698FD74," +
		"A09AB4EB-BB7E-45A9-84FD-46EBF6B2997D," +
		"8BBCE98E-B54F-41EA-8F96-9EE6311513C0," +
		"98A73A94-5F11-4F90-A035-E5609FB9C63F," +
		"5FC6F290-9AB1-492E-AF2C-FBD31E9E3002",
		language: "C/C++" },
	{ forumIDs: 
		"E2798A59-79D5-4833-9C57-87D46A8B907A," +
		"976148B5-B1A9-4A11-B881-96E198962403",
		language: "C#" },
	{ forumIDs: 
		"DC0369D7-BC4B-48FF-8FFA-24B46529CAB3," +
		"CBFF8B5A-57AD-462E-833B-288000C6CC7C," +
		"D593354E-8665-4410-94B5-508D935F5083," +
		"8AB98CD6-4AFB-4F14-947B-586DBA0AD98A," +
		"86FDA20C-918F-4004-9A60-83AC6156C017," +
		"4478B4F9-6258-4863-9A4B-87351EE3020B," +
		"8A63669B-105B-4443-8406-CB0BDCCD157B," +
		"2D8A999F-B552-4BF1-81B2-DA785BDC082A",
		language: "Delphi(Pascal)" },
	{ forumIDs: 
		"B4147360-C993-428F-9C51-0E314FFC441A," +
		"56EAA76E-03F8-4711-902D-155891A52EAB," +
		"C8912383-CD38-4EE5-9E82-22D3DA0BB9B7," +
		"873558A8-B625-4CA5-A186-471147813C69," +
		"EBAB1CD2-C2BF-43E0-BEBE-BA432BCA0E31," +
		"E8970651-6B35-4F81-8317-C4ACCED7CF48," +
		"33FA67FF-A665-455A-8789-C5B59C9D8D5A," +
		"7BDC6604-0E56-44FB-AC04-E97E736F1ECD," +
		"A333AD9B-03A3-4604-96DB-FFB75337742A",
		language: "VB" },
	{ forumIDs: 
		"B7E466C6-291A-4072-ACEE-15D2BE78C647",
		language: "VB.NET" },
	{ forumIDs: 
		"B18C12C4-C4ED-469F-872C-6FE0DA0F975A",
		language: "VBScript" },
	{ forumIDs: 
		"39732074-A685-471F-B95A-119709673C0D",
		language: "Assembly" },
	{ forumIDs: 
		"467D91E3-DD10-480B-A322-71B65E66C736",
		language: "JScript" },
	{ forumIDs: 
		"94985A29-C8E9-4552-9BE4-B01061443744",
		language: "PHP" },
	{ forumIDs: 
		"2EFCA177-6B51-42D9-A509-0216FBCA231E," +
		"A78E0A85-E260-4232-95C9-1872A2B49944," +
		"DF8A1EB4-7ECB-4FCD-A9AE-1BE6FD084AEB," +
		"F215D409-58D5-44C2-884B-1FDC179523E3," +
		"3931C03E-B66C-4189-A4F0-210FD9501803," +
		"02DBED19-8F0B-47ED-8D51-2143CD8ADF06," +
		"6677E88C-D1A7-48AD-9E82-27FCCC00C626," +
		"342057C2-1AC8-47AF-8070-36259792E8F1," +
		"E051865D-0992-4901-928E-4229C77A4F0B," +
		"845A6FCE-C2B5-482C-AFCC-4575B07FE8B4," +
		"4C3EEB74-0853-425E-BFED-58F38483484A," +
		"BEBF6FBC-94E1-43AD-B03C-B3DD371A7FB2," +
		"CE40C5AE-4D20-4DA9-A71F-E52AC2CBD899," +
		"8B327318-2C42-4A49-8AED-EF8C33697E7F," +
		"C02C69AB-3534-4BAF-A3B0-F5DF87F8DAB4," +
		"AA6E8F72-6461-4C23-B790-FD870A35EC3B",
		language: "Java" },
	{ forumIDs: 
		"6E0E6207-DE3A-4C0B-8F8A-052FCBA6392A," +
		"A487DFB4-AD04-4694-AAE7-2BF358DE9B52," +
		"A8983D7F-322C-49E5-8EC2-548C623D1929," +
		"BA09FE7E-2FB7-42D3-805E-578A4A8485E1," +
		"55B4468C-6FDE-444F-BDE0-6E82082B1B73," +
		"D63A305D-A283-4704-9675-D386FACAE96A," +
		"F5ECBFE4-F43F-4CB9-9F32-EFEACF9FD57A," +
		"DFFA884A-2C7E-4D78-B327-073A7A091350," +
		"B282A8E8-D232-424E-80AF-497FCB424586," +
		"BA09FE7E-2FB7-42D3-805E-578A4A8485E1," +
		"2139527C-A6DE-49CF-96E6-5E00F39A082C," +
		"FBEB0E20-4AED-4BD6-80AA-AF19ABFEA817," +
		"509C4724-A4B5-4F8F-9A41-BFC4DAFCD6E6," +
		"7AAAD003-1746-4CE6-B96C-D1730C321977," +
		"D63A305D-A283-4704-9675-D386FACAE96A," +
		"FE63BCC5-4E39-4A00-A59D-D59FC803B085," +
		"38563647-4A43-4709-9149-E58CB13BC354," +
		"33FE3BD4-59F5-4ACB-812E-E6C961EE07DA",
		language: "SQL" },
	{ forumIDs: 
		"7459A70B-915A-447F-87C6-378668FA7AB9",
		language: "Perl" }
);


var isIE = navigator.userAgent.indexOf("MSIE") > 0;

function CsdnUbbEditor(editor, op)
{
	this.editor = CsdnUbbEditor.check(editor);
	this.contentLength = 8000;
	this.disabled = false;
	this.options = CsdnUbbEditor.extend({}, op || {});
	this.hashCode = "CsdnUbb_" + (CsdnUbbEditor.counter++).toString(36);
	CsdnUbbEditor.instances[this.hashCode] = this;
	this.initialize();
};

CsdnUbbEditor.defaultLanguage = function ()
{
	var re = /forumId=([a-z\d\-]+)/i;
	var forumId = null;
	if (re.exec(location)) forumId = RegExp.$1.toUpperCase();
	if (forumId == null) return "";
	for (var i = 0; i < defaultLanguages.length; i++)
		if (defaultLanguages[i].forumIDs.indexOf(forumId) >= 0)
			return defaultLanguages[i].language;
	return "";
};

CsdnUbbEditor.extend = function(d, s)
{
	for (var i in s) d[i] = s[i]; 
	return d;
};

CsdnUbbEditor.check = function(e)
{
	if ("object" == typeof e && !e.tagName) return null;
	if ("string" == typeof e && !(e = document.getElementById(e)))
		return null;
	return e;
};

CsdnUbbEditor.loadCssFile = function(cssPath, uniqueId)
{
	if (/\w+\.\w+(\?|$)/.test(cssPath))
	{
		if (!("string" == typeof uniqueId && uniqueId != ""))
		uniqueId = "CsdnCss_" + cssPath.replace(/\W/g, "");
		if (document.getElementById(uniqueId)) return;

		var link = document.createElement("LINK");
		link.href = cssPath;
		link.id = uniqueId;
		link.type = "text/css";
		link.rel = "Stylesheet";
		uniqueId = document.getElementsByTagName("HEAD")[0];
		uniqueId.insertBefore(link, uniqueId.firstChild);
	}
}

CsdnUbbEditor.body = function()
{
	var W, H, SL, ST;
	var w = window, d = document, dd = d.documentElement;

	if (w.innerWidth) W = w.innerWidth;
	else if (dd && dd.clientWidth) W = dd.clientWidth;
	else if (d.body) W = d.body.clientWidth;

	if (w.innerHeight) H = w.innerHeight;
	else if (dd && dd.clientHeight) H = dd.clientHeight; 
	else if (d.body) H = d.body.clientHeight;

	if (w.pageXOffset) SL = w.pageXOffset;
	else if (dd && dd.scrollLeft) SL = dd.scrollLeft;
	else if (d.body) SL = d.body.scrollLeft;

	if (w.pageYOffset) ST = w.pageYOffset;
	else if (dd && dd.scrollTop) ST = dd.scrollTop;
	else if (d.body) ST = d.body.scrollTop;

	return { "scrollTop": ST, "scrollLeft": SL, "clientWidth": W, "clientHeight": H };
}

CsdnUbbEditor.counter = 0;
CsdnUbbEditor.instances = {};
CsdnUbbEditor.instance = function(i)
{
	return CsdnUbbEditor.instances[i];
}

CsdnUbbEditor.realOffset = function(o)
{
	var e = o, x = y = l = t = 0, doc = CsdnUbbEditor.body();
	do { l += e.offsetLeft || 0; t += e.offsetTop || 0; e = e.offsetParent; } while (e);
	do { x += o.scrollLeft || 0; y += o.scrollTop || 0; o = o.parentNode; } while (o);
	return { "x": l - x + doc.scrollLeft, "y": t - y + doc.scrollTop};
}

String.prototype.trim = function()
{
	return this.replace(/(^[\s\t\xa0\u3000]+)|([\u3000\xa0\s\t]+$)/g, "");
}

String.prototype.format = function()
{
	if (arguments.length == 0) return this;
	for (var s = this, i = 0; i < arguments.length; i++)
		s = s.replace(new RegExp("\\{" + i + "\\}", "g"), arguments[i]);
	return s;
}

String.prototype.getByteLength = function()
{
	return this.replace(/[^\x00-\xff]/g, "mm").length;
}

if (!window.attachEvent && window.addEventListener)
{
	Window.prototype.attachEvent = HTMLDocument.prototype.attachEvent =
		HTMLElement.prototype.attachEvent = function(en, func, cancelBubble)
		{
			this.addEventListener(en.toLowerCase().substr(2), func, cancelBubble);
		}
	Window.prototype.detachEvent = HTMLDocument.prototype.detachEvent =
		HTMLElement.prototype.detachEvent = function(en, func, cancelBubble)
		{
			this.removeEventListener(en.toLowerCase().substr(2), func, cancelBubble);
		}
}

if (typeof(HTMLElement) != "undefined" && !window.opera)
{
	var t = HTMLElement.prototype;
	t.__defineGetter__("children", function()
		{
			for (var a = [], j = 0, n, i = 0; i < this.childNodes.length; i++)
			{
				n = this.childNodes[i];
				if (n.nodeType == 1)
				{
					a[j++] = n;
					if (n.name)
					{
						if (!a[n.name]) a[n.name] = [];
						a[n.name][a[n.name].length] = n;
					}
					if (n.id) a[n.id] = n;
				}
			}
			return a;
		}
	);
	t.insertAdjacentHTML = function(where, html)
	{
		var e = this.ownerDocument.createRange();
		e.setStartBefore(this);
		e = e.createContextualFragment(html);
		switch (where)
		{
			case 'beforeBegin': this.parentNode.insertBefore(e, this); break;
			case 'afterBegin': this.insertBefore(e, this.firstChild); break;
			case 'beforeEnd': this.appendChild(e); break;
			case 'afterEnd':
				if (!this.nextSibling)
					this.parentNode.appendChild(e);
				else this.parentNode.insertBefore(e, this.nextSibling); 
				break;
		}
	}
}

(
	function()
	{
		var t = document.getElementsByTagName("SCRIPT");
		t = t[t.length-1].src.replace(/\\/g, "/");
		CsdnUbbEditor.path = (t.lastIndexOf("/")<0) ? "." : t.substring(0, t.lastIndexOf("/"));
	}
)	();

CsdnUbbEditor.loadCssFile(CsdnUbbEditor.path + "/CsdnUbbEditor.css", "CsdnUbbEditor_CSS");

CsdnUbbEditor.contentCounter = function(hashcode)
{
	var box = CsdnUbbEditor.check("wordCounter_" + hashcode);
	if (box)
	{
		var editor = CsdnUbbEditor.instance(hashcode);
		var n = editor.contentLength - editor.editor.value.length;
		if (!isIE) box.innerHTML = n;
		box.parentNode.style.color = n >= 0 ? "" : "#FF0000";
	}
}

CsdnUbbEditor.disable = function(input, hashcode)
{
	var editor = CsdnUbbEditor.instance(hashcode);
	editor.menubar.style.display = input.checked ? "none" : "";
};


CsdnUbbEditor.prototype.initialize = function()
{
	if (!this.editor) return;
	var me = this;
	this.editor.onkeyup = function() { CsdnUbbEditor.contentCounter(me.hashCode); }
	this.editor.onfocus = function() { CsdnUbbEditor.contentCounter(me.hashCode); }
	this.editor.className += " CsdnUbbEditor";

	if (this.editor.form && isIE && !window.opera)
	{
		this.editor.form.attachEvent("onsubmit", function()
		{
			var e = CsdnUbbEditor.check(me.pasteInputId);
			if (e)
			{
				setCookie("UBBContentToClipboard", e.checked);
				if (e.checked) window.clipboardData.setData("Text", me.editor.value);
			}
		});
	}

	this.editor.insertAdjacentHTML("beforeBegin",
		"<div class='CsdnUbbEditorMenubar' id='CsdnUbbEditorMenubar_" + this.hashCode + "' " + (this.disabled ? " style='display: none'" : "") + "></div>");
	this.editor.insertAdjacentHTML("afterEnd",
		"<div class='CsdnUbbEditorStatusbar' id='CsdnUbbEditorStatusbar_" + this.hashCode + "'></div>");
	this.menubar = CsdnUbbEditor.check("CsdnUbbEditorMenubar_" + this.hashCode);
	this.statusbar = CsdnUbbEditor.check("CsdnUbbEditorStatusbar_" + this.hashCode);

	this.colorLayer();
	this.codeLayer();
	this.fontsizeLayer();
};

CsdnUbbEditor.prototype.codeLayer = function()
{
	var item = "<div title='\u8bed\u8a00\u79cd\u7c7b\uff1a{0}' onclick=\"CsdnUbbEditor.instance('" +
		this.hashCode + "').code('{0}')\">{0}</div>";
	var div = document.createElement("DIV"), a = [], me=this;
	div.className = "CsdnUbbEditorCodeLayer";
	div.style.display="none";
	div.id = "CsdnUbbEditorCodeLayer_" + this.hashCode;
	div.onclick = function(e) { (window.event||e).cancelBubble = true; }
	var language = CsdnUbbEditor.defaultLanguage();
	if (language != "")
	{
		var item2 = "<div title='\u9ED8\u8BA4\u8BED\u8A00{0}' onclick=\"CsdnUbbEditor.instance('" +
			this.hashCode + "').code('{0}')\"><b>{0}</b></div>";
		a.push(item2.format(language));
	}
	a.push(item.format("Assembly"));
	a.push(item.format("BatchFile"));
	a.push(item.format("C#"));
	a.push(item.format("C/C++"));
	a.push(item.format("CSS"));
	a.push(item.format("HTML"));
	a.push(item.format("INIFile"));
	a.push(item.format("Java"));
	a.push(item.format("JScript"));
	a.push(item.format("Lua"));
	a.push(item.format("MSIL"));
	a.push(item.format("Delphi(Pascal)"));
	a.push(item.format("Perl"));
	a.push(item.format("PHP"));
	a.push(item.format("Python"));
	a.push(item.format("SQL"));
	a.push(item.format("VB"));
	a.push(item.format("VB.NET"));
	a.push(item.format("VBScript"));
	a.push(item.format("XAML"));
	a.push(item.format("XML"));

	a = a.join("");
	div.innerHTML = a;
	document.body.insertBefore(div, document.body.firstChild);
	document.attachEvent("onclick", function() { me.hideLayer(div.id); } );
};

CsdnUbbEditor.prototype.fontsizeLayer = function()

⌨️ 快捷键说明

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