Smilie / BBCode(s) vraagje.
Ik heb onderstaand script, maar:
Ik stuit nu op het probleem, dat de smilie altijd op het eind word geplaatst, terwijl ik het beter vind als ie op de cursor komt.
Dus, je typt een bericht, bent bij zin 10, maar bedenkt dat je een smilie achter zin 2 wilt hebben, je plaatst je cursor erheen, en de smilie komt helemaal achteraan, i.p.v op/bij de cursor.
Dit script heb ik nu:
Code (php)
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
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
<SCRIPT language=JavaScript>
function icon(theicon) {
document.form.inhoud.value += ""+theicon;
document.form.inhoud.focus();
}
</script>
<a onclick="javascript:icon('(a)')"><img src="smilies/angel.png" /></a>
<a onclick="javascript:icon(':@')"><img src="smilies/angry.png" /></a>
<a onclick="javascript:icon(':cheer:')"><img src="smilies/beer.png" /></a>
<a onclick="javascript:icon(':D')"><img src="smilies/bigsmile.png" /></a>
<a onclick="javascript:icon(':$')"><img src="smilies/blush.png" /></a>
<a onclick="javascript:icon('(c)')"><img src="smilies/clown.png" /></a>
<a onclick="javascript:icon('(h)')"><img src="smilies/cool.png" /></a>
<a onclick="javascript:icon(':S')"><img src="smilies/crazy.png" /></a>
<a onclick="javascript:icon(':((')"><img src="smilies/cry.png" /></a>
<a onclick="javascript:icon(':x')"><img src="smilies/dead.png" /></a>
<a onclick="javascript:icon(':?:')"><img src="smilies/erm.png" /></a>
<a onclick="javascript:icon('8-|')"><img src="smilies/geek.png" /></a>
<a onclick="javascript:icon('8-)')"><img src="smilies/glare.png" /></a>
<a onclick="javascript:icon(':)')"><img src="smilies/happy.png" /></a>
<a onclick="javascript:icon(':|')"><img src="smilies/hmm.png" /></a> <br />
<a onclick="javascript:icon(':k')"><img src="smilies/kiss.png" /></a>
<a onclick="javascript:icon(':}')"><img src="smilies/laughcry.png" /></a>
<a onclick="javascript:icon(':slotje:')"><img src="smilies/lock.png" /></a>
<a onclick="javascript:icon('(L)')"><img src="smilies/loveeyes.png" /></a>
<a onclick="javascript:icon(':piraat:')"><img src="smilies/pirate.png" /></a>
<a onclick="javascript:icon(':(')"><img src="smilies/sad.png" /></a>
<a onclick="javascript:icon('+o(')"><img src="smilies/sick.png" /></a>
<a onclick="javascript:icon(':sst:')"><img src="smilies/silenced.png" /></a>
<a onclick="javascript:icon('|-)')"><img src="smilies/sleepy.png" /></a>
<a onclick="javascript:icon(':O')"><img src="smilies/surprised.png" /></a>
<a onclick="javascript:icon('^o)')"><img src="smilies/sweat.png" /></a>
<a onclick="javascript:icon(':p')"><img src="smilies/tongue.png" /></a>
<a onclick="javascript:icon(':hmm:')"><img src="smilies/undecided.png" /></a>
<a onclick="javascript:icon(';)')"><img src="smilies/wink.png" /></a>
<a onclick="javascript:icon('(xD)')"><img src="smilies/xd.png" /></a> <br />
<a onclick="javascript:icon('[b][/b]')"><img src="bold.gif" /></a>
<a onclick="javascript:icon('[i][/i]')"><img src="italic.gif" /></a>
<a onclick="javascript:icon('[u][/u]')"><img src="underline.gif" /></a><br />
<textarea name="inhoud" value="<?php echo $inhoud; ?>" cols=42 rows=5 id="smilie"></textarea><br />
function icon(theicon) {
document.form.inhoud.value += ""+theicon;
document.form.inhoud.focus();
}
</script>
<a onclick="javascript:icon('(a)')"><img src="smilies/angel.png" /></a>
<a onclick="javascript:icon(':@')"><img src="smilies/angry.png" /></a>
<a onclick="javascript:icon(':cheer:')"><img src="smilies/beer.png" /></a>
<a onclick="javascript:icon(':D')"><img src="smilies/bigsmile.png" /></a>
<a onclick="javascript:icon(':$')"><img src="smilies/blush.png" /></a>
<a onclick="javascript:icon('(c)')"><img src="smilies/clown.png" /></a>
<a onclick="javascript:icon('(h)')"><img src="smilies/cool.png" /></a>
<a onclick="javascript:icon(':S')"><img src="smilies/crazy.png" /></a>
<a onclick="javascript:icon(':((')"><img src="smilies/cry.png" /></a>
<a onclick="javascript:icon(':x')"><img src="smilies/dead.png" /></a>
<a onclick="javascript:icon(':?:')"><img src="smilies/erm.png" /></a>
<a onclick="javascript:icon('8-|')"><img src="smilies/geek.png" /></a>
<a onclick="javascript:icon('8-)')"><img src="smilies/glare.png" /></a>
<a onclick="javascript:icon(':)')"><img src="smilies/happy.png" /></a>
<a onclick="javascript:icon(':|')"><img src="smilies/hmm.png" /></a> <br />
<a onclick="javascript:icon(':k')"><img src="smilies/kiss.png" /></a>
<a onclick="javascript:icon(':}')"><img src="smilies/laughcry.png" /></a>
<a onclick="javascript:icon(':slotje:')"><img src="smilies/lock.png" /></a>
<a onclick="javascript:icon('(L)')"><img src="smilies/loveeyes.png" /></a>
<a onclick="javascript:icon(':piraat:')"><img src="smilies/pirate.png" /></a>
<a onclick="javascript:icon(':(')"><img src="smilies/sad.png" /></a>
<a onclick="javascript:icon('+o(')"><img src="smilies/sick.png" /></a>
<a onclick="javascript:icon(':sst:')"><img src="smilies/silenced.png" /></a>
<a onclick="javascript:icon('|-)')"><img src="smilies/sleepy.png" /></a>
<a onclick="javascript:icon(':O')"><img src="smilies/surprised.png" /></a>
<a onclick="javascript:icon('^o)')"><img src="smilies/sweat.png" /></a>
<a onclick="javascript:icon(':p')"><img src="smilies/tongue.png" /></a>
<a onclick="javascript:icon(':hmm:')"><img src="smilies/undecided.png" /></a>
<a onclick="javascript:icon(';)')"><img src="smilies/wink.png" /></a>
<a onclick="javascript:icon('(xD)')"><img src="smilies/xd.png" /></a> <br />
<a onclick="javascript:icon('[b][/b]')"><img src="bold.gif" /></a>
<a onclick="javascript:icon('[i][/i]')"><img src="italic.gif" /></a>
<a onclick="javascript:icon('[u][/u]')"><img src="underline.gif" /></a><br />
<textarea name="inhoud" value="<?php echo $inhoud; ?>" cols=42 rows=5 id="smilie"></textarea><br />
Hoe krijg ik dit klaar gespeeld?
Bedankt alvast!
Lars
Edit:
Ik heb het veranderd in dit:
Code (php)
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
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
<SCRIPT language=JavaScript>
function icon(theicon) {
var myQuery = document.form.inhoud;
var chaineAj = theicon;
//IE support
if (document.selection) {
myQuery.focus();
sel = document.selection.createRange();
sel.text = chaineAj;
document.form.insert.focus();
}else if(document.form.inhoud.selectionStart || document.form.inhoud.selectionStart == '0') {
var startPos = document.form.inhoud.selectionStart;
var endPos = document.form.inhoud.selectionEnd;
var chaineSql = document.form.inhoud.value;
myQuery.value = chaineSql.substring(0, startPos) + chaineAj + chaineSql.substring(endPos, chaineSql.length);
} else {
myQuery.value += chaineAj;
}
}
</script>
<a onclick="javascript:icon('(a)')"><img src="smilies/angel.png" /></a>
<a onclick="javascript:icon(':@')"><img src="smilies/angry.png" /></a>
<a onclick="javascript:icon(':cheer:')"><img src="smilies/beer.png" /></a>
<a onclick="javascript:icon(':D')"><img src="smilies/bigsmile.png" /></a>
<a onclick="javascript:icon(':$')"><img src="smilies/blush.png" /></a>
<a onclick="javascript:icon('(c)')"><img src="smilies/clown.png" /></a>
<a onclick="javascript:icon('(h)')"><img src="smilies/cool.png" /></a>
<a onclick="javascript:icon(':S')"><img src="smilies/crazy.png" /></a>
<a onclick="javascript:icon(':((')"><img src="smilies/cry.png" /></a>
<a onclick="javascript:icon(':x')"><img src="smilies/dead.png" /></a>
<a onclick="javascript:icon(':?:')"><img src="smilies/erm.png" /></a>
<a onclick="javascript:icon('8-|')"><img src="smilies/geek.png" /></a>
<a onclick="javascript:icon('8-)')"><img src="smilies/glare.png" /></a>
<a onclick="javascript:icon(':)')"><img src="smilies/happy.png" /></a>
<a onclick="javascript:icon(':|')"><img src="smilies/hmm.png" /></a> <br />
<a onclick="javascript:icon(':k')"><img src="smilies/kiss.png" /></a>
<a onclick="javascript:icon(':}')"><img src="smilies/laughcry.png" /></a>
<a onclick="javascript:icon(':slotje:')"><img src="smilies/lock.png" /></a>
<a onclick="javascript:icon('(L)')"><img src="smilies/loveeyes.png" /></a>
<a onclick="javascript:icon(':piraat:')"><img src="smilies/pirate.png" /></a>
<a onclick="javascript:icon(':(')"><img src="smilies/sad.png" /></a>
<a onclick="javascript:icon('+o(')"><img src="smilies/sick.png" /></a>
<a onclick="javascript:icon(':sst:')"><img src="smilies/silenced.png" /></a>
<a onclick="javascript:icon('|-)')"><img src="smilies/sleepy.png" /></a>
<a onclick="javascript:icon(':O')"><img src="smilies/surprised.png" /></a>
<a onclick="javascript:icon('^o)')"><img src="smilies/sweat.png" /></a>
<a onclick="javascript:icon(':p')"><img src="smilies/tongue.png" /></a>
<a onclick="javascript:icon(':hmm:')"><img src="smilies/undecided.png" /></a>
<a onclick="javascript:icon(';)')"><img src="smilies/wink.png" /></a>
<a onclick="javascript:icon('(xD)')"><img src="smilies/xd.png" /></a> <br />
<a onclick="javascript:icon('[b][/b]')"><img src="bold.gif" /></a>
<a onclick="javascript:icon('[i][/i]')"><img src="italic.gif" /></a>
<a onclick="javascript:icon('[u][/u]')"><img src="underline.gif" /></a><br />
<textarea name="inhoud" value="<?php echo $inhoud; ?>" cols=40 rows=5 id="smilie"></textarea><br />
function icon(theicon) {
var myQuery = document.form.inhoud;
var chaineAj = theicon;
//IE support
if (document.selection) {
myQuery.focus();
sel = document.selection.createRange();
sel.text = chaineAj;
document.form.insert.focus();
}else if(document.form.inhoud.selectionStart || document.form.inhoud.selectionStart == '0') {
var startPos = document.form.inhoud.selectionStart;
var endPos = document.form.inhoud.selectionEnd;
var chaineSql = document.form.inhoud.value;
myQuery.value = chaineSql.substring(0, startPos) + chaineAj + chaineSql.substring(endPos, chaineSql.length);
} else {
myQuery.value += chaineAj;
}
}
</script>
<a onclick="javascript:icon('(a)')"><img src="smilies/angel.png" /></a>
<a onclick="javascript:icon(':@')"><img src="smilies/angry.png" /></a>
<a onclick="javascript:icon(':cheer:')"><img src="smilies/beer.png" /></a>
<a onclick="javascript:icon(':D')"><img src="smilies/bigsmile.png" /></a>
<a onclick="javascript:icon(':$')"><img src="smilies/blush.png" /></a>
<a onclick="javascript:icon('(c)')"><img src="smilies/clown.png" /></a>
<a onclick="javascript:icon('(h)')"><img src="smilies/cool.png" /></a>
<a onclick="javascript:icon(':S')"><img src="smilies/crazy.png" /></a>
<a onclick="javascript:icon(':((')"><img src="smilies/cry.png" /></a>
<a onclick="javascript:icon(':x')"><img src="smilies/dead.png" /></a>
<a onclick="javascript:icon(':?:')"><img src="smilies/erm.png" /></a>
<a onclick="javascript:icon('8-|')"><img src="smilies/geek.png" /></a>
<a onclick="javascript:icon('8-)')"><img src="smilies/glare.png" /></a>
<a onclick="javascript:icon(':)')"><img src="smilies/happy.png" /></a>
<a onclick="javascript:icon(':|')"><img src="smilies/hmm.png" /></a> <br />
<a onclick="javascript:icon(':k')"><img src="smilies/kiss.png" /></a>
<a onclick="javascript:icon(':}')"><img src="smilies/laughcry.png" /></a>
<a onclick="javascript:icon(':slotje:')"><img src="smilies/lock.png" /></a>
<a onclick="javascript:icon('(L)')"><img src="smilies/loveeyes.png" /></a>
<a onclick="javascript:icon(':piraat:')"><img src="smilies/pirate.png" /></a>
<a onclick="javascript:icon(':(')"><img src="smilies/sad.png" /></a>
<a onclick="javascript:icon('+o(')"><img src="smilies/sick.png" /></a>
<a onclick="javascript:icon(':sst:')"><img src="smilies/silenced.png" /></a>
<a onclick="javascript:icon('|-)')"><img src="smilies/sleepy.png" /></a>
<a onclick="javascript:icon(':O')"><img src="smilies/surprised.png" /></a>
<a onclick="javascript:icon('^o)')"><img src="smilies/sweat.png" /></a>
<a onclick="javascript:icon(':p')"><img src="smilies/tongue.png" /></a>
<a onclick="javascript:icon(':hmm:')"><img src="smilies/undecided.png" /></a>
<a onclick="javascript:icon(';)')"><img src="smilies/wink.png" /></a>
<a onclick="javascript:icon('(xD)')"><img src="smilies/xd.png" /></a> <br />
<a onclick="javascript:icon('[b][/b]')"><img src="bold.gif" /></a>
<a onclick="javascript:icon('[i][/i]')"><img src="italic.gif" /></a>
<a onclick="javascript:icon('[u][/u]')"><img src="underline.gif" /></a><br />
<textarea name="inhoud" value="<?php echo $inhoud; ?>" cols=40 rows=5 id="smilie"></textarea><br />
En alles is deels opgelost, de smilies komen nu wel op de plek van de cursor, echter als je een stuk tekst selecteert, en je wilt dit bv. dikgedrukt maken, dus je klikt erop, dan is de tekst weg, en de [b*][/b*] tag komt er voor in de plaats, dus hij vervangt het, i.p.v dat het eromheen komt zoals hier.
Hoe speel ik dat klaar?
Lars
Gewijzigd op 01/01/1970 01:00:00 door Lars Groot
Er zijn nog geen reacties op dit bericht.