1 |
efrain |
1 |
// This file is part of Moodle - http://moodle.org/
|
|
|
2 |
//
|
|
|
3 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
4 |
// it under the terms of the GNU General Public License as published by
|
|
|
5 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
6 |
// (at your option) any later version.
|
|
|
7 |
//
|
|
|
8 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
9 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
10 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
11 |
// GNU General Public License for more details.
|
|
|
12 |
//
|
|
|
13 |
// You should have received a copy of the GNU General Public License
|
|
|
14 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
15 |
|
|
|
16 |
/**
|
|
|
17 |
* Options helper for the Moodle Tiny Autosave plugin.
|
|
|
18 |
*
|
|
|
19 |
* @module tiny_autosave/options
|
|
|
20 |
* @copyright 2022 Andrew Lyons <andrew@nicols.co.uk>
|
|
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
22 |
*/
|
|
|
23 |
|
|
|
24 |
import {pluginName} from './common';
|
|
|
25 |
import {
|
|
|
26 |
getContextId,
|
|
|
27 |
getDraftItemId,
|
|
|
28 |
getPluginOptionName,
|
|
|
29 |
} from 'editor_tiny/options';
|
|
|
30 |
import {ensureEditorIsValid} from 'editor_tiny/utils';
|
|
|
31 |
|
|
|
32 |
const initialisedOptionName = getPluginOptionName(pluginName, 'initialised');
|
|
|
33 |
const pageHashName = getPluginOptionName(pluginName, 'pagehash');
|
|
|
34 |
const pageInstanceName = getPluginOptionName(pluginName, 'pageinstance');
|
|
|
35 |
const backoffTime = getPluginOptionName(pluginName, 'backoffTime');
|
|
|
36 |
const autosaveHasReset = getPluginOptionName(pluginName, 'autosaveHasReset');
|
|
|
37 |
|
|
|
38 |
export const register = (editor) => {
|
|
|
39 |
const registerOption = editor.options.register;
|
|
|
40 |
registerOption(initialisedOptionName, {
|
|
|
41 |
processor: 'boolean',
|
|
|
42 |
"default": false,
|
|
|
43 |
});
|
|
|
44 |
|
|
|
45 |
registerOption(pageHashName, {
|
|
|
46 |
processor: 'string',
|
|
|
47 |
"default": '',
|
|
|
48 |
});
|
|
|
49 |
|
|
|
50 |
registerOption(pageInstanceName, {
|
|
|
51 |
processor: 'string',
|
|
|
52 |
"default": '',
|
|
|
53 |
});
|
|
|
54 |
registerOption(pageInstanceName, {
|
|
|
55 |
processor: 'string',
|
|
|
56 |
"default": '',
|
|
|
57 |
});
|
|
|
58 |
registerOption(backoffTime, {
|
|
|
59 |
processor: 'number',
|
|
|
60 |
"default": 500,
|
|
|
61 |
});
|
|
|
62 |
registerOption(autosaveHasReset, {
|
|
|
63 |
processor: 'boolean',
|
|
|
64 |
"default": false,
|
|
|
65 |
});
|
|
|
66 |
};
|
|
|
67 |
|
|
|
68 |
export const isInitialised = (editor) => {
|
|
|
69 |
if (!ensureEditorIsValid(editor)) {
|
|
|
70 |
return false;
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
return editor.options.get(initialisedOptionName);
|
|
|
74 |
};
|
|
|
75 |
export const markInitialised = (editor) => editor.options.set(initialisedOptionName, true);
|
|
|
76 |
export const getPageHash = (editor) => editor.options.get(pageHashName);
|
|
|
77 |
export const getPageInstance = (editor) => editor.options.get(pageInstanceName);
|
|
|
78 |
export const getBackoffTime = (editor) => editor.options.get(backoffTime);
|
|
|
79 |
export const setAutosaveHasReset = (editor) => editor.options.set(autosaveHasReset, true);
|
|
|
80 |
export const hasAutosaveHasReset = (editor) => editor.options.get(autosaveHasReset);
|
|
|
81 |
|
|
|
82 |
export {
|
|
|
83 |
getContextId,
|
|
|
84 |
getDraftItemId,
|
|
|
85 |
};
|