ueditor.config.js文件中设置enableAutoSave参数为false就可以关闭本地保存功能。

ueditor.config.js文件中设置enableAutoSave参数为false就可以关闭本地保存功能。

 

 //启用自动保存

1
,enableAutoSave: false

 

ueditor1.4.3版本是没有效果的,需要修改代码,在ueditor1.5.0版本已经得到修复。

 

修改方法

ueditor.all.js文件

 

找到

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// plugins/autosave.js
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
        },
        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
            }
        }
    }
});

 

以下是新增加的代码

1
2
3
if (!me.getOpt('enableAutoSave')) {
    return;
}
1
enableAutoSave: false

搞定

ueditor1.4.3版本自动保存关闭不了

https://github.com/fex-team/ueditor/issues/470

 

已在1.5.0分支修改

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

本文标题: UEditor 1.4.3版本中去掉本地自动保存功能

posted @ 2016-08-02 22:47  淘代码  阅读(1617)  评论(0编辑  收藏  举报