Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions jquery.pjax.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,21 @@ 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
// links in a new tab as normal.
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
Expand All @@ -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])
}
}

Expand Down
11 changes: 11 additions & 0 deletions test/unit/fn_pjax.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
}
4 changes: 4 additions & 0 deletions test/views/home.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
<input name="bar" value="2">
</form>

<svg version="1.1" xmlns="http://www.w3.org/2000/svg">
<a href="/hello.html"></a>
</svg>

<div style="width:500px;height:10000px;"></div>

<script type="text/javascript">window.parent.iframeLoad(window)</script>