-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcms-render.js
More file actions
59 lines (48 loc) · 1.37 KB
/
cms-render.js
File metadata and controls
59 lines (48 loc) · 1.37 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
(function (global) {
if (!(global.jQuery && global.cms)) {
throw new Error('Missing Dependencies: [jQuery, cms]');
}
var $ = global.jQuery
, cms = global.cms
, elements = cms.elements;
elements.md.render = function ($el, data) {
$el.html(data.text);
};
elements.text.render = function ($el, data) {
$el.html(data);
};
elements.image.render = function ($el, data) {
$el.attr('src', data);
};
elements.button.render = function ($el, data) {
if (typeof data === 'string') {
$el.html(data);
} else {
//assume object
$el.html(data.text);
$el.attr('href', data.link);
}
};
elements.form.render = function ($el, data) {
$el.find('> *').hide(); //depth 1
$.each(data, function (idx, field) {
if (typeof field === 'string') {
//Legacy
$el.find('.' + field).show();
} else {
if (idx === 0) $el.find('> *').remove(); //depth 1
var $field = $('<input type="text"/>')
.attr('name', field.name)
.attr('placeholder', field.name)
.attr('data-validate', JSON.stringify(field.validators));
$el.append($field);
}
});
};
elements.option.render = function ($el, data) {
$.each(data.options, function (idx, option) {
$el.find(option.value).hide();
});
$el.find(data.selected).show();
};
}(this));