Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jquery
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
jquery
Commits
f71a6ec6
Commit
f71a6ec6
authored
Jul 01, 2012
by
timmywil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add back ID shortcut. It's about 3 times faster than going through jQuery.fn.find and merging.
parent
f18b7594
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
14 deletions
+40
-14
core.js
src/core.js
+40
-14
No files found.
src/core.js
View file @
f71a6ec6
...
...
@@ -39,7 +39,7 @@ var
// A simple way to check for HTML strings
// Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
r
htmlString
=
/^
(?:[^
#<
]
*
(
<
[\w\W]
+>
)[^
>
]
*
$
)
/
,
r
quickExpr
=
/^
(?:[^
#<
]
*
(
<
[\w\W]
+>
)[^
>
]
*$|#
([\w\-]
*
)
$
)
/
,
// Match a standalone tag
rsingleTag
=
/^<
(\w
+
)\s
*
\/?
>
(?:
<
\/\1
>
)?
$/
,
...
...
@@ -79,8 +79,8 @@ jQuery.fn = jQuery.prototype = {
init
:
function
(
selector
,
context
,
rootjQuery
)
{
var
match
,
elem
,
ret
,
doc
;
// Handle $(""), $(null), $(undefined), $(false)
, or $("#") for location.hash
if
(
!
selector
||
selector
===
"#"
)
{
// Handle $(""), $(null), $(undefined), $(false)
if
(
!
selector
)
{
return
this
;
}
...
...
@@ -98,21 +98,47 @@ jQuery.fn = jQuery.prototype = {
match
=
[
null
,
selector
,
null
];
}
else
{
match
=
r
htmlString
.
exec
(
selector
);
match
=
r
quickExpr
.
exec
(
selector
);
}
// HANDLE: $(html) -> $(array)
if
(
match
&&
match
[
1
]
)
{
context
=
context
instanceof
jQuery
?
context
[
0
]
:
context
;
doc
=
(
context
&&
context
.
nodeType
?
context
.
ownerDocument
||
context
:
document
);
// Match html or make sure no context is specified for #id
if
(
match
&&
(
match
[
1
]
||
!
context
)
)
{
// scripts is true for back-compat
selector
=
jQuery
.
parseHTML
(
match
[
1
],
doc
,
true
);
if
(
rsingleTag
.
test
(
match
[
1
]
)
&&
jQuery
.
isPlainObject
(
context
)
)
{
this
.
attr
.
call
(
selector
,
context
,
true
);
}
// HANDLE: $(html) -> $(array)
if
(
match
[
1
]
)
{
context
=
context
instanceof
jQuery
?
context
[
0
]
:
context
;
doc
=
(
context
&&
context
.
nodeType
?
context
.
ownerDocument
||
context
:
document
);
// scripts is true for back-compat
selector
=
jQuery
.
parseHTML
(
match
[
1
],
doc
,
true
);
if
(
rsingleTag
.
test
(
match
[
1
]
)
&&
jQuery
.
isPlainObject
(
context
)
)
{
this
.
attr
.
call
(
selector
,
context
,
true
);
}
return
jQuery
.
merge
(
this
,
selector
);
// HANDLE: $(#id)
}
else
{
elem
=
document
.
getElementById
(
match
[
2
]
);
// Check parentNode to catch when Blackberry 4.6 returns
// nodes that are no longer in the document #6963
if
(
elem
&&
elem
.
parentNode
)
{
// Handle the case where IE and Opera return items
// by name instead of ID
if
(
elem
.
id
!==
match
[
2
]
)
{
return
rootjQuery
.
find
(
selector
);
}
return
jQuery
.
merge
(
this
,
selector
);
// Otherwise, we inject the element directly into the jQuery object
this
.
length
=
1
;
this
[
0
]
=
elem
;
}
this
.
context
=
document
;
this
.
selector
=
selector
;
return
this
;
}
// HANDLE: $(expr, $(...))
}
else
if
(
!
context
||
context
.
jquery
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment