diff --git a/jquery.pjax.js b/jquery.pjax.js index bfcccce4..4077ec3e 100644 --- a/jquery.pjax.js +++ b/jquery.pjax.js @@ -61,9 +61,9 @@ function fnPjax(selector, container, options) { function handleClick(event, container, options) { options = optionsFor(container, options) - var link = event.currentTarget + var el = event.currentTarget - if (link.tagName.toUpperCase() !== 'A') + if (el.tagName.toUpperCase() !== 'A') throw "$.fn.pjax or $.pjax.click requires an anchor element" // Middle click, cmd click, and ctrl click should open @@ -71,6 +71,11 @@ function handleClick(event, container, options) { if ( event.which > 1 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey ) return + var link = el + if (link.href instanceof SVGAnimatedString) { + link = parseURL(link.getAttribute('href')) + } + // Ignore cross origin links if ( location.protocol !== link.protocol || location.hostname !== link.hostname ) return @@ -85,18 +90,18 @@ function handleClick(event, container, options) { var defaults = { url: link.href, - container: $(link).attr('data-pjax'), - target: link + container: $(el).attr('data-pjax'), + target: el } var opts = $.extend({}, defaults, options) var clickEvent = $.Event('pjax:click') - $(link).trigger(clickEvent, [opts]) + $(el).trigger(clickEvent, [opts]) if (!clickEvent.isDefaultPrevented()) { pjax(opts) event.preventDefault() - $(link).trigger('pjax:clicked', [opts]) + $(el).trigger('pjax:clicked', [opts]) } } diff --git a/test/unit/fn_pjax.js b/test/unit/fn_pjax.js index 4e1488d9..2cb00ff0 100644 --- a/test/unit/fn_pjax.js +++ b/test/unit/fn_pjax.js @@ -255,4 +255,15 @@ if ($.support.pjax) { frame.$("a[href='/dinosaurs.html']").click() }) + + asyncTest("supports links inside svg", function() { + var frame = this.frame + + frame.$("#main").pjax("a").on("pjax:end", function() { + equal(frame.location.pathname, "/hello.html") + start() + }) + + frame.$("svg a[href='/hello.html']").click() + }) } diff --git a/test/views/home.erb b/test/views/home.erb index bbf1493c..3d83c26d 100644 --- a/test/views/home.erb +++ b/test/views/home.erb @@ -14,6 +14,10 @@ + +