|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
time saver
either add the following to the box as a default value or... add a javascript button that would pop it in.
these three lines reversed [/highlight] [highlight=php] I think I'm getting carpal tunnel just from writing thoe two lines... |
|
#2
|
|||
|
|||
|
RE: time saver
Yeah..I think some javascript to add tags would be cool...will work on it.
|
|
#3
|
|||||
|
|||||
|
RE: time saver
got some help from ababab but try this function
Code:
<script type="text/javascript">
<!-- hide this stuff from other browsers
var x=0;
var tagname;
var tag;
var closetag;
function addtag(tagname)
{
tag=("[" + tagname + "]");
closetag="n[/" + tagname + "]n";
x++
if (x == 1){
document.getElementById("a").value+=tag;
}else{
x = 0;
document.getElementById("a").value+=closetag;
}
}
// end hiding -->
</script>
php Code:
it's probably not the most elegant solution but it works. I probably should have used the document object model to drill down through the form to get to the text area but I'm rusty at javascript and ababad's code originaly was tweaking a div not a text area. here it is in action: http://www.azwc.com/cw/ I tried to make it dynamic so that you could put the other tags like <code> on it's own button. |
|
#4
|
||||
|
||||
|
RE: time saver
I tweaked it a little and here it is with multiple buttons
http://www.azwc.com/cw/javascripttest3.html |
|
#5
|
|||
|
|||
|
RE: time saver
I guess the one issue I have with it is that is takes the cursor out of the text box after inserting the tags. Could it leave the cursor after the tag when done?
|
|
#6
|
||||
|
||||
|
RE: time saver
took me a minute to figure out how to get the cursor at the end of the text, the only thing you'll need to do is change the index of the form element to correspond with where the text area is in the form. For some reason it's not working if the very first thing you do is hit a button it places the focus before the button but if you already typed anything else it puts the cursor on the next line. maybe someone better at javascript than me knows why this is. I'll post in client side forum and see what people have to say.
here it is working: www.azwc.com/cw/javascripttest3.html Code:
<script type="text/javascript">
<!-- hide this stuff from other browsers
var x=0;
var tagname;
var tag;
var closetag;
var cnt;
function addtag(tagname)
{
tag=("[" + tagname + "]n");
closetag="n[/" + tagname + "]n";
x++
if (x == 1){
document.getElementById("a").value+=tag;
}else{
x = 0;
document.getElementById("a").value+=closetag;
}
cnt = document.getElementById("a").length;
document.getElementById("a").focus(cnt);
}
// end hiding -->
</script>
<body>
<form>
<input type="button" value="[highlight=php]" onclick="addtag('php')">
<input type="button" value="[code]" onclick="addtag('code')">
<input type="button" value="[quote]" onclick="addtag('quote')">
</br>
<textarea id="a" name="textarea" cols="40" rows="10" value=""></textarea>
</form>
|
|
#7
|
||||
|
||||
|
RE: time saver
ok I think I got it now:
Code:
<script type="text/javascript">
<!-- hide this stuff from other browsers
var x=0;
var tagname;
var tag;
var closetag;
var cnt;
function addtag(tagname)
{
tag=("[" + tagname + "]n");
closetag="n[/" + tagname + "]n";
x++
if (x == 1){
document.getElementById("a").focus();
document.getElementById("a").value+=tag;
}else{
x = 0;
document.getElementById("a").focus();
document.getElementById("a").value+=closetag;
}
}
// end hiding -->
</script>
<body>
<form>
<input type="button" value="[highlight=php]" onclick="addtag('php')">
<input type="button" value="[code]" onclick="addtag('code')">
<input type="button" value="[quote]" onclick="addtag('quote')">
</br>
<textarea id="a" name="textarea" cols="40" rows="10" value=""></textarea>
</form>
view here: www.azwc.com/cw/javascripttest2.html |
|
#8
|
|||
|
|||
|
RE: time saver
Hmm..for me it puts the cursor before that tag no matter if I type something or not first...
|
|
#9
|
||||
|
||||
|
RE: time saver
hmmm, how can that be? what browser? I tried IE and firefox.
this link? www.azwc.com/cw/javascripttest2.html |
|
#10
|
||||
|
||||
|
RE: time saver
Opera 8.5:
Cursor always goes to the start of the tag, and the tag isn't inserted where the cursor is but always into the end. I think this feature is very neatly done in Wordpress, you might want to consider examining it. |
|
#11
|
||||
|
||||
|
RE: time saver
I'll take a look when I have a little more time, I probably should have downloaded a forum script and seen how they did it but I figured I could throw it together pretty quick.
As for the tag going on the end of the text that's the expected behavior, I didn't even think about someone wanting to put tags in the middle of the code, you could always type them manually or cut and paste I guess. Both firefox and IE put the cursor on the line after the tag in all cases. is there a link to what you mean I didn't see the buttons. |
|
#12
|
||||
|
||||
|
RE: RE: time saver
Quote:
It's so easy to forget when starting to type code. It would be convenient Quote:
Link to what? Wordpress' page that contains the code? I can upload it somewhere and link there if you meant it. |
|
#13
|
|||
|
|||
|
RE: time saver
just my two cents...
1) you have to click the button twice, once for the starting tag and again for the ending tag. one click should throw in both tags otherwise it's not all that "convenient." and the cursor should therefore start inbetween the tags. 2) i should be able to highlight a block of text and then click the button, and it will place the tags around my text rather than at either end of it. |
|
#14
|
||||
|
||||
|
RE: time saver
I'm more than happy to take anyones input on how to get it done, I just thought it was a cool idea and figured we could help Matt get it done.
I kinda suck at the DOM because I rarely do much javascript so I have to muddle through it. Is there a property of the method focus() that would allow me to set the position of the cursor between the tags? writing the code the put both tags at once would be easy and I tried to get the length of the field and subtract the length of the second tag and put the cursor at that point by entering calling focus(cnt-taglength) but that didn't work. tkark, I looked around at the wordpress site but I couldn't find a place where I could fill ina form and thus see the code without registering or downloading the whole script for offsite use (that seemed to be an option but I'm not sure). If you can paste the code they're using I ould love to see it and I'll tweak it until I have it working in IE, safari, firefox. |
|
#15
|
||||
|
||||
|
RE: time saver
I removed some parts of the page, but the essential should still be there: http://haukku.mine.nu/~tohoq/wp/
|