Commit | Line | Data |
---|---|---|
92342261 | 1 | // Load rules on variant page |
1d184b4c BA |
2 | Vue.component('my-rules', { |
3 | data: function() { | |
4 | return { content: "" }; | |
5 | }, | |
a5d56686 BA |
6 | template: ` |
7 | <div class="col-sm-12 col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2"> | |
8 | <div v-html="content" class="section-content"></div> | |
9 | </div> | |
10 | `, | |
1d184b4c BA |
11 | mounted: function() { |
12 | // AJAX request to get rules content (plain text, HTML) | |
da06a6eb BA |
13 | ajax("/rules/" + variant, "GET", response => { |
14 | let replaceByDiag = (match, p1, p2) => { | |
7931e479 | 15 | const args = this.parseFen(p2); |
da06a6eb BA |
16 | return getDiagram(args); |
17 | }; | |
7931e479 BA |
18 | this.content = response.replace(/(fen:)([^:]*):/g, replaceByDiag); |
19 | }); | |
1d184b4c BA |
20 | }, |
21 | methods: { | |
da06a6eb BA |
22 | parseFen(fen) { |
23 | const fenParts = fen.split(" "); | |
24 | return { | |
25 | position: fenParts[0], | |
26 | marks: fenParts[1], | |
27 | orientation: fenParts[2], | |
5915f720 | 28 | shadow: fenParts[3], |
da06a6eb | 29 | }; |
1d184b4c BA |
30 | }, |
31 | }, | |
32 | }) |