1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
2
"http://www.w3.org/TR/html4/strict.dtd">
6
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
7
<title>Focus and Blur Event Test for Opera</title>
8
<script type="text/javascript" src="../../../../build/yui/yui.js"></script>
10
<body class="yui3-skin-sam">
12
<h1>Opera Focus and Blur Event Test</h1>
16
By default the <code>focus</code> and <code>blur</code> events do not
17
bubble. This is problematic for developers wishing to listen for these
18
events via event delegation. Use of capture phase event listeners for
19
<code>focus</code> and <code>blur</code> is useful in that they enable
20
the use of these events when using event delegation.
23
Opera implements capture phase events per spec rather than
24
the more useful way it is implemented in other browsers:
25
The event doesn't fire on a target unless there is a
26
listener on an element in the target's ancestry. If a
27
capture phase listener is added only to the element that
28
will be the target of the event, the listener won't fire.
31
To work around the implementation of capture phase events in Opera,
32
the YUI3 Event Utility uses the <code>DOMFocusIn</code> and
33
<code>DOMFocusOut</code> events
34
rather than capture phase listeners for <code>focus</code> and
38
<h2>Using this Test</h2>
40
Use the keyboard or mouse to place focus into and the remove focus
41
from the following text box. You should see a log message appear
42
for each event in Opera.
46
<input type="text" id="text-1">
48
<script type="text/javascript">
60
}).use('console', 'node', 'event-focus', function (Y) {
62
(new Y.Console()).render();
64
var textBox = document.getElementById("text-1");
66
// The following standard capture phase focus and blur event
67
// listeners will not be called in Opera.
69
textBox.addEventListener("focus", function () {
71
Y.log("text-1 standard DOM capture phase focus listener called");
75
textBox.addEventListener("blur", function () {
77
Y.log("text-1 standard DOM capture phase blur listener called");
82
// The following YUI3 focus and blur event listeners WILL be
85
Y.on("focus", function () {
87
Y.log("focus listener called for text box!");
91
Y.on("blur", function () {
93
Y.log("blur listener called for text box!");