11 Polymer.NeonAnimationRunnerBehavior
16 * The id of the element that the tooltip is anchored to. This element
17 * must be a sibling of the tooltip.
21 observer: '_forChanged'
25 * Positions the tooltip to the top, right, bottom, left of its content.
33 * If true, no parts of the tooltip will ever be shown offscreen.
41 * The spacing between the top of the tooltip and the element it is
50 * This property is deprecated, but left over so that it doesn't
51 * break exiting code. Please use `offset` instead. If both `offset` and
52 * `marginTop` are provided, `marginTop` will be ignored.
53 * @deprecated since version 1.0.3
65 name: 'fade-in-animation',
70 name: 'fade-out-animation',
84 'neon-animation-finish': '_onAnimationFinish'
88 * Returns the target element that this tooltip is anchored to. It is
89 * either the element given by the `for` attribute, or the immediate parent
93 var parentNode = Polymer.dom(this).parentNode;
94 // If the parentNode is a document fragment, then we need to use the host.
95 var ownerRoot = Polymer.dom(this).getOwnerRoot();
99 target = Polymer.dom(ownerRoot).querySelector('#' + this.for);
101 target = parentNode.nodeType == Node.DOCUMENT_FRAGMENT_NODE ?
102 ownerRoot.host : parentNode;
108 attached: function() {
109 this._target = this.target;
111 this.listen(this._target, 'mouseenter', 'show');
112 this.listen(this._target, 'focus', 'show');
113 this.listen(this._target, 'mouseleave', 'hide');
114 this.listen(this._target, 'blur', 'hide');
117 detached: function() {
119 this.unlisten(this._target, 'mouseenter', 'show');
120 this.unlisten(this._target, 'focus', 'show');
121 this.unlisten(this._target, 'mouseleave', 'hide');
122 this.unlisten(this._target, 'blur', 'hide');
130 if (Polymer.dom(this).textContent.trim() === '')
133 this.cancelAnimation();
135 this.toggleClass('hidden', false, this.$.tooltip);
136 this.updatePosition();
137 this._showing = true;
139 this.playAnimation('entry');
146 this._showing = false;
147 this.playAnimation('exit');
150 _forChanged: function() {
151 this._target = this.target;
154 updatePosition: function() {
158 var offset = this.offset;
159 // If a marginTop has been provided by the user (pre 1.0.3), use it.
160 if (this.marginTop != 14 && this.offset == 14)
161 offset = this.marginTop;
163 var parentRect = this.offsetParent.getBoundingClientRect();
164 var targetRect = this._target.getBoundingClientRect();
165 var thisRect = this.getBoundingClientRect();
167 var horizontalCenterOffset = (targetRect.width - thisRect.width) / 2;
168 var verticalCenterOffset = (targetRect.height - thisRect.height) / 2;
170 var targetLeft = targetRect.left - parentRect.left;
171 var targetTop = targetRect.top - parentRect.top;
173 var tooltipLeft, tooltipTop;
175 switch (this.position) {
177 tooltipLeft = targetLeft + horizontalCenterOffset;
178 tooltipTop = targetTop - thisRect.height - offset;
181 tooltipLeft = targetLeft + horizontalCenterOffset;
182 tooltipTop = targetTop + targetRect.height + offset;
185 tooltipLeft = targetLeft - thisRect.width - offset;
186 tooltipTop = targetTop + verticalCenterOffset;
189 tooltipLeft = targetLeft + targetRect.width + offset;
190 tooltipTop = targetTop + verticalCenterOffset;
194 // TODO(noms): This should use IronFitBehavior if possible.
195 if (this.fitToVisibleBounds) {
196 // Clip the left/right side.
197 if (tooltipLeft + thisRect.width > window.innerWidth) {
198 this.style.right = '0px';
199 this.style.left = 'auto';
201 this.style.left = Math.max(0, tooltipLeft) + 'px';
202 this.style.right = 'auto';
205 // Clip the top/bottom side.
206 if (tooltipTop + thisRect.height > window.innerHeight) {
207 this.style.bottom = '0px';
208 this.style.top = 'auto';
210 this.style.top = Math.max(0, tooltipTop) + 'px';
211 this.style.bottom = 'auto';
214 this.style.left = tooltipLeft + 'px';
215 this.style.top = tooltipTop + 'px';
220 _onAnimationFinish: function() {
221 if (!this._showing) {
222 this.toggleClass('hidden', true, this.$.tooltip);