Commit d760052d authored by Daniel Cothran's avatar Daniel Cothran
Browse files

Issue #3261881 by tatianag, andileco, nikathone: Deprecate jquery.once and use...

Issue #3261881 by tatianag, andileco, nikathone: Deprecate jquery.once and use the new core/once lib
parent 8ff0af85
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -9,8 +9,8 @@ charts_chartjs:
    /libraries/chartjs/dist/chart.js: { }
    /libraries/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.bundle.js: { }
  dependencies:
    - core/jquery
    - core/drupal
    - core/jquery
    - core/once
chartjs:
  version: 1.x
+14 −11
Original line number Diff line number Diff line
@@ -7,21 +7,24 @@
  Drupal.behaviors.chartsChartjs = {
    attach: function (context, settings) {
      var contents = new Drupal.Charts.Contents();
      once('load-charts-chartjs', '.charts-chartjs', context).forEach(function (elt) {
      $('.charts-chartjs').each(function () {
        // Store attributes before switching div for canvas element.
        var $chart = $(elt);
        var chartId = $chart.attr('id');
        var dataChart = "data-chart='" + $chart.attr('data-chart') + "'";
        var style = 'style="' + $chart.attr('style') + '"';
        var chartId = $(this).attr('id');
        var dataChart = "data-chart='" + document.getElementById(chartId).getAttribute("data-chart") + "'";
        var style = 'style="' + document.getElementById(chartId).getAttribute('style') + '"';
        $(this).replaceWith(function (n) {
          return '<canvas ' + dataChart + style + 'id="' + chartId + '"' + '>' + n + '</canvas>'
        });
        //$('#' + chartId).once().each(function () {
        once('load-charts-chartjs', '#' + chartId, context).forEach(function () {
         var chartjsChart = $(this).attr('data-chart');
          var chart = contents.getData(chartId);
          var options = chart['options'];
        new Chart(chartId, {
          var myChart = new Chart(chartId, {
            type: chart['type'],
            data: chart['data'],
          options: options,
            options: options
          });
        });
      });
    }