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
30249ab5
Commit
30249ab5
authored
Sep 12, 2011
by
Dave Methvin
Committed by
timmywil
Sep 19, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve delegation/change tests to display event firing order and duplicate events.
parent
06e56acb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
158 additions
and
228 deletions
+158
-228
delegatetest.html
test/delegatetest.html
+158
-228
No files found.
test/delegatetest.html
View file @
30249ab5
<!DOCTYPE html>
<html>
<html>
<head>
<head>
<script
src=
'../dist/jquery.js'
type=
'text/javascript'
></script>
<title>
Change Tests
</title>
<style>
<script>
.red
{
var
version
=
location
.
search
&&
location
.
search
.
substr
(
1
);
background-color
:
red
;
if
(
version
)
{
border
:
solid
3px
red
;
version
=
"http://code.jquery.com/jquery-"
+
version
+
".js"
;
}
}
else
{
</style>
version
=
"../dist/jquery.js"
;
</head>
}
<body>
document
.
write
(
'<script src="'
+
version
+
'"><'
+
'/script>'
);
<h2>
Change Tests
</h2>
</script>
<table>
<style>
<tr>
table
{
<td>
border-collapse
:
collapse
;
Change each:
empty-cells
:
show
;
</td>
}
<td>
th
{
<select
class=
'select_test'
>
text-align
:
left
;
<option
value=
'one'
>
change me 1
</option>
}
<option
value=
'two'
>
change me 2
</option>
thead
td
{
<option
value=
'three'
>
change me 3
</option>
width
:
11%
;
</select>
}
<select
class=
'select_test'
>
tbody
td
{
<option
value=
'one'
>
change me 1
</option>
background
:
#fed
;
<option
value=
'two'
selected=
"selected"
>
change me 2
</option>
}
<option
value=
'three'
>
change me 3
</option>
th
,
td
{
</select>
border
:
1px
solid
#bbb
;
</td>
}
<td>
</style>
<select
class=
'mselect_test'
multiple=
"multiple"
>
</head>
<option
value=
'one'
>
change me 1
</option>
<body>
<option
value=
'two'
>
change me 2
</option>
<h2>
Delegate Tests (
<span
id=
"version"
>
BAD FILE IN URL
</span>
,
<span
id=
"fileversion"
>
x
</span>
)
</h2>
<option
value=
'three'
>
change me 3
</option>
</select>
<table
id=
"changes"
>
</td>
<thead>
<td>
<tr>
<input
type=
"checkbox"
class=
"checkbox_test"
name=
"mycheckbox"
id=
"checkbox1"
/>
<th>
<label
for=
"checkbox1"
>
Checkbox 1
</label><br/>
Controls:
<input
type=
"checkbox"
class=
"checkbox_test"
name=
"mycheckbox"
id=
"checkbox2"
/>
</th>
<label
for=
"checkbox2"
>
Checkbox 2
</label><br
/>
<td
id=
"select-one"
>
<input
type=
"checkbox"
class=
"checkbox_test"
name=
"mycheckbox"
id=
"checkbox3"
disabled=
"disabled"
/>
<select>
<label
for=
"checkbox3"
>
Checkbox 3
</label>
<option
value=
'one1'
>
one1
</option>
</td>
<option
value=
'one2'
>
one2
</option>
<td>
<option
value=
'one3'
>
one3
</option>
<button
class=
"button_test"
name=
"mybutton1"
id=
"button1"
>
Button
</button><br
/>
</select>
<button
class=
"button_test"
name=
"mybutton1"
id=
"button1"
><span>
Button w/ child
</span></button><br
/>
<select>
<button
class=
"button_test"
name=
"mybutton1"
id=
"button1"
disabled=
"disabled"
>
Button Disabled
</button><br
/>
<option
value=
'two1'
>
two1
</option>
<button
class=
"button_test"
name=
"mybutton1"
id=
"button1"
disabled=
"disabled"
><span
disabled=
"disabled"
>
Button w/ child Dis.
</span></button><br
/>
<option
value=
'two2'
selected=
"selected"
>
two2
</option>
</td>
<option
value=
'two3'
>
two3
</option>
<td>
</select>
<input
type=
"radio"
class=
"radio_test"
name=
"myradio"
id=
"radio1"
/>
</td>
<label
for=
"radio1"
>
Radio1
</label><br/>
<td
id=
"select-mult"
>
<input
type=
"radio"
class=
"radio_test"
name=
"myradio"
id=
"radio2"
/>
<select
multiple=
"multiple"
>
<label
for=
"radio2"
>
Radio2
</label><br
/>
<option
value=
'multi1'
>
multi1
</option>
<input
type=
"radio"
class=
"radio_test"
name=
"myradio"
id=
"radio3"
disabled=
"disabled"
/>
<option
value=
'multi2'
>
multi2
</option>
<label
for=
"radio3"
>
Radio3
</label>
<option
value=
'multi3'
>
multi3
</option>
</td>
</select>
<td>
</td>
<input
class=
"file_test"
id=
"file1"
type=
"file"
/>
<td
id=
"checkbox"
>
<td>
<input
type=
"checkbox"
name=
"mycheckbox"
id=
"check1"
/>
<input
class=
'test'
value=
''
id=
'input'
size=
'10'
/>
<label
for=
"check1"
>
check1
</label><br/>
<input
class=
'test'
value=
'test'
id=
'input2'
size=
'10'
readonly=
"readonly"
/>
<input
type=
"checkbox"
name=
"mycheckbox"
id=
"check2"
/>
</td>
<label
for=
"check2"
>
check2
</label><br
/>
<td>
<input
type=
"checkbox"
name=
"mycheckbox"
id=
"check3"
disabled=
"disabled"
/>
<textarea
rows=
'2'
></textarea>
<label
for=
"check3"
>
check3
</label>
</td>
</td>
</td>
<td
id=
"button"
>
<td>
$(document).bind('change')
<br
/>
<button
name=
"mybutton1"
id=
"button1"
>
Button
</button><br
/>
$(document).bind('click')
<button
name=
"mybutton2"
id=
"button2"
><span>
Button w/ child
</span></button><br
/>
</td>
<button
name=
"mybutton3"
id=
"button3"
disabled=
"disabled"
>
Button Disabled
</button><br
/>
</tr>
<button
name=
"mybutton4"
id=
"button4"
disabled=
"disabled"
><span
disabled=
"disabled"
>
Button, child Disabled
</span></button><br
/>
<tr>
</td>
<td>
Live:
</td>
<td
id=
"radio"
>
<td
id=
'select'
class=
"red"
>
SELECT
</td>
<input
type=
"radio"
name=
"myradio"
id=
"radio1"
/>
<td
id=
'mselect'
class=
"red"
>
MULTI
</td>
<label
for=
"radio1"
>
Radio1
</label><br/>
<td
id=
'checkbox'
class=
"red"
>
CHECKBOX
</td>
<input
type=
"radio"
name=
"myradio"
id=
"radio2"
/>
<td
id=
'button'
class=
"red"
>
BUTTON
</td>
<label
for=
"radio2"
>
Radio2
</label><br
/>
<td
id=
'radio'
class=
"red"
>
RADIO
</td>
<input
type=
"radio"
name=
"myradio"
id=
"radio3"
disabled=
"disabled"
/>
<td
id=
'file'
class=
"red"
>
FILE
</td>
<label
for=
"radio3"
>
Radio3
</label>
<td
id=
'text'
class=
"red"
>
TEXT
</td>
</td>
<td
id=
'textarea'
class=
"red"
>
TEXTAREA
</td>
<td
id=
"file"
>
<td
id=
'boundChange'
class=
"red"
>
DOCUMENT
</td>
<input
class=
"file_test"
id=
"file1"
type=
"file"
/>
</tr>
</td>
<tr>
<td
id=
"text"
>
<td>
Bind:
</td>
<input
class=
'test'
value=
''
id=
'input'
size=
'10'
/>
<td
id=
'selectbind'
class=
"red"
>
SELECT
</td>
<input
class=
'test'
value=
'test'
id=
'input2'
size=
'10'
readonly=
"readonly"
/>
<td
id=
'mselectbind'
class=
"red"
>
MULTI
</td>
</td>
<td
id=
'checkboxbind'
class=
"red"
>
CHECKBOX
</td>
<td
id=
"textarea"
>
<td
id=
'buttonbind'
class=
"red"
>
BUTTON
</td>
<textarea
rows=
'2'
></textarea>
<td
id=
'radiobind'
class=
"red"
>
RADIO
</td>
</td>
<td
id=
'filebind'
class=
"red"
>
FILE
</td>
<td
id=
'textbind'
class=
"red"
>
TEXT
</td>
</tr>
<td
id=
'textareabind'
class=
"red"
>
TEXTAREA
</td>
</thead>
</tr>
<tbody>
<tr>
</tbody>
<td>
Focusin:
</td>
</table>
<td
id=
'selectfocus'
class=
"red"
>
SELECT
</td>
<p>
NOTE: Only IE supports beforeactivate/beforedeactivate; buttons do not support change events.
</p>
<td
id=
'mselectfocus'
class=
"red"
>
MULTI
</td>
<td
id=
'checkboxfocus'
class=
"red"
>
CHECKBOX
</td>
<td
id=
'buttonfocus'
class=
"red"
>
BUTTON
</td>
<td
id=
'radiofocus'
class=
"red"
>
RADIO
</td>
<td
id=
'filefocus'
class=
"red"
>
FILE
</td>
<td
id=
'textfocus'
class=
"red"
>
TEXT
</td>
<td
id=
'textareafocus'
class=
"red"
>
TEXTAREA
</td>
<td
id=
'boundFocus'
class=
"red"
>
DOCUMENT
</td>
</tr>
<tr>
<td>
Focusout:
</td>
<td
id=
'selectblur'
class=
"red"
>
SELECT
</td>
<td
id=
'mselectblur'
class=
"red"
>
MULTI
</td>
<td
id=
'checkboxblur'
class=
"red"
>
CHECKBOX
</td>
<td
id=
'buttonblur'
class=
"red"
>
BUTTON
</td>
<td
id=
'radioblur'
class=
"red"
>
RADIO
</td>
<td
id=
'fileblur'
class=
"red"
>
FILE
</td>
<td
id=
'textblur'
class=
"red"
>
TEXT
</td>
<td
id=
'textareablur'
class=
"red"
>
TEXTAREA
</td>
<td
id=
'boundBlur'
class=
"red"
>
DOCUMENT
</td>
</tr>
<tr>
<td>
Live Focus:
</td>
<td
id=
'selectlfocus'
class=
"red"
>
SELECT
</td>
<td
id=
'mselectlfocus'
class=
"red"
>
MULTI
</td>
<td
id=
'checkboxlfocus'
class=
"red"
>
CHECKBOX
</td>
<td
id=
'buttonlfocus'
class=
"red"
>
BUTTON
</td>
<td
id=
'radiolfocus'
class=
"red"
>
RADIO
</td>
<td
id=
'filelfocus'
class=
"red"
>
FILE
</td>
<td
id=
'textlfocus'
class=
"red"
>
TEXT
</td>
<td
id=
'textarealfocus'
class=
"red"
>
TEXTAREA
</td>
</tr>
<tr>
<td>
Live Blur:
</td>
<td
id=
'selectlblur'
class=
"red"
>
SELECT
</td>
<td
id=
'mselectlblur'
class=
"red"
>
MULTI
</td>
<td
id=
'checkboxlblur'
class=
"red"
>
CHECKBOX
</td>
<td
id=
'buttonlblur'
class=
"red"
>
BUTTON
</td>
<td
id=
'radiolblur'
class=
"red"
>
RADIO
</td>
<td
id=
'filelblur'
class=
"red"
>
FILE
</td>
<td
id=
'textlblur'
class=
"red"
>
TEXT
</td>
<td
id=
'textarealblur'
class=
"red"
>
TEXTAREA
</td>
</tr>
<tr>
<td>
Live Click:
</td>
<td
id=
'selectlclick'
class=
"red"
>
SELECT
</td>
<td
id=
'mselectlclick'
class=
"red"
>
MULTI
</td>
<td
id=
'checkboxlclick'
class=
"red"
>
CHECKBOX
</td>
<td
id=
'buttonlclick'
class=
"red"
>
BUTTON
</td>
<td
id=
'radiolclick'
class=
"red"
>
RADIO
</td>
<td
id=
'filelclick'
class=
"red"
>
FILE
</td>
<td
id=
'textlclick'
class=
"red"
>
TEXT
</td>
<td
id=
'textarealclick'
class=
"red"
>
TEXTAREA
</td>
<td
id=
'boundClick'
class=
"red"
>
DOCUMENT
</td>
</tr>
</table>
<h2>
Submit Tests
</h2>
<h2>
Submit Tests
</h2>
<table>
<table>
<tr>
<tr>
...
@@ -184,92 +130,76 @@
...
@@ -184,92 +130,76 @@
</tr>
</tr>
</table>
</table>
<ul
id=
"log"
></ul>
<script
type=
'text/javascript'
>
<script
type=
'text/javascript'
>
jQuery
.
fn
.
addChangeClickTest
=
function
(
id
,
prevent
)
{
this
.
bind
(
"focusin"
,
function
(){
jQuery
(
id
+
"focus"
).
blink
();
}).
bind
(
"focusout"
,
function
(){
jQuery
(
id
+
"blur"
).
blink
();
});
this
.
bind
(
"focus"
,
function
(){
jQuery
(
id
+
"lfocus"
).
blink
();
}).
bind
(
"blur"
,
function
(){
jQuery
(
id
+
"lblur"
).
blink
();
});
return
this
.
bind
(
"change"
,
function
(
e
){
jQuery
(
id
+
"bind"
).
blink
();
}).
live
(
"change"
,
function
(
e
){
if
(
prevent
)
{
e
.
preventDefault
();
}
jQuery
(
id
).
blink
();
}).
live
(
"click"
,
function
(
e
){
jQuery
(
id
+
"lclick"
).
blink
();
});
};
$
(
"#version"
).
text
(
version
);
$
(
"#fileversion"
).
text
(
$
.
fn
.
jquery
);
jQuery
.
fn
.
addSubmitTest
=
function
(
id
,
prevent
)
{
// Events we want to track in row-order
return
this
.
live
(
"submit"
,
function
(
e
){
var
events
=
"bind-change live-change live-beforeactivate live-focusin bind-focus live-keydown live-beforedeactivate live-focusout bind-blur live-click"
.
split
(
" "
),
if
(
prevent
)
{
counter
=
0
;
e
.
preventDefault
();
blinker
=
function
(
event
){
}
if
(
!
counter
)
{
$
(
"#changes tbody td"
).
text
(
""
);
jQuery
(
id
).
blink
();
}
});
var
$els
=
event
.
data
,
};
prev
=
$els
.
text
();
prev
=
prev
?
prev
+
" | "
:
""
;
jQuery
.
fn
.
blink
=
function
(){
return
$els
return
this
.
css
(
"backgroundColor"
,
"green"
).
css
(
"border"
,
"solid 3px green"
).
delay
(
700
).
queue
(
function
(
next
){
.
text
(
prev
+
++
counter
+
" "
+
(
this
.
value
.
replace
(
/^on$/
,
""
)
||
this
.
id
||
this
.
checked
||
""
))
jQuery
(
this
).
css
(
"backgroundColor"
,
""
);
.
css
(
"backgroundColor"
,
"#0f0"
)
next
();
.
delay
(
1000
)
});
.
queue
(
function
(
next
){
$els
.
css
(
"backgroundColor"
,
"#afa"
);
--
counter
;
next
();
});
};
};
$
(
document
).
bind
(
"focusin"
,
function
()
{
for
(
var
i
=
0
;
i
<
events
.
length
;
i
++
)
{
jQuery
(
"#boundFocus"
).
blink
();
var
m
=
events
[
i
].
split
(
"-"
),
});
api
=
m
[
0
],
type
=
m
[
1
],
$
(
document
).
bind
(
"focusout"
,
function
()
{
$row
=
$
(
"<tr><th>"
+
type
+
" "
+
api
+
"</th></tr>"
);
jQuery
(
"#boundBlur"
).
blink
();
});
$
(
document
).
bind
(
"click"
,
function
()
{
$
(
"#changes thead td"
).
each
(
function
(){
jQuery
(
"#boundClick"
).
blink
();
var
id
=
"#"
+
this
.
id
,
});
$cell
=
$
(
'<td></td>'
);
if
(
api
==
"bind"
)
{
$
(
"td.red"
).
live
(
"hover"
,
function
(
e
)
{
$
(
this
).
find
(
"input, button, select, textarea"
).
bind
(
type
,
$cell
,
blinker
);
if
(
e
.
type
===
"mouseenter"
)
{
$
(
this
).
css
(
"backgroundColor"
,
"green"
);
}
else
{
}
else
{
$
(
this
).
css
(
"backgroundColor"
,
""
);
$
(
id
+
" input,"
+
id
+
" button,"
+
id
+
" select,"
+
id
+
" textarea"
).
live
(
type
,
$cell
,
blinker
);
}
}
$row
.
append
(
$cell
);
});
});
$
(
"#changes tbody"
).
append
(
$row
);
}
// Buttons don't fire change events so show the cell as gray
$
(
"#changes tbody"
).
find
(
"tr:eq(0), tr:eq(1)"
).
find
(
"td:eq(3)"
).
css
(
"background"
,
"#eee"
);
$
(
".select_test"
).
addChangeClickTest
(
"#select"
);
jQuery
.
fn
.
blink
=
function
(){
$
(
".mselect_test"
).
addChangeClickTest
(
"#mselect"
);
return
this
.
css
(
"backgroundColor"
,
"green"
).
css
(
"border"
,
"solid 3px green"
).
delay
(
700
).
queue
(
function
(
next
){
$
(
".checkbox_test"
).
addChangeClickTest
(
"#checkbox"
);
jQuery
(
this
).
css
(
"backgroundColor"
,
""
);
$
(
".radio_test"
).
addChangeClickTest
(
"#radio"
);
next
();
$
(
".file_test"
).
addChangeClickTest
(
"#file"
);
$
(
'textarea'
).
addChangeClickTest
(
"#textarea"
);
$
(
'#input'
).
addChangeClickTest
(
"#text"
);
$
(
'button'
).
addChangeClickTest
(
"#button"
);
$
(
document
).
bind
(
"change"
,
function
(){
jQuery
(
"#boundChange"
).
blink
();
});
});
};
$
(
"#text_submit"
).
addSubmitTest
(
"#textSubmit"
,
true
);
jQuery
.
fn
.
addSubmitTest
=
function
(
id
,
prevent
)
{
$
(
"#password_submit"
).
addSubmitTest
(
"#passwordSubmit"
,
true
);
return
this
.
live
(
"submit"
,
function
(
e
){
$
(
"#submit_submit"
).
addSubmitTest
(
"#submitSubmit"
,
true
);
if
(
prevent
)
{
$
(
document
).
bind
(
"submit"
,
function
(){
e
.
preventDefault
();
jQuery
(
"#boundSubmit"
).
blink
();
}
jQuery
(
id
).
blink
();
});
});
};
$
(
"#text_submit"
).
addSubmitTest
(
"#textSubmit"
,
true
);
$
(
"#password_submit"
).
addSubmitTest
(
"#passwordSubmit"
,
true
);
$
(
"#submit_submit"
).
addSubmitTest
(
"#submitSubmit"
,
true
);
$
(
document
).
bind
(
"submit"
,
function
(){
jQuery
(
"#boundSubmit"
).
blink
();
});
</script>
</script>
</body>
</body>
</html>
</html>
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