Browse Source

Remove jquery dependency from DOMInput and Output classes

Lucas de Souza 5 years ago
parent
commit
84c893a27a
2 changed files with 27 additions and 13 deletions
  1. 16 10
      js/io/domInput.js
  2. 11 3
      js/io/domOutput.js

+ 16 - 10
js/io/domInput.js

@@ -4,21 +4,27 @@ export class DOMInput extends Input{
 
   constructor (element) {
     super();
-    this.el = $(element);
+    let id = element
+    if(element[0] == '#') {
+      id = element.substring(1);
+    }
+    this.el = document.getElementById(id);
     this.listeners = [];
     this.setupEvents();
   }
 
   setupEvents () {
-    this.el.on('keydown', (e) => {
-      const code = e.keyCode || e.which;
-      if (code === 13) {
-        let text = this.el.val();
-        text = text.replace('[\n\r]+', '');
-        this.notifyInput(text);
-        this.el.val('');
-      }
-    });
+    this.el.addEventListener('keydown', this.captureInput.bind(this));
+  }
+
+  captureInput (event) {
+    const code = event.keyCode || event.which;
+    if (code === 13) {
+      let text = this.el.value;
+      text = text.replace('[\n\r]+', '');
+      this.notifyInput(text);
+      this.el.value = "";
+    }
   }
 
   requestInput (callback) {

+ 11 - 3
js/io/domOutput.js

@@ -4,17 +4,25 @@ export class DOMOutput extends Output {
 
   constructor (selector) {
     super();
-    this.el = $(selector);
+    let id = selector;
+    if (selector[0] == '#') {
+      id = selector.substring(1);
+    }
+    this.el = document.getElementById(id);
   }
 
   sendOutput (text) {
     text = text.replace("\n", '</br>');
     text = text.replace(/\t/g,'&#9;');
-    const span = $('<span />').addClass('ivprog-io-output-text').html(text);
+    const span = document.createElement('span');
+    span.classList.add('ivprog-io-output-text');
+    span.innerHTML = text;
     this.el.append(span);
   }
 
   clear () {
-    this.el.empty();
+    while(this.el.childNodes.length > 0) {
+      this.el.removeChild(this.el.firstChild);
+    }
   }
 }