This repository has been archived by the owner on Apr 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbbcode2text.js
134 lines (109 loc) · 3.75 KB
/
bbcode2text.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
function addText(elname, wrap1, wrap2) {
if (document.selection) { // for IE
var str = document.selection.createRange().text;
document.forms['bbcode2text'].elements[elname].focus();
var sel = document.selection.createRange();
sel.text = wrap1 + str + wrap2;
return;
} else if ((typeof document.forms['bbcode2text'].elements[elname].selectionStart) != 'undefined') { // for Mozilla
var txtarea = document.forms['bbcode2text'].elements[elname];
var selLength = txtarea.textLength;
var selStart = txtarea.selectionStart;
var selEnd = txtarea.selectionEnd;
var oldScrollTop = txtarea.scrollTop;
//if (selEnd == 1 || selEnd == 2)
//selEnd = selLength;
var s1 = (txtarea.value).substring(0,selStart);
var s2 = (txtarea.value).substring(selStart, selEnd)
var s3 = (txtarea.value).substring(selEnd, selLength);
txtarea.value = s1 + wrap1 + s2 + wrap2 + s3;
txtarea.selectionStart = s1.length;
txtarea.selectionEnd = s1.length + s2.length + wrap1.length + wrap2.length;
txtarea.scrollTop = oldScrollTop;
txtarea.focus();
return;
} else {
insertText(elname, wrap1 + wrap2);
}
}
function insertText(elname, what) {
if (document.forms['bbcode2text'].elements[elname].createTextRange) {
document.forms['bbcode2text'].elements[elname].focus();
document.selection.createRange().duplicate().text = what;
} else if ((typeof document.forms['bbcode2text'].elements[elname].selectionStart) != 'undefined') { // for Mozilla
var tarea = document.forms['bbcode2text'].elements[elname];
var selEnd = tarea.selectionEnd;
var txtLen = tarea.value.length;
var txtbefore = tarea.value.substring(0,selEnd);
var txtafter = tarea.value.substring(selEnd, txtLen);
var oldScrollTop = tarea.scrollTop;
tarea.value = txtbefore + what + txtafter;
tarea.selectionStart = txtbefore.length + what.length;
tarea.selectionEnd = txtbefore.length + what.length;
tarea.scrollTop = oldScrollTop;
tarea.focus();
} else {
document.forms['bbcode2text'].elements[elname].value += what;
document.forms['bbcode2text'].elements[elname].focus();
}
}
function tag_url()
{
var FoundErrors = '';
var enterURL = prompt("Please enter the url", "http://");
var enterTITLE = prompt("please enter the url name", "My Webpage");
if (!enterURL) {
FoundErrors += " " + "No url entered";
}
if (!enterTITLE) {
FoundErrors += " " + "No url name entered";
}
if (FoundErrors) {
alert("Error!"+FoundErrors);
return;
}
addText('body', '[url='+enterURL+']'+enterTITLE, '[/url]');
}
function tag_image()
{
var FoundErrors = '';
var enterURL = prompt("Please enter the image url", "http://");
if (!enterURL) {
FoundErrors += " " + "No image url added";
}
if (FoundErrors) {
alert("Error!"+FoundErrors);
return;
}
addText('body', '[img]'+enterURL, '[/img]');
}
function tag_list()
{
var listvalue = "init";
var thelist = "";
while ( (listvalue != "") && (listvalue != null) )
{
listvalue = prompt("list_prompt", "");
if ( (listvalue != "") && (listvalue != null) )
{
thelist = thelist+"[*]"+listvalue+"\n";
}
}
if ( thelist != "" )
{
addText('body', '[list]\n'+thelist, '[/list]\n');
}
}
function alterfont(theval, thetag)
{
if (theval == 0)
return;
addText('body', '[' + thetag + '=' + theval + ']', '[/' + thetag + ']');
document.bbcode2text.ffont.selectedIndex = 0;
document.bbcode2text.fsize.selectedIndex = 0;
document.bbcode2text.fcolor.selectedIndex = 0;
}
function more_emoticons()
{
window.open('emoticonloader.php','Emoticons', 'width=300,height=500,resizable=yes,scrollbars=yes');
}