?? ubb.js
字號:
var ubb_w=400;
var ubb_h=300;
var ubb_name="OSPod.Forum UBB ";
var ubb_content = document.getElementById("post_content");
function ubb_init(control){
ubb_content = control;
}
//Save text
function storeCaret (textEl){
if(textEl.createTextRange)
textEl.caretPos = document.selection.createRange().duplicate();
}
function ubb_inserticon(em) {
ubb_content.value += em;
}
function ubb_setfocus() {
ubb_content.focus();
}
function getSelection(txtarea) {
var retValue = "";
if (txtarea.createTextRange && txtarea.caretPos) {
if(txtarea.caretPos.text.length > 0) {
retValue = txtarea.caretPos.text;
}
} else if (document.getElementById) {
var selLength = txtarea.textLength;
var selStart = txtarea.selectionStart;
var selEnd = txtarea.selectionEnd;
if (selEnd==1 || selEnd==2) selEnd = selLength;
var s2 = (txtarea.value).substring(selStart, selEnd)
if (s2.length > 0) {
retValue = s2;
}
}
return retValue;
}
//增加
function addST(start, end) {
var selection = getSelection(ubb_content);
var inserttext = "";
if (selection.length > 0) {
inserttext = start + selection + end;
insertString(inserttext);
}
}
// *******************************************************
function insertString(thetext) {
if (ubb_content.createTextRange && ubb_content.caretPos) {
var caretPos = ubb_content.caretPos;
var newText = thetext;
if (caretPos.text.charAt(caretPos.text.length - 1) == ' ') newText = newText + ' ';
if (caretPos.text.charAt(0) == ' ') newText = ' ' + newText;
caretPos.text = newText;
} else if (document.getElementById) {
var selLength = ubb_content.textLength;
var selStart = ubb_content.selectionStart;
var selEnd = ubb_content.selectionEnd;
if (selEnd==1 || selEnd==2) selEnd = selLength;
var s1 = (ubb_content.value).substring(0, selStart);
var s2 = (ubb_content.value).substring(selStart, selEnd)
var s3 = (ubb_content.value).substring(selEnd, selLength);
var newText = thetext;
if (s2.charAt(s2.length - 1) == ' ') newText = newText + ' ';
if (s2.charAt(0) == ' ') newText = ' ' + newText;
ubb_content.value = s1 + thetext + s3;
} else {
ubb_content.value += thetext;
}
// ubb_setfocus();
}
// *******************************************************
function ubb_bold(){
addST("[b]","[/b]");
}
function ubb_italicize(){
addST("[i]","[/i]");
}
function ubb_underline(){
addST("[u]","[/u]");
}
function ubb_left() {
addST("[align=left]","[/align]");
}
function ubb_center() {
addST("[align=center]","[/align]");
}
function ubb_right() {
addST("[align=right]","[/align]");
}
function ubb_size(size){
if (size && size != "") {
addST("[size=" + size + "]","[/size]");
}
}
function ubb_font(font){
if (font && font != "") {
addST("[face=" + font + "]","[/face]");
}
}
function ubb_color(color) {
if (color && color != "") {
addST("[color=" + color + "]","[/color]");
}
}
function ubb_code(){
var selection = getSelection(ubb_content);
var inserttext = "";
if (selection.length > 0) {
txt=prompt(ubb_name+"輸入代碼的類型:\n支持java,xml,c#,css,c,delphi,js,php,python,ruby,sql,vb","");
if (txt ==null || Trim(txt) == ""){
addST("[code]","[/code]");
} else {
addST("[code="+Trim(txt)+"]","[/code]");
}
}
}
function ubb_rcode(){
var selection = getSelection(ubb_content);
var inserttext = "";
if (selection.length > 0) {
addST("[rcode]","[/rcode]");
}
}
function ubb_table(){
var trtxt = prompt(ubb_name+"輸入行數","1");
if(trtxt > 99 || trtxt < 0){
alert("請輸入1-99之間的整數");
return;
}
var tbtxt = prompt(ubb_name+"輸入列數","1");
if(tbtxt > 99 || trtxt < 0){
alert("請輸入1-99之間的整數");
return;
}
if(trtxt ==null || Trim(trtxt)==""){
trtxt=1;
}
if(tbtxt ==null || Trim(tbtxt)==""){
tbtxt=1;
}
var selection = getSelection(ubb_content);
inserttext = "[table]";
for(var i=0;i<trtxt;i++){
inserttext +="[tr]";
for(var j=0;j<tbtxt;j++){
inserttext +="[td][/td]";
}
inserttext +="[/tr]";
}
inserttext += "[/table]";
insertString(inserttext);
}
function ubb_quote(){
addST("[quote]","[/quote]");
}
function ubb_email() {
txt2=prompt(ubb_name+"連接 名稱","");
if (txt2!=null) {
txt=prompt(ubb_name+"連接 Email地址","");
if (txt!=null) {
if (txt2 == "") txt2 = txt;
ubb_AddText("[email="+txt+"]"+txt2 + "[/email]");
}
}
}
function ubb_link(){
txt2=prompt(ubb_name+"連接 名稱","");
if (txt2!=null) {
txt=prompt(ubb_name+"連接 URL地址","http://");
if (txt!=null) {
if (txt2 == "") txt2 = txt;
ubb_AddText("[url='"+txt+"']"+txt2 + "[/url]");
}
}
}
function ubb_AddText(NewCode){
if(document.all)
ubb_insertAtCaret(ubb_content, NewCode);
else
ubb_content.value += NewCode;
ubb_setfocus();
}
function ubb_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 ubb_image(){
txt=prompt(ubb_name+"圖片 URL地址","http://");
if(txt!=null){
ubb_AddText("\r[img]"+txt + "[/img]");
}
}
function ubb_flash(){
stxt=prompt(ubb_name+"Flash 寬度 高度",ubb_w+","+ubb_h);
if (stxt!=null) {
txt=prompt(ubb_name+"Flash URL地址","http://");
if(txt!=null) {
ubb_AddText("\r[flash=" + stxt + "]" + txt + "[/flash]");
}
}
}
function ubb_list(){
var selection = getSelection(ubb_content);
if (selection.length > 0) {
selection = ubb_relaceLi(selection);
selection = "[ul][li]" + selection + "[/li][/ul]";
insertString(selection);
}
}
function ubb_relaceLi(txt){
txt = txt.replace(/\r\n|\n/ig,"[/li][li]");
return txt;
}
function ubb_listnamber(){
var selection = getSelection(ubb_content);
if (selection.length > 0) {
selection = ubb_relaceLi(selection);
selection = "[ol][li]" + selection + "[/li][/ol]";
insertString(selection);
}
}
function ubb_hr(){
ubb_AddText("[hr]");
}
function ubb_strikethrough(){
addST("[s]","[/s]");
}
function ubb_sub(){
addST("[sub]","[/sub]");
}
function ubb_sup(){
addST("[sup]","[/sup]");
}
function ubb_fly(){
addST("[fly]","[/fly]");
}
function ubb_move(){
addST("[move=left]","[/move]");
}
function ubb_glow(){
stxt=prompt(ubb_name+"發光字長度,顏色,邊界大小","255,red,2");
if (stxt != null) {
addST("[glow="+stxt+"]","[/glow]");
}
}
function ubb_tag(){
addST("[tag]","[/tag]");
}
function ubb_free(){
addST("[free]","[/free]");
}
function ubb_hidden(){
var selection = getSelection(ubb_content);
if (selection.length > 0) {
addST("[hidden]","[/hidden]");
} else {
ubb_content.value = "[hidden]"+ ubb_content.value+"[/hidden]";
}
}
function ubb_money(){
stxt=prompt(ubb_name+"請輸入財富限制數量","10");
if (stxt){
var selection = getSelection(ubb_content);
if (selection.length > 0) {
addST("[money="+stxt+"]","[/money]");
} else {
ubb_content.value = "[money="+stxt+"]"+ ubb_content.value+"[/money]";
}
}
}
function ubb_score(){
stxt=prompt(ubb_name+"請輸入積分限制數量","10");
if (stxt){
var selection = getSelection(ubb_content);
if (selection.length > 0) {
addST("[score="+stxt+"]","[/score]");
} else {
ubb_content.value = "[score="+stxt+"]"+ ubb_content.value+"[/score]";
}
}
}
function ubb_level(){
stxt=prompt(ubb_name+"請輸入積分限制數量","1");
if (stxt){
var selection = getSelection(ubb_content);
if (selection.length > 0) {
addST("[level="+stxt+"]","[/level]");
} else {
ubb_content.value = "[level="+stxt+"]"+ ubb_content.value+"[/level]";
}
}
}
function ubb_shadow(){
stxt=prompt(ubb_name+"陰影字長度,顏色,邊界大小","255,blue,1");
if (stxt != null) {
addST("[shadow="+stxt+"]","[/shadow]");
}
}
function ubb_rm(){
stxt=prompt(ubb_name+"Realplay文件 寬度,高度",ubb_w+","+ubb_h);
if (stxt!=null) {
txt=prompt(ubb_name+"Realplay文件 URL地址","http://");
if(txt!=null) ubb_AddText("\r[rm="+stxt+"]"+txt + "[/rm]");
}
}
function ubb_mp(){
stxt=prompt(ubb_name+"Windows Media Player文件 寬度,高度",ubb_w+","+ubb_h);
if (stxt!=null) {
txt=prompt(ubb_name+"Windows Media Player文件 URL地址","http://");
if(txt!=null) ubb_AddText("\r[mp="+stxt+"]"+txt + "[/mp]");
}
}
function ubb_dir(){
stxt=prompt(ubb_name+"Shockwave格式文件 寬度,高度",ubb_w+","+ubb_h);
if (stxt!=null) {
txt=prompt(ubb_name+"shockwave格式文件 URL地址","http://");
if(txt!=null) ubb_AddText("\r[dir="+stxt+"]"+txt + "[/dir]");
}
}
function ubb_qt(){
stxt=prompt(ubb_name+"Quick Time格式文件 寬度,高度",ubb_w+","+ubb_h);
if (stxt!=null) {
txt=prompt(ubb_name+"Quick Time格式文件 URL地址","http://");
if(txt!=null) ubb_AddText("\r[qt="+stxt+"]"+txt + "[/qt]");
}
}
function ubb_copy() {
if (document.all){
ubb_setfocus();
document.execCommand("copy");
} else {
var rng = document.body.createTextRange();
rng.moveToElementText(ubb_content);
rng.scrollIntoView();
rng.select();
rng.execCommand("Copy");
rng.collapse(false);
}
/*
var rng = ubb_content.createTextRange();
// var rng = document.body.createTextRange();
// rng.moveToElementText(getSelection(ubb_content));
//rng.scrollIntoView();
//rng.select();
rng.execCommand("Copy");
//rng.collapse(false);
*/
}
function ubb_paste() {
ubb_setfocus();
if (document.all){
document.execCommand("paste");
}
/*
var rng = document.body.createTextRange();
rng.moveToElementText(ubb_content);
rng.scrollIntoView();
rng.select();
rng.execCommand("paste");
rng.collapse(false);
*/
}
function ubb_cut() {
ubb_setfocus();
if (document.all){
document.execCommand("cut");
}
}
function ubb_undo() {
ubb_setfocus();
if (document.all){
document.execCommand("undo");
}
}
function ubb_redo() {
ubb_setfocus();
if (document.all){
document.execCommand("redo");
}
}
//UBB運行代碼
function runCode(objDiv) {
var obj = getUBBRcode(objDiv);
if(obj){
//var obj = objDiv.childNodes(2);
var winname = window.open('', "_blank", '');
winname.document.open('text/html', 'replace');
winname.opener = null // 防止代碼對父頁面修改
winname.document.write(obj.value);
winname.document.close();
}
}
function getUBBRcode(objDiv){
try{
for(var i=0;i<objDiv.childNodes.length;i++ ){
if(objDiv.childNodes(i).name == "ubb_rcode"){
return objDiv.childNodes(i);
}
}
} catch(e){
}
return null;
}
function saveCode(objDiv) {
var obj = getUBBRcode(objDiv);
if(obj){
var winname = window.open('', '_blank', 'top=10000');
winname.document.open('text/html', 'replace');
winname.document.write(obj.value);
winname.document.execCommand('saveas','','code.htm');
winname.close();
}
}
function copyCode(objDiv) {
var obj = getUBBRcode(objDiv);
if(obj){
var rng = document.body.createTextRange();
rng.moveToElementText(obj);
rng.scrollIntoView();
rng.select();
rng.execCommand("Copy");
rng.collapse(false);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -