1 | var bbcode = new Array(); |
---|
2 | var theSelection = false; |
---|
3 | |
---|
4 | function BBCfs(form, field, box) { |
---|
5 | BBCwrite(form, field, "[size="+ box.value +"]", "[/size]", true); |
---|
6 | box.selectedIndex = 2; |
---|
7 | } |
---|
8 | function BBCfc(form, field, box) { |
---|
9 | BBCfont(form, field, "color", box); |
---|
10 | box.selectedIndex = 0; |
---|
11 | } |
---|
12 | |
---|
13 | function BBCfont(form, field, code, box) { |
---|
14 | BBCwrite(form, field, "["+code+"="+box.value+"]", "[/"+code+"]", true); |
---|
15 | } |
---|
16 | |
---|
17 | function BBCwmi(form, field, type) { |
---|
18 | if (type == 'img') { var URL = prompt("Please enter image URL","http://"); } |
---|
19 | else { var URL = prompt("Enter the Email Address",""); } |
---|
20 | if (URL == null) { return; } |
---|
21 | if (!URL) { return alert("Error : You didn't write the Address"); } |
---|
22 | BBCwrite(form, field, '', "["+type+"]"+URL+"[/"+type+"]", true); |
---|
23 | } |
---|
24 | |
---|
25 | function BBCcode(form, field, img) { |
---|
26 | var code = img.name; |
---|
27 | if (BBCwrite(form, field, "["+code+"]", "[/"+code+"]")) { return; } |
---|
28 | if (bbcode[form+field+code] == null) { |
---|
29 | ToAdd = "["+code+"]"; |
---|
30 | re = new RegExp(code+".(\\w+)$"); |
---|
31 | img.src = img.src.replace(re, code+"1.$1"); |
---|
32 | bbcode[form+field+code] = 1; |
---|
33 | } else { |
---|
34 | ToAdd = "[/"+code+"]"; |
---|
35 | re = new RegExp(code+"1.(\\w+)$"); |
---|
36 | img.src = img.src.replace(re, code+".$1"); |
---|
37 | bbcode[form+field+code] = null; |
---|
38 | } |
---|
39 | BBCwrite(form, field, '', ToAdd, true); |
---|
40 | } |
---|
41 | |
---|
42 | function BBClist(form, field, img) { |
---|
43 | var code = img.name; |
---|
44 | if (BBCwrite(form, field, "["+code+"]\n[li]", "\n[/"+code+"]")) { return; } |
---|
45 | if (bbcode[form+field+code] == null) { |
---|
46 | ToAdd = "["+code+"]\n[li]"; |
---|
47 | re = new RegExp(code+".(\\w+)$"); |
---|
48 | img.src = img.src.replace(re, code+"1.$1"); |
---|
49 | bbcode[form+field+code] = 1; |
---|
50 | } else { |
---|
51 | ToAdd = "\n[/"+code+"]\n"; |
---|
52 | re = new RegExp(code+"1.(\\w+)$"); |
---|
53 | img.src = img.src.replace(re, code+".$1"); |
---|
54 | bbcode[form+field+code] = null; |
---|
55 | } |
---|
56 | BBCwrite(form, field, '', ToAdd, true); |
---|
57 | } |
---|
58 | |
---|
59 | function BBCurl(form, field) { |
---|
60 | var URL = prompt("Enter the URL", "http://"); |
---|
61 | if (URL == null) { return; } |
---|
62 | if (!URL) { return alert("Error: You didn't write the URL "); } |
---|
63 | if (BBCwrite(form, field, "[url="+URL+"]", "[/url]")) { return; } |
---|
64 | var TITLE = prompt("Enter the page name", "Web Page Name"); |
---|
65 | if (TITLE == null) { return; } |
---|
66 | var Add = "]"+URL; |
---|
67 | if (TITLE) { Add = "="+URL+"]"+TITLE; } |
---|
68 | BBCwrite(form, field, '', "[url"+Add+"[/url]", true); |
---|
69 | } |
---|
70 | |
---|
71 | function BBCwrite(form, field, start, end, force) { |
---|
72 | var textarea = document.forms[form].elements[field]; |
---|
73 | |
---|
74 | storeCaret(textarea); |
---|
75 | |
---|
76 | if (textarea.caretPos) { |
---|
77 | textarea.focus(); |
---|
78 | // Attempt to create a text range (IE). |
---|
79 | theSelection = document.selection.createRange().text; |
---|
80 | if (force || theSelection != '') { |
---|
81 | document.selection.createRange().text = start + theSelection + end; |
---|
82 | textarea.focus(); |
---|
83 | return true; |
---|
84 | } |
---|
85 | } else if (typeof(textarea.selectionStart) != "undefined") { |
---|
86 | // Mozilla text range replace. |
---|
87 | var text = new Array(); |
---|
88 | text[0] = textarea.value.substr(0, textarea.selectionStart); |
---|
89 | text[1] = textarea.value.substr(textarea.selectionStart, textarea.selectionEnd-textarea.selectionStart); |
---|
90 | text[2] = textarea.value.substr(textarea.selectionEnd); |
---|
91 | caretPos = textarea.selectionEnd+start.length+end.length; |
---|
92 | if (force || text[1] != '') { |
---|
93 | textarea.value = text[0]+start+text[1]+end+text[2]; |
---|
94 | if (textarea.setSelectionRange) { |
---|
95 | textarea.focus(); |
---|
96 | textarea.setSelectionRange(caretPos, caretPos); |
---|
97 | } |
---|
98 | return true; |
---|
99 | } |
---|
100 | } else if (force) { |
---|
101 | // Just put it on the end. |
---|
102 | textarea.value += start+end; |
---|
103 | textarea.focus(textarea.value.length-1); |
---|
104 | return true; |
---|
105 | } |
---|
106 | return false; |
---|
107 | } |
---|
108 | |
---|
109 | function storeCaret(text) { |
---|
110 | if (text.createTextRange) text.caretPos = document.selection.createRange().duplicate(); |
---|
111 | } |
---|
112 | |
---|
113 | function helpline ( form, field, text ) { |
---|
114 | if ( typeof(document.forms[form].elements[field]) != "undefined") { |
---|
115 | document.forms[form].elements[field].value = text; |
---|
116 | } |
---|
117 | } |
---|