📄 ubbcode.js
字号:
var text_input = "文字";
function AddText(NewCode) {
if(document.all){
insertAtCaret(document.myform.content, NewCode);
setfocus();
} else{
document.myform.content.value += NewCode;
setfocus();
}
}
function storeCaret (textEl){
if(textEl.createTextRange){
textEl.caretPos = document.selection.createRange().duplicate();
}
}
function insertAtCaret (textEl, text){
if (textEl.createTextRange && textEl.caretPos){
var caretPos = textEl.caretPos;
caretPos.text += caretPos.text.charAt(caretPos.text.length - 2) == ' ' ? text + ' ' : text;
} else if(textEl) {
textEl.value += text;
} else {
textEl.value = text;
}
}
function email() {
if (document.selection && document.selection.type == "Text") {
var range = document.selection.createRange();
range.text = "[email]" + range.text + "[/email]";
} else {
txt2=prompt("请输入链接显示的文字,如果留空则直接显示邮件地址。","");
if (txt2!=null) {
txt=prompt("请输入邮件地址。","name@domain.com");
if (txt!=null) {
if (txt2=="") {
AddTxt="[email]"+txt+"[/email]";
} else {
AddTxt="[email="+txt+"]"+txt2+"[/email]";
}
AddText(AddTxt);
}
}
}
}
function chsize(size) {
if (document.selection && document.selection.type == "Text") {
var range = document.selection.createRange();
range.text = "[size=" + size + "]" + range.text + "[/size]";
} else {
txt=prompt("请输入要设置为指定字号的文字。",text_input);
if (txt!=null) {
AddTxt="[size="+size+"]"+txt;
AddText(AddTxt);
AddText("[/size]");
}
}
}
function chfont(font) {
// if (helpmode){
// alert(font_help);
if (document.selection && document.selection.type == "Text") {
var range = document.selection.createRange();
range.text = "[font=" + font + "]" + range.text + "[/font]";
} else {
txt=prompt("请输入要设置成指定字体的文字。",text_input);
if (txt!=null) {
AddTxt="[font="+font+"]"+txt;
AddText(AddTxt);
AddText("[/font]");
}
}
}
function bold() {
if (document.selection && document.selection.type == "Text") {
var range = document.selection.createRange();
range.text = "[b]" + range.text + "[/b]";
} else {
txt=prompt("请输入要设置成粗体的文字。",text_input);
if (txt!=null) {
AddTxt="[b]"+txt;
AddText(AddTxt);
AddText("[/b]");
}
}
}
function italicize() {
if (document.selection && document.selection.type == "Text") {
var range = document.selection.createRange();
range.text = "[i]" + range.text + "[/i]";
} else {
txt=prompt("请输入要设置成斜体的文字。",text_input);
if (txt!=null) {
AddTxt="[i]"+txt;
AddText(AddTxt);
AddText("[/i]");
}
}
}
function quote() {
if (document.selection && document.selection.type == "Text") {
var range = document.selection.createRange();
range.text = "[quote]" + range.text + "[/quote]";
} else {
txt=prompt("请输入要作为引用显示的文字。",text_input);
if(txt!=null) {
AddTxt="\r[quote]\r"+txt;
AddText(AddTxt);
AddText("\r[/quote]");
}
}
}
function chcolor(color) {
if (document.selection && document.selection.type == "Text") {
var range = document.selection.createRange();
range.text = "[color=" + color + "]" + range.text + "[/color]";
} else {
txt=prompt("请输入要设置成指定颜色的文字。",text_input);
if(txt!=null) {
AddTxt="[color="+color+"]"+txt;
AddText(AddTxt);
AddText("[/color]");
}
}
}
function center() {
if (document.selection && document.selection.type == "Text") {
var range = document.selection.createRange();
range.text = "[align=center]" + range.text + "[/align]";
} else {
txt=prompt("请输入要居中对齐的文字。",text_input);
if (txt!=null) {
AddTxt="\r[align=center]"+txt;
AddText(AddTxt);
AddText("[/align]");
}
}
}
function hyperlink() {
txt2=prompt("请输入链接显示的文字,如果留空则直接显示链接。","");
if (txt2!=null) {
txt=prompt("请输入 URL。","http://");
if (txt!=null) {
if (txt2=="") {
AddTxt="[url]"+txt;
AddText(AddTxt);
AddText("[/url]");
} else {
AddTxt="[url="+txt+"]"+txt2;
AddText(AddTxt);
AddText("[/url]");
}
}
}
}
function image() {
txt=prompt("请输入图像的 URL。","http://");
if(txt!=null) {
AddTxt="\r[img]"+txt;
AddText(AddTxt);
AddText("[/img]");
}
}
function flash() {
txt=prompt("请输入 Fash 动画的 URL。","http://");
if(txt!=null) {
AddTxt="\r[swf]"+txt;
AddText(AddTxt);
AddText("[/swf]");
}
}
function code() {
if (document.selection && document.selection.type == "Text") {
var range = document.selection.createRange();
range.text = "[code]" + range.text + "[/code]";
} else {
txt=prompt("请输入要插入的代码。","");
if (txt!=null) {
AddTxt="\r[code]"+txt;
AddText(AddTxt);
AddText("[/code]");
}
}
}
function wma() {
txt=prompt("请输入音频文件的 URL。","http://");
if(txt!=null) {
AddTxt="\r[wma=500,350]"+txt;
AddText(AddTxt);
AddText("[/wma]");
}
}
function wmv() {
txt=prompt("请输入视频文件的 URL。","http://");
if(txt!=null) {
AddTxt="\r[wmv=500,350]"+txt;
AddText(AddTxt);
AddText("[/wmv]");
}
}
function rm() {
txt=prompt("请输入Real媒体地址。","http://");
if(txt!=null) {
AddTxt="\r[rm=500,350]"+txt;
AddText(AddTxt);
AddText("[/rm]");
}
}
function Cmov() {
txt=prompt("quick time 文件的地址","");
if (txt!=null) {
AddTxt="[qt=500,350]"+txt;
AddText(AddTxt);
AddTxt="[/qt]";
AddText(AddTxt);
}
}
function list() {
txt=prompt("'请选择列表格式:字母式列表输入 \"A\";数字式列表输入 \"1\"。也可留空。","");
while ((txt!="") && (txt!="A") && (txt!="a") && (txt!="1") && (txt!=null)) {
txt=prompt("错误:列表格式只能选择输入 \"A\" 或 \"1\"。","");
}
if (txt!=null) {
if (txt=="") {
AddTxt="\r[list]\r\n";
} else {
AddTxt="\r[list="+txt+"]\r";
}
txt="1";
while ((txt!="") && (txt!=null)) {
txt=prompt("请输入列表项目内容,如果留空表示项目结束。","");
if (txt!="") {
AddTxt+="[*]"+txt+"\r";
}
}
AddTxt+="[/list]\r\n";
AddText(AddTxt);
}
}
function underline() {
if (document.selection && document.selection.type == "Text") {
var range = document.selection.createRange();
range.text = "[u]" + range.text + "[/u]";
} else {
txt=prompt("请输入要加下划线的文字。",text_input);
if (txt!=null) {
AddTxt="[u]"+txt;
AddText(AddTxt);
AddText("[/u]");
}
}
}
function underline() {
if (document.selection && document.selection.type == "Text") {
var range = document.selection.createRange();
range.text = "[u]" + range.text + "[/u]";
} else {
txt=prompt("请输入要加下划线的文字。",text_input);
if (txt!=null) {
AddTxt="[u]"+txt;
AddText(AddTxt);
AddText("[/u]");
}
}
}
function sub() {
if (document.selection && document.selection.type == "Text") {
var range = document.selection.createRange();
range.text = "[sub]" + range.text + "[/sub]";
} else {
txt=prompt("请输入要加的下标文字。",text_input);
if (txt!=null) {
AddTxt="[sub]"+txt;
AddText(AddTxt);
AddText("[/sub]");
}
}
}
function sup() {
if (document.selection && document.selection.type == "Text") {
var range = document.selection.createRange();
range.text = "[sup]" + range.text + "[/sup]";
} else {
txt=prompt("请输入要加的上标文字。",text_input);
if (txt!=null) {
AddTxt="[sup]"+txt;
AddText(AddTxt);
AddText("[/sup]");
}
}
}
function Cfly() {
if (document.selection && document.selection.type == "Text") {
var range = document.selection.createRange();
range.text = "[fly]" + range.text + "[/fly]";
} else {
txt=prompt("请输入文字",text_input);
if (txt!=null) {
AddTxt="[fly]"+txt;
AddText(AddTxt);
AddText("[/fly]");
}
}
}
function Cmove() {
if (document.selection && document.selection.type == "Text") {
var range = document.selection.createRange();
range.text = "[move]" + range.text + "[/move]";
} else {
txt=prompt("请输入文字",text_input);
if (txt!=null) {
AddTxt="[move]"+txt;
AddText(AddTxt);
AddText("[/move]");
}
}
}
function Cglow() {
txt2=prompt("文字的长度、颜色和边界大小","255,red,2");
if (txt2!=null) {
txt=prompt("请输入文字","文字");
if (txt!=null) {
if (txt2=="") {
AddTxt="[glow]"+txt;
AddText(AddTxt);
AddText("[/glow]");
} else {
AddTxt="[glow="+txt2+"]"+txt;
AddText(AddTxt);
AddText("[/glow]");
}
}
}
}
function Cshadow() {
txt2=prompt("文字的长度、颜色和边界大小","255,red,1");
if (txt2!=null) {
txt=prompt("请输入文字","文字");
if (txt!=null) {
if (txt2=="") {
AddTxt="[shadow]"+txt;
AddText(AddTxt);
AddText("[/shadow]");
} else {
AddTxt="[shadow="+txt2+"]"+txt;
AddText(AddTxt);
AddText("[/shadow]");
}
}
}
}
function move() {
txt=prompt("要产生移动效果的文字","文字");
if (txt!=null) {
AddTxt="[move]"+txt;
AddText(AddTxt);
AddTxt="[/move]";
AddText(AddTxt);
}
}
function blogquote(objID,strAuthor,strTime){
document.myform.content.value += "[quote][b]最初由 [color=blue]"+strAuthor+"[/color] 发表于 "+strTime+":[/b]\n"+document.getElementById(objID).innerText+"[/quote]";
setfocus();
}
function setfocus() {
document.myform.content.focus();
}
function ShowMagicFrame()
{
var obj=document.getElementById("magicFrame");
var buttonElement = document.getElementById("magicImage");
if (obj.style.visibility=="hidden")
{
obj.style.top = (getOffsetTop(buttonElement) + buttonElement.offsetHeight - 5)+"px";
obj.style.left = (getOffsetLeft(buttonElement) - 410 + 5)+"px";
obj.style.visibility="visible";
}else {
obj.style.visibility="hidden";
}
}
function getOffsetTop(elm) {
var mOffsetTop = elm.offsetTop;
var mOffsetParent = elm.offsetParent;
while(mOffsetParent){
mOffsetTop += mOffsetParent.offsetTop;
mOffsetParent = mOffsetParent.offsetParent;
}
return mOffsetTop;
}
//Colour pallete left offset
function getOffsetLeft(elm) {
var mOffsetLeft = elm.offsetLeft;
var mOffsetParent = elm.offsetParent;
while(mOffsetParent) {
mOffsetLeft += mOffsetParent.offsetLeft;
mOffsetParent = mOffsetParent.offsetParent;
}
return mOffsetLeft;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -