using js modules

This commit is contained in:
Devaev Maxim 2019-07-13 06:38:55 +03:00
parent ad97aecaf4
commit 98468bfa30
20 changed files with 104 additions and 70 deletions

View File

@ -1,20 +1,3 @@
globals:
Atx: true
Hid: true
Keyboard: true
Mouse: true
Msd: true
Session: true
Streamer: true
Keypad: true
WindowManager: true
wm: true
tools: true
checkBrowser: true
"$": true
"$$": true
"$$$": true
env:
browser: true
es6: true
@ -23,6 +6,7 @@ extends: "eslint:recommended"
parserOptions:
ecmaVersion: 6
sourceType: module
rules:
indent:

View File

@ -41,12 +41,10 @@
<link rel="stylesheet" href="share/css/start.css">
<link rel="stylesheet" href="share/css/index/index.css">
<script src="share/js/bb.js"></script>
<script src="share/js/tools.js"></script>
<script src="share/js/wm.js"></script>
<script src="share/js/index/main.js"></script>
<script>window.onload = main;</script>
<script type="module">
import {main} from "./share/js/index/main.js";
main();
</script>
</head>
<body>

View File

@ -38,10 +38,12 @@
<link rel="stylesheet" href="../share/css/main.css">
<link rel="stylesheet" href="../share/css/start.css">
<script src="../share/js/tools.js"></script>
<script src="../share/js/ipmi/main.js"></script>
<script>window.onload = main;</script>
<script type="module">
import {main} from "/share/js/ipmi/main.js";
main();
</script>
</head>
<body>

View File

@ -50,20 +50,10 @@
<link rel="stylesheet" href="../share/css/kvm/keyboard.css">
<link rel="stylesheet" href="../share/css/kvm/about.css">
<script src="../share/js/bb.js"></script>
<script src="../share/js/tools.js"></script>
<script src="../share/js/wm.js"></script>
<script src="../share/js/keypad.js"></script>
<script src="../share/js/kvm/stream.js"></script>
<script src="../share/js/kvm/atx.js"></script>
<script src="../share/js/kvm/keyboard.js"></script>
<script src="../share/js/kvm/mouse.js"></script>
<script src="../share/js/kvm/hid.js"></script>
<script src="../share/js/kvm/msd.js"></script>
<script src="../share/js/kvm/session.js"></script>
<script src="../share/js/kvm/main.js"></script>
<script>window.onload = main;</script>
<script type="module">
import {main} from "/share/js/kvm/main.js";
main();
</script>
</head>
<body class="body-no-select">

View File

@ -40,12 +40,10 @@
<link rel="stylesheet" href="../share/css/modals.css">
<link rel="stylesheet" href="../share/css/login/login.css">
<script src="../share/js/bb.js"></script>
<script src="../share/js/tools.js"></script>
<script src="../share/js/wm.js"></script>
<script src="../share/js/login/main.js"></script>
<script>window.onload = main;</script>
<script type="module">
import {main} from "/share/js/login/main.js";
main();
</script>
</head>
<body>

View File

