|
|
Send spam to: website@xeonlive.com nick@xeonlive.com georgiapeach1241@aol.com Client Side Scripting By Jonathan Street This function relies on some global variables. One for each set of tags we want to use. The value of these variables tells the function whether the tag is already open. Firstly lets assume the bold tag is being opened for the very first time. The value of b is 2 and is fed to the function in the place of v. The function begins with an if statement. Using modulus we evaluate the value of v. Modulus gives us the remainder of a division. As v is 2 there is no remainder (2 divided by 2 gives a whole number, 1, giving a remainder of 0) and so this condition is true and the first block of code is performed. On the first line the value of the bold (in our scenario) button will be changed to the new value. Next the post textarea is assigned to the variable post. On the third line the opening tag is added onto the end before we focus back onto the textarea. Finally in the last line of the function we add one to the global variable. The next time the bold tag button is clicked a different course of events unfolds. v is now 3 so the modulus function returns 1 and the else section of the if statement is performed. Instead of opening a tag we are now closing it. 'tagclose' and 'oldbut' are used instead of 'tagadd' and 'newbut' but apart from this these four lines are identical to those seen previously. Again we add one to the value of v and the whole thing is ready to start again. Next is the font function. This function is even simpler. The opening tag and closing tag are both supplied as variables to the function and all that happens is they are both tacked onto the end of the users post. In some bbcode editors (certainly phpBB and probably others) highlighting text and then using this function will wrap the highlighted text in the appropriate bbcode tags. This editor doesn't have this functionality. If this is something you feel your users will need it should be possible to reconstruct this functionality by looking at the source html for an editor that allows this. Next the smilie function. You'll notice that this is almost exactly the same as the font function. The only difference being one less variable is supplied. Needless to say I won't therefore be commenting on this any further. Now to give the user a little help. This function is used to display some helpful text in the helpbox whenever the user moves their mouse over one of the bbcode buttons. First we assign the strings of help text to variables. The function itself is supplied an indicator as to which button the user has just moved their mouse over. This is then converted into the correct variable and the value of the helpbox is changed to the correct string. Next is the confirm_reset function. The purpose of this function is to offer the user a second chance if they accidently click the start over button. We create a confirm box that tells them to click ok to continue and start over or click cancel to go back to working on what they have already done. If they click ok the first part of the statement, return true, goes into effect and the form is wiped. If they click cancel the second part of the statement goes into effect, return false, and their work is safe, the form isn't wiped. The final function now. This is more for our benefit rather than the users but I think it is still valuable. It's the checkForm function First of all we assign some variables for the subject box and the post box. I've imaginatively called them subject and post. The main function is two if statements, one nested inside the other. The basic idea is that if both the subject and the post are fewer than 2 characters long we don't let the submission be made and we alert the user of this. We then consider what will happen if only the subject is less than 2 characters long. Again we prevent the user submitting with return false and create an alert box. We do the same then for the post length. Finally if both the subject and post are both longer than 2 characters in length we return true and the submission is made. You may well want to make the minimum length for the post longer depending on the sort of submissions you are expecting. That's almost it now. Just one page to go. Next Page
|
![]() |
This site best viewed in a W3C standard browser at 800*600 or higher Site design by Red Squirrel | Contact © Copyright 2010 Ryan Auclair/IceTeks, All rights reserved |