This repository was archived by the owner on Jul 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
65 lines (53 loc) · 1.58 KB
/
index.js
File metadata and controls
65 lines (53 loc) · 1.58 KB
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
var db = require.main.require('./src/database');
var validator = require('validator');
var plugin = {};
function getCustomCSS(uid, callback) {
if (!uid) {
return callback(null, '');
}
db.getObjectField('user:' + uid + ':settings', 'customCSS', function(err, customCSS) {
if (err) {
return callback(err);
}
callback(null, customCSS || '');
});
}
function setCustomCSS(uid, customCSS, callback) {
if (!uid) {
return callback(new Error('[[error:invalid-data]]'));
}
db.setObjectField('user:' + uid + ':settings', 'customCSS', String(customCSS || ''), function(err) {
callback(err);
});
}
plugin.addCustomSetting = function(data, callback) {
var customCSS = data.settings.customCSS || '';
data.customSettings.push({
'title': 'Custom CSS',
'content': '<textarea data-property="customCSS" class="form-control" type="textarea">' + validator.escape(customCSS) + '</textarea><p class="help-block">Requires a refresh to take effect.</p>'
});
callback(null, data);
};
plugin.saveUserSettings = function(data) {
setCustomCSS(data.uid, data.settings.customCSS, function() { });
};
plugin.getUserSettings = function(data, callback) {
data.settings.customCSS = data.settings.customCSS || '';
callback(null, data);
};
plugin.renderHeader = function(data, callback) {
if (!data.req.uid) {
return callback(null, data);
}
getCustomCSS(data.req.uid, function(err, customCSS) {
if (err) {
return callback(err);
}
if (customCSS) {
data.templateValues.useCustomCSS = true;
data.templateValues.customCSS += customCSS;
}
callback(null, data);
});
};
module.exports = plugin;