ubbcode.js
Upload User: jhtang88
Upload Date: 2014-01-27
Package Size: 28528k
Code Size: 18k
Category:

Jsp/Servlet

Development Platform:

Java

  1. var Quote = 0;
  2. var Bold  = 0;
  3. var Italic = 0;
  4. var Underline = 0;
  5. var Code = 0;
  6. var Center = 0;
  7. var Strike = 0;
  8. var Sound = 0;
  9. var Swf = 0;
  10. var Ra = 0;
  11. var Rm = 0;
  12. var Marquee = 0;
  13. var Fly = 0;
  14. var fanzi=0;
  15. var text_enter_url      = "请输入连接网址";
  16. var text_enter_txt      = "请输入连接说明";
  17. var text_enter_image    = "请输入图片网址";
  18. var text_enter_sound    = "请输入声音文件网址";
  19. var text_enter_swf      = "请输入FLASH动画网址";
  20. var text_enter_ra      = "请输入Real音乐网址";
  21. var text_enter_rm      = "请输入Real影片网址";
  22. var text_enter_wmv      = "请输入Media影片网址";
  23. var text_enter_wma      = "请输入Media音乐网址";
  24. var text_enter_mov      = "请输入QuickTime音乐网址";
  25. var text_enter_sw      = "请输入shockwave音乐网址";
  26. var text_enter_email    = "请输入邮件网址";
  27. var error_no_url        = "您必须输入网址";
  28. var error_no_txt        = "您必须连接说明";
  29. var error_no_title      = "您必须输入首页标题";
  30. var error_no_email      = "您必须输入邮件网址";
  31. var error_no_gset       = "必须正确按照各式输入!";
  32. var error_no_gtxt       = "必须输入文字!";
  33. var text_enter_guang1   = "文字的长度、颜色和边界大小";
  34. var text_enter_guang2   = "要产生效果的文字!";
  35. var text_enter_points   = "请输入数值,如:1000 (即限制经验在1000点以下的用户不能浏览该内容!)";
  36. var error_no_points     = "您必须输入数值,如:1000";
  37. var text_enter_money    = "请输入数值,如:1000 (即限制金钱在1000点以下的用户不能浏览该内容!)";
  38. var error_no_moeny      = "您必须输入数值,如:1000";
  39. var text_enter_power    = "请输入数值,如:1000 (即限制威望在1000点以下的用户不能浏览该内容!)";
  40. var error_no_power      = "您必须输入数值,如:1000";
  41. var text_enter_post     = "请输入数值,如:1000 (即限制发表文章在1000点以下的用户不能浏览该内容!)";
  42. var error_no_post       = "您必须输入数值,如:1000";
  43. var text_enter_usercp   = "请输入数值,如:1000 (即限制魅力值在1000点以下的用户不能浏览该内容!)";
  44. var error_no_usercp     = "您必须输入数值,如:1000";
  45. var text_t  = "文字";
  46. var wait_send = "帖子正在发出,请耐心等待!";
  47. var text_code = " 代码";
  48. var text_flash_info = "FlashnFlash 动画.n用法: [flash=宽度, 高度]Flash 文件的地址[/flash]";
  49. var text_flash_size = "flash宽度,高度"
  50. var text_flash_url  = "Flash 文件的地址";
  51. var text_rm_info  = "realplayn播放realplay文件.n用法: [rm=宽度, 高度]文件地址[/rm]";
  52. var text_movie_size  = "视频的宽度,高度";
  53. var text_url  = "视频文件的地址";
  54. var text_input  = "请输入";
  55. var text_media_info  = "Media Playern播放Media Player文件.n用法: [mp=宽度, 高度]文件地址[/mp]";
  56. var text_media_size  = "视频的宽度,高度";
  57. var text_quicktime_info = "QuickTimen播放QuickTime文件.n用法: [qt=宽度, 高度]文件地址[/qt]";
  58. var text_shockwave_info = "Shockwaven插入Shockwave文件.n用法: [dir=宽度, 高度]文件地址[/dir]";
  59. function commentWrite(NewCode) {
  60. document.frmAnnounce.Content.value+=NewCode;
  61. document.frmAnnounce.Content.focus();
  62. return;
  63. }
  64. function storeCaret(text) { 
  65. if (text.createTextRange) {
  66. text.caretPos = document.selection.createRange().duplicate();
  67. }
  68.     if(event.ctrlKey && window.event.keyCode==13){i++;if (i>1) {alert(wait_send);return false;}this.document.form.submit();}
  69. }
  70. function AddText(text) {
  71. if (document.frmAnnounce.Content.createTextRange && document.frmAnnounce.Content.caretPos) {      
  72. var caretPos = document.frmAnnounce.Content.caretPos;      
  73. caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
  74. text + ' ' : text;
  75. }
  76. else document.frmAnnounce.Content.value += text;
  77. document.frmAnnounce.Content.focus(caretPos);
  78. }
  79. function inputs(str)
  80. {
  81. AddText(str);
  82. }
  83. function Curl() {
  84. var FoundErrors = '';
  85. var enterURL   = prompt(text_enter_url, "http://");
  86. var enterTxT   = prompt(text_enter_txt, enterURL);
  87. if (!enterURL)    {
  88. FoundErrors += "n" + error_no_url;
  89. }
  90. if (!enterTxT)    {
  91. FoundErrors += "n" + error_no_txt;
  92. }
  93. if (FoundErrors)  {
  94. alert(FoundErrors);
  95. return;
  96. }
  97. var temp = enterURL;
  98. var regwhich = new RegExp("http","i")
  99. enterURL = temp.replace(regwhich,"hhttttpp")//防止在fchar.ubb中被重复替换地址
  100. var ToAdd = "[URL="+enterURL+"]"+enterTxT+"[/URL]";
  101. document.frmAnnounce.Content.value+=ToAdd;
  102. document.frmAnnounce.Content.focus();
  103. }
  104. function Cimage() {
  105. var FoundErrors = '';
  106. var enterURL   = prompt(text_enter_image, "http://");
  107. if (!enterURL) {
  108. FoundErrors += "n" + error_no_url;
  109. }
  110. if (FoundErrors) {
  111. alert(FoundErrors);
  112. return;
  113. }
  114. var temp = enterURL;
  115. var regwhich = new RegExp("http","i")
  116. enterURL = temp.replace(regwhich,"hhttttpp")//防止在fchar.ubb中被重复替换地址
  117. var ToAdd = "[img]"+enterURL+"[/img]";
  118. document.frmAnnounce.Content.value+=ToAdd;
  119. document.frmAnnounce.Content.focus();
  120. }
  121. function Cemail() {
  122. var emailAddress = prompt(text_enter_email,"");
  123. if (!emailAddress) { alert(error_no_email); return; }
  124. var ToAdd = "[EMAIL]"+emailAddress+"[/EMAIL]";
  125. commentWrite(ToAdd);
  126. }
  127. function Ccode() {
  128. if (Code == 0) {
  129. ToAdd = "[CODE]";
  130. document.form.code.value = text_code;
  131. Code = 1;
  132. } else {
  133. ToAdd = "[/CODE]";
  134. document.form.code.value = text_code;
  135. Code = 0;
  136. }
  137. commentWrite(ToAdd);
  138. }
  139. function Cquote() {
  140. fontbegin="[QUOTE]";
  141. fontend="[/QUOTE]";
  142. fontchuli();
  143. }
  144. function Cbold() {
  145. fontbegin="[B]";
  146. fontend="[/B]";
  147. fontchuli();
  148. }
  149. function Citalic() {
  150. fontbegin="[I]";
  151. fontend="[/I]";
  152. fontchuli();
  153. }
  154. function Cunder() {
  155. fontbegin="[U]";
  156. fontend="[/U]";
  157. fontchuli();
  158. }
  159. function Ccenter() {
  160. fontbegin="[center]";
  161. fontend="[/center]";
  162. fontchuli();
  163. }
  164. function Cstrike() {
  165. fontbegin="[strike]";
  166. fontend="[/strike]";
  167. fontchuli();
  168. }
  169. function money() {
  170. var FoundErrors = '';
  171. var entermoney  =prompt(text_enter_money,"1000");
  172. if (!entermoney) {
  173. FoundErrors += "n" + error_no_money;
  174. }
  175. if (FoundErrors) {
  176. alert(FoundErrors);
  177. return;
  178. }
  179. var ToAdd = "[Money="+entermoney+"][/Money]";
  180. document.frmAnnounce.Content.value+=ToAdd;
  181. document.frmAnnounce.Content.focus();
  182. }
  183. function usercp() {
  184. var FoundErrors = '';
  185. var enterusercp  =prompt(text_enter_usercp,"1000");
  186. if (!enterusercp) {
  187. FoundErrors += "n" + error_no_usercp;
  188. }
  189. if (FoundErrors) {
  190. alert(FoundErrors);
  191. return;
  192. }
  193. var ToAdd = "[UserCP="+enterusercp+"][/UserCP]";
  194. document.frmAnnounce.Content.value+=ToAdd;
  195. document.frmAnnounce.Content.focus();
  196. }
  197. function power() {
  198. var FoundErrors = '';
  199. var enterpower  =prompt(text_enter_power,"1000");
  200. if (!enterpower) {
  201. FoundErrors += "n" + error_no_power;
  202. }
  203. if (FoundErrors) {
  204. alert(FoundErrors);
  205. return;
  206. }
  207. var ToAdd = "[Power="+enterpower+"][/Power]";
  208. document.frmAnnounce.Content.value+=ToAdd;
  209. document.frmAnnounce.Content.focus();
  210. }
  211. function article() {
  212. var FoundErrors = '';
  213. var enterpost  =prompt(text_enter_post,"1000");
  214. if (!enterpost) {
  215. FoundErrors += "n" + error_no_post;
  216. }
  217. if (FoundErrors) {
  218. alert(FoundErrors);
  219. return;
  220. }
  221. var ToAdd = "[Post="+enterpost+"][/Post]";
  222. document.frmAnnounce.Content.value+=ToAdd;
  223. document.frmAnnounce.Content.focus();
  224. }
  225. function replyview() {
  226. var ToAdd = "[replyview][/replyview]";
  227. document.frmAnnounce.Content.value+=ToAdd;
  228. document.frmAnnounce.Content.focus();
  229. }
  230. function Csound() {
  231. var FoundErrors = '';
  232. var enterURL   = prompt(text_enter_sound, "http://");
  233. if (!enterURL) {
  234. FoundErrors += "n" + error_no_url;
  235. }
  236. if (FoundErrors) {
  237. alert(FoundErrors);
  238. return;
  239. }
  240. var ToAdd = "[SOUND]"+enterURL+"[/SOUND]";
  241. document.frmAnnounce.Content.value+=ToAdd;
  242. document.frmAnnounce.Content.focus();
  243. }
  244. helpstat = false;
  245. stprompt = true;
  246. basic = false;
  247. function thelp(swtch){
  248. if (swtch == 1){
  249. basic = false;
  250. stprompt = false;
  251. helpstat = true;
  252. } else if (swtch == 0) {
  253. helpstat = false;
  254. stprompt = false;
  255. basic = true;
  256. } else if (swtch == 2) {
  257. helpstat = false;
  258. basic = false;
  259. stprompt = true;
  260. }
  261. }
  262. function Cswf() {
  263.   if (helpstat){
  264. alert(text_flash_info);
  265. } else if (basic) {
  266. AddTxt="[flash=500,350][/flash]";
  267. AddText(AddTxt);
  268. } else {                  
  269. txt2=prompt(text_flash_size,"500,350"); 
  270. if (txt2!=null) {
  271.                 txt=prompt(text_flash_url, "http://");
  272. if (txt!=null) {
  273. var temp = txt;
  274. var regwhich = new RegExp("http","i")
  275. txt = temp.replace(regwhich,"hhttttpp")//防止在fchar.ubb中被重复替换地址
  276.          if (txt2=="") {             
  277. AddTxt="[flash=500,350]"+txt;
  278. AddText(AddTxt);
  279. AddTxt="[/flash]";
  280. AddText(AddTxt);
  281.             }else{
  282. AddTxt="[flash="+txt2+"]"+txt;
  283. AddText(AddTxt);
  284. AddTxt="[/flash]";
  285. AddText(AddTxt);
  286.  }        
  287.     }  
  288.        }
  289.     }
  290. }
  291. function Crm() {
  292. if (helpstat) {
  293.         alert(text_rm_info);
  294. } else if (basic) {
  295. AddTxt="[rm=500,350][/rm]";
  296. AddText(AddTxt);
  297. } else { 
  298. txt2=prompt(text_rm_size,"500,350"); 
  299. if (txt2!=null) {
  300. txt=prompt(text_movie_size, text_rm_input);
  301. if (txt!=null) {
  302. var temp = txt;
  303. var regwhich = new RegExp("http","i")
  304. txt = temp.replace(regwhich,"hhttttpp")//防止在fchar.ubb中被重复替换地址
  305. regwhich = new RegExp("ftp","i")
  306. txt = txt.replace(regwhich,"ffttpp")//防止在fchar.ubb中被重复替换地址
  307. if (txt2=="") {
  308. AddTxt="[rm=500,350]"+txt;
  309. AddText(AddTxt);
  310. AddTxt="[/rm]";
  311. AddText(AddTxt);
  312. } else {
  313. AddTxt="[rm="+txt2+"]"+txt;
  314. AddText(AddTxt);
  315. AddTxt="[/rm]";
  316. AddText(AddTxt);
  317. }         
  318. }
  319. }
  320. }
  321. function Cwmv() {
  322. if (helpstat) {
  323.         alert(text_media_info);
  324. } else if (basic) {
  325. AddTxt="[mp=500,350][/mp]";
  326. AddText(AddTxt);
  327. } else { 
  328. txt2=prompt(text_movie_size,"500,350"); 
  329. if (txt2!=null) {
  330. txt=prompt(text_url, text_input);
  331. if (txt!=null) {
  332. var temp = txt;
  333. var regwhich = new RegExp("http","i")
  334. txt = temp.replace(regwhich,"hhttttpp")//防止在fchar.ubb中被重复替换地址
  335. regwhich = new RegExp("ftp","i")
  336. txt = txt.replace(regwhich,"ffttpp")//防止在fchar.ubb中被重复替换地址
  337. if (txt2=="") {
  338. AddTxt="[mp=500,350]"+txt;
  339. AddText(AddTxt);
  340. AddTxt="[/mp]";
  341. AddText(AddTxt);
  342. } else {
  343. AddTxt="[mp="+txt2+"]"+txt;
  344. AddText(AddTxt);
  345. AddTxt="[/mp]";
  346. AddText(AddTxt);
  347. }         
  348. }
  349. }
  350. }
  351. function Cmov() {
  352. if (helpstat) {
  353.         alert(text_quicktime_info);
  354. } else if (basic) {
  355. AddTxt="[qt=500,350][/qt]";
  356. AddText(AddTxt);
  357. } else { 
  358. txt2=prompt(text_movie_size, "500,350"); 
  359. if (txt2!=null) {
  360. txt=prompt(text_url, text_input);
  361. if (txt!=null) {
  362. var temp = txt;
  363. var regwhich = new RegExp("http","i")
  364. txt = temp.replace(regwhich,"hhttttpp")//防止在fchar.ubb中被重复替换地址
  365. regwhich = new RegExp("ftp","i")
  366. txt = txt.replace(regwhich,"ffttpp")//防止在fchar.ubb中被重复替换地址
  367. if (txt2=="") {
  368. AddTxt="[qt=500,350]"+txt;
  369. AddText(AddTxt);
  370. AddTxt="[/qt]";
  371. AddText(AddTxt);
  372. } else {
  373. AddTxt="[qt="+txt2+"]"+txt;
  374. AddText(AddTxt);
  375. AddTxt="[/qt]";
  376. AddText(AddTxt);
  377. }         
  378. }
  379. }
  380. }
  381. function Cdir() {
  382. if (helpstat) {
  383.         alert(text_shockwave_info);
  384. } else if (basic) {
  385. AddTxt="[dir=500,350][/dir]";
  386. AddText(AddTxt);
  387. } else { 
  388. txt2=prompt(text_movie_size,"500,350"); 
  389. if (txt2!=null) {
  390. txt=prompt(text_url, text_input);
  391. if (txt!=null) {
  392. if (txt2=="") {
  393. AddTxt="[dir=500,350]"+txt;
  394. AddText(AddTxt);
  395. AddTxt="[/dir]";
  396. AddText(AddTxt);
  397. } else {
  398. AddTxt="[dir="+txt2+"]"+txt;
  399. AddText(AddTxt);
  400. AddTxt="[/dir]";
  401. AddText(AddTxt);
  402. }         
  403. }
  404. }
  405. }
  406. function Cra() {
  407. var FoundErrors = '';
  408. var enterURL   = prompt(text_enter_ra, "http://");
  409. if (!enterURL) {
  410. FoundErrors += "n" + error_no_url;
  411. }
  412. if (FoundErrors) {
  413. alert(FoundErrors);
  414. return;
  415. }
  416. var ToAdd = "[RA]"+enterURL+"[/RA]";
  417. document.frmAnnounce.Content.value+=ToAdd;
  418. document.frmAnnounce.Content.focus();
  419. }
  420. function Cfanzi() {
  421. fontbegin="[xray]";
  422. fontend="[/xray]";
  423. fontchuli();
  424. }
  425. function Cwma() {
  426. var FoundErrors = '';
  427. var enterURL   = prompt(text_enter_wma, "http://");
  428. if (!enterURL) {
  429. FoundErrors += "n" + error_no_url;
  430. }
  431. if (FoundErrors) {
  432. alert(FoundErrors);
  433. return;
  434. }
  435. var ToAdd = "[wma]"+enterURL+"[/wma]";
  436. document.frmAnnounce.Content.value+=ToAdd;
  437. document.frmAnnounce.Content.focus();
  438. }
  439. function Cmarquee() {
  440. fontbegin="[move]";
  441. fontend="[/move]";
  442. fontchuli();
  443. }
  444. function Cfly() {
  445. fontbegin="[fly]";
  446. fontend="[/fly]";
  447. fontchuli();
  448. }
  449. function paste(text) {
  450. if (opener.document.frmAnnounce.Content.createTextRange && opener.document.frmAnnounce.Content.caretPos) {      
  451. var caretPos = opener.document.frmAnnounce.Content.caretPos;      
  452. caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
  453. text + ' ' : text;
  454. }
  455. else opener.document.frmAnnounce.Content.value += text;
  456. opener.document.frmAnnounce.Content.focus(caretPos);
  457. }
  458. function showsize(size){
  459. fontbegin="[size="+size+"]";
  460. fontend="[/size]";
  461. fontchuli();
  462. }
  463. function showfont(font){
  464. fontbegin="[face="+font+"]";
  465. fontend="[/face]";
  466. fontchuli();
  467. }
  468. function showcolor(color){
  469. fontbegin="[color="+color+"]";
  470. fontend="[/color]";
  471. fontchuli();
  472. }
  473. function fontchuli(){
  474. if ((document.selection)&&(document.selection.type == "Text")) {
  475. var range = document.selection.createRange();
  476. var ch_text=range.text;
  477. range.text = fontbegin + ch_text + fontend;
  478. else {
  479. document.frmAnnounce.Content.value=fontbegin+document.frmAnnounce.Content.value+fontend;
  480. document.frmAnnounce.Content.focus();
  481. }
  482. }
  483. function Cguang() {
  484. var FoundErrors = '';
  485. var enterSET   = prompt(text_enter_guang1, "255,red,2");
  486. var enterTxT   = prompt(text_enter_guang2, text_t);
  487. if (!enterSET)    {
  488. FoundErrors += "n" + error_no_gset;
  489. }
  490. if (!enterTxT)    {
  491. FoundErrors += "n" + error_no_gtxt;
  492. }
  493. if (FoundErrors)  {
  494. alert(FoundErrors);
  495. return;
  496. }
  497. var ToAdd = "[glow="+enterSET+"]"+enterTxT+"[/glow]";
  498. document.frmAnnounce.Content.value+=ToAdd;
  499. document.frmAnnounce.Content.focus();
  500. }
  501. function Cying() {
  502. var FoundErrors = '';
  503. var enterSET   = prompt(text_enter_guang1, "255,blue,1");
  504. var enterTxT   = prompt(text_enter_guang2, text_t);
  505. if (!enterSET)    {
  506. FoundErrors += "n" + error_no_gset;
  507. }
  508. if (!enterTxT)    {
  509. FoundErrors += "n" + error_no_gtxt;
  510. }
  511. if (FoundErrors)  {
  512. alert(FoundErrors);
  513. return;
  514. }
  515. var ToAdd = "[SHADOW="+enterSET+"]"+enterTxT+"[/SHADOW]";
  516. document.frmAnnounce.Content.value+=ToAdd;
  517. document.frmAnnounce.Content.focus();
  518. }
  519. ie = (document.all)? true:false
  520. if (ie){
  521. function ctlent(eventobject){if(event.ctrlKey && window.event.keyCode==13){this.document.frmAnnounce.submit();}}
  522. }
  523. function DoTitle(addTitle) { 
  524. var revisedTitle; 
  525. var currentTitle = document.frmAnnounce.topic.value; 
  526. revisedTitle = currentTitle+addTitle; 
  527. document.frmAnnounce.topic.value=revisedTitle; 
  528. document.frmAnnounce.topic.focus(); 
  529. return; }
  530. function insertsmilie(smilieface){
  531. document.frmAnnounce.Content.value+=smilieface;
  532. }
  533. function gopreview()
  534. {
  535. document.forms[1].title.value=document.forms[0].subject.value;
  536. document.forms[1].body.value=document.forms[0].Content.value;
  537. var popupWin = window.open('preview.asp', 'preview_page', 'scrollbars=yes,width=750,height=450');
  538. document.forms[1].submit()
  539. }
  540. // 回复可见
  541. function replyCanSee(){
  542. fontbegin = "[REPLY]";
  543. fontend = "[/REPLY]";
  544. if ((document.selection)&&(document.selection.type == "Text")) {
  545. var range = document.selection.createRange();
  546. var ch_text=range.text;
  547. range.text = fontbegin + ch_text + fontend;
  548. }
  549. else {
  550. document.frmAnnounce.Content.value=fontbegin+document.frmAnnounce.Content.value+fontend;
  551. document.frmAnnounce.Content.focus();
  552. }
  553. }
  554. function canSee(moneyCode) {
  555. var FoundErrors = '';
  556. var enterpoints = prompt(text_enter_points, "1000");
  557. if (!enterpoints) {
  558. FoundErrors += "n" + error_no_points;
  559. }
  560. if (FoundErrors) {
  561. alert("错误!"+FoundErrors);
  562. return;
  563. }
  564. fontbegin = "[HIDE=" + moneyCode + ","+enterpoints+"]";
  565. fontend = "[/HIDE]";
  566. if ((document.selection)&&(document.selection.type == "Text")) {
  567. var range = document.selection.createRange();
  568. var ch_text=range.text;
  569. range.text = fontbegin + ch_text + fontend;
  570. }
  571. else {
  572. document.frmAnnounce.Content.value=fontbegin+document.frmAnnounce.Content.value+fontend;
  573. document.frmAnnounce.Content.focus();
  574. }
  575. }
  576. function usePoint() {
  577. var ary = showModalDialog('point_sel.jsp',window.self,'dialogWidth:526px;dialogHeight:435px;status:no;help:no;');
  578. if (ary==null)
  579. return;
  580. var fontbegin = "[point=" + ary[0] + "," + ary[1] + "]";
  581. var fontend = "[/point]";
  582. if ((document.selection)&&(document.selection.type == "Text")) {
  583. var range = document.selection.createRange();
  584. var ch_text=range.text;
  585. range.text = fontbegin + ch_text + fontend;
  586. }
  587. else {
  588. document.frmAnnounce.Content.value=fontbegin+document.frmAnnounce.Content.value+fontend;
  589. document.frmAnnounce.Content.focus();
  590. }
  591. }
  592. function payme() {
  593. var ary = showModalDialog('point_sel.jsp',window.self,'dialogWidth:526px;dialogHeight:435px;status:no;help:no;');
  594. if (ary==null)
  595. return;
  596. var fontbegin = "[payme=" + ary[0] + "," + ary[1] + "]";
  597. var fontend = "[/payme]";
  598. if ((document.selection)&&(document.selection.type == "Text")) {
  599. var range = document.selection.createRange();
  600. var ch_text=range.text;
  601. range.text = fontbegin + ch_text + fontend;
  602. }
  603. else {
  604. document.frmAnnounce.Content.value=fontbegin+document.frmAnnounce.Content.value+fontend;
  605. document.frmAnnounce.Content.focus();
  606. }
  607. }