-
Notifications
You must be signed in to change notification settings - Fork 185
/
templates.js
112 lines (95 loc) · 3.49 KB
/
templates.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
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
104
105
106
107
108
109
110
111
112
import * as dom from './dom.js';
import * as escape from './escape.js';
/**
* HTML templates used by the editor and default commands
* @type {Object}
* @private
*/
var _templates = {
html:
'<!DOCTYPE html>' +
'<html{attrs}>' +
'<head>' +
'<meta http-equiv="Content-Type" ' +
'content="text/html;charset={charset}" />' +
'<link rel="stylesheet" type="text/css" href="{style}" />' +
'</head>' +
'<body contenteditable="true" {spellcheck}><p></p></body>' +
'</html>',
toolbarButton: '<a class="sceditor-button sceditor-button-{name}" ' +
'data-sceditor-command="{name}" unselectable="on">' +
'<div unselectable="on">{dispName}</div></a>',
emoticon: '<img src="{url}" data-sceditor-emoticon="{key}" ' +
'alt="{key}" title="{tooltip}" />',
fontOpt: '<a class="sceditor-font-option" href="#" ' +
'data-font="{font}"><font face="{font}">{font}</font></a>',
sizeOpt: '<a class="sceditor-fontsize-option" data-size="{size}" ' +
'href="#"><font size="{size}">{size}</font></a>',
pastetext:
'<div><label for="txt">{label}</label> ' +
'<textarea cols="20" rows="7" id="txt"></textarea></div>' +
'<div><input type="button" class="button" value="{insert}" />' +
'</div>',
table:
'<div><label for="rows">{rows}</label><input type="text" ' +
'id="rows" value="2" /></div>' +
'<div><label for="cols">{cols}</label><input type="text" ' +
'id="cols" value="2" /></div>' +
'<div><input type="button" class="button" value="{insert}"' +
' /></div>',
image:
'<div><label for="image">{url}</label> ' +
'<input type="text" id="image" dir="ltr" placeholder="https://" /></div>' +
'<div><label for="width">{width}</label> ' +
'<input type="text" id="width" size="2" dir="ltr" /></div>' +
'<div><label for="height">{height}</label> ' +
'<input type="text" id="height" size="2" dir="ltr" /></div>' +
'<div><input type="button" class="button" value="{insert}" />' +
'</div>',
email:
'<div><label for="email">{label}</label> ' +
'<input type="text" id="email" dir="ltr" /></div>' +
'<div><label for="des">{desc}</label> ' +
'<input type="text" id="des" /></div>' +
'<div><input type="button" class="button" value="{insert}" />' +
'</div>',
link:
'<div><label for="link">{url}</label> ' +
'<input type="text" id="link" dir="ltr" placeholder="https://" /></div>' +
'<div><label for="des">{desc}</label> ' +
'<input type="text" id="des" /></div>' +
'<div><input type="button" class="button" value="{ins}" /></div>',
youtubeMenu:
'<div><label for="link">{label}</label> ' +
'<input type="text" id="link" dir="ltr" placeholder="https://" /></div>' +
'<div><input type="button" class="button" value="{insert}" />' +
'</div>',
youtube:
'<iframe width="560" height="315" frameborder="0" allowfullscreen ' +
'src="https://www.youtube-nocookie.com/embed/{id}?wmode=opaque&start={time}" ' +
'data-youtube-id="{id}"></iframe>'
};
/**
* Replaces any params in a template with the passed params.
*
* If createHtml is passed it will return a DocumentFragment
* containing the parsed template.
*
* @param {string} name
* @param {Object} [params]
* @param {boolean} [createHtml]
* @returns {string|DocumentFragment}
* @private
*/
export default function (name, params, createHtml) {
var template = _templates[name];
Object.keys(params).forEach(function (name) {
template = template.replace(
new RegExp(escape.regex('{' + name + '}'), 'g'), params[name]
);
});
if (createHtml) {
template = dom.parseHTML(template);
}
return template;
};