|
5 | 5 | * QQ:155122504
|
6 | 6 | *
|
7 | 7 | */
|
8 |
| -(function(factory) { |
9 |
| - "use strict"; |
10 |
| - if (typeof define === "function" && (define.amd || define.cmd)) { |
11 |
| - define(["jquery"], factory); |
12 |
| - } else { |
13 |
| - factory((typeof(jQuery) != "undefined") ? jQuery : window.Zepto); |
14 |
| - } |
| 8 | +(function (factory) { |
| 9 | + "use strict"; |
| 10 | + if (typeof define === "function" && (define.amd || define.cmd)) { |
| 11 | + define(["jquery"], factory); |
| 12 | + } else { |
| 13 | + factory((typeof (jQuery) != "undefined") ? jQuery : window.Zepto); |
15 | 14 | }
|
16 |
| - (function($) { |
| 15 | +} |
| 16 | + (function ($) { |
17 | 17 | "use strict";
|
18 | 18 | $.extend({
|
19 |
| - LogOut: function() { |
| 19 | + LogOut: function () { |
20 | 20 | location.href = "/console/logout" + "?rnd=" + Math.random();
|
21 | 21 | }
|
22 | 22 | });
|
23 | 23 |
|
24 |
| - $.fn.ConsoleLogin = function(options) { |
| 24 | + $.fn.ConsoleLogin = function (options) { |
25 | 25 | if (options === undefined) {
|
26 | 26 | options = {};
|
27 | 27 | }
|
|
35 | 35 |
|
36 | 36 | username.focus();
|
37 | 37 |
|
38 |
| - var boxMsg = function(t) { |
| 38 | + var boxMsg = function (t) { |
39 | 39 | loginBoxMsg.html(t);
|
40 | 40 | loginBoxMsg.show();
|
41 | 41 | };
|
42 | 42 | var p = null;
|
43 |
| - $loginForm.bind("form-pre-serialize", function(event, form, options, veto) { |
| 43 | + $loginForm.bind("form-pre-serialize", function (event, form, options, veto) { |
44 | 44 | p = userpwd.val();
|
45 | 45 | });
|
46 | 46 |
|
47 | 47 | if (standalone === true) {
|
48 |
| - var keyEvt = function(obj) { |
| 48 | + var keyEvt = function (obj) { |
49 | 49 | $.post("/console/chksshdaddr?rnd=" + Math.random(), {
|
50 | 50 | "vm_addr": obj.val()
|
51 |
| - }, function(data) { |
| 51 | + }, function (data) { |
52 | 52 | console.log("data:", data);
|
53 | 53 | var json = data;
|
54 |
| - if (typeof(data) != "object") { |
| 54 | + if (typeof (data) != "object") { |
55 | 55 | json = $.parseJSON(data);
|
56 | 56 | }
|
57 | 57 | if (json.ok) {
|
|
60 | 60 | }
|
61 | 61 | });
|
62 | 62 | };
|
63 |
| - src_vmaddr.unbind("keyup").keyup(function(evt) { |
| 63 | + src_vmaddr.unbind("keyup").keyup(function (evt) { |
64 | 64 | keyEvt($(this));
|
65 | 65 | });
|
66 |
| - src_vmaddr.unbind("paste").bind("paste", function(evt) { |
| 66 | + src_vmaddr.unbind("paste").bind("paste", function (evt) { |
67 | 67 | keyEvt($(this));
|
68 | 68 | });
|
69 |
| - src_vmaddr.unbind("blur").blur(function(evt) { |
| 69 | + src_vmaddr.unbind("blur").blur(function (evt) { |
70 | 70 | keyEvt($(this));
|
71 | 71 | });
|
72 | 72 | }
|
73 | 73 |
|
74 | 74 | $loginForm.ajaxForm({
|
75 | 75 | dataType: "json",
|
76 |
| - beforeSubmit: function(a, f, o) { |
| 76 | + beforeSubmit: function (a, f, o) { |
77 | 77 | loginBoxMsg.hide();
|
78 | 78 | if (standalone === true) {
|
79 | 79 | if (src_vmaddr.val().length === 0) {
|
|
102 | 102 | return false;
|
103 | 103 | }
|
104 | 104 | },
|
105 |
| - success: function(data) { |
| 105 | + success: function (data) { |
106 | 106 | var json = data;
|
107 |
| - if (typeof(data) != "object") { |
| 107 | + if (typeof (data) != "object") { |
108 | 108 | json = $.parseJSON(data);
|
109 | 109 | }
|
110 | 110 | if (json.ok) {
|
|
118 | 118 | });
|
119 | 119 | };
|
120 | 120 |
|
121 |
| - $.fn.OpenTerminal = function(options) { |
| 121 | + $.fn.OpenTerminal = function (options) { |
122 | 122 | if (options === undefined) {
|
123 | 123 | options = {};
|
124 | 124 | }
|
125 | 125 | var wsaddr, $console = this;
|
126 | 126 | wsaddr = options.wsaddr === undefined ? "ws://127.0.0.1:8080/console" : options.wsaddr;
|
127 | 127 |
|
128 |
| - var resizeTerminal = function(t, c, r) { |
| 128 | + var resizeTerminal = function (t, c, r) { |
129 | 129 | var appbar_height = $("#c-appbar").height();
|
130 | 130 | var body_height = $(window).height();
|
131 | 131 | var body_width = $(window).width();
|
|
134 | 134 | t.resize(c, r);
|
135 | 135 | };
|
136 | 136 |
|
137 |
| - var getSize = function() { |
| 137 | + var getSize = function () { |
138 | 138 | function getCharSize() {
|
139 | 139 | var span = $("<span>", { text: "qwertyuiopasdfghjklzxcvbnm" });
|
140 | 140 | $console.append(span);
|
|
173 | 173 | var term = null;
|
174 | 174 | var socket = new WebSocket(wsaddr + "?cols=" + cols + "&rows=" + rows);
|
175 | 175 |
|
176 |
| - socket.onopen = function() { |
| 176 | + Terminal.applyAddon(fit); |
| 177 | + Terminal.applyAddon(attach); |
| 178 | + |
| 179 | + socket.onopen = function () { |
177 | 180 | term = new Terminal({
|
178 | 181 | termName: "xterm",
|
179 | 182 | cols: cols,
|
|
186 | 189 | colors: Terminal.xtermColors
|
187 | 190 | });
|
188 | 191 |
|
| 192 | + console.log(term); |
| 193 | + |
189 | 194 | term.attach(socket);
|
190 | 195 | term._initialized = true;
|
191 | 196 |
|
|
194 | 199 |
|
195 | 200 | resizeTerminal(term, cols, rows);
|
196 | 201 |
|
197 |
| - $(window).resize(function() { |
| 202 | + $(window).resize(function () { |
198 | 203 | resizeTerminal(term, cols, rows);
|
199 | 204 | });
|
200 | 205 |
|
201 |
| - term.on("title", function(title) { |
| 206 | + term.on("title", function (title) { |
202 | 207 | $(document).prop("title", title);
|
203 | 208 | });
|
204 | 209 |
|
205 |
| - term.on('paste', function(data, ev) { |
206 |
| - term.write(data); |
207 |
| - }); |
208 |
| - |
209 | 210 | window.term = term;
|
210 | 211 | window.socket = socket;
|
211 | 212 | };
|
212 |
| - socket.onclose = function(e) { |
| 213 | + socket.onclose = function (e) { |
213 | 214 | term.destroy();
|
214 | 215 | var span = $("<span></span>");
|
215 | 216 | span.text("网络中断(与服务器端连接已断开,请重新连接或联系管理员)。");
|
|
224 | 225 | });
|
225 | 226 | span.appendTo($console);
|
226 | 227 | };
|
227 |
| - socket.onerror = function(e) { |
| 228 | + socket.onerror = function (e) { |
228 | 229 | console.log("Socket error:", e);
|
229 | 230 | };
|
230 | 231 | };
|
231 | 232 |
|
232 |
| - $.fn.loading = function(options) { |
| 233 | + $.fn.loading = function (options) { |
233 | 234 | if (options === undefined) {
|
234 | 235 | options = {};
|
235 | 236 | }
|
|
0 commit comments