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
c2d6847d
Commit
c2d6847d
authored
Dec 01, 2012
by
Dave Methvin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #12989. Remove ajax "global" event behavior.
parent
b382af68
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
143 deletions
+43
-143
event.js
src/event.js
+11
-27
ajax.js
test/unit/ajax.js
+32
-116
No files found.
src/event.js
View file @
c2d6847d
...
...
@@ -198,33 +198,30 @@ jQuery.event = {
},
trigger
:
function
(
event
,
data
,
elem
,
onlyHandlers
)
{
// Don't do events on text and comment nodes
if
(
elem
&&
(
elem
.
nodeType
===
3
||
elem
.
nodeType
===
8
)
)
{
return
;
}
// Event object or event type
var
cache
,
i
,
cur
,
old
,
ontype
,
special
,
handle
,
eventPath
,
bubbleType
,
var
i
,
cur
,
old
,
ontype
,
special
,
handle
,
eventPath
,
bubbleType
,
type
=
event
.
type
||
event
,
namespaces
=
event
.
namespace
?
event
.
namespace
.
split
(
"."
)
:
[];
elem
=
elem
||
document
;
// Don't do events on text and comment nodes
if
(
elem
.
nodeType
===
3
||
elem
.
nodeType
===
8
)
{
return
;
}
// focus/blur morphs to focusin/out; ensure we're not firing them right now
if
(
rfocusMorph
.
test
(
type
+
jQuery
.
event
.
triggered
)
)
{
return
;
}
if
(
type
.
indexOf
(
"."
)
>=
0
)
{
if
(
type
.
indexOf
(
"."
)
>=
0
)
{
// Namespaced trigger; create a regexp to match event type in handle()
namespaces
=
type
.
split
(
"."
);
type
=
namespaces
.
shift
();
namespaces
.
sort
();
}
if
(
!
elem
&&
!
jQuery
.
event
.
global
[
type
]
)
{
// No jQuery handlers for this event type, and it can't have inline handlers
return
;
}
// Caller can pass in an Event, Object, or just an event type string
event
=
typeof
event
===
"object"
?
// jQuery.Event object
...
...
@@ -236,22 +233,9 @@ jQuery.event = {
event
.
type
=
type
;
event
.
isTrigger
=
true
;
event
.
namespace
=
namespaces
.
join
(
"."
);
event
.
namespace
=
namespaces
.
join
(
"."
);
event
.
namespace_re
=
event
.
namespace
?
new
RegExp
(
"(^|
\\
.)"
+
namespaces
.
join
(
"
\\
.(?:.*
\\
.|)"
)
+
"(
\\
.|$)"
)
:
null
;
ontype
=
type
.
indexOf
(
":"
)
<
0
?
"on"
+
type
:
""
;
// Handle a global trigger
if
(
!
elem
)
{
// TODO: Stop taunting the data cache; remove global events and always attach to document
cache
=
jQuery
.
cache
;
for
(
i
in
cache
)
{
if
(
cache
[
i
].
events
&&
cache
[
i
].
events
[
type
]
)
{
jQuery
.
event
.
trigger
(
event
,
data
,
cache
[
i
].
handle
.
elem
,
true
);
}
}
return
;
}
ontype
=
type
.
indexOf
(
":"
)
<
0
?
"on"
+
type
:
""
;
// Clean up the event in case it is being reused
event
.
result
=
undefined
;
...
...
test/unit/ajax.js
View file @
c2d6847d
...
...
@@ -7,7 +7,10 @@ module( "ajax", {
return
callback
;
};
},
teardown
:
moduleTeardown
teardown
:
function
()
{
jQuery
(
document
).
off
(
"ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError ajaxSuccess"
);
moduleTeardown
();
}
});
(
function
()
{
...
...
@@ -16,24 +19,16 @@ module( "ajax", {
return
;
}
function
addGlobalEvents
()
{
jQuery
(
document
).
on
(
"ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError ajaxSuccess"
,
function
(
e
)
{
ok
(
true
,
e
.
type
);
});
}
//----------- jQuery.ajax()
ajaxTest
(
"jQuery.ajax() - success callbacks"
,
8
,
{
setup
:
function
()
{
jQuery
(
"#foo"
).
ajaxStart
(
function
()
{
ok
(
true
,
"ajaxStart"
);
}).
ajaxStop
(
function
()
{
ok
(
true
,
"ajaxStop"
);
}).
ajaxSend
(
function
()
{
ok
(
true
,
"ajaxSend"
);
}).
ajaxComplete
(
function
()
{
ok
(
true
,
"ajaxComplete"
);
}).
ajaxError
(
function
()
{
ok
(
false
,
"ajaxError"
);
}).
ajaxSuccess
(
function
()
{
ok
(
true
,
"ajaxSuccess"
);
});
},
setup
:
addGlobalEvents
,
url
:
url
(
"data/name.html"
),
beforeSend
:
function
()
{
ok
(
true
,
"beforeSend"
);
...
...
@@ -47,21 +42,7 @@ module( "ajax", {
});
ajaxTest
(
"jQuery.ajax() - success callbacks - (url, options) syntax"
,
8
,
{
setup
:
function
()
{
jQuery
(
"#foo"
).
ajaxStart
(
function
()
{
ok
(
true
,
"ajaxStart"
);
}).
ajaxStop
(
function
()
{
ok
(
true
,
"ajaxStop"
);
}).
ajaxSend
(
function
()
{
ok
(
true
,
"ajaxSend"
);
}).
ajaxComplete
(
function
()
{
ok
(
true
,
"ajaxComplete"
);
}).
ajaxError
(
function
()
{
ok
(
false
,
"ajaxError"
);
}).
ajaxSuccess
(
function
()
{
ok
(
true
,
"ajaxSuccess"
);
});
},
setup
:
addGlobalEvents
,
create
:
function
(
options
)
{
return
jQuery
.
ajax
(
url
(
"data/name.html"
),
options
);
},
...
...
@@ -77,21 +58,7 @@ module( "ajax", {
});
ajaxTest
(
"jQuery.ajax() - success callbacks (late binding)"
,
8
,
{
setup
:
function
()
{
jQuery
(
"#foo"
).
ajaxStart
(
function
()
{
ok
(
true
,
"ajaxStart"
);
}).
ajaxStop
(
function
()
{
ok
(
true
,
"ajaxStop"
);
}).
ajaxSend
(
function
()
{
ok
(
true
,
"ajaxSend"
);
}).
ajaxComplete
(
function
()
{
ok
(
true
,
"ajaxComplete"
);
}).
ajaxError
(
function
()
{
ok
(
false
,
"ajaxError"
);
}).
ajaxSuccess
(
function
()
{
ok
(
true
,
"ajaxSuccess"
);
});
},
setup
:
addGlobalEvents
,
url
:
url
(
"data/name.html"
),
beforeSend
:
function
()
{
ok
(
true
,
"beforeSend"
);
...
...
@@ -109,21 +76,7 @@ module( "ajax", {
});
ajaxTest
(
"jQuery.ajax() - success callbacks (oncomplete binding)"
,
8
,
{
setup
:
function
()
{
jQuery
(
"#foo"
).
ajaxStart
(
function
()
{
ok
(
true
,
"ajaxStart"
);
}).
ajaxStop
(
function
()
{
ok
(
true
,
"ajaxStop"
);
}).
ajaxSend
(
function
()
{
ok
(
true
,
"ajaxSend"
);
}).
ajaxComplete
(
function
()
{
ok
(
true
,
"ajaxComplete"
);
}).
ajaxError
(
function
()
{
ok
(
false
,
"ajaxError"
);
}).
ajaxSuccess
(
function
()
{
ok
(
true
,
"ajaxSuccess"
);
});
},
setup
:
addGlobalEvents
,
url
:
url
(
"data/name.html"
),
beforeSend
:
function
()
{
ok
(
true
,
"beforeSend"
);
...
...
@@ -141,21 +94,7 @@ module( "ajax", {
});
ajaxTest
(
"jQuery.ajax() - error callbacks"
,
8
,
{
setup
:
function
()
{
jQuery
(
"#foo"
).
ajaxStart
(
function
()
{
ok
(
true
,
"ajaxStart"
);
}).
ajaxStop
(
function
()
{
ok
(
true
,
"ajaxStop"
);
}).
ajaxSend
(
function
()
{
ok
(
true
,
"ajaxSend"
);
}).
ajaxComplete
(
function
()
{
ok
(
true
,
"ajaxComplete"
);
}).
ajaxError
(
function
()
{
ok
(
true
,
"ajaxError"
);
}).
ajaxSuccess
(
function
()
{
ok
(
false
,
"ajaxSuccess"
);
});
},
setup
:
addGlobalEvents
,
url
:
url
(
"data/name.php?wait=5"
),
beforeSend
:
function
()
{
ok
(
true
,
"beforeSend"
);
...
...
@@ -237,7 +176,7 @@ module( "ajax", {
ajaxTest
(
"jQuery.ajax() - headers"
,
4
,
{
setup
:
function
()
{
jQuery
(
"#foo"
).
ajaxSend
(
function
(
evt
,
xhr
)
{
jQuery
(
document
).
ajaxSend
(
function
(
evt
,
xhr
)
{
xhr
.
setRequestHeader
(
"ajax-send"
,
"test"
);
});
},
...
...
@@ -394,18 +333,8 @@ module( "ajax", {
];
});
ajaxTest
(
"jQuery.ajax() - abort"
,
8
,
{
setup
:
function
()
{
jQuery
(
"#foo"
).
ajaxStart
(
function
()
{
ok
(
true
,
"ajaxStart"
);
}).
ajaxStop
(
function
()
{
ok
(
true
,
"ajaxStop"
);
}).
ajaxSend
(
function
()
{
ok
(
true
,
"ajaxSend"
);
}).
ajaxComplete
(
function
()
{
ok
(
true
,
"ajaxComplete"
);
});
},
ajaxTest
(
"jQuery.ajax() - abort"
,
9
,
{
setup
:
addGlobalEvents
,
url
:
url
(
"data/name.php?wait=5"
),
beforeSend
:
function
()
{
ok
(
true
,
"beforeSend"
);
...
...
@@ -660,14 +589,14 @@ module( "ajax", {
var
success
=
function
()
{
successCount
++
;
};
jQuery
(
"#foo"
).
ajaxError
(
function
(
e
,
xml
,
s
,
ex
)
{
jQuery
(
document
).
on
(
"ajaxError.passthru"
,
function
(
e
,
xml
,
s
,
ex
)
{
errorCount
++
;
errorEx
+=
": "
+
xml
.
status
;
});
jQuery
(
"#foo"
).
one
(
"ajaxStop"
,
function
()
{
jQuery
(
document
).
one
(
"ajaxStop"
,
function
()
{
equal
(
successCount
,
5
,
"Check all ajax calls successful"
);
equal
(
errorCount
,
0
,
"Check no ajax errors (status"
+
errorEx
+
")"
);
jQuery
(
"#foo"
).
unbind
(
"ajaxError
"
);
jQuery
(
document
).
off
(
"ajaxError.passthru
"
);
start
();
});
...
...
@@ -1592,7 +1521,7 @@ module( "ajax", {
pass
=
function
()
{
ok
(
passed
++
<
2
,
"Error callback executed"
);
if
(
passed
==
2
)
{
jQuery
(
"#qunit-fixture"
).
unbind
(
"ajaxError
"
);
jQuery
(
document
).
off
(
"ajaxError.setupTest
"
);
start
();
}
},
...
...
@@ -1601,7 +1530,7 @@ module( "ajax", {
start
();
};
jQuery
(
"#qunit-fixture"
).
ajaxError
(
pass
);
jQuery
(
document
).
on
(
"ajaxError.setupTest"
,
pass
);
jQuery
.
ajaxSetup
({
timeout
:
1000
...
...
@@ -1767,20 +1696,8 @@ module( "ajax", {
});
asyncTest
(
"jQuery.fn.load() - 404 error callbacks"
,
6
,
function
()
{
jQuery
(
"#foo"
).
ajaxStart
(
function
()
{
ok
(
true
,
"ajaxStart"
);
}).
ajaxStop
(
function
()
{
ok
(
true
,
"ajaxStop"
);
start
();
}).
ajaxSend
(
function
()
{
ok
(
true
,
"ajaxSend"
);
}).
ajaxComplete
(
function
()
{
ok
(
true
,
"ajaxComplete"
);
}).
ajaxError
(
function
()
{
ok
(
true
,
"ajaxError"
);
}).
ajaxSuccess
(
function
()
{
ok
(
false
,
"ajaxSuccess"
);
});
addGlobalEvents
();
jQuery
(
document
).
ajaxStop
(
start
);
jQuery
(
"<div/>"
).
load
(
"data/404.html"
,
function
()
{
ok
(
true
,
"complete"
);
});
...
...
@@ -1921,9 +1838,9 @@ module( "ajax", {
jQuery
.
ajaxSetup
({
dataType
:
"json"
});
jQuery
(
"#first"
).
ajaxComplete
(
function
(
e
,
xml
,
s
)
{
jQuery
(
document
).
ajaxComplete
(
function
(
e
,
xml
,
s
)
{
strictEqual
(
s
.
dataType
,
"html"
,
"Verify the load() dataType was html"
);
jQuery
(
"#first"
).
unbind
(
"ajaxComplete"
);
jQuery
(
document
).
unbind
(
"ajaxComplete"
);
start
();
});
jQuery
(
"#first"
).
load
(
"data/test3.html"
);
...
...
@@ -1938,12 +1855,11 @@ module( "ajax", {
"foo"
:
"bar"
}
});
jQuery
(
"#foo"
)
.
load
(
"data/echoQuery.php"
,
data
)
.
ajaxComplete
(
function
(
event
,
jqXHR
,
options
)
{
ok
(
~
options
.
data
.
indexOf
(
"foo=bar"
),
"Data from ajaxSettings was used"
);
start
();
});
jQuery
(
"#foo"
).
load
(
"data/echoQuery.php"
,
data
);
jQuery
(
document
).
ajaxComplete
(
function
(
event
,
jqXHR
,
options
)
{
ok
(
~
options
.
data
.
indexOf
(
"foo=bar"
),
"Data from ajaxSettings was used"
);
start
();
});
});
//----------- jQuery.post()
...
...
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