mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-20 04:11:51 +00:00
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 !
This commit is contained in:
parent
28ccc76aa1
commit
26e8ab3693
1 changed files with 15 additions and 4 deletions
|
|
@ -227,10 +227,12 @@ function callerFile(offset) {
|
||||||
* Triggers a browser event. Attempts to choose the right event if one is
|
* Triggers a browser event. Attempts to choose the right event if one is
|
||||||
* not specified.
|
* not specified.
|
||||||
*
|
*
|
||||||
* @param {Object} Either a wrapped jQuery/jqLite node or a DOMElement
|
* @param {Object} element Either a wrapped jQuery/jqLite node or a DOMElement
|
||||||
* @param {string} Optional event type.
|
* @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 && !element.nodeName) element = element[0];
|
||||||
if (!element) return;
|
if (!element) return;
|
||||||
if (!type) {
|
if (!type) {
|
||||||
|
|
@ -254,6 +256,12 @@ function browserTrigger(element, type) {
|
||||||
element = element.parentNode;
|
element = element.parentNode;
|
||||||
type = 'change';
|
type = 'change';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
keys = keys || [];
|
||||||
|
function pressed(key) {
|
||||||
|
return indexOf(keys, key) !== -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (msie < 9) {
|
if (msie < 9) {
|
||||||
switch(element.type) {
|
switch(element.type) {
|
||||||
case 'radio':
|
case 'radio':
|
||||||
|
|
@ -267,6 +275,8 @@ function browserTrigger(element, type) {
|
||||||
// forcing the browser to compute the element position (by reading its CSS)
|
// forcing the browser to compute the element position (by reading its CSS)
|
||||||
// puts the element in consistent state.
|
// puts the element in consistent state.
|
||||||
element.style.posLeft;
|
element.style.posLeft;
|
||||||
|
|
||||||
|
// TODO(vojta): create event objects with pressed keys to get it working on IE<9
|
||||||
var ret = element.fireEvent('on' + type);
|
var ret = element.fireEvent('on' + type);
|
||||||
if (lowercase(element.type) == 'submit') {
|
if (lowercase(element.type) == 'submit') {
|
||||||
while(element) {
|
while(element) {
|
||||||
|
|
@ -293,7 +303,8 @@ function browserTrigger(element, type) {
|
||||||
return originalPreventDefault.apply(evnt, arguments);
|
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);
|
element.dispatchEvent(evnt);
|
||||||
finalProcessDefault = !(appWindow.angular['ff-684208-preventDefault'] || !fakeProcessDefault)
|
finalProcessDefault = !(appWindow.angular['ff-684208-preventDefault'] || !fakeProcessDefault)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue