mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
userAction keyBoards events fixed for Opera
This commit is contained in:
parent
4a577e5ba2
commit
4545852eb1
@ -44,9 +44,8 @@ $.userAction = function(el, type, options) {
|
|||||||
o.x = o.x || xy.x; o.y = o.y || xy.y;
|
o.x = o.x || xy.x; o.y = o.y || xy.y;
|
||||||
|
|
||||||
var EVENT_DEFAULT = {
|
var EVENT_DEFAULT = {
|
||||||
|
target: this.target,
|
||||||
view: window,
|
view: window,
|
||||||
detail: 0,
|
|
||||||
isTrusted: false,
|
|
||||||
bubbles: o.bubbles || true,
|
bubbles: o.bubbles || true,
|
||||||
cancelable: o.cancelable || false,
|
cancelable: o.cancelable || false,
|
||||||
ctrlKey: o.ctrlKey || false,
|
ctrlKey: o.ctrlKey || false,
|
||||||
@ -62,17 +61,14 @@ $.userAction = function(el, type, options) {
|
|||||||
$.extend({}, EVENT_DEFAULT, {
|
$.extend({}, EVENT_DEFAULT, {
|
||||||
clientX: o.x, clientY: o.y,
|
clientX: o.x, clientY: o.y,
|
||||||
screenX: o.screenX || 0, screenY: o.screenY || 0,
|
screenX: o.screenX || 0, screenY: o.screenY || 0,
|
||||||
relatedTarget: $(o.relatedTarget)[0] || null,
|
relatedTarget: $(o.relatedTarget)[0] || null, detail: 0,
|
||||||
button: o.button || ($.browser.msie ? 1 : 0)
|
button: o.button || ($.browser.msie ? 1 : 0), isTrusted: false
|
||||||
}) :
|
}) :
|
||||||
$.extend({}, EVENT_DEFAULT, {
|
$.extend({}, EVENT_DEFAULT, {
|
||||||
keyCode: o.keyCode || 0, charCode: o.charCode || 0
|
keyCode: o.keyCode || 0, charCode: o.charCode || 0
|
||||||
});
|
});
|
||||||
|
|
||||||
if (o.before) o.before.apply(this.target, [
|
if (o.before) o.before.apply(this.target, [ $.event.fix(EVT), o.x, o.y, this]);
|
||||||
// simulate correct target before the event fire
|
|
||||||
// the browser just set the correct EVT.target after dispatchment
|
|
||||||
$.event.fix(EVT).target = this.target, o.x, o.y, this]);
|
|
||||||
|
|
||||||
// check event type for mouse events
|
// check event type for mouse events
|
||||||
if (isMouse) {
|
if (isMouse) {
|
||||||
@ -86,7 +82,7 @@ $.userAction = function(el, type, options) {
|
|||||||
EVT = this.keyboardEvent(EVT);
|
EVT = this.keyboardEvent(EVT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (o.after) o.after.apply(this.target, [EVT, o.x, o.y, this]);
|
if (o.after) o.after.apply(this.target, [$.event.fix(EVT), o.x, o.y, this]);
|
||||||
};
|
};
|
||||||
|
|
||||||
$.extend($.userAction.prototype, {
|
$.extend($.userAction.prototype, {
|
||||||
@ -138,12 +134,12 @@ $.extend($.userAction.prototype, {
|
|||||||
keyboardEvent: function(EVT) {
|
keyboardEvent: function(EVT) {
|
||||||
var evt, type = this.type, o = this.options;
|
var evt, type = this.type, o = this.options;
|
||||||
|
|
||||||
//Safari 2.x doesn't implement initMouseEvent()
|
// check for DOM-compliant browsers first
|
||||||
if ($.isFunction(document.createEvent)) {
|
if ($.isFunction(document.createEvent)) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// try to create key event
|
// try to create key event
|
||||||
evt = document.createEvent("KeyEvents");
|
evt = document.createEvent(StringPool.KEY_EVENTS);
|
||||||
|
|
||||||
evt.initKeyEvent(type,
|
evt.initKeyEvent(type,
|
||||||
EVT.bubbles, EVT.cancelable, EVT.view, EVT.ctrlKey,
|
EVT.bubbles, EVT.cancelable, EVT.view, EVT.ctrlKey,
|
||||||
@ -152,15 +148,19 @@ $.extend($.userAction.prototype, {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
// we need another try-catch for Safari 2.x
|
// we need another try-catch for Safari 2.x
|
||||||
try {
|
try {
|
||||||
// generic event, will fail in Safari 2.x
|
// generic event for opera and webkit nightlies, will fail in Safari 2.x
|
||||||
evt = document.createEvent("Events");
|
evt = document.createEvent(StringPool.EVENTS);
|
||||||
} catch (uierror){
|
} catch (ierr){
|
||||||
// create a UIEvent for Safari 2.x
|
// Safari 2.x - create a UIEvent
|
||||||
evt = document.createEvent("UIEvents");
|
evt = document.createEvent(StringPool.UI_EVENTS);
|
||||||
} finally {
|
} finally {
|
||||||
evt.initEvent(type, EVT.bubbles, EVT.cancelable);
|
evt.initEvent(type, EVT.bubbles, EVT.cancelable);
|
||||||
// initialize
|
|
||||||
$.extend(evt, EVT);
|
// initializing
|
||||||
|
$.each(EVT, function(k, v) {
|
||||||
|
// using try-catch for avoiding Opera NO_MODIFICATION_ALLOWED_ERR
|
||||||
|
try { evt[k] = v; } catch(e) { }
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,7 +178,7 @@ $.extend($.userAction.prototype, {
|
|||||||
evt.keyCode = (EVT.charCode > 0) ? EVT.charCode : EVT.keyCode;
|
evt.keyCode = (EVT.charCode > 0) ? EVT.charCode : EVT.keyCode;
|
||||||
|
|
||||||
// fire the event
|
// fire the event
|
||||||
this.target.fireEvent("on" + type, evt);
|
this.target.fireEvent(StringPool.ON + type, evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
return evt;
|
return evt;
|
||||||
@ -204,8 +204,10 @@ var StringPool = {
|
|||||||
NUMBER: 'number',
|
NUMBER: 'number',
|
||||||
MOUSEOVER: 'mouseover',
|
MOUSEOVER: 'mouseover',
|
||||||
MOUSEOUT: 'mouseout',
|
MOUSEOUT: 'mouseout',
|
||||||
MOUSE_EVENTS: "MouseEvents",
|
MOUSE_EVENTS: 'MouseEvents',
|
||||||
UI_EVENTS: "UIEvents"
|
UI_EVENTS: 'UIEvents',
|
||||||
|
KEY_EVENTS: 'KeyEvents',
|
||||||
|
EVENTS: 'Events'
|
||||||
};
|
};
|
||||||
|
|
||||||
})(jQuery);
|
})(jQuery);
|
@ -53,20 +53,23 @@
|
|||||||
});*/
|
});*/
|
||||||
|
|
||||||
$('#key').keydown(function() {
|
$('#key').keydown(function() {
|
||||||
//alert('keydown')
|
alert('keydown')
|
||||||
//console.log('keydown')
|
//console.log('keydown')
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
|
||||||
// TODO - works in all browsers, but have to fix a bug on opera
|
// TODO - works in all browsers, but have to fix a bug on opera
|
||||||
$('#key').userAction("keydown", {
|
$('#key').userAction("keydown", {
|
||||||
charCode: 67,
|
charCode: 67,
|
||||||
keyCOde: 67,
|
keyCode: 67,
|
||||||
after: function(e) {
|
after: function(e) {
|
||||||
//console.log(e)
|
console.log(e)
|
||||||
|
},
|
||||||
|
before: function(e) {
|
||||||
|
console.log(e)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
|
|
||||||
// mouseover on the center of the target
|
// mouseover on the center of the target
|
||||||
$('.ui-resizable-e').userAction("mouseover");
|
$('.ui-resizable-e').userAction("mouseover");
|
||||||
|
Loading…
Reference in New Issue
Block a user