1 // Copyright 2014 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 cr.define('print_preview', function() {
9 * Modal dialog base component.
10 * @param {!print_preview.MetricsContext} metricsContext Metrics
11 * context to record usage statistics.
13 * @extends {print_preview.Component}
15 function Overlay(metricsContext) {
16 print_preview.Component.call(this);
18 /** @private {!print_preview.MetricsContext} */
19 this.metricsContext_ = metricsContext;
23 __proto__: print_preview.Component.prototype,
25 /** @return {!print_preview.MetricsContext} */
26 get metricsContext() {
27 return this.metricsContext_;
31 enterDocument: function() {
32 print_preview.Component.prototype.enterDocument.call(this);
34 this.getElement().addEventListener('webkitTransitionEnd', function f(e) {
35 if (e.target == e.currentTarget && e.propertyName == 'opacity' &&
36 e.target.classList.contains('transparent')) {
37 setIsVisible(e.target, false);
41 this.getElement().addEventListener('keydown', function f(e) {
42 // Escape pressed -> cancel the dialog.
43 if (e.keyCode == 27 && !e.shiftKey && !e.ctrlKey && !e.altKey &&
52 this.getChildElement('.page > .close-button'),
54 this.cancel.bind(this));
57 this.getElement(), 'click', this.onOverlayClick_.bind(this));
59 this.getChildElement('.page'),
61 this.onAnimationEnd_.bind(this));
64 /** @return {boolean} Whether the component is visible. */
65 getIsVisible: function() {
66 return !this.getElement().classList.contains('transparent');
69 /** @param {boolean} isVisible Whether the component is visible. */
70 setIsVisible: function(isVisible) {
71 if (this.getIsVisible() == isVisible)
74 setIsVisible(this.getElement(), true);
75 setTimeout(function(element) {
76 element.classList.remove('transparent');
77 }.bind(this, this.getElement()), 0);
79 this.getElement().classList.add('transparent');
81 this.onSetVisibleInternal(isVisible);
84 /** Closes the dialog. */
86 this.setIsVisible(false);
87 this.onCancelInternal();
91 * @param {boolean} isVisible Whether the component is visible.
94 onSetVisibleInternal: function(isVisible) {},
97 onCancelInternal: function() {},
100 * Called when the overlay is clicked. Pulses the page.
101 * @param {Event} e Contains the element that was clicked.
104 onOverlayClick_: function(e) {
105 if (e.target && e.target.classList.contains('overlay'))
106 e.target.querySelector('.page').classList.add('pulse');
110 * Called when an animation ends on the page.
111 * @param {Event} e Contains the target done animating.
114 onAnimationEnd_: function(e) {
115 if (e.target && e.animationName == 'pulse')
116 e.target.classList.remove('pulse');