blob: 02776c58b86b8e351e8924dd57ebe07423b36e74 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
cr.define('print_preview', function() {
'use strict';
/**
* Creates a HeaderFooterSettings object. This object encapsulates all
* settings and logic related to the headers and footers checkbox.
* @constructor
*/
function HeaderFooterSettings() {
this.headerFooterOption_ = $('header-footer-option');
this.headerFooterCheckbox_ = $('header-footer');
this.headerFooterApplies_ = false;
this.addEventListeners_();
}
cr.addSingletonGetter(HeaderFooterSettings);
HeaderFooterSettings.prototype = {
/**
* The checkbox corresponding to the headers and footers option.
* @type {HTMLInputElement}
*/
get headerFooterCheckbox() {
return this.headerFooterCheckbox_;
},
/**
* Checks whether the Headers and Footers checkbox is checked or not.
* @return {boolean} true if Headers and Footers are checked.
*/
hasHeaderFooter: function() {
return this.headerFooterApplies_ && this.headerFooterCheckbox_.checked;
},
/**
* Sets the state of the headers footers checkbox.
* @param {boolean} checked True if the headers footers checkbox shoule be
* checked, false if not.
*/
setChecked: function(checked) {
this.headerFooterCheckbox_.checked = checked;
},
/**
* Adding listeners to header footer related controls.
* @private
*/
addEventListeners_: function() {
this.headerFooterCheckbox_.onclick =
this.onHeaderFooterChanged_.bind(this);
document.addEventListener(customEvents.PDF_LOADED,
this.onPDFLoaded_.bind(this));
document.addEventListener(customEvents.MARGINS_SELECTION_CHANGED,
this.onMarginsSelectionChanged_.bind(this));
},
onMarginsSelectionChanged_: function(event) {
this.headerFooterApplies_ = event.selectedMargins !=
print_preview.MarginSettings.MARGINS_VALUE_NO_MARGINS;
this.setVisible_(this.headerFooterApplies_);
},
/**
* Listener executing when the user selects or de-selects the headers
* and footers option.
* @private
*/
onHeaderFooterChanged_: function() {
requestPrintPreview();
},
/**
* Listener executing when a |customEvents.PDF_LOADED| event occurs.
* @private
*/
onPDFLoaded_: function() {
if (!previewModifiable)
this.setVisible_(false);
},
/**
* Hides or shows |this.headerFooterOption|.
* @param {boolean} visible True if |this.headerFooterOption| should be
* shown.
* @private
*/
setVisible_: function(visible) {
if (visible)
fadeInOption(this.headerFooterOption_);
else
fadeOutOption(this.headerFooterOption_);
}
};
return {
HeaderFooterSettings: HeaderFooterSettings
};
});
|