This repository has been archived by the owner on May 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
browserTest.html
119 lines (113 loc) · 2.81 KB
/
browserTest.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Browser Test</title>
<script type="text/javascript" src="jquery-1.6.2.js"></script>
</head>
<body>
<input type="text" value="left" />
<input id="test" type="text" value="hello" maxlength="20" />
<input type="text" value="right" /><br />
<input type="checkbox" id="simulateKeypress" />Simulate Keypress<br />
<textarea id="log" cols="50" rows="20"></textarea><br />
<input type="button" value="Clear" onclick="$('#log').val('')" />
<script type="text/javascript" language="javascript">
$(document).ready(function ()
{
function insertAt(s, index, value)
{
return s.slice(0, index) + value + s.slice(index);
}
function getSelection(element)
{
var selection = {};
if(element.setSelectionRange)
{
selection.start = element.selectionStart;
selection.length = element.selectionEnd - selection.start;
}
else if(document.selection && document.selection.createRange)
{
var range = document.selection.createRange();
selection.start = 0 - range.duplicate().moveStart('character', -100000);
selection.length = range.text.length;
}
return selection;
}
var test = $("#test");
var logArea = $("#log");
function log(message)
{
var selection = getSelection(test[0]);
var value = test.val();
var selectionEnd = selection.start + selection.length;
if(selectionEnd != selection.start)
value = insertAt(value, selectionEnd, "^");
value = insertAt(value, selection.start, "^");
logArea.val(message + "\t\t\"" + value + "\"\n" + logArea.val());
}
test
.blur(function (e)
{
log("blur");
})
.focus(function (e)
{
log("focus");
})
.focusin(function (e)
{
log("focusin");
})
.focusout(function (e)
{
log("focusout");
})
.change(function (e)
{
log("change");
})
.keydown(function (e)
{
log("keydown: " + e.which);
})
.keypress(function (e)
{
log("keypress: '" + String.fromCharCode(e.which) + "' (" + e.which + ")");
if($("#simulateKeypress").is(':checked'))
{
if(e.ctrlKey || e.altKey || e.metaKey || e.which < 32)
return true;
if((32 <= e.which && e.which <= 126) || e.which >= 128)
test.val(test.val() + String.fromCharCode(e.which));
return false;
}
})
.keyup(function (e)
{
log("keyup: " + e.which);
})
.bind("cut", function (e)
{
log("cut");
})
.bind("paste", function (e)
{
log("paste");
})
.bind("input", function (e)
{
log("input");
})
.bind("click", function (e)
{
log("click");
})
.bind("select", function (e)
{
log("select");
});
});
</script>
</body>
</html>