1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | 'use strict';
|
23 |
|
24 | Object.defineProperty(exports, "__esModule", {
|
25 | value: true
|
26 | });
|
27 | exports.PDFFindBar = undefined;
|
28 |
|
29 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
30 |
|
31 | var _pdf_find_controller = require('./pdf_find_controller');
|
32 |
|
33 | var _ui_utils = require('./ui_utils');
|
34 |
|
35 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
36 |
|
37 | var PDFFindBar = function () {
|
38 | function PDFFindBar(options) {
|
39 | var _this = this;
|
40 |
|
41 | var l10n = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _ui_utils.NullL10n;
|
42 |
|
43 | _classCallCheck(this, PDFFindBar);
|
44 |
|
45 | this.opened = false;
|
46 | this.bar = options.bar || null;
|
47 | this.toggleButton = options.toggleButton || null;
|
48 | this.findField = options.findField || null;
|
49 | this.highlightAll = options.highlightAllCheckbox || null;
|
50 | this.caseSensitive = options.caseSensitiveCheckbox || null;
|
51 | this.findMsg = options.findMsg || null;
|
52 | this.findResultsCount = options.findResultsCount || null;
|
53 | this.findStatusIcon = options.findStatusIcon || null;
|
54 | this.findPreviousButton = options.findPreviousButton || null;
|
55 | this.findNextButton = options.findNextButton || null;
|
56 | this.findController = options.findController || null;
|
57 | this.eventBus = options.eventBus;
|
58 | this.l10n = l10n;
|
59 | if (this.findController === null) {
|
60 | throw new Error('PDFFindBar cannot be used without a ' + 'PDFFindController instance.');
|
61 | }
|
62 | this.toggleButton.addEventListener('click', function () {
|
63 | _this.toggle();
|
64 | });
|
65 | this.findField.addEventListener('input', function () {
|
66 | _this.dispatchEvent('');
|
67 | });
|
68 | this.bar.addEventListener('keydown', function (e) {
|
69 | switch (e.keyCode) {
|
70 | case 13:
|
71 | if (e.target === _this.findField) {
|
72 | _this.dispatchEvent('again', e.shiftKey);
|
73 | }
|
74 | break;
|
75 | case 27:
|
76 | _this.close();
|
77 | break;
|
78 | }
|
79 | });
|
80 | this.findPreviousButton.addEventListener('click', function () {
|
81 | _this.dispatchEvent('again', true);
|
82 | });
|
83 | this.findNextButton.addEventListener('click', function () {
|
84 | _this.dispatchEvent('again', false);
|
85 | });
|
86 | this.highlightAll.addEventListener('click', function () {
|
87 | _this.dispatchEvent('highlightallchange');
|
88 | });
|
89 | this.caseSensitive.addEventListener('click', function () {
|
90 | _this.dispatchEvent('casesensitivitychange');
|
91 | });
|
92 | this.eventBus.on('resize', this._adjustWidth.bind(this));
|
93 | }
|
94 |
|
95 | _createClass(PDFFindBar, [{
|
96 | key: 'reset',
|
97 | value: function reset() {
|
98 | this.updateUIState();
|
99 | }
|
100 | }, {
|
101 | key: 'dispatchEvent',
|
102 | value: function dispatchEvent(type, findPrev) {
|
103 | this.eventBus.dispatch('find', {
|
104 | source: this,
|
105 | type: type,
|
106 | query: this.findField.value,
|
107 | caseSensitive: this.caseSensitive.checked,
|
108 | phraseSearch: true,
|
109 | highlightAll: this.highlightAll.checked,
|
110 | findPrevious: findPrev
|
111 | });
|
112 | }
|
113 | }, {
|
114 | key: 'updateUIState',
|
115 | value: function updateUIState(state, previous, matchCount) {
|
116 | var _this2 = this;
|
117 |
|
118 | var notFound = false;
|
119 | var findMsg = '';
|
120 | var status = '';
|
121 | switch (state) {
|
122 | case _pdf_find_controller.FindState.FOUND:
|
123 | break;
|
124 | case _pdf_find_controller.FindState.PENDING:
|
125 | status = 'pending';
|
126 | break;
|
127 | case _pdf_find_controller.FindState.NOT_FOUND:
|
128 | findMsg = this.l10n.get('find_not_found', null, 'Phrase not found');
|
129 | notFound = true;
|
130 | break;
|
131 | case _pdf_find_controller.FindState.WRAPPED:
|
132 | if (previous) {
|
133 | findMsg = this.l10n.get('find_reached_top', null, 'Reached top of document, continued from bottom');
|
134 | } else {
|
135 | findMsg = this.l10n.get('find_reached_bottom', null, 'Reached end of document, continued from top');
|
136 | }
|
137 | break;
|
138 | }
|
139 | if (notFound) {
|
140 | this.findField.classList.add('notFound');
|
141 | } else {
|
142 | this.findField.classList.remove('notFound');
|
143 | }
|
144 | this.findField.setAttribute('data-status', status);
|
145 | Promise.resolve(findMsg).then(function (msg) {
|
146 | _this2.findMsg.textContent = msg;
|
147 | _this2._adjustWidth();
|
148 | });
|
149 | this.updateResultsCount(matchCount);
|
150 | }
|
151 | }, {
|
152 | key: 'updateResultsCount',
|
153 | value: function updateResultsCount(matchCount) {
|
154 | if (!this.findResultsCount) {
|
155 | return;
|
156 | }
|
157 | if (!matchCount) {
|
158 | this.findResultsCount.classList.add('hidden');
|
159 | this.findResultsCount.textContent = '';
|
160 | } else {
|
161 | this.findResultsCount.textContent = matchCount.toLocaleString();
|
162 | this.findResultsCount.classList.remove('hidden');
|
163 | }
|
164 | this._adjustWidth();
|
165 | }
|
166 | }, {
|
167 | key: 'open',
|
168 | value: function open() {
|
169 | if (!this.opened) {
|
170 | this.opened = true;
|
171 | this.toggleButton.classList.add('toggled');
|
172 | this.bar.classList.remove('hidden');
|
173 | }
|
174 | this.findField.select();
|
175 | this.findField.focus();
|
176 | this._adjustWidth();
|
177 | }
|
178 | }, {
|
179 | key: 'close',
|
180 | value: function close() {
|
181 | if (!this.opened) {
|
182 | return;
|
183 | }
|
184 | this.opened = false;
|
185 | this.toggleButton.classList.remove('toggled');
|
186 | this.bar.classList.add('hidden');
|
187 | this.findController.active = false;
|
188 | }
|
189 | }, {
|
190 | key: 'toggle',
|
191 | value: function toggle() {
|
192 | if (this.opened) {
|
193 | this.close();
|
194 | } else {
|
195 | this.open();
|
196 | }
|
197 | }
|
198 | }, {
|
199 | key: '_adjustWidth',
|
200 | value: function _adjustWidth() {
|
201 | if (!this.opened) {
|
202 | return;
|
203 | }
|
204 | this.bar.classList.remove('wrapContainers');
|
205 | var findbarHeight = this.bar.clientHeight;
|
206 | var inputContainerHeight = this.bar.firstElementChild.clientHeight;
|
207 | if (findbarHeight > inputContainerHeight) {
|
208 | this.bar.classList.add('wrapContainers');
|
209 | }
|
210 | }
|
211 | }]);
|
212 |
|
213 | return PDFFindBar;
|
214 | }();
|
215 |
|
216 | exports.PDFFindBar = PDFFindBar; |
\ | No newline at end of file |