-
Notifications
You must be signed in to change notification settings - Fork 648
/
test-static-02.html
104 lines (93 loc) · 3.93 KB
/
test-static-02.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<html>
<head>
<style>
* {font-family: mono; font-size:0.95em}
.eventNotifier{width: 100px; float: left; color:navy; border: dotted 1px navy; padding: 4px; background-color:white; margin:3px}
.dirty{border: solid 1px #0ca2ff; color:white; background-color:#0ca2ff}
</style>
</head>
<body>
<h3>Test #01</h3>
<input type='text' id='input_01'/>
<p>
type 'ctrl+l ' to focus.<br/>
type 'shift+3' to insert 'Shift#' into the text box.<br/>
type 'a' inside the textbox and have 'b' inserted instead.
</p>
<hr />
<h3>Test #02</h3>
<table>
<tbody>
<tr>
<td><input type='text' id='input_02' class='foo'></td>
</tr>
<tr>
<td><input type='text' id='input_03' class='foo'></td>
</tr>
<tr>
<td><input type='text' id='input_04' class='foo'></td>
</tr>
<tr>
<td><input type='text' id='input_05' class='foo'></td>
</tr>
<tr>
<td><input type='text' id='input_06' class='foo'></td>
</tr>
</tbody>
</table>
<input type='button' value='UnBind Click' onclick="unbindClick()" />
<input type='button' value='UnBind Keyup' onclick="unbindKeyup()" />
</body>
<hr />
<div id="logger"></div>
<script src="jquery-1.7.1.min.js"></script>
<!-- <script src="jquery-1.3.2.min.js"></script> -->
<script src="jquery.hotkeys.js"></script>
<script>
$(document).ready(function(){
$(document).bind('keydown.ctrl_l', function(){$('#input_01')[0].focus();})
.bind('keydown.shift_#', function(){$('#input_01')[0].value = "Shift#";});
$('#input_01').bind('keyup.a', function(event){
var v = $('#input_01')[0].value;
v = v.replace("a", "b");
v = $('#input_01')[0].value = v;
})
//.bind('keyup', function () { alert (arguments); })
.bind('click', function (event){
if (event.target == $('html')[0]){
alert("save the planet, don't waste energy over meaningless clicking");
}
});
$('input.foo').bind(
'keydown.ctrl_k', function(event){
log('binding keydown/ctrl+k to <b>input</b> applied on <b>#' + event.target.id + '</b>');
event.stopPropagation();
event.preventDefault();
}
);
// shouldn't do anything since event isn't attached to element itself
$('table').bind('keydown.ctrl_l click keyup.ctrl_l', clickHandler);
// it would work if using event delegation tho.. also with jQuery 1.7+ $.fn.on()
$('table').delegate('input', 'keydown.ctrl_j keyup.ctrl_j', delegateHandler);
});
function clickHandler(event){
log('binding ' + event.type + ' with(ctrl+l) to <b>table</b> applied on <b>#' + event.target.id + '</b>');
event.stopPropagation();
event.preventDefault();
}
function delegateHandler(event){
log('binding ' + event.type + ' with(ctrl+j) to <b>table</b> with event delegation applied on <b>#' + event.target.id + '</b>');
event.stopPropagation();
event.preventDefault();
}
function unbindClick(){
$('table').unbind('click', clickHandler).unbind('keyup.ctrl_l', clickHandler);
}
function unbindKeyup(){
$('table').unbind('keyup.ctrl_l', clickHandler);
}
function log(msg){
$('#logger').html(msg);
}
</script>
</html>