If I have an SVG element and use an xlink:href to add a link that element, then Extlink doesn't parse any further links on the page, effectively breaking Extlink's functionality anywhere after that SVG element.

As an example:

  <g>
    <defs>
      <polygon id="SVGID_1_" points="176.6,24.1 230.7,24.1 231.4,2.5 177.3,2.5      "/>
    </defs>
    <clipPath id="SVGID_2_">
      <use xlink:href="#SVGID_1_"  style="overflow:visible;"/>
    </clipPath>
    <a xlink:href="http://www.example.com/" target="_blank">
      <path class="..."/>
      <rect x="175" width="58px" height="25px" style="fill: transparent;"></rect>
    </a>
  </g>

If I simply remove the line:

    <a xlink:href="http://www.example.com/" target="_blank">

Then everything works fine. I'd like to be able to use links in SVGs.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

geerlingguy created an issue. See original summary.

geerlingguy’s picture

It looks like it's this line in particular, in extlink.js:

var url = this.href.toLowerCase();

In the case of an xlink:href in an SVG, it throws a TypeError:

Uncaught TypeError: this.href.toLowerCase is not a function

If I print this.href to console.log, I get:

SVGAnimatedString {}
animVal: "http://www.example.com/"
baseVal: "http://www.example.com/"
__proto__: SVGAnimatedString
geerlingguy’s picture

Status: Active » Needs review
FileSize
859 bytes

Attached patch fixes the issue, at least for xlink:href links inside SVGs... I can't imagine any other link types at this point.

geerlingguy’s picture

FileSize
933 bytes

Patch above forgot to remove the actual line that was causing all the mayhem! Here's the correct patch.

  • elachlan committed 2760c4a on 8.x-1.x authored by geerlingguy
    Issue #2670902 by geerlingguy: SVG xlink:href breaks Extlink JS
    
    Signed-...

  • elachlan committed cc1954f on 7.x-1.x authored by geerlingguy
    Issue #2670902 by geerlingguy: SVG xlink:href breaks Extlink JS
    
    Signed-...
elachlan’s picture

Status: Needs review » Fixed

Thanks. Now in 7.x and 8.x.

geerlingguy’s picture

@elachlan - Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.