-
Notifications
You must be signed in to change notification settings - Fork 4
/
gk-text.html
48 lines (39 loc) · 1.11 KB
/
gk-text.html
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
<element name='gk-text'>
<template>
<h1 id='{{id}}' style='{{style}}'>
<content></content>
</h1>
</template>
<script>
var utils = require('./js/utils');
registerElement('gk-text', {
html: '',
init: function () {
this.html = this.$ele.html().trim();
var tagName = this.$ele.prop('tagName').toLowerCase(),
newTagName = this.$originEle[0].tagName.toLowerCase();
if (newTagName !== tagName) {
utils.changeTagNameOfGKElment(this, newTagName);
}
},
text: function (val) {
if (val !== undefined) {
return this.$ele.text(val);
} else {
return this.$ele.text();
}
},
apply: function (info) {
var html = this.html;
for (var property in info) {
if (info.hasOwnProperty(property)) {
var regex = new RegExp('\\${' + property + '}', "gi");
html = html.replace(regex, info[property]);
}
}
var $html = $('<div>' + html + '</div>');
this.$ele.html($html.html());
}
});
</script>
</element>