-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdoc-access.js
54 lines (41 loc) · 1.46 KB
/
doc-access.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
//noinspection JSLint
var g = typeof global === 'undefined' ? window : global;
//noinspection JSLint,JSHint
(function (papyrus) {
require('./doc');
var spcf = papyrus.spcf;
var Doc = papyrus.Doc;
var stripSeqMark = Doc._p.stripSeqMark;
Doc._p.getPrivacyMode = function () {
return this.get('.am') || 'public';
};
Doc._p.isPublic = function () {
return this.getPrivacyMode() === 'public';
};
Doc._p.isReadonly = function () {
return 'true' === this.get('.ar');
};
Doc._p.isPasswordProtected = function () {
return 'true' === this.get('.ap');
};
function onPrivatePublic(spec, mode) {
if (spcf.pattern(spec) !== '!.') { return; }
papyrus.emit('privacyModeChanged', this, mode || 'public');
}
function onReadOnly(spec, ro) {
if (spcf.pattern(spec) !== '!.') { return; }
papyrus.emit('readOnlyChanged', this, 'true' === ro);
}
function onPassword(spec, withPwd) {
if (spcf.pattern(spec) !== '!.') { return; }
papyrus.emit('passwordChanged', this, 'true' === withPwd);
}
//access-controls
papyrus.addFilter('.am', stripSeqMark);
papyrus.addFilter('.ar', stripSeqMark);
papyrus.addFilter('.ap', stripSeqMark);
papyrus.addFilter('.aP', stripSeqMark);
papyrus.addFilter('.am', onPrivatePublic);
papyrus.addFilter('.ar', onReadOnly);
papyrus.addFilter('.ap', onPassword);
}(g['papyrus'] = g['papyrus'] || {}));