Linux: Depend on liberation-fonts package for RPMs.
[chromium-blink-merge.git] / ui / webui / resources / cr_elements / v1_0 / cr_events / cr_events.js
blob99d083791b5d4e1fbb39d6df7fe229fa2a76a2f7
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 /**
6 * @fileoverview
7 * `cr-events` provides helpers for handling events in Chrome Polymer elements.
9 * Example:
11 * <cr-events id="events"></cr-events>
13 * Usage:
15 * this.$.events.forward(this.$.element, ['change']);
17 * @element cr-events
19 Polymer({
20 is: 'cr-events',
22 /**
23 * Sets up an element to forward events across the shadow boundary, for events
24 * which normally stop at the root node (see http://goo.gl/WGMO9x).
25 * @param {!HTMLElement} element The element to forward events from.
26 * @param {!Array<string>} events The events to forward.
28 forward: function(element, events) {
29 for (var i = 0; i < events.length; i++)
30 element.addEventListener(events[i], this.forwardEvent_);
33 /**
34 * Forwards events that don't automatically cross the shadow boundary
35 * if the event should bubble.
36 * @param {!Event} e The event to forward.
37 * @param {*} detail Data passed when initializing the event.
38 * @param {Node=} opt_sender Node that declared the handler.
39 * @private
41 forwardEvent_: function(e, detail, opt_sender) {
42 if (!e.bubbles)
43 return;
45 var node = e.path[e.path.length - 1];
46 if (node instanceof ShadowRoot) {
47 // Forward the event to the shadow host.
48 e.stopPropagation();
49 node.host.fire(e.type, detail, node.host, true, e.cancelable);
52 });