2011-09-12 00:38:54 +00:00
|
|
|
<!DOCTYPE html>
|
2010-11-12 05:42:53 +00:00
|
|
|
<html>
|
2011-09-12 00:38:54 +00:00
|
|
|
<head>
|
2011-09-21 02:18:34 +00:00
|
|
|
<title>Event Delegation Tests</title>
|
2012-01-12 02:35:13 +00:00
|
|
|
<script src="data/include_js.php"></script>
|
2011-09-12 00:38:54 +00:00
|
|
|
<style>
|
|
|
|
table {
|
|
|
|
border-collapse: collapse;
|
|
|
|
empty-cells: show;
|
|
|
|
}
|
|
|
|
th {
|
|
|
|
text-align: left;
|
|
|
|
}
|
|
|
|
thead td {
|
|
|
|
width: 11%;
|
|
|
|
}
|
|
|
|
tbody td {
|
|
|
|
background: #fed;
|
|
|
|
}
|
|
|
|
th, td {
|
|
|
|
border: 1px solid #bbb;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
2012-01-12 02:35:13 +00:00
|
|
|
<h2>Delegate Tests (<span id="fileversion">x</span>)</h2>
|
2011-09-12 00:38:54 +00:00
|
|
|
|
|
|
|
<table id="changes">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>
|
|
|
|
Controls:
|
|
|
|
</th>
|
|
|
|
<td id="select-one">
|
|
|
|
<select>
|
|
|
|
<option value='one1'>one1</option>
|
|
|
|
<option value='one2'>one2</option>
|
|
|
|
<option value='one3'>one3</option>
|
|
|
|
</select>
|
|
|
|
<select>
|
|
|
|
<option value='two1'>two1</option>
|
|
|
|
<option value='two2' selected="selected">two2</option>
|
|
|
|
<option value='two3'>two3</option>
|
|
|
|
</select>
|
|
|
|
</td>
|
|
|
|
<td id="select-mult">
|
|
|
|
<select multiple="multiple">
|
|
|
|
<option value='multi1'>multi1</option>
|
|
|
|
<option value='multi2'>multi2</option>
|
|
|
|
<option value='multi3'>multi3</option>
|
|
|
|
</select>
|
|
|
|
</td>
|
|
|
|
<td id="checkbox">
|
|
|
|
<input type="checkbox" name="mycheckbox" id="check1"/>
|
|
|
|
<label for="check1">check1</label><br/>
|
|
|
|
<input type="checkbox" name="mycheckbox" id="check2"/>
|
|
|
|
<label for="check2">check2</label><br />
|
|
|
|
<input type="checkbox" name="mycheckbox" id="check3" disabled="disabled"/>
|
|
|
|
<label for="check3">check3</label>
|
|
|
|
</td>
|
|
|
|
<td id="radio">
|
|
|
|
<input type="radio" name="myradio" id="radio1"/>
|
|
|
|
<label for="radio1">Radio1</label><br/>
|
|
|
|
<input type="radio" name="myradio" id="radio2"/>
|
|
|
|
<label for="radio2">Radio2</label><br />
|
|
|
|
<input type="radio" name="myradio" id="radio3" disabled="disabled"/>
|
|
|
|
<label for="radio3">Radio3</label>
|
|
|
|
</td>
|
|
|
|
<td id="file">
|
|
|
|
<input class="file_test" id="file1" type="file"/>
|
|
|
|
</td>
|
|
|
|
<td id="text">
|
|
|
|
<input class='test' value='' id='input' size='10' />
|
|
|
|
<input class='test' value='test' id='input2' size='10' readonly="readonly" />
|
|
|
|
</td>
|
|
|
|
<td id="textarea">
|
|
|
|
<textarea rows='2'></textarea>
|
|
|
|
</td>
|
2011-09-21 02:18:34 +00:00
|
|
|
<td id="button">
|
|
|
|
<button name="mybutton1" id="button1">Button</button><br />
|
|
|
|
<button name="mybutton2" id="button2"><span>Button w/ child</span></button><br />
|
|
|
|
<button name="mybutton3" id="button3" disabled="disabled">Button Disabled</button><br />
|
|
|
|
<button name="mybutton4" id="button4" disabled="disabled"><span disabled="disabled">Button, child Disabled</span></button><br />
|
|
|
|
</td>
|
2011-09-12 00:38:54 +00:00
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
2011-09-12 01:18:32 +00:00
|
|
|
<p>NOTE: Only IE supports propertychange, beforeactivate, beforedeactivate; buttons do not support change events.</p>
|
2011-09-12 00:38:54 +00:00
|
|
|
|
2010-11-12 05:42:53 +00:00
|
|
|
<h2>Submit Tests</h2>
|
|
|
|
<table>
|
|
|
|
<tr>
|
|
|
|
<td>
|
|
|
|
Submit each:
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<form action="" id="text_submit">
|
|
|
|
<input class='test' type='text' value='Key Return To Submit'/>
|
|
|
|
</form>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<form action="" id="password_submit">
|
|
|
|
<input class='test' type='password' value=''/>
|
|
|
|
</form>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<form action="" id="submit_submit">
|
|
|
|
<input type='submit' value="Click Me To Submit" />
|
|
|
|
</form>
|
|
|
|
</td>
|
|
|
|
<td>$(document).bind('submit')</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>Results:</td>
|
|
|
|
<td id='textSubmit' class="red">TEXT</td>
|
|
|
|
<td id='passwordSubmit' class="red">PASSWORD</td>
|
|
|
|
<td id='submitSubmit' class="red">BUTTON</td>
|
|
|
|
<td id='boundSubmit' class="red">DOCUMENT</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
|
2011-11-16 02:06:53 +00:00
|
|
|
<form id="autosub"><input type=submit name=subme /></form>
|
|
|
|
|
2011-09-12 00:38:54 +00:00
|
|
|
<script type='text/javascript'>
|
2010-11-12 05:42:53 +00:00
|
|
|
|
2011-09-12 00:38:54 +00:00
|
|
|
$("#fileversion").text($.fn.jquery);
|
2011-02-18 18:09:07 +00:00
|
|
|
|
2011-11-16 02:06:53 +00:00
|
|
|
// Try an auto-submit, it should only fire once
|
|
|
|
$(function(){
|
|
|
|
var triggered = false;
|
|
|
|
$("#autosub input").trigger("keypress");
|
|
|
|
$("body").on("submit", "#autosub", function( e ){
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
if ( triggered ) {
|
|
|
|
alert("autosubmit FAIL");
|
|
|
|
}
|
|
|
|
triggered = true;
|
|
|
|
});
|
|
|
|
$("#autosub").submit().remove();
|
|
|
|
});
|
|
|
|
|
2011-09-12 00:38:54 +00:00
|
|
|
// Events we want to track in row-order
|
2011-09-21 02:18:34 +00:00
|
|
|
var events = "bind-change live-change on-change bind-propertychange live-beforeactivate live-focusin bind-focus live-beforedeactivate live-focusout bind-blur live-click live-keydown".split(" "),
|
2011-09-12 00:38:54 +00:00
|
|
|
counter = 0;
|
|
|
|
blinker = function(event){
|
|
|
|
if ( !counter ) {
|
|
|
|
$("#changes tbody td").text("");
|
|
|
|
}
|
2011-09-12 01:18:32 +00:00
|
|
|
var $el = event.data,
|
|
|
|
prev = $el.text();
|
2011-09-12 00:38:54 +00:00
|
|
|
prev = prev? prev +" | " : "";
|
2011-09-12 01:18:32 +00:00
|
|
|
return $el
|
2011-09-12 00:38:54 +00:00
|
|
|
.text(prev + ++counter+" " + (this.value.replace(/^on$/,"") || this.id || this.checked || ""))
|
|
|
|
.css("backgroundColor","#0f0")
|
2011-09-12 01:18:32 +00:00
|
|
|
.delay(800)
|
2011-09-12 00:38:54 +00:00
|
|
|
.queue(function(next){
|
2011-09-12 01:18:32 +00:00
|
|
|
$el.css("backgroundColor","#afa");
|
2011-09-12 00:38:54 +00:00
|
|
|
--counter;
|
|
|
|
next();
|
|
|
|
});
|
2010-11-12 05:42:53 +00:00
|
|
|
};
|
|
|
|
|
2011-09-12 00:38:54 +00:00
|
|
|
for ( var i=0; i < events.length; i++ ) {
|
|
|
|
var m = events[i].split("-"),
|
|
|
|
api = m[0],
|
|
|
|
type = m[1],
|
|
|
|
$row = $("<tr><th>"+type+" "+api+"</th></tr>");
|
2011-02-18 18:09:07 +00:00
|
|
|
|
2011-09-12 00:38:54 +00:00
|
|
|
$("#changes thead td").each(function(){
|
|
|
|
var id = "#"+this.id,
|
|
|
|
$cell = $('<td></td>');
|
2011-09-12 01:18:32 +00:00
|
|
|
if ( api == "on" ) {
|
|
|
|
$(this).find("input, button, select, textarea").each(function(){
|
|
|
|
this["on"+type] = function(e){ e = $.event.fix(e||event); e.data = $cell; blinker.call(this, e); };
|
|
|
|
});
|
|
|
|
} else if ( api == "bind" ) {
|
2011-09-12 00:38:54 +00:00
|
|
|
$(this).find("input, button, select, textarea").bind(type, $cell, blinker);
|
2010-11-12 05:42:53 +00:00
|
|
|
} else {
|
2011-09-12 00:38:54 +00:00
|
|
|
$(id+" input,"+id+" button,"+id+" select,"+id+" textarea").live(type, $cell, blinker);
|
2010-11-12 05:42:53 +00:00
|
|
|
}
|
2011-09-12 00:38:54 +00:00
|
|
|
$row.append($cell);
|
2010-11-12 05:42:53 +00:00
|
|
|
});
|
2011-09-12 00:38:54 +00:00
|
|
|
$("#changes tbody").append($row);
|
|
|
|
}
|
2010-11-12 05:42:53 +00:00
|
|
|
|
2011-09-12 00:38:54 +00:00
|
|
|
jQuery.fn.blink = function(){
|
2011-11-16 02:06:53 +00:00
|
|
|
return this
|
|
|
|
.css("backgroundColor","green")
|
|
|
|
.text( (parseInt(this.text(), 10) || 0) + 1 )
|
|
|
|
.delay(700).queue(function(next){
|
|
|
|
jQuery(this).css("backgroundColor","#afa");
|
|
|
|
next();
|
|
|
|
});
|
2011-09-12 00:38:54 +00:00
|
|
|
};
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2011-09-12 00:38:54 +00:00
|
|
|
jQuery.fn.addSubmitTest = function( id, prevent ) {
|
|
|
|
return this.live("submit", function(e){
|
|
|
|
if ( prevent ) {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
jQuery(id).blink();
|
2010-11-12 05:42:53 +00:00
|
|
|
});
|
2011-09-12 00:38:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$("#text_submit").addSubmitTest("#textSubmit", true);
|
|
|
|
$("#password_submit").addSubmitTest("#passwordSubmit", true);
|
|
|
|
$("#submit_submit").addSubmitTest("#submitSubmit", true);
|
2011-11-16 02:06:53 +00:00
|
|
|
$("#prog_submit").addSubmitTest("#submitSubmit", true);
|
2011-09-12 00:38:54 +00:00
|
|
|
$(document).bind("submit", function(){
|
|
|
|
jQuery("#boundSubmit").blink();
|
|
|
|
});
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2011-09-12 00:38:54 +00:00
|
|
|
</script>
|
|
|
|
</body>
|
2010-11-12 05:42:53 +00:00
|
|
|
</html>
|