aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVojta Jina2011-10-12 13:57:09 -0700
committerIgor Minar2011-10-13 11:10:19 -0700
commit26e8ab3693eb0ad388247ae5c35cd52eaa709b0c (patch)
tree0e0d6995b7c4667eea3db4a563d0dbfd215fe41c
parent28ccc76aa17f6107bea692ad4782cfb209e7a10f (diff)
downloadangular.js-26e8ab3693eb0ad388247ae5c35cd52eaa709b0c.tar.bz2
feat(scenario): allow key pressing when triggering browser event
Add parameter to our browserTriger function to allow specifying which keys are pressed. Note, this does not work on IE<9 !
-rw-r--r--src/scenario/Scenario.js19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/scenario/Scenario.js b/src/scenario/Scenario.js
index 8d34bd0e..0df74dae 100644
--- a/src/scenario/Scenario.js
+++ b/src/scenario/Scenario.js
@@ -227,10 +227,12 @@ function callerFile(offset) {
* Triggers a browser event. Attempts to choose the right event if one is
* not specified.
*
- * @param {Object} Either a wrapped jQuery/jqLite node or a DOMElement
- * @param {string} Optional event type.
+ * @param {Object} element Either a wrapped jQuery/jqLite node or a DOMElement
+ * @param {string} type Optional event type.
+ * @param {Array.<string>=} keys Optional list of pressed keys
+ * (valid values: 'alt', 'meta', 'shift', 'ctrl')
*/
-function browserTrigger(element, type) {
+function browserTrigger(element, type, keys) {
if (element && !element.nodeName) element = element[0];
if (!element) return;
if (!type) {
@@ -254,6 +256,12 @@ function browserTrigger(element, type) {
element = element.parentNode;
type = 'change';
}
+
+ keys = keys || [];
+ function pressed(key) {
+ return indexOf(keys, key) !== -1;
+ }
+
if (msie < 9) {
switch(element.type) {
case 'radio':
@@ -267,6 +275,8 @@ function browserTrigger(element, type) {
// forcing the browser to compute the element position (by reading its CSS)
// puts the element in consistent state.
element.style.posLeft;
+
+ // TODO(vojta): create event objects with pressed keys to get it working on IE<9
var ret = element.fireEvent('on' + type);
if (lowercase(element.type) == 'submit') {
while(element) {
@@ -293,7 +303,8 @@ function browserTrigger(element, type) {
return originalPreventDefault.apply(evnt, arguments);
};
- evnt.initMouseEvent(type, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, element);
+ evnt.initMouseEvent(type, true, true, window, 0, 0, 0, 0, 0, pressed('ctrl'), pressed('alt'),
+ pressed('shift'), pressed('meta'), 0, element);
element.dispatchEvent(evnt);
finalProcessDefault = !(appWindow.angular['ff-684208-preventDefault'] || !fakeProcessDefault)