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
d483ce0a
Commit
d483ce0a
authored
Oct 10, 2010
by
Jared Grippe
Committed by
wycats
Jan 14, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added jQuery.subclass
parent
a8fa5f2e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
5 deletions
+98
-5
core.js
src/core.js
+26
-5
core.js
test/unit/core.js
+72
-0
No files found.
src/core.js
View file @
d483ce0a
...
@@ -3,7 +3,7 @@ var jQuery = (function() {
...
@@ -3,7 +3,7 @@ var jQuery = (function() {
// Define a local copy of jQuery
// Define a local copy of jQuery
var
jQuery
=
function
(
selector
,
context
)
{
var
jQuery
=
function
(
selector
,
context
)
{
// The jQuery object is actually just the init constructor 'enhanced'
// The jQuery object is actually just the init constructor 'enhanced'
return
new
jQuery
.
fn
.
init
(
selector
,
context
);
return
new
jQuery
.
fn
.
init
(
selector
,
context
,
rootjQuery
);
},
},
// Map over jQuery in case of overwrite
// Map over jQuery in case of overwrite
...
@@ -78,7 +78,8 @@ var jQuery = function( selector, context ) {
...
@@ -78,7 +78,8 @@ var jQuery = function( selector, context ) {
class2type
=
{};
class2type
=
{};
jQuery
.
fn
=
jQuery
.
prototype
=
{
jQuery
.
fn
=
jQuery
.
prototype
=
{
init
:
function
(
selector
,
context
)
{
constructor
:
jQuery
,
init
:
function
(
selector
,
context
,
rootjQuery
)
{
var
match
,
elem
,
ret
,
doc
;
var
match
,
elem
,
ret
,
doc
;
// Handle $(""), $(null), or $(undefined)
// Handle $(""), $(null), or $(undefined)
...
@@ -112,6 +113,7 @@ jQuery.fn = jQuery.prototype = {
...
@@ -112,6 +113,7 @@ jQuery.fn = jQuery.prototype = {
// HANDLE: $(html) -> $(array)
// HANDLE: $(html) -> $(array)
if
(
match
[
1
]
)
{
if
(
match
[
1
]
)
{
context
=
context
instanceof
jQuery
?
context
[
0
]
:
context
;
doc
=
(
context
?
context
.
ownerDocument
||
context
:
document
);
doc
=
(
context
?
context
.
ownerDocument
||
context
:
document
);
// If a single string is passed in and it's a single tag
// If a single string is passed in and it's a single tag
...
@@ -171,7 +173,7 @@ jQuery.fn = jQuery.prototype = {
...
@@ -171,7 +173,7 @@ jQuery.fn = jQuery.prototype = {
// HANDLE: $(expr, context)
// HANDLE: $(expr, context)
// (which is just equivalent to: $(context).find(expr)
// (which is just equivalent to: $(context).find(expr)
}
else
{
}
else
{
return
jQuery
(
context
).
find
(
selector
);
return
this
.
constructor
(
context
).
find
(
selector
);
}
}
// HANDLE: $(function)
// HANDLE: $(function)
...
@@ -222,7 +224,7 @@ jQuery.fn = jQuery.prototype = {
...
@@ -222,7 +224,7 @@ jQuery.fn = jQuery.prototype = {
// (returning the new matched element set)
// (returning the new matched element set)
pushStack
:
function
(
elems
,
name
,
selector
)
{
pushStack
:
function
(
elems
,
name
,
selector
)
{
// Build a new jQuery matched element set
// Build a new jQuery matched element set
var
ret
=
jQuery
();
var
ret
=
this
.
constructor
();
if
(
jQuery
.
isArray
(
elems
)
)
{
if
(
jQuery
.
isArray
(
elems
)
)
{
push
.
apply
(
ret
,
elems
);
push
.
apply
(
ret
,
elems
);
...
@@ -287,7 +289,7 @@ jQuery.fn = jQuery.prototype = {
...
@@ -287,7 +289,7 @@ jQuery.fn = jQuery.prototype = {
},
},
end
:
function
()
{
end
:
function
()
{
return
this
.
prevObject
||
jQuery
(
null
);
return
this
.
prevObject
||
this
.
constructor
(
null
);
},
},
// For internal use only.
// For internal use only.
...
@@ -960,6 +962,25 @@ jQuery.extend({
...
@@ -960,6 +962,25 @@ jQuery.extend({
return
{
browser
:
match
[
1
]
||
""
,
version
:
match
[
2
]
||
"0"
};
return
{
browser
:
match
[
1
]
||
""
,
version
:
match
[
2
]
||
"0"
};
},
},
subclass
:
function
(){
function
jQuerySubclass
(
selector
,
context
)
{
return
new
jQuerySubclass
.
fn
.
init
(
selector
,
context
);
}
jQuerySubclass
.
superclass
=
this
;
jQuerySubclass
.
fn
=
jQuerySubclass
.
prototype
=
this
();
jQuerySubclass
.
fn
.
constructor
=
jQuerySubclass
;
jQuerySubclass
.
subclass
=
this
.
subclass
;
jQuerySubclass
.
fn
.
init
=
function
init
(
selector
,
context
)
{
if
(
context
&&
context
instanceof
jQuery
&&
!
(
context
instanceof
jQuerySubclass
)){
context
=
jQuerySubclass
(
context
);
}
return
jQuery
.
fn
.
init
.
call
(
this
,
selector
,
context
,
rootjQuerySubclass
);
};
jQuerySubclass
.
fn
.
init
.
prototype
=
jQuerySubclass
.
fn
;
var
rootjQuerySubclass
=
jQuerySubclass
(
document
);
return
jQuerySubclass
;
},
browser
:
{}
browser
:
{}
});
});
...
...
test/unit/core.js
View file @
d483ce0a
...
@@ -1063,3 +1063,75 @@ test("jQuery.when()", function() {
...
@@ -1063,3 +1063,75 @@ test("jQuery.when()", function() {
});
});
}
}
});
});
test
(
"jQuery.subclass"
,
function
(){
expect
(
378
);
var
Subclass
=
jQuery
.
subclass
(),
SubclassSubclass
=
Subclass
.
subclass
(),
jQueryDocument
=
jQuery
(
document
),
selectors
,
contexts
,
methods
,
method
,
arg
,
description
;
jQueryDocument
.
toString
=
function
(){
return
'jQueryDocument'
;
};
Subclass
.
fn
.
subclassMethod
=
function
(){};
SubclassSubclass
.
fn
.
subclassSubclassMethod
=
function
(){};
selectors
=
[
'body'
,
'html, body'
,
'<div></div>'
]
methods
=
[
// all methods that return a new jQuery instance
[
'eq'
,
1
],
[
'add'
,
document
],
[
'end'
],
[
'has'
],
[
'closest'
,
'div'
],
[
'filter'
,
document
],
[
'find'
]
]
contexts
=
[
undefined
,
document
,
jQueryDocument
];
jQuery
.
each
(
selectors
,
function
(
i
,
selector
){
jQuery
.
each
(
methods
,
function
(){
method
=
this
[
0
]
arg
=
this
[
1
]
jQuery
.
each
(
contexts
,
function
(
i
,
context
){
description
=
'("'
+
selector
+
'", '
+
context
+
').'
+
method
+
'('
+
(
arg
||
''
)
+
')'
;
same
(
jQuery
(
selector
,
context
)[
method
](
arg
).
subclassMethod
,
undefined
,
'jQuery'
+
description
+
' doesnt have Subclass methods'
);
same
(
jQuery
(
selector
,
context
)[
method
](
arg
).
subclassSubclassMethod
,
undefined
,
'jQuery'
+
description
+
' doesnt have SubclassSubclass methods'
);
same
(
Subclass
(
selector
,
context
)[
method
](
arg
).
subclassMethod
,
Subclass
.
fn
.
subclassMethod
,
'Subclass'
+
description
+
' has Subclass methods'
);
same
(
Subclass
(
selector
,
context
)[
method
](
arg
).
subclassSubclassMethod
,
undefined
,
'Subclass'
+
description
+
' doesnt have SubclassSubclass methods'
);
same
(
SubclassSubclass
(
selector
,
context
)[
method
](
arg
).
subclassMethod
,
Subclass
.
fn
.
subclassMethod
,
'SubclassSubclass'
+
description
+
' has Subclass methods'
);
same
(
SubclassSubclass
(
selector
,
context
)[
method
](
arg
).
subclassSubclassMethod
,
SubclassSubclass
.
fn
.
subclassSubclassMethod
,
'SubclassSubclass'
+
description
+
' has SubclassSubclass methods'
);
});
});
});
});
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