Skip to content

Commit

Permalink
Added another query parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
7131 committed Dec 10, 2021
1 parent c8d0fe5 commit 8f90b1b
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions controller.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
// Controller class
const Controller = function() {
// get the query string
// fields
this._prev = "";
if (window.location.search != "") {
let results = window.location.search.match(/[?&]pattern=([^&#]*)/);
if (2 <= results.length) {
this._prev = decodeURIComponent(results[1].replace(/\+/g, " "));
}
}

// other fields
this._parser = new Parser(Grammar, Converter);
this._validator = new Validator();

Expand Down Expand Up @@ -42,10 +34,26 @@ Controller.prototype = {
this._jmj = new Jmj({ "canvas": board });

// analyze the query string
if (this._prev != "") {
this._patternText.value = this._prev;
this._analyze({});
const pattern = this._getParam("pattern");
if (pattern != "") {
this._patternText.value = pattern;
const run = this._getParam("run");
if (run == "yes" || run == "true") {
this._start({});
} else {
this._analyze({});
}
}
},

// get the query parameter
"_getParam": function(key) {
const pattern = new RegExp("[?&]" + key + "=([^&]*)");
const value = window.location.search.match(pattern);
if (!Array.isArray(value)) {
return "";
}
return decodeURIComponent(value[1].replace(/\+/g, " "));
},

// "Analyze" button process
Expand Down

0 comments on commit 8f90b1b

Please sign in to comment.