-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathContentBox.js
More file actions
103 lines (89 loc) · 2.73 KB
/
ContentBox.js
File metadata and controls
103 lines (89 loc) · 2.73 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
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
/**
* # ContentBox
* Copyright(c) 2019 Stefano Balietti
* MIT Licensed
*
* Displays some content.
*
* www.nodegame.org
*/
(function(node) {
"use strict";
node.widgets.register('ContentBox', ContentBox);
// ## Meta-data
ContentBox.version = '0.2.0';
ContentBox.description = 'Simply displays some content';
ContentBox.title = false;
ContentBox.panel = false;
ContentBox.className = 'contentbox';
// ## Dependencies
ContentBox.dependencies = {};
/**
* ## ContentBox constructor
*
*/
function ContentBox() {
// ### ContentBox.mainText
// The main text above the content.
this.mainText = null;
// ### ContentBox.content
// Some content to be displayed.
this.content = null;
// ### ContentBox.hint
// A hint text.
this.hint = null;
}
// ## ContentBox methods
ContentBox.prototype.init = function(opts) {
// Set the mainText, if any.
if ('string' === typeof opts.mainText) {
this.mainText = opts.mainText;
}
else if ('undefined' !== typeof opts.mainText) {
throw new TypeError('ContentBox.init: mainText must ' +
'be string or undefined. Found: ' +
opts.mainText);
}
// Set the content, if any.
if ('string' === typeof opts.content) {
this.content = opts.content;
}
else if ('undefined' !== typeof opts.content) {
throw new TypeError('ContentBox.init: content must ' +
'be string or undefined. Found: ' +
opts.content);
}
// Set the content, if any.
if ('string' === typeof opts.hint) {
this.hint = opts.hint;
}
else if ('undefined' !== typeof opts.hint) {
throw new TypeError('ContentBox.init: hint must ' +
'be string or undefined. Found: ' +
opts.hint);
}
};
ContentBox.prototype.append = function() {
// MainText.
if (this.mainText) {
W.append('span', this.bodyDiv, {
className: 'contentbox-maintext',
innerHTML: this.mainText
});
}
// Content.
if (this.content) {
W.append('div', this.bodyDiv, {
className: 'contentbox-content',
innerHTML: this.content
});
}
// Hint.
if (this.hint) {
W.append('span', this.bodyDiv, {
className: 'contentbox-hint',
innerHTML: this.hint
});
}
};
})(node);