JavaScript 65.5%
Python 17.8%
CSS 13%
HTML 3.7%
1"use strict";23Object.defineProperty(exports, "__esModule", {4 value: true5});6exports.getPointerEvent = getPointerEvent;7exports.releaseCapture = releaseCapture;8exports.setCapture = setCapture;9exports.stopEvent = stopEvent;10/*11 * noVNC: HTML5 VNC client12 * Copyright (C) 2018 The noVNC authors13 * Licensed under MPL 2.0 (see LICENSE.txt)14 *15 * See README.md for usage and integration instructions.16 */1718/*19 * Cross-browser event and position routines20 */2122function getPointerEvent(e) {23 return e.changedTouches ? e.changedTouches[0] : e.touches ? e.touches[0] : e;24}25function stopEvent(e) {26 e.stopPropagation();27 e.preventDefault();28}2930// Emulate Element.setCapture() when not supported31var _captureRecursion = false;32var _elementForUnflushedEvents = null;33document.captureElement = null;34function _captureProxy(e) {35 // Recursion protection as we'll see our own event36 if (_captureRecursion) return;3738 // Clone the event as we cannot dispatch an already dispatched event39 var newEv = new e.constructor(e.type, e);40 _captureRecursion = true;41 if (document.captureElement) {42 document.captureElement.dispatchEvent(newEv);43 } else {44 _elementForUnflushedEvents.dispatchEvent(newEv);45 }46 _captureRecursion = false;4748 // Avoid double events49 e.stopPropagation();5051 // Respect the wishes of the redirected event handlers52 if (newEv.defaultPrevented) {53 e.preventDefault();54 }5556 // Implicitly release the capture on button release57 if (e.type === "mouseup") {58 releaseCapture();59 }60}6162// Follow cursor style of target element63function _capturedElemChanged() {64 var proxyElem = document.getElementById("noVNC_mouse_capture_elem");65 proxyElem.style.cursor = window.getComputedStyle(document.captureElement).cursor;66}67var _captureObserver = new MutationObserver(_capturedElemChanged);68function setCapture(target) {69 if (target.setCapture) {70 target.setCapture();71 document.captureElement = target;72 } else {73 // Release any existing capture in case this method is74 // called multiple times without coordination75 releaseCapture();76 var proxyElem = document.getElementById("noVNC_mouse_capture_elem");77 if (proxyElem === null) {78 proxyElem = document.createElement("div");79 proxyElem.id = "noVNC_mouse_capture_elem";80 proxyElem.style.position = "fixed";81 proxyElem.style.top = "0px";82 proxyElem.style.left = "0px";83 proxyElem.style.width = "100%";84 proxyElem.style.height = "100%";85 proxyElem.style.zIndex = 10000;86 proxyElem.style.display = "none";87 document.body.appendChild(proxyElem);8889 // This is to make sure callers don't get confused by having90 // our blocking element as the target91 proxyElem.addEventListener('contextmenu', _captureProxy);92 proxyElem.addEventListener('mousemove', _captureProxy);93 proxyElem.addEventListener('mouseup', _captureProxy);94 }95 document.captureElement = target;9697 // Track cursor and get initial cursor98 _captureObserver.observe(target, {99 attributes: true100 });101 _capturedElemChanged();102 proxyElem.style.display = "";103104 // We listen to events on window in order to keep tracking if it105 // happens to leave the viewport106 window.addEventListener('mousemove', _captureProxy);107 window.addEventListener('mouseup', _captureProxy);108 }109}110function releaseCapture() {111 if (document.releaseCapture) {112 document.releaseCapture();113 document.captureElement = null;114 } else {115 if (!document.captureElement) {116 return;117 }118119 // There might be events already queued. The event proxy needs120 // access to the captured element for these queued events.121 // E.g. contextmenu (right-click) in Microsoft Edge122 //123 // Before removing the capturedElem pointer we save it to a124 // temporary variable that the unflushed events can use.125 _elementForUnflushedEvents = document.captureElement;126 document.captureElement = null;127 _captureObserver.disconnect();128 var proxyElem = document.getElementById("noVNC_mouse_capture_elem");129 proxyElem.style.display = "none";130 window.removeEventListener('mousemove', _captureProxy);131 window.removeEventListener('mouseup', _captureProxy);132 }133}