HEX
Server: nginx/1.28.1
System: Linux 10-41-63-61 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User: www (1001)
PHP: 7.4.33
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/bs.kntsleep.com/system/extend/ueditor/_src/plugins/charts.js
UE.plugin.register("charts", function() {
  var me = this;

  return {
    bindEvents: {
      chartserror: function() {}
    },
    commands: {
      charts: {
        execCommand: function(cmd, data) {
          var tableNode = domUtils.findParentByTagName(
            this.selection.getRange().startContainer,
            "table",
            true
          ),
            flagText = [],
            config = {};

          if (!tableNode) {
            return false;
          }

          if (!validData(tableNode)) {
            me.fireEvent("chartserror");
            return false;
          }

          config.title = data.title || "";
          config.subTitle = data.subTitle || "";
          config.xTitle = data.xTitle || "";
          config.yTitle = data.yTitle || "";
          config.suffix = data.suffix || "";
          config.tip = data.tip || "";
          //数据对齐方式
          config.dataFormat = data.tableDataFormat || "";
          //图表类型
          config.chartType = data.chartType || 0;

          for (var key in config) {
            if (!config.hasOwnProperty(key)) {
              continue;
            }

            flagText.push(key + ":" + config[key]);
          }

          tableNode.setAttribute("data-chart", flagText.join(";"));
          domUtils.addClass(tableNode, "edui-charts-table");
        },
        queryCommandState: function(cmd, name) {
          var tableNode = domUtils.findParentByTagName(
            this.selection.getRange().startContainer,
            "table",
            true
          );
          return tableNode && validData(tableNode) ? 0 : -1;
        }
      }
    },
    inputRule: function(root) {
      utils.each(root.getNodesByTagName("table"), function(tableNode) {
        if (tableNode.getAttr("data-chart") !== undefined) {
          tableNode.setAttr("style");
        }
      });
    },
    outputRule: function(root) {
      utils.each(root.getNodesByTagName("table"), function(tableNode) {
        if (tableNode.getAttr("data-chart") !== undefined) {
          tableNode.setAttr("style", "display: none;");
        }
      });
    }
  };

  function validData(table) {
    var firstRows = null,
      cellCount = 0;

    //行数不够
    if (table.rows.length < 2) {
      return false;
    }

    //列数不够
    if (table.rows[0].cells.length < 2) {
      return false;
    }

    //第一行所有cell必须是th
    firstRows = table.rows[0].cells;
    cellCount = firstRows.length;

    for (var i = 0, cell; (cell = firstRows[i]); i++) {
      if (cell.tagName.toLowerCase() !== "th") {
        return false;
      }
    }

    for (var i = 1, row; (row = table.rows[i]); i++) {
      //每行单元格数不匹配, 返回false
      if (row.cells.length != cellCount) {
        return false;
      }

      //第一列不是th也返回false
      if (row.cells[0].tagName.toLowerCase() !== "th") {
        return false;
      }

      for (var j = 1, cell; (cell = row.cells[j]); j++) {
        var value = utils.trim(cell.innerText || cell.textContent || "");

        value = value
          .replace(new RegExp(UE.dom.domUtils.fillChar, "g"), "")
          .replace(/^\s+|\s+$/g, "");

        //必须是数字
        if (!/^\d*\.?\d+$/.test(value)) {
          return false;
        }
      }
    }

    return true;
  }
});