www.gusucode.com > 翼动留言板 2.1源码程序 > inc/ubbcode.js

    /*
'************************************************************************************
'开发组		翼动工作室
'姓名		郑景德
'网名		旭日
'QQ			3178920
'个人网站		http://www.wingroom.com
'本页:
		'UBB函数
	注:objname为表单名
'
'************************************************************************************
*/
helpstat = false;
stprompt = true;
basic = false;
//把生成的代码写到文本框中
function AddText(objname,NewCode){
	document.all[objname].value += NewCode;
}
//加粗
function bold(objname){
	if (helpstat){
		alert("加粗标记\n使文本加粗.\n用法:[b]这是加粗的文字[/b]");
	} else if (document.selection && document.selection.type == "Text") {
			var range = document.selection.createRange();
			range.text = "[b]" + range.text + "[/b]";
	} else if (basic){
		AddTxt = "[b][/b]";
		AddText(objname,AddTxt);
	} else{
		txt = prompt("文字将被变粗.","文字");
		if (txt!=null){
			AddTxt = "[b]"+txt+"[/b]";
			AddText(objname,AddTxt);
		}
	}
}
//倾斜
function italicize(objname){
	if (helpstat){
		alert("倾斜标记\n使文本倾斜.\n用法:[i]这是倾斜的文字[/i]");
	} else if (document.selection && document.selection.type == "Text") {
			var range = document.selection.createRange();
			range.text = "[i]" + range.text + "[/i]";
	} else if (basic){
		AddTxt = "[i][/i]";
		AddText(objname,AddTxt);
	} else{
		txt = prompt("文字将被倾斜.","文字");
		if (txt!=null){
			AddTxt = "[i]"+txt+"[/i]";
			AddText(objname,AddTxt);
		}
	}
}
//下划线
function underline(objname){
	if (helpstat){
		alert("下划线标记\n使文本加下划线.\n用法:[u]这是倾斜的文字[/u]");
	} else if (document.selection && document.selection.type == "Text") {
			var range = document.selection.createRange();
			range.text = "[u]" + range.text + "[/u]";
	} else if (basic){
		AddTxt = "[u][/u]";
		AddText(objname,AddTxt);
	} else{
		txt = prompt("文字将被加下划线.","文字");
		if (txt!=null){
			AddTxt = "[u]"+txt+"[/u]";
			AddText(objname,AddTxt);
		}
	}
}
//居中
function center(objname){
	if (helpstat){
		alert("居中标记\n使文本居中.\n用法:[align=center]这是居中的文字[/align]");
	} else if (document.selection && document.selection.type == "Text") {
			var range = document.selection.createRange();
			range.text = "[align=center]" + range.text + "[/align]";
	} else if (basic){
		AddTxt = "[align=center][/align]";
		AddText(objname,AddTxt);
	} else{
		txt = prompt("文字将被居中.","文字");
		if (txt){
			AddTxt = "[align=center]"+txt+"[/align]";
			AddText(objname,AddTxt);
		}
	}
}
//插入网址
function url(objname){
	if (helpstat){
		alert("超级链接标记\n用法:[url=http://www.wingroom.com]翼动工作室[/url]");
	} else if (document.selection && document.selection.type == "Text")	{
			var range = document.selection.createRange();
			range.text = "[url=http://www.wingroom.com]" + range.text + "[/url]";
	} else if (basic)
	{
		AddTxt = "[url=http://www.wingroom.com]翼动工作室[/url]";
		AddText(objname,AddTxt);
	}
	else {
		txt1 = prompt("显示的文字\n如果为空,将显示你的网址.","文字");
		txt2 = prompt("链接到的地址.","http://www.wingroom.com");
		if (txt2) {
			if (txt1){
				AddTxt = "[url="+txt2+"]"+txt1+"[/url]";
				AddText(objname,AddTxt);
			}else{
				AddTxt = "[url="+txt2+"]"+txt2+"[/url]";
				AddText(objname,AddTxt);
			}
		}
	}
}
//邮件链接
function email(objname){
	if (helpstat){
		alert("Email链接标记\n用法:[email=54ano@163.com]旭日的邮箱[/email]");
	} else if (document.selection && document.selection.type == "Text")	{
			var range = document.selection.createRange();
			range.text = "[email=54ano@163.com]" + range.text + "[/email]";
	}
	else if (basic)
	{
		AddTxt = "[email=54ano@163.com]文字[/email]";
		AddText(objname,AddTxt);
	}
	else {
		txt1 = prompt("显示的文字\n如果为空,将显示你的邮箱.","文字");
		txt2 = prompt("链接到的邮箱地址.","54ano@163.com");
		if (txt2) {
			if (txt1){
				AddTxt = "[email="+txt2+"]"+txt1+"[/email]";
				AddText(objname,AddTxt);
			}else{
				AddTxt = "[email="+txt2+"]"+txt2+"[/email]";
				AddText(objname,AddTxt);
			}
		}
	}
}
//飞行字
function fly(objname){
	if (helpstat){
		alert("飞行字标记\n使文本左右移动.\n用法:[fly]这是飞行的文字[/fly]");
	} else if (document.selection && document.selection.type == "Text") {
			var range = document.selection.createRange();
			range.text = "[fly]" + range.text + "[/fly]";
	} else if (basic){
		AddTxt = "[fly][/fly]";
		AddText(objname,AddTxt);
	} else{
		txt = prompt("文字将左右移动.","文字");
		if (txt){
			AddTxt = "[fly]"+txt+"[/fly]";
			AddText(objname,AddTxt);
		}
	}
}
//阴影字
function shadow(objname){
	if (helpstat){
		alert("阴影字标记\n使文本加上阴影.\n用法:[shadow=255,blue,1]这是阴影的文字[/shadow]");
	} else if (document.selection && document.selection.type == "Text") {
			var range = document.selection.createRange();
			range.text = "[shadow=255,blue,1]" + range.text + "[/shadow]";
	} else if (basic){
		AddTxt = "[shadow=255,blue,1][/shadow]";
		AddText(objname,AddTxt);
	} else{
		txt1 = prompt("文字的长度,颜色,边界大小.","255,blue,1");
		txt2 = prompt("要产生阴影效果的文字","文字");
		if (txt2){
			if (txt1){
				AddTxt = "[shadow="+txt1+"]"+txt2+"[/shadow]";
				AddText(objname,AddTxt);
			} else{
				AddTxt = "[shadow=255,blue,1]"+txt2+"[/shadow]";
				AddText(objname,AddTxt);				
			}
		}
	}
}
//插入图片
function image(objname){
	if (helpstat){
		alert("图片标记\n插入图片.\n用法:[img]这是图片的地址[/img]");
	} else if (document.selection && document.selection.type == "Text") {
			var range = document.selection.createRange();
			range.text = "[img]" + range.text + "[/img]";
	} else if (basic){
		AddTxt = "[img][/img]";
		AddText(objname,AddTxt);
	} else{
		txt = prompt("图片的地址.","http://");
		if (txt){
			AddTxt = "[img]"+txt+"[/img]";
			AddText(objname,AddTxt);
		}
	}
}
//帮助
function help(){
	alert("您好,如果有什么问题\n请登录http://www.wingroom.com询问站长\n\n页面:\n\r\rhttp://www.wingroom.com/UBB/help.htm\n\n\t\t\t--翼动工作室");
}