boardom Forum Index boardom
b2 message board
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Quicktags link/image hack

 
Post new topic   Reply to topic    boardom Forum Index -> Hacks
View previous topic :: View next topic  
Author Message
swirlee



Joined: 15 Jul 2002
Posts: 8

PostPosted: Tue Jul 16, 2002 11:16 pm    Post subject: Quicktags link/image hack Reply with quote

This may have been done already, but a quick search revealed nothing similar, so I'm posting it. If it's been done before, please let me know -- it was probably done better. On with it..

The quicktags buttons in b2 are very useful for dropping in bold, italics, and the like, but the link and image buttons always bugged me because when clicked the button, the tag appeared, but it was empty, and I had to back up quite a ways in order to type paste the URL. I've seen message boards that have a link button on the posting page that pops up a javascript prompt that you can type your URL into and it'll automagically format the link tag for you, so I set out to duplicate that functionality in b2.

The code I wrote pops up a prompt in which you can type a URL. If you leave it blank or leave it with the default "http://", it will default to an empty tag (href="" or src=""). If you're using the image button, it pops up a second prompt in which you can enter the ALT text. If you leave this prompt with the default "ALT", it will also default to an empty tag. Important: The code isn't perfect. If you use the link button without any text highlighted in the Post field, it will pop up two URL boxes, one for the opening tag and one for the closing tag (this doesn't hurt anything or change the closing tag, but it might get annoying). Also, for some reason, if you're posting an image and you leave the ALT prompt completely blank or press escape, the img tag will not appear at all. I'm not sure why this is. Also, there's zero error handling built in, and it may respond badly to quotation marks or apostrophes are fine entered into the prompts. I don't plan on developing the code any further -- I'm not great with JavaScript, and I can live with the little bugs. If someone else wants to take it and make it more robust and less buggy, please, by all means, do so. But if you do, let me know (credit would be nice, but mostly I just want to use the code).

Anyhow, here it is. Disclaimer: I make no guarantees.

First, open up b2-include/b2quicktags.js, and paste in the following function (anywhere is fine, so long as it's not inside any other functions -- I put mine at the very end).

Code:
function bblink(formObj, bbnumber) {
   oldtag = bbtags[bbnumber];
   current_url = prompt("URL:","http://");
   if((current_url == null) || (current_url == "http://")) { current_url = ""; }
   if(bbnumber == 16) {
      bbtags[bbnumber] = '<a href="' + current_url + '">';
      bbstyle(formObj, bbnumber);
   }
   if(bbnumber == 14) {
      current_alt = prompt("ALT:","ALT");
      if((current_alt == null) || (current_alt == "ALT")) { alttag = ''; } else { alttag = ' alt="' + current_alt + '"'; }
      bbtags[bbnumber] = '<img src="' + current_url + '" border="0"' + alttag + ' />';
      bbstyle(formObj, bbnumber);
   }
   bbtags[bbnumber] = oldtag;
}



Now, open up b2-include/b2quicktags.php and scroll down to the lines for the image and link buttons (26 and 29 on mine). In onClick for each, change "bbstyle" to "bblink" (so you'll have onClick="bblink(this.form,14)" and onClick="bblink(this.form,16)"), and you're done. If you only want to use it for images or only for links, only apply this change to the one you wish.

Once again, I make no guarantees, and I'd love to see someone turn this into a more mature hack, if it hasn't been done already.[/url]

[Edit] Yet more disclaimer: This has only been tested on IE6! YRMV.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    boardom Forum Index -> Hacks All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2 © 2001, 2002 phpBB Group