View Full Version : vb code menu
darksidepuffin
04-09-2004, 01:00 PM
Hey peeps,
I can only guess that this is done in javascript,but can someone point out exactly how to go about creating a menu similar to the one used to 'click'/'select and click' vbcode shown when you add/edit a post?
tia :)
agent002
04-09-2004, 01:08 PM
eh? sorry, but what's that "click/select and click" thing?
darksidepuffin
04-09-2004, 01:13 PM
Originally posted by agent002
eh? sorry, but what's that "click/select and click" thing?
erm..sorry...kinda went with action based vs atchual description.Click being buttons that onclick insert the appropriate code,select and click being an additional ability to select text and apply the code around it.Basically what I mean is the vb code menu bar.I have a basic idea of how to do it,just not exactly sure on the rest of it.I might be able to figure the rest out myself if I knew how to detect what text is selected and work with it :)
agent002
04-09-2004, 01:39 PM
Unfortunately, you can get the currently selected text, using document.selection, in internet explorer only. This is about what you could use:
<html>
<head>
<title>insert code thingy</title>
<script type="text/javascript">
function insertFontCode(){
var textareaID = 'message';
if(document.selection){
if(document.selection.createRange().parentElement().id == textareaID &&
document.selection.createRange().text !== ''){
var p = prompt('Change font of selected text to:', '');
if(!p || p == null) return false;
document.selection.createRange().text = '[font='+p+']'+document.selection.createRange().text+'[/font]';
return false;
}
}
var p = prompt('Type some text:', '');
if(!p || p == null) return false;
var p2 = prompt('Choose a font:', '');
if(!p2 || p2 == null) return false;
document.getElementById(textareaID).value += '[font='+p2+']'+p+'[/font]';
}
</script>
</head>
<body>
<input type="button" value="Font" onclick="insertFontCode();"><br><br>
<textarea id="message" rows="10" cols="60"></textarea>
</body>
</html>
:)
darksidepuffin
04-09-2004, 02:20 PM
[edit: your right,quoting code is REALLY annoying ;)]
Thanks Jere :)
although,since it is indeed ie only...I'll probably have to avoid such usage of javascript(one of the reasons I don't use a lot of it,as as such never learned it) ^^;;
I'll toy with it in a bit,at the moment I'm adding category support to my cms :D
agent002
04-09-2004, 02:26 PM
one part being IE only is not a reason to leave it off, if that's what you intended. In a browser other than IE, you simply get the "Type some text:" prompt instead, no JavaScript error.
darksidepuffin
04-09-2004, 02:29 PM
Originally posted by agent002
one part being IE only is not a reason to leave it off, if that's what you intended. In a browser other than IE, you simply get the "Type some text:" prompt instead, no JavaScript error.
well..what I meant was the selection part...not the whole thing :D ...altho since it does degrade successfully,you could be right ^_^
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.