-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathimggallery.html
56 lines (47 loc) · 1.48 KB
/
imggallery.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
49
50
51
52
53
54
55
56
<element name='imggallery'>
<template>
<ul id='{{id}}' style='{{style}}' data-gk-click='{{onclick}}'>
<content></content>
</ul>
</template>
<script>
var utils = require('./js/utils');
registerElement('imggallery', {
init: function() {
var tagName = this.$ele.prop('tagName').toLowerCase(),
newTagName = this.$originEle[0].tagName.toLowerCase();
this.html = this.$ele.html().trim();
if (typeof String.prototype.trim !== 'function') {
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g, '');
}
}
if (newTagName !== tagName) {
utils.changeTagNameOfGKElment(this, newTagName);
}
this.templateHTML = this.$originEle.html();
},
onclick: function(callback) {
this.$ele.on('click', callback);
},
model: function(model) {
var iterator = typeof this.arrayModelName == 'undefined' ?
model : model[this.arrayModelName],
self = this;
this.$ele.html('');
$(iterator).each(function(idx, obj) {
var newOne = self.templateHTML;
for (var key in obj) {
var regex = new RegExp('{{' + key + '}}|\\${' + key + '}', "g");
newOne = newOne.replace(regex, obj[key]);
if ('data-src' === key) {
var srcRegex = new RegExp(key, "g");
newOne = newOne.replace(srcRegex, 'src');
}
}
self.$ele.append(newOne);
});
}
});
</script>
</element>