Lame hack of the URL-inserter
Posted: Tue Feb 15, 2005 2:05 am
I'll admit into sucking at javascript. The idea isn't even really new or anything, but it not beeing default annoyed me;
When making an URL by using the nifty javascript that's built in, there is no
by default. There should be - if I were to decide ofcourse. Clicking a link doesn't mean I want to surf away from the current site I am browsing, and with s9y:s system of having an exit-URL on the same domain before actually redirecting renders all TBE (for Firefox) features useless.
So I wrote this - I know - lame hack (taken from serendipity_editor.js - anyone is ofc free to use this code if they are experiencing the same annoyance as me)
There's still one problem that needs to be addressed; using a prompt isn't really the ideal solution - it had to do though since I am/was tired while writing this and couldn't get the variables to post properly when inserted directly into the line. Sorry, someday I might care enough to do this.
Output of all this is;
which ofc is not good since the whole "target=_blank" is within' "s, which should not be necessary - any webdeveloper will prefer target="_blank".
If any of the developers, or me, comes up with a better solution for this (there must be), I would appreciate if they would post it here and include it in the next stable, if they find it reasonable (they should! ).
When making an URL by using the nifty javascript that's built in, there is no
Code: Select all
target="_blank"
So I wrote this - I know - lame hack (taken from serendipity_editor.js - anyone is ofc free to use this code if they are experiencing the same annoyance as me)
Code: Select all
function wrapSelectionWithLink(txtarea) {
var my_link = prompt("Enter URL:","http://");
var my_target = prompt("Enter Target:","target=_blank");
if (document.all && getIESelection(txtarea) == "" ||
document.getElementById && getMozSelection(txtarea) == "") {
var my_desc = prompt("Enter Description", '');
}
if (my_link != null & my_target!= null) {
lft = "<a href=\"" + my_link + "\" \"" + my_target + "\">";
if (my_desc != null && my_desc != "") {
rgt = my_desc + "</a>";
} else {
rgt = "</a>";
}
wrapSelection(txtarea, lft, rgt);
}
return;
}
Code: Select all
lft = "<a href=\"" + my_link + "\" \"" + my_target + "\">";
Output of all this is;
Code: Select all
<a href="http://www.marinmo.net" "target=_blank">Marinmo.net</a>
If any of the developers, or me, comes up with a better solution for this (there must be), I would appreciate if they would post it here and include it in the next stable, if they find it reasonable (they should! ).