<commit_before>/*
 * noVNC: HTML5 VNC client
 * Copyright (C) 2012 <NAME>
 * Licensed under LGPL-3 (see LICENSE.txt)
 *
 * See README.md for usage and integration instructions.
 */

"use strict";
/*jslint white: false, browser: true */
/*global window, $D, Util, WebUtil, RFB, Display */

// Load supporting scripts
window.onscriptsload = function () {
	//UI.load();
};
window.onload = function () {
	//UI.keyboardinputReset();
};

var INCLUDE_URI = "/core/plugins/tools/novnc/assets/novnc/";

/*Util.load_scripts([
	"webutil.js",
	"base64.js",
	"websock.js",
	"des.js",
	"keysymdef.js",
	"keyboard.js",
	"input.js",
	"display.js",
	"jsunzip.js",
	"rfb.js",
	"keysym.js"
]);*/


var UI = {

	rfb_state:        'loaded',
	settingsOpen:      false,
	connSettingsOpen:  false,
	clipboardOpen:     false,
	keyboardVisible:   false,
	clipSetting:       false,
	clipSettingLocked: false,

	// Render default UI and initialize settings menu
	load: function() {
		var html = '';

		UI.rfb = new RFB({
			'focusContainer': $D('app-content'),
			'target':        $D('noVNC_canvas'),
			'encrypt':       encrypt,
			'true_color':    true,
			'local_cursor':  true,
			'shared':        true,
			'view_only':     false,
			//'updateState':  UI.updateState,
			'onUpdateState': UI.updateState,
			'onClipboard':   UI.clipReceive,
			'onPasswordRequired': function() {
				alert('Connection failed: bad password');
			},
			'onFBResize': function() {
				// Update containers dimensions
				// Need a slight delay here to give the canvas time to have its dimensions
				// updated before attempting to grab those dimensions
				var resizeContainersTimeout = setTimeout(function(){
					console.log('RESIZED');
					UI.resizeContainers(0, 0);
				}, 500);
			}
		});

		UI.updateVisualState();

		// Unfocus clipboard when over the VNC area
		//$D('VNC_screen').onmousemove = function () {
		//         var keyboard = UI.rfb.get_keyboard();
		//        if ((! keyboard) || (! keyboard.get_focused())) {
		//            $D('VNC_clipboard_text').blur();
		//         }
		//    };

		// Show mouse selector buttons on touch screen devices
		if ('ontouchstart' in document.documentElement || window.navigator.msPointerEnabled) {
			// Show mobile buttons
			$D('noVNC_mobile_buttons').style.display = "inline";
			UI.setMouseButton();

			// Remove the address bar
			setTimeout(function() { window.scrollTo(0, 1); }, 100);
			UI.clipSetting = false; //true;
			//UI.clipSettingLocked = true;
		} else {
			UI.clipSetting = false;
		}

		//iOS Safari does not support CSS position:fixed.
		//This detects iOS devices and enables javascript workaround.
		if ((navigator.userAgent.match(/iPhone/i)) ||
			(navigator.userAgent.match(/iPod/i)) ||
			(navigator.userAgent.match(/iPad/i))) {
			//UI.setOnscroll();
			//UI.setResize();
		}

		UI.setViewClip(UI.clipSetting);
		Util.addEvent(window, 'resize', UI.setViewClip);

		//Util.addEvent(document, 'keyup', UI.checkFocusBounds);
		//Util.addEvent(document, 'keydown', UI.checkFocusBounds);
		//Util.addEvent(document, 'keypress', UI.checkFocusBounds);
		Util.addEvent(document, 'click', UI.checkFocusBounds);
		UI.rfb._focusContainer.focus();

		/*Util.addEvent(window, 'beforeunload', function () {
			if (UI.rfb_state === 'normal') {
				return "You are currently connected.";
			}
		});*/

		//Finally, connect with globals
		UI.rfb.connect(host, port, password, connectPath);
	},

	checkFocusBounds: function(e) {
		var evt = (e ? e : window.event),
			c = UI.rfb._focusContainer;

		var pos = Util.getEventPosition(e, c, UI.rfb.get_mouse()._scale);

		if ((pos.realx >= 0) && (pos.realy >= 0) &&
			(pos.realx < c.offsetWidth) &&
			(pos.realy < c.offsetHeight)) {
			c.focus();
		}
	},

	resizeContainers: function(w, h) {
		var container = $D('noVNC_container'),
			wrapper   = $D('app-content');

		if (!w || !h) {
			var canvas = $D('noVNC_canvas');
			w = canvas.width;
			h = canvas.height;
		}

		if (container.style.width.replace('px', '') != w.toString()
		 || container.style.height.replace('px', '') != h.toString()) {
			// Set the continer's dimensions
			container.style.width  = w + 'px';
			container.style.height = h + 'px';
			// Set the wrap's dimensions
			wrapper.style.width  = w + 'px';
			wrapper.style.height = h + 'px';
			// If the resize button exists...
			if ($D('app-size')) {
				$D('app-size').innerHTML = w.toString() + ' x ' + h.toString();
			}
		}
	},

	// Show the clipboard panel
	toggleClipboardPanel: function() {
		//Toggle Clipboard Panel
		if (UI.clipboardOpen === true) {
			$D('noVNC_clipboard').style.display = "none";
			$D('clipboardButton').className = "noVNC_status_button";
			UI.clipboardOpen = false;
		} else {
			$D('noVNC_clipboard').style.display = "block";<commit_msg>[fix] Update wrapping container's width on load Width wouldn't be properly set on the app-wrap container on initial page load for a resized tool.<commit_after>/*
 * noVNC: HTML5 VNC client
 * Copyright (C) 2012 <NAME>
 * Licensed under LGPL-3 (see LICENSE.txt)
 *
 * See README.md for usage and integration instructions.
 */

"use strict";
/*jslint white: false, browser: true */
/*global window, $D, Util, WebUtil, RFB, Display */

// Load supporting scripts
window.onscriptsload = function () {
	//UI.load();
};
window.onload = function () {
	//UI.keyboardinputReset();
};

var INCLUDE_URI = "/core/plugins/tools/novnc/assets/novnc/";

/*Util.load_scripts([
	"webutil.js",
	"base64.js",
	"websock.js",
	"des.js",
	"keysymdef.js",
	"keyboard.js",
	"input.js",
	"display.js",
	"jsunzip.js",
	"rfb.js",
	"keysym.js"
]);*/


var UI = {

	rfb_state:        'loaded',
	settingsOpen:      false,
	connSettingsOpen:  false,
	clipboardOpen:     false,
	keyboardVisible:   false,
	clipSetting:       false,
	clipSettingLocked: false,

	// Render default UI and initialize settings menu
	load: function() {
		var html = '';

		UI.rfb = new RFB({
			'focusContainer': $D('app-content'),
			'target':        $D('noVNC_canvas'),
			'encrypt':       encrypt,
			'true_color':    true,
			'local_cursor':  true,
			'shared':        true,
			'view_only':     false,
			//'updateState':  UI.updateState,
			'onUpdateState': UI.updateState,
			'onClipboard':   UI.clipReceive,
			'onPasswordRequired': function() {
				alert('Connection failed: bad password');
			},
			'onFBResize': function() {
				// Update containers dimensions
				// Need a slight delay here to give the canvas time to have its dimensions
				// updated before attempting to grab those dimensions
				var resizeContainersTimeout = setTimeout(function(){
					console.log('RESIZED');
					UI.resizeContainers(0, 0);
				}, 500);
			}
		});

		UI.updateVisualState();

		// Unfocus clipboard when over the VNC area
		//$D('VNC_screen').onmousemove = function () {
		//         var keyboard = UI.rfb.get_keyboard();
		//        if ((! keyboard) || (! keyboard.get_focused())) {
		//            $D('VNC_clipboard_text').blur();
		//         }
		//    };

		// Show mouse selector buttons on touch screen devices
		if ('ontouchstart' in document.documentElement || window.navigator.msPointerEnabled) {
			// Show mobile buttons
			$D('noVNC_mobile_buttons').style.display = "inline";
			UI.setMouseButton();

			// Remove the address bar
			setTimeout(function() { window.scrollTo(0, 1); }, 100);
			UI.clipSetting = false; //true;
			//UI.clipSettingLocked = true;
		} else {
			UI.clipSetting = false;
		}

		//iOS Safari does not support CSS position:fixed.
		//This detects iOS devices and enables javascript workaround.
		if ((navigator.userAgent.match(/iPhone/i)) ||
			(navigator.userAgent.match(/iPod/i)) ||
			(navigator.userAgent.match(/iPad/i))) {
			//UI.setOnscroll();
			//UI.setResize();
		}

		UI.setViewClip(UI.clipSetting);
		Util.addEvent(window, 'resize', UI.setViewClip);

		//Util.addEvent(document, 'keyup', UI.checkFocusBounds);
		//Util.addEvent(document, 'keydown', UI.checkFocusBounds);
		//Util.addEvent(document, 'keypress', UI.checkFocusBounds);
		Util.addEvent(document, 'click', UI.checkFocusBounds);
		UI.rfb._focusContainer.focus();

		/*Util.addEvent(window, 'beforeunload', function () {
			if (UI.rfb_state === 'normal') {
				return "You are currently connected.";
			}
		});*/

		//Finally, connect with globals
		UI.rfb.connect(host, port, password, connectPath);
	},

	checkFocusBounds: function(e) {
		var evt = (e ? e : window.event),
			c = UI.rfb._focusContainer;

		var pos = Util.getEventPosition(e, c, UI.rfb.get_mouse()._scale);

		if ((pos.realx >= 0) && (pos.realy >= 0) &&
			(pos.realx < c.offsetWidth) &&
			(pos.realy < c.offsetHeight)) {
			c.focus();
		}
	},

	resizeContainers: function(w, h) {
		var container = $D('noVNC_container'),
			wrapper   = $D('app-content');

		if (!w || !h) {
			var canvas = $D('noVNC_canvas');
			w = canvas.width;
			h = canvas.height;
		}

		if (container.style.width.replace('px', '') != w.toString()
		 || container.style.height.replace('px', '') != h.toString()) {
			// Set the continer's dimensions
			container.style.width  = w + 'px';
			container.style.height = h + 'px';
			// Set the wrap's dimensions
			wrapper.style.width  = w + 'px';
			wrapper.style.height = h + 'px';
			// Set the parent's dimensions
			var appwrap = $D('app-wrap');
			if (typeof appwrap !== 'undefined') {
				appwrap.style.width  = w + 'px';
			}
			// If the resize button exists...
			if ($D('app-size')) {
				$D('app-size').innerHTML = w.toString() + ' x ' + h.toString();
			}
		}
	},

	// Show the clipboard panel
	toggleClipboardPanel: function() {
		//Toggle Clipboard Panel
		if (UI.clipboardOpen === true) {
			$D('noVNC_clipboard').style.display = "none";
			$D('clipboardButton').className = "noVNC_status_button";
			UI.clipboardOpen = false;
		} else {
			$D('noVNC_clipboard').style.display = "block";
{'fraction_non_alphanumeric': 0.16894371941272432, 'fraction_numerical': 0.004078303425774877, 'mean_word_length': 3.190089705254165, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7315085', 'n_tokens_mistral': 3770, 'n_tokens_neox': 3318, 'n_words': 748}