829bf3b11754fe9c045d1e95dcd8dca3ee3ad5da
[vchess.git] / public / javascripts / components / rules.js
1 // Load rules on variant page
2 Vue.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)
9 ajax("/rules/" + variant, "GET", response => {
10 let replaceByDiag = (match, p1, p2) => {
11 const args = this.parseFen(p2);
12 return getDiagram(args);
13 };
14 this.content = response.replace(/(fen:)([^:]*):/g, replaceByDiag);
15 });
16 },
17 methods: {
18 parseFen(fen) {
19 const fenParts = fen.split(" ");
20 return {
21 position: fenParts[0],
22 marks: fenParts[1],
23 orientation: fenParts[2],
24 };
25 },
26 },
27 })