riktar / jkanban

Vanilla Javascript plugin for manage kanban boards

Home Page:https://www.riccardotartaglia.it/jkanban/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HEX colors for boards headers

Brecht272727 opened this issue · comments

Hi, is it possible to add a HEX color to the board header?
Now we use a class in the boards JSON but we need to add the color before in the css stylesheet.
It is better to have a different color attribute if we load the boards JSON.
Maybe there is a workaround?

I found out myself how to do this. See the code below.
We send the boardId via the ajax to database and in success response we retrieve the board_header_background_color and board_header_text_color. It's all outside the library.

      function change_background_colors_boards() {
        var titles = document.getElementsByClassName("kanban-title-board");
        if (titles.length == 0) {
          return;
        }

        for (var column = 0; column < titles.length; column++) {
          let currentColumn = titles[column];
          let boardId = currentColumn.parentElement.parentElement.dataset.id;
          
          $.ajax({
              url: 'assets/ajax/kanban-fetch-background-colors-board-header.php',
              dataType: 'json',
              cache: false,
              data: {boardId: boardId},
              type: "POST",
              success: function (data) {
                $(currentColumn.parentElement).css("background-color", data.board_header_background_color);
                $(currentColumn.parentElement).css("color", data.board_header_text_color);
              },
              error: function (xhr, status, error) {
                  console.log('An error occurred');
                  var err = eval("(" + xhr.responseText + ")");
                  console.log(err);
              }
          });          
          
        }
      }

      change_background_colors_boards();

There is a better way instead of ajax call again and again