@ -20,7 +20,7 @@
*****************************************************************************/
function checkBrowser() {
export function checkBrowser() {
if (
!window.navigator
|| window.navigator.userAgent.indexOf("MSIE ") > 0

View File

@ -20,10 +20,13 @@
*****************************************************************************/
var wm;
import {tools, $} from "../tools.js";
import {checkBrowser} from "../bb.js";
import {wm, initWindowManager} from "../wm.js";
function main() {
wm = new WindowManager();
export function main() {
initWindowManager();
if (checkBrowser()) {
__setAppText();

View File

@ -20,7 +20,10 @@
*****************************************************************************/
function main() {
import {$} from "../tools.js";
export function main() {
let host = window.location.hostname;
let site = window.location.protocol + "//" + window.location.host;
$("ipmi-text").innerHTML = `

View File

@ -20,7 +20,10 @@
*****************************************************************************/
function Keypad(keys_parent, key_callback) {
import {tools, $$$} from "./tools.js";
export function Keypad(keys_parent, key_callback) {
var self = this;
/************************************************************************/

View File

@ -20,7 +20,11 @@
*****************************************************************************/
function Atx() {
import {tools, $} from "../tools.js";
import {wm} from "../wm.js";
export function Atx() {
var self = this;
/************************************************************************/

View File

@ -20,7 +20,14 @@
*****************************************************************************/
function Hid() {
import {tools, $, $$$} from "../tools.js";
import {wm} from "../wm.js";
import {Keyboard} from "./keyboard.js";
import {Mouse} from "./mouse.js";
export function Hid() {
var self = this;
/************************************************************************/

View File

@ -20,7 +20,11 @@
*****************************************************************************/
function Keyboard() {
import {tools, $} from "../tools.js";
import {Keypad} from "../keypad.js";
export function Keyboard() {
var self = this;
/************************************************************************/

View File

@ -20,9 +20,14 @@
*****************************************************************************/
var wm;
import {tools, $} from "../tools.js";
import {checkBrowser} from "../bb.js";
import {wm, initWindowManager} from "../wm.js";
function main() {
import {Session} from "./session.js";
export function main() {
if (checkBrowser()) {
window.onbeforeunload = function(event) {
let text = "Are you sure you want to close Pi-KVM session?";
@ -30,7 +35,7 @@ function main() {
return text;
};
wm = new WindowManager();
initWindowManager();
tools.setOnClick($("show-about-button"), () => wm.showWindow($("about-window")));
tools.setOnClick($("show-keyboard-button"), () => wm.showWindow($("keyboard-window")));

View File

@ -20,7 +20,11 @@
*****************************************************************************/
function Mouse() {
import {tools, $} from "../tools.js";
import {Keypad} from "../keypad.js";
export function Mouse() {
var self = this;
/************************************************************************/

View File

@ -20,7 +20,11 @@
*****************************************************************************/
function Msd() {
import {tools, $} from "../tools.js";
import {wm} from "../wm.js";
export function Msd() {
var self = this;
/************************************************************************/

View File

@ -20,7 +20,16 @@
*****************************************************************************/
function Session() {
import {tools, $} from "../tools.js";
import {wm} from "../wm.js";
import {Hid} from "./hid.js";
import {Atx} from "./atx.js";
import {Msd} from "./msd.js";
import {Streamer} from "./stream.js";
export function Session() {
// var self = this;
/************************************************************************/

View File

@ -20,7 +20,11 @@
*****************************************************************************/
function Streamer() {
import {tools, $} from "../tools.js";
import {wm} from "../wm.js";
export function Streamer() {
var self = this;
/************************************************************************/
@ -103,7 +107,7 @@ function Streamer() {
__client_id = stream_client.slice(stream_client.indexOf("/") + 1);
}
if (stream.clients_stat.hasOwnProperty(__client_id)) {
if (Object.prototype.hasOwnProperty.call(stream.clients_stat, __client_id)) {
__client_fps = stream.clients_stat[__client_id].fps;
} else {
__clearState();

View File

@ -20,11 +20,14 @@
*****************************************************************************/
var wm;
import {tools, $} from "../tools.js";
import {checkBrowser} from "../bb.js";
import {wm, initWindowManager} from "../wm.js";
function main() {
export function main() {
if (checkBrowser()) {
wm = new WindowManager();
initWindowManager();
tools.setOnClick($("login-button"), __login);
$("user-input").onkeyup = $("passwd-input").onkeyup = function(event) {

View File

@ -20,7 +20,7 @@
*****************************************************************************/
var tools = new function() {
export var tools = new function() {
let __debug = (new URL(window.location.href)).searchParams.get("debug");
this.setDefault = function(dict, key, value) {
@ -160,6 +160,6 @@ var tools = new function() {
this.info("Browser:", this.browser);
};
var $ = (id) => document.getElementById(id);
var $$ = (cls) => document.getElementsByClassName(cls);
var $$$ = (selector) => document.querySelectorAll(selector);
export var $ = (id) => document.getElementById(id);
export var $$ = (cls) => document.getElementsByClassName(cls);
export var $$$ = (selector) => document.querySelectorAll(selector);

View File

@ -20,7 +20,16 @@
*****************************************************************************/
function WindowManager() {
import {tools, $, $$, $$$} from "./tools.js";
export var wm;
export function initWindowManager() {
wm = new __WindowManager();
}
function __WindowManager() {
var self = this;
/************************************************************************/