-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbrainy-table-cell-behavior.html
More file actions
85 lines (74 loc) · 2.21 KB
/
brainy-table-cell-behavior.html
File metadata and controls
85 lines (74 loc) · 2.21 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
<link rel="import" href="brainy-table-templatizer-behavior.html">
<script>
var Brainy = window.Brainy || {};
/**
* A behavior implemented by cells instances.
*
* @polymerBehavior Brainy.TableCellBehaviorImpl
*/
Brainy.TableCellBehaviorImpl = {
properties: {
alignRight: {
type: Boolean,
reflectToAttribute: true
},
column: Object,
flex: Number,
hidden: Boolean,
order: Number,
template: Object,
width: String
},
observers: [
'_alignRightChanged(alignRight)',
'_columnChanged(_instance, column)',
'_columnPathChanged(_instance, column.*)',
'_flexChanged(flex)',
'_hiddenChanged(hidden)',
'_orderChanged(order)',
'_widthChanged(width)'
],
attached: function() {
if (!Polymer.Settings.useNativeShadow) {
// cell is supposed to be placed outside the local dom of brainy-table.
Polymer.StyleTransformer.dom(this, 'brainy-table', this._scopeCssViaAttr, true);
if (this.domHost) {
Polymer.StyleTransformer.dom(this, this.domHost.tagName.toLowerCase(), this._scopeCssViaAttr, false);
}
}
},
_alignRightChanged: function(alignRight) {
this.style.justifyContent = alignRight ? 'flex-end' : 'flex-start';
},
_hiddenChanged: function(hidden) {
this.toggleAttribute('hidden', hidden);
},
_orderChanged: function(order) {
this.style.order = order;
},
_flexChanged: function(flex) {
this.style.flexGrow = flex;
},
_widthChanged: function(width) {
this.style.flexBasis = width;
},
_columnChanged: function(instance, column) {
instance.column = column;
},
_columnPathChanged: function(instance, column) {
// sometimes instance isn't ready to be notified yet and throws an error.
this.async(function() {
// TODO: hack to avoid: https://github.com/Polymer/polymer/issues/3307
this._parentProps = this._parentProps || {};
instance.notifyPath(column.path, column.value);
});
}
};
/**
* @polymerBehavior
*/
Brainy.TableCellBehavior = [
Brainy.TableTemplatizerBehavior,
Brainy.TableCellBehaviorImpl
];
</script>