Skip to content

Commit 7160655

Browse files
committed
Avoid re-wrapping a DOM node repeatedly
1 parent bb2892f commit 7160655

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

jquery.pjax.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ function handleClick(event, container, options) {
5757
options = optionsFor(container, options)
5858

5959
var link = event.currentTarget
60+
var $link = $(link)
6061

6162
if (link.tagName.toUpperCase() !== 'A')
6263
throw "$.fn.pjax or $.pjax.click requires an anchor element"
@@ -80,18 +81,18 @@ function handleClick(event, container, options) {
8081

8182
var defaults = {
8283
url: link.href,
83-
container: $(link).attr('data-pjax'),
84+
container: $link.attr('data-pjax'),
8485
target: link
8586
}
8687

8788
var opts = $.extend({}, defaults, options)
8889
var clickEvent = $.Event('pjax:click')
89-
$(link).trigger(clickEvent, [opts])
90+
$link.trigger(clickEvent, [opts])
9091

9192
if (!clickEvent.isDefaultPrevented()) {
9293
pjax(opts)
9394
event.preventDefault()
94-
$(link).trigger('pjax:clicked', [opts])
95+
$link.trigger('pjax:clicked', [opts])
9596
}
9697
}
9798

@@ -131,12 +132,12 @@ function handleSubmit(event, container, options) {
131132
defaults.contentType = false;
132133
} else {
133134
// Can't handle file uploads, exit
134-
if ($(form).find(':file').length) {
135+
if ($form.find(':file').length) {
135136
return;
136137
}
137138

138139
// Fallback to manually serializing the fields
139-
defaults.data = $(form).serializeArray();
140+
defaults.data = $form.serializeArray()
140141
}
141142

142143
pjax($.extend({}, defaults, options))

0 commit comments

Comments
 (0)