-
Notifications
You must be signed in to change notification settings - Fork 92
/
paper-datatable-edit-dialog.html
137 lines (124 loc) · 3.84 KB
/
paper-datatable-edit-dialog.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../paper-styles/paper-styles.html">
<link rel="import" href="../paper-material/paper-material.html">
<link rel="import" href="../iron-form/iron-form.html">
<link rel="import" href="../iron-resizable-behavior/iron-resizable-behavior.html">
<dom-module id="paper-datatable-edit-dialog">
<template>
<style>
:host{
position: absolute;
z-index: 10;
display: none;
}
:host([visible]){
display: block;
}
paper-material {
position:absolute;
left:0px;
top:0px;
right:0px;
min-width: 100px;
display: inline-block;
padding: 4px 24px;
background: var(--paper-datatable-edit-dialog-color, --paper-grey-50);
border-radius: 2px;
box-sizing: border-box;
@apply(--paper-datatable-edit-dialog);
}
</style>
<paper-material id="material" elevation="1">
<form is="iron-form" id="form" on-iron-form-presubmit="dismiss">
<content select="*"></content>
</form>
</paper-material>
</template>
<script>
/**
* This shouldn't be showing up here, but I can't see to get this documentation system to ignore this file,
* so just ignore it.
*
* This element is used internally to render the dialog boxes when `<paper-datatable-column>` is used with the
* `[dialog]` attribute.
*/
Polymer({
is: 'paper-datatable-edit-dialog',
properties: {
positionedRelativeTo: {
type: Element,
observer: 'setLocationRelativeTo'
},
visible: {
type: Boolean,
reflectToAttribute: true
}
},
behaviors: [
Polymer.IronResizableBehavior
],
listeners: {
'iron-resize': 'setLocationRelativeTo'
},
ready: function(){
this.addEventListener('keyup', function(ev){
var genericEvent = Polymer.dom(ev);
if(ev.keyCode == 13 && genericEvent.path[0].nodeName.toLowerCase() !== 'textarea'){
this.dismiss();
}
}.bind(this));
document.body.addEventListener('click', function(ev){
var path = Polymer.dom(ev).path;
if(this.positionedRelativeTo && path.indexOf(this) == -1 && path.indexOf(this.positionedRelativeTo) == -1){
this.dismiss(ev);
}
}.bind(this));
},
dismiss: function(ev){
this.set('visible', undefined);
this.positionedRelativeTo = undefined;
if(ev)
ev.preventDefault();
},
findFocus: function() {
var paperInput = Polymer.dom(this).querySelector('paper-input')
if (paperInput) {
paperInput.$.input.focus();
}
var paperInput = Polymer.dom(this).querySelector('paper-textarea')
if (paperInput) {
var position = paperInput.$.input.$.textarea.value.length;
paperInput.$.input.$.textarea.focus();
paperInput.$.input.$.textarea.setSelectionRange(position, position);
}
var input = Polymer.dom(this).querySelector('input')
if (input) {
input.focus();
}
},
setLocationRelativeTo: function(){
if(this.positionedRelativeTo) {
this.set('visible', true)
this.revealTime = Date.now();
var relativeToParent = this.parentNode;
while (relativeToParent !== window) {
if (relativeToParent.nodeName == '#document-fragment') {
relativeToParent = relativeToParent.host;
} else {
if (getComputedStyle(relativeToParent).position == 'relative' || getComputedStyle(relativeToParent).position == 'absolute') {
break;
}
relativeToParent = Polymer.dom(relativeToParent).parentNode;
}
}
var parent = relativeToParent.getBoundingClientRect();
var child = this.positionedRelativeTo.getBoundingClientRect();
this.style.top = child.top - 2 - parent.top + "px";
this.style.left = child.left - parent.left + "px";
this.style.right = Math.max(parent.right - child.right, 0) + "px";
this.$.material.style.minHeight = child.height + 2 + "px";
}
}
});
</script>
</dom-module>