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
.shiftKey
&& !e
.ctrlKey
&& !e
.altKey
&& !e
.metaKey
) {
44 if (e
.keyCode
== 27) {
48 } else if (e
.keyCode
== 13) {
49 var activeElementTag
= document
.activeElement
?
50 document
.activeElement
.tagName
.toUpperCase() : '';
51 if (activeElementTag
!= 'BUTTON' && activeElementTag
!= 'SELECT') {
52 if (this.onEnterPressedInternal()) {
62 this.getChildElement('.page > .close-button'),
64 this.cancel
.bind(this));
67 this.getElement(), 'click', this.onOverlayClick_
.bind(this));
69 this.getChildElement('.page'),
71 this.onAnimationEnd_
.bind(this));
74 /** @return {boolean} Whether the component is visible. */
75 getIsVisible: function() {
76 return !this.getElement().classList
.contains('transparent');
79 /** @param {boolean} isVisible Whether the component is visible. */
80 setIsVisible: function(isVisible
) {
81 if (this.getIsVisible() == isVisible
)
84 setIsVisible(this.getElement(), true);
85 setTimeout(function(element
) {
86 element
.classList
.remove('transparent');
87 }.bind(this, this.getElement()), 0);
89 this.getElement().classList
.add('transparent');
91 this.onSetVisibleInternal(isVisible
);
94 /** Closes the dialog. */
96 this.setIsVisible(false);
97 this.onCancelInternal();
101 * @param {boolean} isVisible Whether the component is visible.
104 onSetVisibleInternal: function(isVisible
) {},
107 onCancelInternal: function() {},
110 * @return {boolean} Whether the event was handled.
113 onEnterPressedInternal: function() {
118 * Called when the overlay is clicked. Pulses the page.
119 * @param {Event} e Contains the element that was clicked.
122 onOverlayClick_: function(e
) {
123 if (e
.target
&& e
.target
.classList
.contains('overlay'))
124 e
.target
.querySelector('.page').classList
.add('pulse');
128 * Called when an animation ends on the page.
129 * @param {Event} e Contains the target done animating.
132 onAnimationEnd_: function(e
) {
133 if (e
.target
&& e
.animationName
== 'pulse')
134 e
.target
.classList
.remove('pulse');