Skip to content

Commit

Permalink
Other fixes to syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
studiofuga committed Sep 23, 2023
1 parent 8d124d3 commit eb646ec
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
30 changes: 23 additions & 7 deletions javascripts/discourse/initializers/pgn-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function configString (element) {

// ****** //

function parseParameters(element) {
function parseParameters(element, boardname) {
//## alternative for default values?
//const PgnBaseDefaults = { locale: 'fr', width: '400px', pieceStyle: 'merida' };

Expand All @@ -112,12 +112,17 @@ function parseParameters(element) {
const gameClean = cleanup_pgnv(game);

// NOTE: create all params with default
const id = (element.dataset.id || 'board');
const id = (element.dataset.id || boardname);
const pieceStyle = (element.dataset.pieceStyle || 'merida');

console.log("Attrs: boardname = " + boardname);
console.log("Game: " + game);

// TODO fill attrs with parameters found above.
// Use the parseParameters above?
return {};
return {
game: game
};
}

function createContainer(elem, boardname) {
Expand All @@ -134,6 +139,13 @@ function createContainer(elem, boardname) {


function initialize(api) {
let _glued = [];

function cleanUp() {
_glued.forEach(g => g.cleanUp());
_glued = [];
}

const register = getRegister(api);
function attachWidget(container, attrs) {
const glue = new WidgetGlue(
Expand All @@ -145,7 +157,7 @@ function initialize(api) {
_glued.push(glue);
}

api.decorateCookedElement(($cooked, postWidget) => {
api.decorateCooked(($cooked, postWidget) => {
const nodes = $cooked[0].querySelectorAll(
"div[data-wrap=discourse-pgn]"
);
Expand All @@ -158,16 +170,20 @@ function initialize(api) {
};

var wcount = 0;
placeholderNodes.forEach((elem, dataId, wcount) => {
var boardname = "board-" + id + "-" + count;
nodes.forEach((elem, dataId, wcount) => {
var boardname = "board-" + dataId + "-" + wcount;
console.log("BoardName: " + boardname);
var container = createContainer(elem, boardname);
var attrs = parseParameters(elem);
var attrs = parseParameters(elem, boardname);
attrs.boardname = boardname;
attachWidget(container, attrs);

wcount = wcount + 1;
});

}, { id: "discourse-pgn" });

api.cleanupStream(cleanUp);
}

export default {
Expand Down
4 changes: 3 additions & 1 deletion javascripts/discourse/widgets/pgn-viewer-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ createWidget("pgnviewer-widget", {
buildKey: (attrs) => `dice-result-${attrs.postId}-${attrs.rollId}`,

html(attrs) {
console.log("Rendering attrs: " + attrs);

var pgnv = new PGNV;
var pgnwidget = pgnv.pgnView('board', {
pgn: game,
pgn: attrs.game,
pieceStyle: 'merida'
});

Expand Down

0 comments on commit eb646ec

Please sign in to comment.