2 Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
3 This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
4 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
5 The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
6 Code distributed by Google as part of the polymer project is also
7 subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
11 The `core-tooltip` element creates a hover tooltip centered for the content
12 it contains. It can be positioned on the top|bottom|left|right of content using
13 the `position` attribute.
15 To include HTML in the tooltip, include the `tip` attribute on the relevant
20 <core-tooltip label="I'm a tooltip">
21 <span>Hover over me.</span>
24 <b>Example</b> - positioning the tooltip to the right:
26 <core-tooltip label="I'm a tooltip to the right" position="right">
27 <core-icon-button icon="drawer"></core-icon-button>
30 <b>Example</b> - no arrow and showing by default:
32 <core-tooltip label="Tooltip with no arrow and always on" noarrow show>
36 <b>Example</b> - disable the tooltip.
38 <core-tooltip label="Disabled label never shows" disabled>
42 <b>Example</b> - rich tooltip using the `tip` attribute:
45 <div>Example of a rich information tooltip</div>
47 <img src="profile.jpg">Foo <b>Bar</b> - <a href="#">@baz</a>
51 By default, the `tip` attribute specifies the HTML content for a rich tooltip.
52 You can customize this attribute with the `tipAttribute` attribute:
54 <core-tooltip tipAttribute="htmltooltip">
55 <div>Example of a rich information tooltip</div>
61 @group Polymer Core Elements
63 @extends core-focusable
64 @mixins Polymer.CoreFocusable
65 @homepage http://www.polymer-project.org/components/core-tooltip/index.html
68 <link rel=
"import" href=
"../polymer/polymer.html">
69 <link rel=
"import" href=
"../core-focusable/core-focusable.html">
70 <link rel=
"import" href=
"../core-resizable/core-resizable.html">
72 <!-- TODO: would be nice to inherit from label to get .htmlFor, and .control,
73 but the latter is readonly. -->
74 <!-- TODO: support off center arrows. -->
75 <!-- TODO: detect mobile and apply the .large class, instead of manual
77 <!-- TODO: possibly reuse core-overlay. -->
78 <polymer-element name=
"core-tooltip" attributes=
"noarrow position label show tipAttribute" role=
"tooltip" tabindex=
"0">
81 <link rel=
"stylesheet" href=
"core-tooltip.css">
82 <div id=
"tooltip" hidden?=
"{{!hasTooltipContent}}"
83 class=
"core-tooltip {{position}} {{ {noarrow: noarrow, show: show && !disabled} | tokenList}}">
84 <content id=
"c" select=
"[{{tipAttribute}}]">{{label}}
</content>
96 * A simple string label for the tooltip to display. To display a rich
97 * HTML tooltip instead, omit `label` and include the `tip` attribute
98 * on a child node of `core-tooltip`.
107 'core-resize': 'positionChanged'
111 // Indicates whether the tooltip has a set label propety or
112 // an element with the `tip` attribute.
113 hasTooltipContent
: 'label || !!tipElement'
118 * Forces the tooltip to display. If `disabled` is set, this property is ignored.
124 show
: {value
: false, reflect
: true},
127 * Positions the tooltip to the top, right, bottom, left of its content.
129 * @attribute position
133 position
: {value
: 'bottom', reflect
: true},
136 * If true, the tooltip an arrow pointing towards the content.
142 noarrow
: {value
: false, reflect
: true}
146 * Customizes the attribute used to specify which content
147 * is the rich HTML tooltip.
149 * @attribute tipAttribute
155 attached: function() {
156 this.updatedChildren();
157 this.resizableAttachedHandler();
160 detached: function() {
161 this.resizableDetachedHandler();
164 updatedChildren: function () {
165 this.tipElement
= null;
167 for (var i
= 0, el
; el
= this.$.c
.getDistributedNodes()[i
]; ++i
) {
168 if (el
.hasAttribute
&& el
.hasAttribute('tip')) {
169 this.tipElement
= el
;
174 // Job ensures we're not double calling setPosition() on DOM attach.
175 this.job('positionJob', this.setPosition
);
177 // Monitor children to re-position tooltip when light dom changes.
178 this.onMutation(this, this.updatedChildren
);
181 labelChanged: function(oldVal
, newVal
) {
182 this.job('positionJob', this.setPosition
);
185 positionChanged: function(oldVal
, newVal
) {
186 this.job('positionJob', this.setPosition
);
189 setPosition: function() {
190 var controlWidth
= this.clientWidth
;
191 var controlHeight
= this.clientHeight
;
192 var toolTipWidth
= this.$.tooltip
.clientWidth
;
193 var toolTipHeight
= this.$.tooltip
.clientHeight
;
195 switch (this.position
) {
198 this.$.tooltip
.style
.left
= (controlWidth
- toolTipWidth
) / 2 + 'px';
199 this.$.tooltip
.style
.top
= null;
203 this.$.tooltip
.style
.left
= null;
204 this.$.tooltip
.style
.top
= (controlHeight
- toolTipHeight
) / 2 + 'px';
211 Polymer
.mixin2(proto
, Polymer
.CoreFocusable
);
212 Polymer
.mixin(proto
, Polymer
.CoreResizable
);