Almost finished problems logic. TODO: showProblem() part
[vchess.git] / public / javascripts / components / rules.js
CommitLineData
92342261 1// Load rules on variant page
1d184b4c
BA
2Vue.component('my-rules', {
3 data: function() {
4 return { content: "" };
5 },
6 template: `<div v-html="content" class="section-content"></div>`,
7 mounted: function() {
8 // AJAX request to get rules content (plain text, HTML)
da06a6eb
BA
9 ajax("/rules/" + variant, "GET", response => {
10 let replaceByDiag = (match, p1, p2) => {
7931e479 11 const args = this.parseFen(p2);
da06a6eb
BA
12 return getDiagram(args);
13 };
7931e479
BA
14 this.content = response.replace(/(fen:)([^:]*):/g, replaceByDiag);
15 });
1d184b4c
BA
16 },
17 methods: {
da06a6eb
BA
18 parseFen(fen) {
19 const fenParts = fen.split(" ");
20 return {
21 position: fenParts[0],
22 marks: fenParts[1],
23 orientation: fenParts[2],
24 };
1d184b4c
BA
25 },
26 },
27})