| 1 |
<!DOCTYPE html> |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
<html> |
| 6 |
<head> |
| 7 |
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> |
| 8 |
<title>dijit.focus Test</title> |
| 9 |
<style type="text/css"> |
| 10 |
@import "../../themes/claro/document.css"; |
| 11 |
@import "../../themes/claro/claro.css"; |
| 12 |
@import "../css/dijitTests.css"; |
| 13 |
</style> |
| 14 |
|
| 15 |
<script type="text/javascript" src="../../../dojo/dojo.js" |
| 16 |
data-dojo-config="isDebug: true, parseOnLoad: true"></script> |
| 17 |
<script type="text/javascript"> |
| 18 |
dojo.require("dijit.dijit"); // optimize: load dijit layer |
| 19 |
|
| 20 |
dojo.require("dijit.form.DateTextBox"); |
| 21 |
dojo.require("dijit.form.ComboBox"); |
| 22 |
dojo.require("dijit.form.NumberSpinner"); |
| 23 |
dojo.require("dijit.form.ComboButton"); |
| 24 |
|
| 25 |
dojo.require("dijit.Menu"); |
| 26 |
dojo.require("dijit.MenuItem"); |
| 27 |
dojo.require("dijit.PopupMenuItem"); |
| 28 |
|
| 29 |
dojo.require("dijit.layout.ContentPane"); |
| 30 |
|
| 31 |
dojo.require("dijit._base.focus"); |
| 32 |
|
| 33 |
// This code does animation to change border color and width to show |
| 34 |
// active vs. non-active widgets. |
| 35 |
var queue=[]; |
| 36 |
var animation; |
| 37 |
function animateBorderColor(widget, color, startWidth, endWidth){ |
| 38 |
if(animation){ |
| 39 |
queue.push(arguments); |
| 40 |
return; |
| 41 |
} |
| 42 |
var s = widget.domNode.style; |
| 43 |
s.borderStyle="solid"; |
| 44 |
s.outlineStyle="solid"; |
| 45 |
animation = dojo.animateProperty({ |
| 46 |
node: widget.domNode, |
| 47 |
duration: 50, |
| 48 |
properties: { |
| 49 |
// depending on browser and node type, sometimes border or outline is ineffective. |
| 50 |
// doing both seems to work in all cases though (for at least one of them) |
| 51 |
borderColor: { end: color }, |
| 52 |
borderWidth: { start: startWidth, end: endWidth }, |
| 53 |
outlineColor: { end: color }, |
| 54 |
outlineWidth: { start: startWidth, end: endWidth } |
| 55 |
}, |
| 56 |
onEnd: function(){ |
| 57 |
animation=null; |
| 58 |
if(queue.length){ |
| 59 |
animateBorderColor.apply(null, queue.shift()); |
| 60 |
} |
| 61 |
} |
| 62 |
}); |
| 63 |
animation.play(); |
| 64 |
} |
| 65 |
|
| 66 |
// This flag controls animation and can be disabled by the test harness in robot/focus_mouse.html |
| 67 |
animate = !window.location.search.match("animate=false"); |
| 68 |
|
| 69 |
dojo.ready(function(){ |
| 70 |
dojo.subscribe("widgetFocus", function(widget){ |
| 71 |
console.log("focused on widget " + (widget?widget:"nothing")); |
| 72 |
if(animate){ |
| 73 |
animateBorderColor(widget, "#ff0000", 1, 3); |
| 74 |
} |
| 75 |
}); |
| 76 |
dojo.subscribe("widgetBlur", function(widget){ |
| 77 |
console.log("blurred widget " + (widget?widget:"nothing")); |
| 78 |
if(animate){ |
| 79 |
animateBorderColor(widget, "#0000ff", 3, 1); |
| 80 |
} |
| 81 |
}); |
| 82 |
dojo.subscribe("focusNode", function(node){ console.log("focused on node " + (node?(node.id||node.tagName):"nothing"));}); |
| 83 |
|
| 84 |
// Focus notification also comes through watch() on each widget |
| 85 |
dijit.registry.forEach(function(widget){ |
| 86 |
widget.watch("focused", function(name, oldValue, newValue){ |
| 87 |
console.log(this.id + "." + name + ": " + oldValue + " ---> " + newValue); |
| 88 |
}); |
| 89 |
}, this); |
| 90 |
}); |
| 91 |
</script> |
| 92 |
<style> |
| 93 |
div, fieldset, form, input { |
| 94 |
padding: 3px; |
| 95 |
margin: 3px; |
| 96 |
border: 1px solid blue; |
| 97 |
} |
| 98 |
</style> |
| 99 |
</head> |
| 100 |
<body style="background-color: #fff; color: black; padding: 0; margin: 0" class="claro"> |
| 101 |
|
| 102 |
<h3>Widget Focus Test</h3> |
| 103 |
<p> |
| 104 |
This is for testing code to detect onBlur and onFocus on a widget level.<br> |
| 105 |
Focused widgets' borders will turn red.<br> |
| 106 |
Also, check the console log for focus and blur events on widgets. |
| 107 |
</p> |
| 108 |
|
| 109 |
<label>a form ContentPane widget:</label><br> |
| 110 |
<form id="form" data-dojo-type="dijit/layout/ContentPane" > |
| 111 |
<label for="first">simple input: </label><input id="first"/><br> |
| 112 |
|
| 113 |
<label>a fieldset ContentPane widget:</label><br> |
| 114 |
<fieldset id=fieldset1 data-dojo-type="dijit/layout/ContentPane"> |
| 115 |
<label for="select">a ComboBox widget:</label> |
| 116 |
<select id=select data-dojo-type="dijit/form/ComboBox"> |
| 117 |
<option>this</option> |
| 118 |
<option>is</option> |
| 119 |
<option>a</option> |
| 120 |
<option>list</option> |
| 121 |
</select> |
| 122 |
<label for="plain">a plain input:</label> |
| 123 |
<input id=plain value=plain/> |
| 124 |
</fieldset> |
| 125 |
<br> |
| 126 |
<label>another fieldset ContentPane:</label><br> |
| 127 |
<fieldset id=fieldset2 data-dojo-type="dijit/layout/ContentPane"> |
| 128 |
<label for="date">a DateTextBox widget:</label> |
| 129 |
<input id=date data-dojo-type="dijit/form/DateTextBox"/><br> |
| 130 |
|
| 131 |
<label for="textarea">a plain textarea:</label><br> |
| 132 |
<textarea id=textarea>hello there!</textarea><br> |
| 133 |
|
| 134 |
<label for="spinner">a Spinner widget:</label> |
| 135 |
<input id=spinner data-dojo-type="dijit/form/NumberSpinner" data-dojo-props='value:100'/><br> |
| 136 |
|
| 137 |
<label>a Combobutton widget:</label> |
| 138 |
<div id=button data-dojo-type="dijit/form/ComboButton" data-dojo-props='tabIndex:"0"'> |
| 139 |
<span>push me</span> |
| 140 |
<div id=menu data-dojo-type="dijit/Menu"> |
| 141 |
<div id=mi1 data-dojo-type="dijit/MenuItem">menu item 1</div> |
| 142 |
<div id=mi2 data-dojo-type="dijit/MenuItem">menu item 2</div> |
| 143 |
<div id=popupMenuItem data-dojo-type="dijit/PopupMenuItem"> |
| 144 |
<span>submenu</span> |
| 145 |
<div id=submenu data-dojo-type="dijit/Menu"> |
| 146 |
<div id=smi1 data-dojo-type="dijit/MenuItem">submenu item 1</div> |
| 147 |
<div id=smi2 data-dojo-type="dijit/MenuItem">submenu item 2</div> |
| 148 |
</div> |
| 149 |
</div> |
| 150 |
</div> |
| 151 |
</div> |
| 152 |
</fieldset> |
| 153 |
</form> |
| 154 |
</body> |
| 155 |
</html> |