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.setViewClip();
|
||||||
UI.setBarPosition();
|
UI.setBarPosition();
|
||||||
|
|
||||||
Util.addEvent(window, 'resize', function () {
|
window.addEventListener('resize', function () {
|
||||||
UI.applyResizeMode();
|
UI.applyResizeMode();
|
||||||
UI.setViewClip();
|
UI.setViewClip();
|
||||||
UI.updateViewDrag();
|
UI.updateViewDrag();
|
||||||
|
@ -160,17 +160,17 @@ var UI;
|
||||||
document.documentElement.webkitRequestFullscreen ||
|
document.documentElement.webkitRequestFullscreen ||
|
||||||
document.body.msRequestFullscreen)) {
|
document.body.msRequestFullscreen)) {
|
||||||
document.getElementById('noVNC_fullscreen_button').style.display = "inline";
|
document.getElementById('noVNC_fullscreen_button').style.display = "inline";
|
||||||
Util.addEvent(window, 'fullscreenchange', UI.updateFullscreenButton);
|
window.addEventListener('fullscreenchange', UI.updateFullscreenButton);
|
||||||
Util.addEvent(window, 'mozfullscreenchange', UI.updateFullscreenButton);
|
window.addEventListener('mozfullscreenchange', UI.updateFullscreenButton);
|
||||||
Util.addEvent(window, 'webkitfullscreenchange', UI.updateFullscreenButton);
|
window.addEventListener('webkitfullscreenchange', UI.updateFullscreenButton);
|
||||||
Util.addEvent(window, 'msfullscreenchange', 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
|
// While connected we want to display a confirmation dialogue
|
||||||
// if the user tries to leave the page
|
// 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') {
|
if (UI.rfb && UI.rfb_state === 'normal') {
|
||||||
var msg = "You are currently connected.";
|
var msg = "You are currently connected.";
|
||||||
e.returnValue = msg;
|
e.returnValue = msg;
|
||||||
|
|
|
@ -122,12 +122,12 @@
|
||||||
//Util.Debug(">> Keyboard.grab");
|
//Util.Debug(">> Keyboard.grab");
|
||||||
var c = this._target;
|
var c = this._target;
|
||||||
|
|
||||||
Util.addEvent(c, 'keydown', this._eventHandlers.keydown);
|
c.addEventListener('keydown', this._eventHandlers.keydown);
|
||||||
Util.addEvent(c, 'keyup', this._eventHandlers.keyup);
|
c.addEventListener('keyup', this._eventHandlers.keyup);
|
||||||
Util.addEvent(c, 'keypress', this._eventHandlers.keypress);
|
c.addEventListener('keypress', this._eventHandlers.keypress);
|
||||||
|
|
||||||
// Release (key up) if window loses focus
|
// Release (key up) if window loses focus
|
||||||
Util.addEvent(window, 'blur', this._eventHandlers.blur);
|
window.addEventListener('blur', this._eventHandlers.blur);
|
||||||
|
|
||||||
//Util.Debug("<< Keyboard.grab");
|
//Util.Debug("<< Keyboard.grab");
|
||||||
},
|
},
|
||||||
|
@ -136,10 +136,10 @@
|
||||||
//Util.Debug(">> Keyboard.ungrab");
|
//Util.Debug(">> Keyboard.ungrab");
|
||||||
var c = this._target;
|
var c = this._target;
|
||||||
|
|
||||||
Util.removeEvent(c, 'keydown', this._eventHandlers.keydown);
|
c.removeEventListener('keydown', this._eventHandlers.keydown);
|
||||||
Util.removeEvent(c, 'keyup', this._eventHandlers.keyup);
|
c.removeEventListener('keyup', this._eventHandlers.keyup);
|
||||||
Util.removeEvent(c, 'keypress', this._eventHandlers.keypress);
|
c.removeEventListener('keypress', this._eventHandlers.keypress);
|
||||||
Util.removeEvent(window, 'blur', this._eventHandlers.blur);
|
window.removeEventListener('blur', this._eventHandlers.blur);
|
||||||
|
|
||||||
// Release (key up) all keys that are in a down state
|
// Release (key up) all keys that are in a down state
|
||||||
this._allKeysUp();
|
this._allKeysUp();
|
||||||
|
@ -347,44 +347,44 @@
|
||||||
var c = this._target;
|
var c = this._target;
|
||||||
|
|
||||||
if ('ontouchstart' in document.documentElement) {
|
if ('ontouchstart' in document.documentElement) {
|
||||||
Util.addEvent(c, 'touchstart', this._eventHandlers.mousedown);
|
c.addEventListener('touchstart', this._eventHandlers.mousedown);
|
||||||
Util.addEvent(window, 'touchend', this._eventHandlers.mouseup);
|
window.addEventListener('touchend', this._eventHandlers.mouseup);
|
||||||
Util.addEvent(c, 'touchend', this._eventHandlers.mouseup);
|
c.addEventListener('touchend', this._eventHandlers.mouseup);
|
||||||
Util.addEvent(c, 'touchmove', this._eventHandlers.mousemove);
|
c.addEventListener('touchmove', this._eventHandlers.mousemove);
|
||||||
} else {
|
} else {
|
||||||
Util.addEvent(c, 'mousedown', this._eventHandlers.mousedown);
|
c.addEventListener('mousedown', this._eventHandlers.mousedown);
|
||||||
Util.addEvent(window, 'mouseup', this._eventHandlers.mouseup);
|
window.addEventListener('mouseup', this._eventHandlers.mouseup);
|
||||||
Util.addEvent(c, 'mouseup', this._eventHandlers.mouseup);
|
c.addEventListener('mouseup', this._eventHandlers.mouseup);
|
||||||
Util.addEvent(c, 'mousemove', this._eventHandlers.mousemove);
|
c.addEventListener('mousemove', this._eventHandlers.mousemove);
|
||||||
Util.addEvent(c, (Util.Engine.gecko) ? 'DOMMouseScroll' : 'mousewheel',
|
c.addEventListener((Util.Engine.gecko) ? 'DOMMouseScroll' : 'mousewheel',
|
||||||
this._eventHandlers.mousewheel);
|
this._eventHandlers.mousewheel);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Work around right and middle click browser behaviors */
|
/* Work around right and middle click browser behaviors */
|
||||||
Util.addEvent(document, 'click', this._eventHandlers.mousedisable);
|
document.addEventListener('click', this._eventHandlers.mousedisable);
|
||||||
Util.addEvent(document.body, 'contextmenu', this._eventHandlers.mousedisable);
|
document.body.addEventListener('contextmenu', this._eventHandlers.mousedisable);
|
||||||
},
|
},
|
||||||
|
|
||||||
ungrab: function () {
|
ungrab: function () {
|
||||||
var c = this._target;
|
var c = this._target;
|
||||||
|
|
||||||
if ('ontouchstart' in document.documentElement) {
|
if ('ontouchstart' in document.documentElement) {
|
||||||
Util.removeEvent(c, 'touchstart', this._eventHandlers.mousedown);
|
c.removeEventListener('touchstart', this._eventHandlers.mousedown);
|
||||||
Util.removeEvent(window, 'touchend', this._eventHandlers.mouseup);
|
window.removeEventListener('touchend', this._eventHandlers.mouseup);
|
||||||
Util.removeEvent(c, 'touchend', this._eventHandlers.mouseup);
|
c.removeEventListener('touchend', this._eventHandlers.mouseup);
|
||||||
Util.removeEvent(c, 'touchmove', this._eventHandlers.mousemove);
|
c.removeEventListener('touchmove', this._eventHandlers.mousemove);
|
||||||
} else {
|
} else {
|
||||||
Util.removeEvent(c, 'mousedown', this._eventHandlers.mousedown);
|
c.removeEventListener('mousedown', this._eventHandlers.mousedown);
|
||||||
Util.removeEvent(window, 'mouseup', this._eventHandlers.mouseup);
|
window.removeEventListener('mouseup', this._eventHandlers.mouseup);
|
||||||
Util.removeEvent(c, 'mouseup', this._eventHandlers.mouseup);
|
c.removeEventListener('mouseup', this._eventHandlers.mouseup);
|
||||||
Util.removeEvent(c, 'mousemove', this._eventHandlers.mousemove);
|
c.removeEventListener('mousemove', this._eventHandlers.mousemove);
|
||||||
Util.removeEvent(c, (Util.Engine.gecko) ? 'DOMMouseScroll' : 'mousewheel',
|
c.removeEventListener((Util.Engine.gecko) ? 'DOMMouseScroll' : 'mousewheel',
|
||||||
this._eventHandlers.mousewheel);
|
this._eventHandlers.mousewheel);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Work around right and middle click browser behaviors */
|
/* Work around right and middle click browser behaviors */
|
||||||
Util.removeEvent(document, 'click', this._eventHandlers.mousedisable);
|
document.removeEventListener('click', this._eventHandlers.mousedisable);
|
||||||
Util.removeEvent(document.body, 'contextmenu', 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};
|
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) {
|
Util.stopEvent = function (e) {
|
||||||
"use strict";
|
e.stopPropagation();
|
||||||
if (e.stopPropagation) { e.stopPropagation(); }
|
e.preventDefault();
|
||||||
else { e.cancelBubble = true; }
|
|
||||||
|
|
||||||
if (e.preventDefault) { e.preventDefault(); }
|
|
||||||
else { e.returnValue = false; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Util._cursor_uris_supported = null;
|
Util._cursor_uris_supported = null;
|
||||||
|
|
|
@ -107,9 +107,9 @@
|
||||||
canvas = new Display({'target' : document.getElementById('canvas')});
|
canvas = new Display({'target' : document.getElementById('canvas')});
|
||||||
keyboard = new Keyboard({'target': document,
|
keyboard = new Keyboard({'target': document,
|
||||||
'onKeyPress': rfbKeyPress});
|
'onKeyPress': rfbKeyPress});
|
||||||
Util.addEvent(document, 'keypress', rawKey);
|
document.addEventListener('keypress', rawKey);
|
||||||
Util.addEvent(document, 'keydown', rawKey);
|
document.addEventListener('keydown', rawKey);
|
||||||
Util.addEvent(document, 'keyup', rawKey);
|
document.addEventListener('keyup', rawKey);
|
||||||
mouse = new Mouse({'target': document.getElementById('canvas'),
|
mouse = new Mouse({'target': document.getElementById('canvas'),
|
||||||
'onMouseButton': mouseButton,
|
'onMouseButton': mouseButton,
|
||||||
'onMouseMove': mouseMove});
|
'onMouseMove': mouseMove});
|
||||||
|
|
Loading…
Reference in New Issue