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
c470db69
Commit
c470db69
authored
Apr 07, 2011
by
Dave Methvin
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:jquery/jquery
parents
14193e44
6832595c
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
535 additions
and
319 deletions
+535
-319
core.js
src/core.js
+10
-17
deferred.js
src/deferred.js
+30
-2
effects.js
src/effects.js
+14
-3
queue.js
src/queue.js
+44
-1
support.js
src/support.js
+142
-152
core.js
test/unit/core.js
+20
-0
deferred.js
test/unit/deferred.js
+252
-126
effects.js
test/unit/effects.js
+23
-18
No files found.
src/core.js
View file @
c470db69
...
...
@@ -565,24 +565,17 @@ jQuery.extend({
noop
:
function
()
{},
// Evalulates a script in a global context
// Evaluates a script in a global context
// Workarounds based on findings by Jim Driscoll
// http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context
globalEval
:
function
(
data
)
{
if
(
data
&&
rnotwhite
.
test
(
data
)
)
{
// Inspired by code by Andrea Giammarchi
// http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
var
head
=
document
.
head
||
document
.
getElementsByTagName
(
"head"
)[
0
]
||
document
.
documentElement
,
script
=
document
.
createElement
(
"script"
);
if
(
jQuery
.
support
.
scriptEval
()
)
{
script
.
appendChild
(
document
.
createTextNode
(
data
)
);
}
else
{
script
.
text
=
data
;
}
// Use insertBefore instead of appendChild to circumvent an IE6 bug.
// This arises when a base node is used (#2709).
head
.
insertBefore
(
script
,
head
.
firstChild
);
head
.
removeChild
(
script
);
if
(
data
&&
rnotwhite
.
test
(
data
)
)
{
// We use execScript on Internet Explorer
// We use an anonymous function so that context is window
// rather than jQuery in Firefox
(
window
.
execScript
||
function
(
data
)
{
window
[
"eval"
].
call
(
window
,
data
);
}
)(
data
);
}
},
...
...
src/deferred.js
View file @
c470db69
(
function
(
jQuery
)
{
var
// Promise methods
promiseMethods
=
"
then done fail isResolved isRejected promise
"
.
split
(
" "
),
promiseMethods
=
"
done fail isResolved isRejected promise then always chain
"
.
split
(
" "
),
// Static reference to slice
sliceDeferred
=
[].
slice
;
...
...
@@ -100,10 +100,38 @@ jQuery.extend({
deferred
.
done
(
doneCallbacks
).
fail
(
failCallbacks
);
return
this
;
},
always
:
function
()
{
return
deferred
.
done
.
apply
(
deferred
,
arguments
).
fail
.
apply
(
this
,
arguments
);
},
fail
:
failDeferred
.
done
,
rejectWith
:
failDeferred
.
resolveWith
,
reject
:
failDeferred
.
resolve
,
isRejected
:
failDeferred
.
isResolved
,
// Chain
chain
:
function
(
fnDone
,
fnFail
)
{
return
jQuery
.
Deferred
(
function
(
newDefer
)
{
jQuery
.
each
(
{
done
:
[
fnDone
,
"resolve"
],
fail
:
[
fnFail
,
"reject"
]
},
function
(
handler
,
data
)
{
var
fn
=
data
[
0
],
action
=
data
[
1
],
returned
;
if
(
jQuery
.
isFunction
(
fn
)
)
{
deferred
[
handler
](
function
()
{
returned
=
fn
.
apply
(
this
,
arguments
);
if
(
jQuery
.
isFunction
(
returned
.
promise
)
)
{
returned
.
promise
().
then
(
newDefer
.
resolve
,
newDefer
.
reject
);
}
else
{
newDefer
[
action
](
returned
);
}
});
}
else
{
deferred
[
handler
](
newDefer
[
action
]
);
}
}
);
}).
promise
();
},
// Get a promise for this deferred
// If obj is provided, the promise aspect is added to the object
promise
:
function
(
obj
)
{
...
...
@@ -169,4 +197,4 @@ jQuery.extend({
}
});
})(
jQuery
);
})(
jQuery
);
\ No newline at end of file
src/effects.js
View file @
c470db69
...
...
@@ -11,7 +11,17 @@ var elemdisplay = {},
[
"width"
,
"marginLeft"
,
"marginRight"
,
"paddingLeft"
,
"paddingRight"
],
// opacity animations
[
"opacity"
]
];
],
fxNow
;
function
clearFxNow
()
{
fxNow
=
undefined
;
}
function
createFxNow
()
{
setTimeout
(
clearFxNow
,
0
);
return
(
fxNow
=
jQuery
.
now
()
);
}
jQuery
.
fn
.
extend
({
show
:
function
(
speed
,
easing
,
callback
)
{
...
...
@@ -349,7 +359,7 @@ jQuery.fx.prototype = {
var
self
=
this
,
fx
=
jQuery
.
fx
;
this
.
startTime
=
jQuery
.
n
ow
();
this
.
startTime
=
fxNow
||
createFxN
ow
();
this
.
start
=
from
;
this
.
end
=
to
;
this
.
unit
=
unit
||
this
.
unit
||
(
jQuery
.
cssNumber
[
this
.
prop
]
?
""
:
"px"
);
...
...
@@ -394,7 +404,8 @@ jQuery.fx.prototype = {
// Each step of an animation
step
:
function
(
gotoEnd
)
{
var
t
=
jQuery
.
now
(),
done
=
true
;
var
t
=
fxNow
||
createFxNow
(),
done
=
true
;
if
(
gotoEnd
||
t
>=
this
.
options
.
duration
+
this
.
startTime
)
{
this
.
now
=
this
.
end
;
...
...
src/queue.js
View file @
c470db69
...
...
@@ -28,7 +28,8 @@ jQuery.extend({
type
=
type
||
"fx"
;
var
queue
=
jQuery
.
queue
(
elem
,
type
),
fn
=
queue
.
shift
();
fn
=
queue
.
shift
(),
defer
;
// If the fx queue is dequeued, always remove the progress sentinel
if
(
fn
===
"inprogress"
)
{
...
...
@@ -49,6 +50,17 @@ jQuery.extend({
if
(
!
queue
.
length
)
{
jQuery
.
removeData
(
elem
,
type
+
"queue"
,
true
);
// Look if we have observers and resolve if needed
if
((
defer
=
jQuery
.
data
(
elem
,
type
+
"defer"
,
undefined
,
true
)
))
{
// Give room for hard-coded callbacks to fire first
// and eventually add another animation on the element
setTimeout
(
function
()
{
if
(
!
jQuery
.
data
(
elem
,
type
+
"queue"
,
undefined
,
true
)
)
{
jQuery
.
removeData
(
elem
,
type
+
"defer"
,
true
);
defer
.
resolve
();
}
},
0
);
}
}
}
});
...
...
@@ -93,6 +105,37 @@ jQuery.fn.extend({
clearQueue
:
function
(
type
)
{
return
this
.
queue
(
type
||
"fx"
,
[]
);
},
// Get a promise resolved when queues of a certain type
// are emptied (fx is the type by default)
promise
:
function
(
type
,
object
)
{
if
(
typeof
type
!==
"string"
)
{
object
=
type
;
type
=
undefined
;
}
type
=
type
||
"fx"
;
var
defer
=
jQuery
.
Deferred
(),
elements
=
this
,
i
=
elements
.
length
,
count
=
1
,
deferDataKey
=
type
+
"defer"
,
queueDataKey
=
type
+
"queue"
;
function
resolve
()
{
if
(
!
(
--
count
)
)
{
defer
.
resolveWith
(
elements
,
[
elements
]
);
}
}
while
(
i
--
)
{
if
((
tmp
=
jQuery
.
data
(
elements
[
i
],
deferDataKey
,
undefined
,
true
)
||
jQuery
.
data
(
elements
[
i
],
queueDataKey
,
undefined
,
true
)
&&
jQuery
.
data
(
elements
[
i
],
deferDataKey
,
jQuery
.
_Deferred
(),
true
)
))
{
count
++
;
tmp
.
done
(
resolve
);
}
}
resolve
();
return
defer
.
promise
();
}
});
...
...
src/support.js
View file @
c470db69
This diff is collapsed.
Click to expand it.
test/unit/core.js
View file @
c470db69
...
...
@@ -172,6 +172,26 @@ test("selector state", function() {
);
});
test
(
"globalEval"
,
function
()
{
expect
(
3
);
jQuery
.
globalEval
(
"var globalEvalTest = true;"
);
ok
(
window
.
globalEvalTest
,
"Test variable declarations are global"
);
window
.
globalEvalTest
=
false
;
jQuery
.
globalEval
(
"globalEvalTest = true;"
);
ok
(
window
.
globalEvalTest
,
"Test variable assignments are global"
);
window
.
globalEvalTest
=
false
;
jQuery
.
globalEval
(
"this.globalEvalTest = true;"
);
ok
(
window
.
globalEvalTest
,
"Test context (this) is the window object"
);
window
.
globalEvalTest
=
undefined
;
});
if
(
!
isLocal
)
{
test
(
"browser"
,
function
()
{
stop
();
...
...
test/unit/deferred.js
View file @
c470db69
This diff is collapsed.
Click to expand it.
test/unit/effects.js
View file @
c470db69
...
...
@@ -717,59 +717,64 @@ jQuery.each( {
var
anim
=
{
width
:
t_w
,
height
:
t_h
,
opacity
:
t_o
};
elem
.
animate
(
anim
,
50
,
function
(){
elem
.
animate
(
anim
,
50
);
jQuery
.
when
(
elem
).
done
(
function
(
elem
){
elem
=
elem
[
0
];
if
(
t_w
==
"show"
)
equals
(
this
.
style
.
display
,
"block"
,
"Showing, display should block: "
+
this
.
style
.
display
);
equals
(
elem
.
style
.
display
,
"block"
,
"Showing, display should block: "
+
elem
.
style
.
display
);
if
(
t_w
==
"hide"
||
t_w
==
"show"
)
ok
(
f_w
===
""
?
this
.
style
.
width
===
f_w
:
this
.
style
.
width
.
indexOf
(
f_w
)
===
0
,
"Width must be reset to "
+
f_w
+
": "
+
this
.
style
.
width
);
ok
(
f_w
===
""
?
elem
.
style
.
width
===
f_w
:
elem
.
style
.
width
.
indexOf
(
f_w
)
===
0
,
"Width must be reset to "
+
f_w
+
": "
+
elem
.
style
.
width
);
if
(
t_h
==
"hide"
||
t_h
==
"show"
)
ok
(
f_h
===
""
?
this
.
style
.
height
===
f_h
:
this
.
style
.
height
.
indexOf
(
f_h
)
===
0
,
"Height must be reset to "
+
f_h
+
": "
+
this
.
style
.
height
);
ok
(
f_h
===
""
?
elem
.
style
.
height
===
f_h
:
elem
.
style
.
height
.
indexOf
(
f_h
)
===
0
,
"Height must be reset to "
+
f_h
+
": "
+
elem
.
style
.
height
);
var
cur_o
=
jQuery
.
style
(
this
,
"opacity"
);
var
cur_o
=
jQuery
.
style
(
elem
,
"opacity"
);
if
(
t_o
==
"hide"
||
t_o
==
"show"
)
equals
(
cur_o
,
f_o
,
"Opacity must be reset to "
+
f_o
+
": "
+
cur_o
);
if
(
t_w
==
"hide"
)
equals
(
this
.
style
.
display
,
"none"
,
"Hiding, display should be none: "
+
this
.
style
.
display
);
equals
(
elem
.
style
.
display
,
"none"
,
"Hiding, display should be none: "
+
elem
.
style
.
display
);
if
(
t_o
.
constructor
==
Number
)
{
equals
(
cur_o
,
t_o
,
"Final opacity should be "
+
t_o
+
": "
+
cur_o
);
ok
(
jQuery
.
css
(
this
,
"opacity"
)
!=
""
||
cur_o
==
t_o
,
"Opacity should be explicitly set to "
+
t_o
+
", is instead: "
+
cur_o
);
ok
(
jQuery
.
css
(
elem
,
"opacity"
)
!=
""
||
cur_o
==
t_o
,
"Opacity should be explicitly set to "
+
t_o
+
", is instead: "
+
cur_o
);
}
if
(
t_w
.
constructor
==
Number
)
{
equals
(
this
.
style
.
width
,
t_w
+
"px"
,
"Final width should be "
+
t_w
+
": "
+
this
.
style
.
width
);
equals
(
elem
.
style
.
width
,
t_w
+
"px"
,
"Final width should be "
+
t_w
+
": "
+
elem
.
style
.
width
);
var
cur_w
=
jQuery
.
css
(
this
,
"width"
);
var
cur_w
=
jQuery
.
css
(
elem
,
"width"
);
ok
(
this
.
style
.
width
!=
""
||
cur_w
==
t_w
,
"Width should be explicitly set to "
+
t_w
+
", is instead: "
+
cur_w
);
ok
(
elem
.
style
.
width
!=
""
||
cur_w
==
t_w
,
"Width should be explicitly set to "
+
t_w
+
", is instead: "
+
cur_w
);
}
if
(
t_h
.
constructor
==
Number
)
{
equals
(
this
.
style
.
height
,
t_h
+
"px"
,
"Final height should be "
+
t_h
+
": "
+
this
.
style
.
height
);
equals
(
elem
.
style
.
height
,
t_h
+
"px"
,
"Final height should be "
+
t_h
+
": "
+
elem
.
style
.
height
);
var
cur_h
=
jQuery
.
css
(
this
,
"height"
);
var
cur_h
=
jQuery
.
css
(
elem
,
"height"
);
ok
(
this
.
style
.
height
!=
""
||
cur_h
==
t_h
,
"Height should be explicitly set to "
+
t_h
+
", is instead: "
+
cur_w
);
ok
(
elem
.
style
.
height
!=
""
||
cur_h
==
t_h
,
"Height should be explicitly set to "
+
t_h
+
", is instead: "
+
cur_w
);
}
if
(
t_h
==
"show"
)
{
var
old_h
=
jQuery
.
css
(
this
,
"height"
);
jQuery
(
this
).
append
(
"<br/>Some more text<br/>and some more..."
);
var
old_h
=
jQuery
.
css
(
elem
,
"height"
);
jQuery
(
elem
).
append
(
"<br/>Some more text<br/>and some more..."
);
if
(
/Auto/
.
test
(
fn
)
)
{
notEqual
(
jQuery
.
css
(
this
,
"height"
),
old_h
,
"Make sure height is auto."
);
notEqual
(
jQuery
.
css
(
elem
,
"height"
),
old_h
,
"Make sure height is auto."
);
}
else
{
equals
(
jQuery
.
css
(
this
,
"height"
),
old_h
,
"Make sure height is not auto."
);
equals
(
jQuery
.
css
(
elem
,
"height"
),
old_h
,
"Make sure height is not auto."
);
}
}
// manually remove generated element
jQuery
(
this
).
remove
();
jQuery
(
elem
).
remove
();
start
();
});
...
...
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