-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrow-adder-lite.html
111 lines (105 loc) · 4.02 KB
/
row-adder-lite.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
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
<link rel="import" href="../polymer/polymer.html">
<dom-module id="row-adder-lite">
<style is="custom-style">
:host {
--grid-column-start: initial;
--grid-column-end: initial;
--grid-row-start: initial;
--grid-row-end: initial;
display: block;
position: relative;
grid-column-start: var(--grid-column-start);
grid-column-end: var(--grid-column-end);
grid-row-start: var(--grid-row-start);
grid-row-end: var(--grid-row-end);
}
</style>
<template>
</template>
<script>
Polymer({
is: 'row-adder-lite',
properties: {
elName: {
type: String,
reflectToAttribute: true,
notify: true,
value: ''
},
componentProperties: {
type: Object,
reflectToAttribute: false,
notify: true
},
path: {
type: String,
reflectToAttribute: true,
notify: true
},
id: {
type: String,
reflectToAttribute: true,
notify: true,
value: ''
},
innercomponents: {
type: Object,
notify: true
},
usercontent: {
type: Object,
notify: true,
reflectToAttribute: false
}
},
ready: function() {
this.createUserComponent();
this.updateGrids();
},
updateGrids: function() {
// add properties to the created element
for(var i = 0; i < this.componentProperties.length; i++) {
if(!!this.componentProperties[i] && this.componentProperties[i].name == 'display') {
var data = this.componentProperties[i].value || '';
for(var j = 0; j < data.length; j++) {
if(!!data[j].value) {
var prop = '--' + this.toPascalCase(data[j].name);
this.customStyle[prop] = '' + data[j].value;
}
}
this.updateStyles();
}
}
},
setComponentProperties: function(el) {
// add properties to the created element
for(var i = 0; i < this.componentProperties.length; i++) {
if(!!this.componentProperties[i] && this.componentProperties[i].name == 'componentProperties') {
var data = this.componentProperties[i].value || '';
for(var j = 0; j < data.length; j++) {
el.setAttribute(this.toPascalCase(data[j].name), data[j].value);
}
}
}
},
setComponentPathProperty: function(el) {
el.setAttribute('path', this.path + this.elName + '/');
},
createUserComponent: function() {
var el = document.createElement(this.elName);
this.setComponentProperties(el);
// Setting content to user components
el.usercontent = this.usercontent;
this.setComponentPathProperty(el);
el.innercomponents = this.innercomponents;
el.setAttribute('path', this.path + this.id);
Polymer.dom(this.root).appendChild(el);
},
toPascalCase: function(s) {
return s.replace(/\.?([A-Z])/g, function (x,y) {
return "-" + y.toLowerCase();
}).replace(/^_/, "");
}
});
</script>
</dom-module>