1
0
mirror of https://github.com/lxsang/antd-web-apps synced 2024-12-31 19:38:21 +01:00
antd-web-apps/apps/assets/scripts/main.js

222 lines
5.4 KiB
JavaScript
Raw Normal View History

2020-06-05 19:55:49 +02:00
// Generated by CoffeeScript 2.5.1
2018-08-28 14:49:03 +02:00
(function() {
2019-12-15 12:13:04 +01:00
var APIManager, BaseObject, MarkOn, WebVNC, require;
2018-08-28 14:49:03 +02:00
window.classes = {};
window.libraries = {};
window.myuri = "/";
window.mobilecheck = function() {
if (navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/BlackBerry/i) || navigator.userAgent.match(/Windows Phone/i)) {
return true;
}
return false;
};
window.makeclass = function(n, o) {
return window.classes[n] = o;
};
2018-09-17 19:43:24 +02:00
/*
window.require = (lib) ->
2020-06-05 19:55:49 +02:00
return new Promise (r, e) ->
return r() if window.libraries[lib]
$.getScript window.myuri + lib
.done (d) ->
window.libraries[lib] = true
r()
.fail (m, s) ->
e(m, s) */
2019-12-15 12:13:04 +01:00
// private function
2018-09-17 19:43:24 +02:00
require = function(lib) {
2018-08-28 14:49:03 +02:00
return new Promise(function(r, e) {
if (window.libraries[lib]) {
return r();
}
return $.getScript(window.myuri + lib).done(function(d) {
window.libraries[lib] = true;
return r();
}).fail(function(m, s) {
return e(m, s);
});
});
};
2019-12-15 12:13:04 +01:00
BaseObject = class BaseObject {
constructor(name) {
2018-08-28 14:49:03 +02:00
this.name = name;
}
2019-12-15 12:13:04 +01:00
ready() {
2018-08-28 14:49:03 +02:00
var me;
me = this;
return new Promise(function(r, e) {
return me.resolveDep().then(function() {
return r();
2019-12-15 12:13:04 +01:00
}).catch(function(m, s) {
2018-08-28 14:49:03 +02:00
return e(m, s);
});
});
2019-12-15 12:13:04 +01:00
}
2018-08-28 14:49:03 +02:00
2019-12-15 12:13:04 +01:00
resolveDep() {
2018-08-28 14:49:03 +02:00
var me;
me = this;
return new Promise(function(r, e) {
var dep, fn;
dep = window.classes[me.name].dependencies;
if (!dep) {
r();
}
fn = function(l, i) {
if (i >= dep.length) {
return r();
}
return require(l[i]).then(function() {
return fn(l, i + 1);
2019-12-15 12:13:04 +01:00
}).catch(function(m, s) {
2018-08-28 14:49:03 +02:00
return e(m, s);
});
};
return fn(dep, 0);
});
2019-12-15 12:13:04 +01:00
}
2018-08-28 14:49:03 +02:00
2019-12-15 12:13:04 +01:00
};
2018-08-28 14:49:03 +02:00
makeclass("BaseObject", BaseObject);
2019-12-15 12:13:04 +01:00
APIManager = class APIManager extends window.classes.BaseObject {
constructor(args1) {
super("APIManager");
2018-09-22 19:11:40 +02:00
this.args = args1;
2018-08-28 14:49:03 +02:00
}
2019-12-15 12:13:04 +01:00
init() {
2018-09-17 19:43:24 +02:00
var cname, me;
me = this;
if (!(this.args && this.args.length > 0)) {
return console.error("No class found");
}
cname = (this.args.splice(0, 1))[0].trim();
2018-08-28 14:49:03 +02:00
return this.ready().then(function() {
if (mobilecheck()) {
mobileConsole.init();
}
2019-12-15 12:13:04 +01:00
// load the class
2018-08-28 14:49:03 +02:00
if (!cname || cname === "") {
return;
}
if (!window.classes[cname]) {
return console.error("Cannot find class ", cname);
}
2018-09-17 19:43:24 +02:00
return (new window.classes[cname](me.args)).init();
2019-12-15 12:13:04 +01:00
}).catch(function(m, s) {
2018-08-28 14:49:03 +02:00
return console.error(m, s);
});
2019-12-15 12:13:04 +01:00
}
2018-08-28 14:49:03 +02:00
2019-12-15 12:13:04 +01:00
};
2018-08-28 14:49:03 +02:00
APIManager.dependencies = ["/assets/scripts/mobile_console.js"];
makeclass("APIManager", APIManager);
2019-12-15 12:13:04 +01:00
MarkOn = class MarkOn extends window.classes.BaseObject {
constructor() {
super("MarkOn");
2018-08-28 14:49:03 +02:00
}
2019-12-15 12:13:04 +01:00
init() {
2018-08-28 14:49:03 +02:00
var me;
me = this;
return this.ready().then(function() {
return me.editor = new SimpleMDE({
2018-08-28 15:07:46 +02:00
element: $("#editor")[0]
2018-08-28 14:49:03 +02:00
});
2019-12-15 12:13:04 +01:00
}).catch(function(m, s) {
2018-08-28 14:49:03 +02:00
return console.error(m, s);
});
2019-12-15 12:13:04 +01:00
}
2018-08-28 14:49:03 +02:00
2019-12-15 12:13:04 +01:00
};
2018-08-28 14:49:03 +02:00
MarkOn.dependencies = ["/rst/gscripts/mde/simplemde.min.js"];
makeclass("MarkOn", MarkOn);
2019-12-15 12:13:04 +01:00
WebVNC = class WebVNC extends window.classes.BaseObject {
constructor() {
super("WebVNC");
2018-09-17 19:43:24 +02:00
}
2019-12-15 12:13:04 +01:00
init() {
2018-09-17 19:43:24 +02:00
var me;
me = this;
return this.ready().then(function() {
2018-09-22 19:11:40 +02:00
return me.initVNCClient();
2019-12-15 12:13:04 +01:00
}).catch(function(m, s) {
2018-09-17 19:43:24 +02:00
return console.error(m, s);
});
2019-12-15 12:13:04 +01:00
}
2018-09-17 19:43:24 +02:00
2019-12-15 12:13:04 +01:00
initVNCClient() {
2018-09-22 19:11:40 +02:00
var args, me;
args = {
element: 'canvas',
2019-12-15 12:13:04 +01:00
//ws: 'wss://localhost:9192/wvnc',
2018-10-03 11:28:39 +02:00
ws: 'wss://lxsang.me/wvnc',
2018-09-22 19:11:40 +02:00
worker: '/assets/scripts/decoder.js'
2018-09-20 20:02:22 +02:00
};
2018-09-22 19:11:40 +02:00
this.client = new WVNC(args);
2018-09-18 19:53:00 +02:00
me = this;
2018-09-22 19:11:40 +02:00
this.client.onpassword = function() {
return new Promise(function(r, e) {
2018-09-23 14:08:19 +02:00
return r('demopass');
2018-09-22 19:11:40 +02:00
});
2018-09-17 19:43:24 +02:00
};
2018-09-22 19:11:40 +02:00
this.client.oncredential = function() {
return new Promise(function(r, e) {
2018-09-23 14:08:19 +02:00
return r('demo', 'demo');
2018-09-22 19:11:40 +02:00
});
2018-09-17 19:43:24 +02:00
};
2018-09-22 19:11:40 +02:00
this.client.oncopy = function(text) {
2018-10-03 11:28:39 +02:00
return cosole.log(text);
2018-09-17 19:43:24 +02:00
};
2018-10-09 12:14:33 +02:00
this.client.onerror = function(m) {
return alert(m);
};
2018-09-22 19:11:40 +02:00
return this.client.init().then(function() {
$("#connect").click(function(e) {
2018-10-03 11:28:39 +02:00
return me.client.connect("/opt/www/vnc.conf", {
2018-09-22 19:11:40 +02:00
bbp: 32,
flag: 3,
2018-10-03 11:28:39 +02:00
quality: 30
2018-09-22 19:11:40 +02:00
});
});
2018-10-03 11:28:39 +02:00
$("#tbstatus").html("32bbp, compression JPEG & ZLib, JPEG quality 30%");
2018-09-22 19:11:40 +02:00
$("#stop").click(function(e) {
return me.client.disconnect();
});
2018-09-23 14:08:19 +02:00
return $("#selscale").on('change', function(e) {
var value;
value = Number(this.value) / 100;
return me.client.setScale(value);
2018-09-22 19:11:40 +02:00
});
2019-12-15 12:13:04 +01:00
//$("#btclipboard").click (e) ->
// me.client.sendTextAsClipboard ($ "#clipboard")[0].value
}).catch(function(m, s) {
2018-09-22 19:11:40 +02:00
return console.error(m, s);
});
2019-12-15 12:13:04 +01:00
}
2018-09-17 19:43:24 +02:00
2019-12-15 12:13:04 +01:00
};
2018-09-17 19:43:24 +02:00
2018-09-22 19:11:40 +02:00
WebVNC.dependencies = ["/assets/scripts/wvnc.js"];
2018-09-17 19:43:24 +02:00
2018-09-22 19:11:40 +02:00
makeclass("WebVNC", WebVNC);
2018-09-17 19:43:24 +02:00
2018-08-28 14:49:03 +02:00
}).call(this);