Hello,

I have a problem with a custom button for bueditor. Perhaps someone here can help me ;)

What should happen:
There is a link in the textfield (for example "http://www.drupal.org/project/bueditor").
The user can mark that link, click on my button and the link should get formatted in the following way:

<strong>Further information</strong>
<a href="http://www.drupal.org/project/bueditor" target="_blank">www.drupal.org</a>

At the moment I use the following "script" as a button:

<strong>Further information</strong>
<a href="%TEXT%" target="_blank">Link</a>

Most of the things I need works. My only problem: The link-name is "Link" and not the domain host (for example "www.drupal.org") at the moment.

Has someone an idea how I can extract the domain host from the url and use it as link-name?

With php, it would work like this:
$domain = parse_url($url);
return $domain["host"];

But how can I get this into the button script?

Comments

ufku’s picture

Try this

js:
var M, domain, link = E.getSelection();
if (M = link.match(/^https?:\/\/([a-z0-9\.\-]+)/i)) {
  domain = M[1];
  E.replaceSelection('<strong>Further information</strong>\n<a href="' + link +' " target="_blank">' + domain + '</a>');
}
Stephen.K’s picture

THANKS!
Works perfectly...

ufku’s picture

Status: Active » Closed (fixed)