Hacking Quicktags: All Links Are Not Created Equal
Posted on 09.30.07 by Widge @ 1:53 am

Okay, next up: the link quicktag. On Needcoffee, we have internal links and external links. Internal links are just plain old links. External links open in a new window. I know that irritates a few people, but I have no idea why. You close the window and you're where you came from. Seems like a no brainer to me.

Anyway. Same deal as before:

1. Go to /wp-includes/js/

2. Edit quicktags.js

3. Look for this code:

edButtons[edButtons.length] =
new edButton('ed_link'
,'link'
,''
,''
,'a'
); // special case


4. Now this is what creates the buttons across the top of your edit area. In my case, I'm altering one and creating another. So I'm going to do this:

edButtons[edButtons.length] =
new edButton('ed_link'
,'int link'
,''
,''
,'a'
); // special case

edButtons[edButtons.length] =
new edButton('ed_extlink'
,'ext link'
,''
,''
,'x'
); // special case

Now, in the first block of code, all I've done is change that third line, which is what the button is labeled. Because I want to differentiate between the two types of links, I've changed "link" to "int link." And then I've basically copied the same code again, but this time the button's called "ext link." Also, you see the sixth lines–that's supposed to be an access key. I never use this, but I went ahead and put an X for the second one, just in case.

Oh, and I almost forgot: you see where the first button does an "ed_link" thing. Well, since I'm not a real coder, I don't know precisely what the hell that does–it does a call out to a function we'll get to in a minute. So I must made "ed_extlink" the second one.

5. Now look for this section of code, that starts with "function edShowButton". It's that aforementioned function business. As before, I've put in line breaks where there normally aren't any, just to preserve the width of my theme here.

	if (button.id == 'ed_img') {
		document.write('<input type="button" id="' + button.id + '" accesskey="'
+ button.access + '" class="ed_button" onclick="edInsertImage(edCanvas);"
value="' + button.display + '" />');
	}
	else if (button.id == 'ed_link') {
		document.write('<input type="button" id="' + button.id + '"
accesskey="' + button.access + '" class="ed_button"
onclick="edInsertLink(edCanvas, ' + i + ');" value="' + button.display + '" />');
	}
	else {
		document.write('<input type="button" id="' + button.id + '"
accesskey="' + button.access + '" class="ed_button"
onclick="edInsertTag(edCanvas, ' + i + ');" value="' + button.display + '"  />');
	}
}

The first bit, the "ed_link" section, we really don't need to screw with. But we need to add a function bit for "ext_edlink." It's basically the same thing as the one above it, so the two together now look like this:

	else if (button.id == 'ed_link') {
		document.write('<input type="button" id="' + button.id + '"
accesskey="' + button.access + '" class="ed_button"
onclick="edInsertLink(edCanvas, ' + i + ');" value="' + button.display + '" />');
	}
	else if (button.id == 'ed_extlink') {
		document.write('<input type="button" id="' + button.id + '"
accesskey="' + button.access + '" class="ed_button"
onclick="edInsertExtLink(edCanvas, ' + i + ');" value="' + button.display + '" />');
	}

No sweat.

6. Now there's a section marked "function edInsertLink" which we don't need to screw with, because really all we've done for internal links is change the button label. But we need to add a new section. Here's what I've put in directly after the edInsertLink bit:

function edInsertExtLink(myField, i, defaultValue) {
	if (!defaultValue) {
		defaultValue = 'http://';
	}
	if (!edCheckOpenTags(i)) {
		var URL = prompt(quicktagsL10n.enterURL, defaultValue);
		if (URL) {
			edButtons[i].tagStart = '<a href="' + URL + '" target="_blank">';
			edInsertTag(myField, i);
		}
	}
	else {
		edInsertTag(myField, i);
	}
}
</a>

Basically all I've done is copy the code, change "edInsertLink" to "edInsertExtLink" and stick the target="_blank"> in. That line used to look like this:

			edButtons[i].tagStart = '<a href="' + URL + '">';
</a>

But I made it this:

			edButtons[i].tagStart = '<a href="' + URL + '" target="_blank">';
</a>

7. And that's it. You should be good.

Bear in mind I'm a writer, not a coder. So if this screws up your site, it's your own lookout. Backup files before you screw with them. YMMV.


Taggification: , , , ,

Filed under: Wordpress
Comments:

« Hacking Quicktags: One Image Directory, Under Eris | Robots.txt is Pretty Damn Important, Yes » No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

(required)

(required)



John Robinson is a writer of prose, poetry and comics who also writes under the pseudonym of Widgett Walls.

Widgett Walls is the director of Needcoffee.com who also writes under the pseudonym of John Robinson.

Don't ask.


This is my latest book. Short stories written especially for you, or at least someone who reminded me a lot of you at the time.

Read it for free here. Or if you like paper, buy it here.

Then tell all your friends about it. Or all your enemies. I'm not particular either way.


Want a translation? Try these:

They're not perfect, but they'll do in a pinch.







Syndication
Feedburner

Amigos
Sarah Brown
Catalyst
Dindrane
Doc Ezra
Tee Quillin
ScottC
Tibby's Bowl
JM Tuffley

Sites Which Distract Me From Writing
Boing Boing
Cringely
Defamer
Warren Ellis
Engadget
Fortean Times
Long Tail
Porphyre
Reason
Wired

Topics
General BS
Insomnia
Travel
Writing Fodder

Active Projects...
Dark Blue Monstropolis
Magnificent Desolation
Something Else
The Sunday Before You


Recent Entries
  • And Now That I've Upgraded to 2.6...
  • Don't Mind Me.
  • Amazon MAB Replacement?
  • My New Mascot
  • A Nice Coda to the Trip
  • The New Yorker Hotel Business Center
  • Blast From the Past
  • Crossposted From My StumbleUpon Blog
  • Update at Last
  • George Clooney Makes Small Films Profitable. Yes.
  • On the Other Side of the Flu
  • Piano and Trumpet For the Win
  • Gun, With Occasional Weightlessness
  • Tor Nørretranders on Permanent Reincarnation
  • Can I Get a Hell Yeah?

  • Wordpress Archives
    July 2008
    May 2008
    April 2008
    March 2008
    February 2008
    January 2008
    December 2007
    November 2007
    October 2007
    September 2007
    August 2007
    July 2007
    June 2007
    May 2007
    April 2007
    March 2007
    February 2007
    January 2007
    December 2006
    November 2006
    October 2006
    September 2006
    August 2006
    July 2006
    June 2006
    May 2006
    April 2006
    March 2006
    February 2006
    January 2006
    December 2005
    November 2005
    October 2005
    September 2005
    August 2005
    July 2005
    June 2005
    May 2005
    April 2005
    March 2005

    Credits and Copyright
    Proudly powered by WordPress. All content © 1997-present by John Robinson.
    Theme by Theron Parlin, but we've mangled it beyond all reason. So don't blame him.