From 0e8615da37032a4b043252023ec6eab5996ab9da Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Thu, 17 Mar 2022 23:19:38 +0300 Subject: update QR code on config updates --- assets/js/main.js | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'assets') diff --git a/assets/js/main.js b/assets/js/main.js index fdda3f4..2d205dd 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -465,8 +465,7 @@ function make_pre_buttons(path, pre) { .append(edit_btn); } -function format_pre_text(text, name) { - var pre = $('
').text(text);
+function format_pre_text(pre, name) {
     return $('
') .append(pre) .append(make_pre_buttons(name, pre)); @@ -475,28 +474,36 @@ function format_pre_text(text, name) { var ConfigFile = function(name, text) { this.name = name; this.text = text; -} - -ConfigFile.prototype.toString = function() { - return this.text; + this.pre = $('
').text(text);
 }
 
 ConfigFile.prototype.format = function() {
-    return format_pre_text(this.toString(), this.name);
+    return format_pre_text(this.pre, this.name);
 }
 
-var QRCode = function(text) {
-    this.text = text;
+var QRCode = function(pre) {
+    this.pre = pre;
 }
 
-QRCode.prototype.format = function() {
+function draw_qr_code(container, text) {
     var canvas = $('');
     var qr = new QRious({
         element: canvas[0],
-        value: this.text,
+        value: text,
         size: 350
     });
-    return $('
').append(canvas); + container.append(canvas); +} + +QRCode.prototype.format = function() { + var container = $('
'); + var pre = this.pre; + pre.on('blur', function() { + container.empty(); + draw_qr_code(container, pre.text()); + }); + draw_qr_code(container, pre.text()); + return container; } function wg_quick_client_file(data) { @@ -774,7 +781,7 @@ GuideWgQuick.prototype.constructor = GuideWgQuick; GuideWgQuick.prototype.for_client = function(data) { var config = wg_quick_client_file(data); - var qr = new QRCode(config.text); + var qr = new QRCode(config.pre); return [config, qr]; } -- cgit v1.2.3