站长资源
中国站长网站

UEditor 1.4.3版本关闭本地保存以及远程图片本地化

1、修改ueditor.config.js,将enableAutoSave修改为false,并把前面的注释给去掉。

2、在第一种的基础上,修改ueditor.config.js,将saveInterval的值改大一点或者修改成0,并把前面的注释给去掉。saveInterval是自动保存的时间,设置成很大也就是自动保存的时间久一点,设置成0好像是无限大。但是我本地设置成了0

3、修改ueditor.all.js,在’contentchange’: function () {函数的第一行添加代码:if (!me.getOpt(‘enableAutoSave’)) {return;}

找到如下代码:

UE.plugin.register("autosave", function() {
  var me = this,
    //无限循环保护
    lastSaveTime = new Date(),
    //最小保存间隔时间
    MIN_TIME = 20,
    //auto save key
    saveKey = null;

  function save(editor) {
    var saveData;

    if (new Date() - lastSaveTime < MIN_TIME) {
      return;
    }

    if (!editor.hasContents()) {
      //这里不能调用命令来删除, 会造成事件死循环
      saveKey && me.removePreferences(saveKey);
      return;
    }

    lastSaveTime = new Date();

    editor._saveFlag = null;

    saveData = me.body.innerHTML;

    if (
      editor.fireEvent("beforeautosave", {
        content: saveData
      }) === false
    ) {
      return;
    }

    me.setPreferences(saveKey, saveData);

    editor.fireEvent("afterautosave", {
      content: saveData
    });
  }

  return {
    defaultOptions: {
      //默认间隔时间
      saveInterval: 500,
      enableAutoSave: true
    },
    bindEvents: {
      ready: function() {
        var _suffix = "-drafts-data",
          key = null;

        if (me.key) {
          key = me.key + _suffix;
        } else {
          key = (me.container.parentNode.id || "ue-common") + _suffix;
        }

        //页面地址+编辑器ID 保持唯一
        saveKey =
          (location.protocol + location.host + location.pathname).replace(
            /[.:\/]/g,
            "_"
          ) + key;
      },

      contentchange: function() {
        if (!me.getOpt("enableAutoSave")) {
          return;
        }

        if (!saveKey) {
          return;
        }

        if (me._saveFlag) {
          window.clearTimeout(me._saveFlag);
        }

        if (me.options.saveInterval > 0) {
          me._saveFlag = window.setTimeout(function() {
            save(me);
          }, me.options.saveInterval);
        } else {
          save(me);
        }
      }
    },
    commands: {
      clearlocaldata: {
        execCommand: function(cmd, name) {
          if (saveKey && me.getPreferences(saveKey)) {
            me.removePreferences(saveKey);
          }
        },
        notNeedUndo: true,
        ignoreContentChange: true
      },

      getlocaldata: {
        execCommand: function(cmd, name) {
          return saveKey ? me.getPreferences(saveKey) || "" : "";
        },
        notNeedUndo: true,
        ignoreContentChange: true
      },

      drafts: {
        execCommand: function(cmd, name) {
          if (saveKey) {
            me.body.innerHTML =
              me.getPreferences(saveKey) || "<p>" + domUtils.fillHtml + "</p>";
            me.focus(true);
          }
        },
        queryCommandState: function() {
          return saveKey ? (me.getPreferences(saveKey) === null ? -1 : 0) : -1;
        },
        notNeedUndo: true,
        ignoreContentChange: true
      }
    }
  };
});

新增加的代码:

if (!me.getOpt("enableAutoSave")) {
   return;
}

详细参考:

https://github.com/fex-team/ueditor/blob/dev-1.5.0/_src/plugins/autosave.js#L71-73

设置之后发现,烦人的提示不存在了,但是远程图片还是会加载,这个比较简单,我们直接设置ueditor.config.js,将

,catchRemoteImageEnable: false //设置是否抓取远程图片

前面注释打开,并设置为false

本文出处:来自互联网信息共享,请勿相信收费信息站长资源 » UEditor 1.4.3版本关闭本地保存以及远程图片本地化

评论 抢沙发

评论前必须登录!