+ firstChars: function(text) {
+ let preparedText = text
+ // Replace line jumps and <br> by spaces
+ .replace(/\n/g, " ")
+ .replace(/<br\/?>/g, " ")
+ .replace(/<[^>]+>/g, "") //remove remaining HTML tags
+ .replace(/[ ]+/g, " ") //remove series of spaces by only one
+ .trim();
+ const maxLength = 32; //arbitrary...
+ if (preparedText.length > maxLength)
+ return preparedText.substr(0, 32) + "...";
+ return preparedText;
+ },
+ copyProblem: function(p1, p2) {
+ for (let key in p1) p2[key] = p1[key];
+ },
+ setHrefPid: function(p) {
+ // Change href => $route changes, watcher notices, call showProblem
+ const curHref = document.location.href;
+ document.location.href = curHref.split("?")[0] + "?id=" + p.id;
+ },
+ backToList: function() {
+ // Change href => $route change, watcher notices, reset showOne to false
+ document.location.href = document.location.href.split("?")[0];
+ },
+ resetCurProb: function() {
+ this.curproblem.id = 0;
+ this.curproblem.uid = 0;
+ this.curproblem.vid = "";
+ this.curproblem.vname = "";
+ this.curproblem.fen = "";
+ this.curproblem.diag = "";
+ this.curproblem.instruction = "";
+ this.curproblem.solution = "";
+ this.curproblem.showSolution = false;
+ },
+ parseHtml: function(txt) {
+ return !txt.match(/<[/a-zA-Z]+>/)
+ ? txt.replace(/\n/g, "<br/>") //no HTML tag
+ : txt;
+ },
+ changeVariant: function(prob) {
+ this.setVname(prob);
+ this.loadVariant(prob.vid, () => {
+ // Set FEN if possible (might not be correct yet)
+ if (V.IsGoodFen(prob.fen)) this.setDiagram(prob);
+ });
+ },
+ loadVariant: async function(vid, cb) {
+ // Condition: vid is a valid variant ID
+ this.loadedVar = 0;
+ const variant = this.st.variants.find(v => v.id == vid);