riktar / jkanban

Vanilla Javascript plugin for manage kanban boards
https://www.riccardotartaglia.it/jkanban/
Apache License 2.0
1.06k stars 296 forks source link

HEX colors for boards headers #177

Closed Brecht272727 closed 1 year ago

Brecht272727 commented 1 year ago

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?

Brecht272727 commented 1 year ago

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();
asimp51 commented 1 year ago

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