Remove unecessary event-related code from Util
The event-related wrapper functions in Util existed mainly for backwards-compat. However, all currently supported browsers support the standard functions, so these wrappers are no longer needed.
This commit is contained in:
parent
e4fef7be2d
commit
b4ef49ea36
14
app/ui.js
14
app/ui.js
|
@ -142,7 +142,7 @@ var UI;
|
|||
UI.setViewClip();
|
||||
UI.setBarPosition();
|
||||
|
||||
Util.addEvent(window, 'resize', function () {
|
||||
window.addEventListener('resize', function () {
|
||||
UI.applyResizeMode();
|
||||
UI.setViewClip();
|
||||
UI.updateViewDrag();
|
||||
|
@ -160,17 +160,17 @@ var UI;
|
|||
document.documentElement.webkitRequestFullscreen ||
|
||||
document.body.msRequestFullscreen)) {
|
||||
document.getElementById('noVNC_fullscreen_button').style.display = "inline";
|
||||
Util.addEvent(window, 'fullscreenchange', UI.updateFullscreenButton);
|
||||
Util.addEvent(window, 'mozfullscreenchange', UI.updateFullscreenButton);
|
||||
Util.addEvent(window, 'webkitfullscreenchange', UI.updateFullscreenButton);
|
||||
Util.addEvent(window, 'msfullscreenchange', UI.updateFullscreenButton);
|
||||
window.addEventListener('fullscreenchange', UI.updateFullscreenButton);
|
||||
window.addEventListener('mozfullscreenchange', UI.updateFullscreenButton);
|
||||
window.addEventListener('webkitfullscreenchange', UI.updateFullscreenButton);
|
||||
window.addEventListener('msfullscreenchange', UI.updateFullscreenButton);
|
||||
}
|
||||
|
||||
Util.addEvent(window, 'load', UI.keyboardinputReset);
|
||||
window.addEventListener('load', UI.keyboardinputReset);
|
||||
|
||||
// While connected we want to display a confirmation dialogue
|
||||
// if the user tries to leave the page
|
||||
Util.addEvent(window, 'beforeunload', function (e) {
|
||||
window.addEventListener('beforeunload', function (e) {
|
||||
if (UI.rfb && UI.rfb_state === 'normal') {
|
||||
var msg = "You are currently connected.";
|
||||
e.returnValue = msg;
|
||||
|
|
|
@ -122,12 +122,12 @@
|
|||
//Util.Debug(">> Keyboard.grab");
|
||||
var c = this._target;
|
||||
|
||||
Util.addEvent(c, 'keydown', this._eventHandlers.keydown);
|
||||
Util.addEvent(c, 'keyup', this._eventHandlers.keyup);
|
||||
Util.addEvent(c, 'keypress', this._eventHandlers.keypress);
|
||||
c.addEventListener('keydown', this._eventHandlers.keydown);
|
||||
c.addEventListener('keyup', this._eventHandlers.keyup);
|
||||
c.addEventListener('keypress', this._eventHandlers.keypress);
|
||||
|
||||
// Release (key up) if window loses focus
|
||||
Util.addEvent(window, 'blur', this._eventHandlers.blur);
|
||||
window.addEventListener('blur', this._eventHandlers.blur);
|
||||
|
||||
//Util.Debug("<< Keyboard.grab");
|
||||
},
|
||||
|
@ -136,10 +136,10 @@
|
|||
//Util.Debug(">> Keyboard.ungrab");
|
||||
var c = this._target;
|
||||
|
||||
Util.removeEvent(c, 'keydown', this._eventHandlers.keydown);
|
||||
Util.removeEvent(c, 'keyup', this._eventHandlers.keyup);
|
||||
Util.removeEvent(c, 'keypress', this._eventHandlers.keypress);
|
||||
Util.removeEvent(window, 'blur', this._eventHandlers.blur);
|
||||
c.removeEventListener('keydown', this._eventHandlers.keydown);
|
||||
c.removeEventListener('keyup', this._eventHandlers.keyup);
|
||||
c.removeEventListener('keypress', this._eventHandlers.keypress);
|
||||
window.removeEventListener('blur', this._eventHandlers.blur);
|
||||
|
||||
// Release (key up) all keys that are in a down state
|
||||
this._allKeysUp();
|
||||
|
@ -347,44 +347,44 @@
|
|||
var c = this._target;
|
||||
|
||||
if ('ontouchstart' in document.documentElement) {
|
||||
Util.addEvent(c, 'touchstart', this._eventHandlers.mousedown);
|
||||
Util.addEvent(window, 'touchend', this._eventHandlers.mouseup);
|
||||
Util.addEvent(c, 'touchend', this._eventHandlers.mouseup);
|
||||
Util.addEvent(c, 'touchmove', this._eventHandlers.mousemove);
|
||||
c.addEventListener('touchstart', this._eventHandlers.mousedown);
|
||||
window.addEventListener('touchend', this._eventHandlers.mouseup);
|
||||
c.addEventListener('touchend', this._eventHandlers.mouseup);
|
||||
c.addEventListener('touchmove', this._eventHandlers.mousemove);
|
||||
} else {
|
||||
Util.addEvent(c, 'mousedown', this._eventHandlers.mousedown);
|
||||
Util.addEvent(window, 'mouseup', this._eventHandlers.mouseup);
|
||||
Util.addEvent(c, 'mouseup', this._eventHandlers.mouseup);
|
||||
Util.addEvent(c, 'mousemove', this._eventHandlers.mousemove);
|
||||
Util.addEvent(c, (Util.Engine.gecko) ? 'DOMMouseScroll' : 'mousewheel',
|
||||
c.addEventListener('mousedown', this._eventHandlers.mousedown);
|
||||
window.addEventListener('mouseup', this._eventHandlers.mouseup);
|
||||
c.addEventListener('mouseup', this._eventHandlers.mouseup);
|
||||
c.addEventListener('mousemove', this._eventHandlers.mousemove);
|
||||
c.addEventListener((Util.Engine.gecko) ? 'DOMMouseScroll' : 'mousewheel',
|
||||
this._eventHandlers.mousewheel);
|
||||
}
|
||||
|
||||
/* Work around right and middle click browser behaviors */
|
||||
Util.addEvent(document, 'click', this._eventHandlers.mousedisable);
|
||||
Util.addEvent(document.body, 'contextmenu', this._eventHandlers.mousedisable);
|
||||
document.addEventListener('click', this._eventHandlers.mousedisable);
|
||||
document.body.addEventListener('contextmenu', this._eventHandlers.mousedisable);
|
||||
},
|
||||
|
||||
ungrab: function () {
|
||||
var c = this._target;
|
||||
|
||||
if ('ontouchstart' in document.documentElement) {
|
||||
Util.removeEvent(c, 'touchstart', this._eventHandlers.mousedown);
|
||||
Util.removeEvent(window, 'touchend', this._eventHandlers.mouseup);
|
||||
Util.removeEvent(c, 'touchend', this._eventHandlers.mouseup);
|
||||
Util.removeEvent(c, 'touchmove', this._eventHandlers.mousemove);
|
||||
c.removeEventListener('touchstart', this._eventHandlers.mousedown);
|
||||
window.removeEventListener('touchend', this._eventHandlers.mouseup);
|
||||
c.removeEventListener('touchend', this._eventHandlers.mouseup);
|
||||
c.removeEventListener('touchmove', this._eventHandlers.mousemove);
|
||||
} else {
|
||||
Util.removeEvent(c, 'mousedown', this._eventHandlers.mousedown);
|
||||
Util.removeEvent(window, 'mouseup', this._eventHandlers.mouseup);
|
||||
Util.removeEvent(c, 'mouseup', this._eventHandlers.mouseup);
|
||||
Util.removeEvent(c, 'mousemove', this._eventHandlers.mousemove);
|
||||
Util.removeEvent(c, (Util.Engine.gecko) ? 'DOMMouseScroll' : 'mousewheel',
|
||||
c.removeEventListener('mousedown', this._eventHandlers.mousedown);
|
||||
window.removeEventListener('mouseup', this._eventHandlers.mouseup);
|
||||
c.removeEventListener('mouseup', this._eventHandlers.mouseup);
|
||||
c.removeEventListener('mousemove', this._eventHandlers.mousemove);
|
||||
c.removeEventListener((Util.Engine.gecko) ? 'DOMMouseScroll' : 'mousewheel',
|
||||
this._eventHandlers.mousewheel);
|
||||
}
|
||||
|
||||
/* Work around right and middle click browser behaviors */
|
||||
Util.removeEvent(document, 'click', this._eventHandlers.mousedisable);
|
||||
Util.removeEvent(document.body, 'contextmenu', this._eventHandlers.mousedisable);
|
||||
document.removeEventListener('click', this._eventHandlers.mousedisable);
|
||||
document.body.removeEventListener('contextmenu', this._eventHandlers.mousedisable);
|
||||
|
||||
}
|
||||
};
|
||||
|
|
36
core/util.js
36
core/util.js
|
@ -232,41 +232,9 @@ Util.getEventPosition = function (e, obj, scale) {
|
|||
return {'x': x / scale, 'y': y / scale, 'realx': realx / scale, 'realy': realy / scale};
|
||||
};
|
||||
|
||||
|
||||
// Event registration. Based on: http://www.scottandrew.com/weblog/articles/cbs-events
|
||||
Util.addEvent = function (obj, evType, fn) {
|
||||
"use strict";
|
||||
if (obj.attachEvent) {
|
||||
var r = obj.attachEvent("on" + evType, fn);
|
||||
return r;
|
||||
} else if (obj.addEventListener) {
|
||||
obj.addEventListener(evType, fn, false);
|
||||
return true;
|
||||
} else {
|
||||
throw new Error("Handler could not be attached");
|
||||
}
|
||||
};
|
||||
|
||||
Util.removeEvent = function (obj, evType, fn) {
|
||||
"use strict";
|
||||
if (obj.detachEvent) {
|
||||
var r = obj.detachEvent("on" + evType, fn);
|
||||
return r;
|
||||
} else if (obj.removeEventListener) {
|
||||
obj.removeEventListener(evType, fn, false);
|
||||
return true;
|
||||
} else {
|
||||
throw new Error("Handler could not be removed");
|
||||
}
|
||||
};
|
||||
|
||||
Util.stopEvent = function (e) {
|
||||
"use strict";
|
||||
if (e.stopPropagation) { e.stopPropagation(); }
|
||||
else { e.cancelBubble = true; }
|
||||
|
||||
if (e.preventDefault) { e.preventDefault(); }
|
||||
else { e.returnValue = false; }
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
};
|
||||
|
||||
Util._cursor_uris_supported = null;
|
||||
|
|
|
@ -107,9 +107,9 @@
|
|||
canvas = new Display({'target' : document.getElementById('canvas')});
|
||||
keyboard = new Keyboard({'target': document,
|
||||
'onKeyPress': rfbKeyPress});
|
||||
Util.addEvent(document, 'keypress', rawKey);
|
||||
Util.addEvent(document, 'keydown', rawKey);
|
||||
Util.addEvent(document, 'keyup', rawKey);
|
||||
document.addEventListener('keypress', rawKey);
|
||||
document.addEventListener('keydown', rawKey);
|
||||
document.addEventListener('keyup', rawKey);
|
||||
mouse = new Mouse({'target': document.getElementById('canvas'),
|
||||
'onMouseButton': mouseButton,
|
||||
'onMouseMove': mouseMove});
|
||||
|
|
Loading…
Reference in New Issue