@internetarchive/bookreader 5.0.0-32-shadydom2 → 5.0.0-32-shadydom3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/BookReader/BookReader.js +2 -32261
  2. package/BookReader/BookReader.js.map +1 -1
  3. package/BookReader/ia-bookreader-bundle.js +1138 -14867
  4. package/BookReader/ia-bookreader-bundle.js.map +1 -1
  5. package/BookReader/icons/1up.svg +1 -12
  6. package/BookReader/icons/2up.svg +1 -15
  7. package/BookReader/icons/advance.svg +3 -26
  8. package/BookReader/icons/chevron-right.svg +1 -1
  9. package/BookReader/icons/close-circle-dark.svg +1 -1
  10. package/BookReader/icons/close-circle.svg +1 -1
  11. package/BookReader/icons/fullscreen.svg +1 -17
  12. package/BookReader/icons/fullscreen_exit.svg +1 -17
  13. package/BookReader/icons/hamburger.svg +1 -15
  14. package/BookReader/icons/left-arrow.svg +1 -12
  15. package/BookReader/icons/magnify-minus.svg +1 -16
  16. package/BookReader/icons/magnify-plus.svg +1 -17
  17. package/BookReader/icons/magnify.svg +1 -15
  18. package/BookReader/icons/pause.svg +1 -23
  19. package/BookReader/icons/play.svg +1 -22
  20. package/BookReader/icons/playback-speed.svg +1 -34
  21. package/BookReader/icons/read-aloud.svg +1 -22
  22. package/BookReader/icons/review.svg +3 -22
  23. package/BookReader/icons/thumbnails.svg +1 -17
  24. package/BookReader/icons/voice.svg +1 -1
  25. package/BookReader/icons/volume-full.svg +1 -22
  26. package/BookReader/images/BRicons.svg +5 -94
  27. package/BookReader/images/books_graphic.svg +1 -177
  28. package/BookReader/images/icon_book.svg +1 -12
  29. package/BookReader/images/icon_bookmark.svg +1 -12
  30. package/BookReader/images/icon_gear.svg +1 -14
  31. package/BookReader/images/icon_hamburger.svg +1 -20
  32. package/BookReader/images/icon_home.svg +1 -21
  33. package/BookReader/images/icon_info.svg +1 -11
  34. package/BookReader/images/icon_one_page.svg +1 -8
  35. package/BookReader/images/icon_pause.svg +1 -1
  36. package/BookReader/images/icon_play.svg +1 -1
  37. package/BookReader/images/icon_playback-rate.svg +1 -15
  38. package/BookReader/images/icon_search_button.svg +1 -8
  39. package/BookReader/images/icon_share.svg +1 -9
  40. package/BookReader/images/icon_skip-ahead.svg +1 -6
  41. package/BookReader/images/icon_skip-back.svg +2 -13
  42. package/BookReader/images/icon_speaker.svg +1 -18
  43. package/BookReader/images/icon_speaker_open.svg +1 -10
  44. package/BookReader/images/icon_thumbnails.svg +1 -12
  45. package/BookReader/images/icon_toc.svg +1 -5
  46. package/BookReader/images/icon_two_pages.svg +1 -9
  47. package/BookReader/images/marker_chap-off.svg +1 -11
  48. package/BookReader/images/marker_chap-on.svg +1 -11
  49. package/BookReader/images/marker_srch-on.svg +1 -11
  50. package/BookReader/jquery-1.10.1.js +2 -108
  51. package/BookReader/plugins/plugin.archive_analytics.js +1 -170
  52. package/BookReader/plugins/plugin.archive_analytics.js.map +1 -1
  53. package/BookReader/plugins/plugin.autoplay.js +1 -163
  54. package/BookReader/plugins/plugin.autoplay.js.map +1 -1
  55. package/BookReader/plugins/plugin.chapters.js +1 -333
  56. package/BookReader/plugins/plugin.chapters.js.map +1 -1
  57. package/BookReader/plugins/plugin.iframe.js +1 -72
  58. package/BookReader/plugins/plugin.iframe.js.map +1 -1
  59. package/BookReader/plugins/plugin.mobile_nav.js +1 -332
  60. package/BookReader/plugins/plugin.mobile_nav.js.map +1 -1
  61. package/BookReader/plugins/plugin.resume.js +1 -241
  62. package/BookReader/plugins/plugin.resume.js.map +1 -1
  63. package/BookReader/plugins/plugin.search.js +1 -1261
  64. package/BookReader/plugins/plugin.search.js.map +1 -1
  65. package/BookReader/plugins/plugin.text_selection.js +1 -839
  66. package/BookReader/plugins/plugin.text_selection.js.map +1 -1
  67. package/BookReader/plugins/plugin.tts.js +2 -9115
  68. package/BookReader/plugins/plugin.tts.js.map +1 -1
  69. package/BookReader/plugins/plugin.url.js +1 -811
  70. package/BookReader/plugins/plugin.url.js.map +1 -1
  71. package/BookReader/plugins/plugin.vendor-fullscreen.js +1 -326
  72. package/BookReader/plugins/plugin.vendor-fullscreen.js.map +1 -1
  73. package/BookReader/webcomponents-bundle.js +2 -411
  74. package/BookReader/webcomponents-bundle.js.map +1 -1
  75. package/package.json +2 -2
  76. package/src/BookNavigator/bookmarks/ia-bookmarks.js +1 -2
@@ -1,1262 +1,2 @@
1
- (self["webpackChunk_internetarchive_bookreader"] = self["webpackChunk_internetarchive_bookreader"] || []).push([["plugins/plugin.search.js"],{
2
-
3
- /***/ "./src/plugins/search/plugin.search.js":
4
- /*!*********************************************!*\
5
- !*** ./src/plugins/search/plugin.search.js ***!
6
- \*********************************************/
7
- /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
8
-
9
- "use strict";
10
- __webpack_require__.r(__webpack_exports__);
11
- /* harmony import */ var regenerator_runtime_runtime_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! regenerator-runtime/runtime.js */ "./node_modules/regenerator-runtime/runtime.js");
12
- /* harmony import */ var regenerator_runtime_runtime_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(regenerator_runtime_runtime_js__WEBPACK_IMPORTED_MODULE_0__);
13
- /* harmony import */ var core_js_modules_es_regexp_exec_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! core-js/modules/es.regexp.exec.js */ "./node_modules/core-js/modules/es.regexp.exec.js");
14
- /* harmony import */ var core_js_modules_es_regexp_exec_js__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_regexp_exec_js__WEBPACK_IMPORTED_MODULE_1__);
15
- /* harmony import */ var core_js_modules_es_string_search_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! core-js/modules/es.string.search.js */ "./node_modules/core-js/modules/es.string.search.js");
16
- /* harmony import */ var core_js_modules_es_string_search_js__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_string_search_js__WEBPACK_IMPORTED_MODULE_2__);
17
- /* harmony import */ var core_js_modules_es_array_find_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! core-js/modules/es.array.find.js */ "./node_modules/core-js/modules/es.array.find.js");
18
- /* harmony import */ var core_js_modules_es_array_find_js__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_array_find_js__WEBPACK_IMPORTED_MODULE_3__);
19
- /* harmony import */ var core_js_modules_es_string_replace_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! core-js/modules/es.string.replace.js */ "./node_modules/core-js/modules/es.string.replace.js");
20
- /* harmony import */ var core_js_modules_es_string_replace_js__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_string_replace_js__WEBPACK_IMPORTED_MODULE_4__);
21
- /* harmony import */ var core_js_modules_es_array_concat_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! core-js/modules/es.array.concat.js */ "./node_modules/core-js/modules/es.array.concat.js");
22
- /* harmony import */ var core_js_modules_es_array_concat_js__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_array_concat_js__WEBPACK_IMPORTED_MODULE_5__);
23
- /* harmony import */ var core_js_modules_es_object_assign_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! core-js/modules/es.object.assign.js */ "./node_modules/core-js/modules/es.object.assign.js");
24
- /* harmony import */ var core_js_modules_es_object_assign_js__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_object_assign_js__WEBPACK_IMPORTED_MODULE_6__);
25
- /* harmony import */ var core_js_modules_es_object_entries_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! core-js/modules/es.object.entries.js */ "./node_modules/core-js/modules/es.object.entries.js");
26
- /* harmony import */ var core_js_modules_es_object_entries_js__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_object_entries_js__WEBPACK_IMPORTED_MODULE_7__);
27
- /* harmony import */ var core_js_modules_web_dom_collections_for_each_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! core-js/modules/web.dom-collections.for-each.js */ "./node_modules/core-js/modules/web.dom-collections.for-each.js");
28
- /* harmony import */ var core_js_modules_web_dom_collections_for_each_js__WEBPACK_IMPORTED_MODULE_8___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_web_dom_collections_for_each_js__WEBPACK_IMPORTED_MODULE_8__);
29
- /* harmony import */ var core_js_modules_es_object_to_string_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! core-js/modules/es.object.to-string.js */ "./node_modules/core-js/modules/es.object.to-string.js");
30
- /* harmony import */ var core_js_modules_es_object_to_string_js__WEBPACK_IMPORTED_MODULE_9___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_object_to_string_js__WEBPACK_IMPORTED_MODULE_9__);
31
- /* harmony import */ var core_js_modules_es_promise_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! core-js/modules/es.promise.js */ "./node_modules/core-js/modules/es.promise.js");
32
- /* harmony import */ var core_js_modules_es_promise_js__WEBPACK_IMPORTED_MODULE_10___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_promise_js__WEBPACK_IMPORTED_MODULE_10__);
33
- /* harmony import */ var core_js_modules_es_array_iterator_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! core-js/modules/es.array.iterator.js */ "./node_modules/core-js/modules/es.array.iterator.js");
34
- /* harmony import */ var core_js_modules_es_array_iterator_js__WEBPACK_IMPORTED_MODULE_11___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_array_iterator_js__WEBPACK_IMPORTED_MODULE_11__);
35
- /* harmony import */ var core_js_modules_es_string_iterator_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! core-js/modules/es.string.iterator.js */ "./node_modules/core-js/modules/es.string.iterator.js");
36
- /* harmony import */ var core_js_modules_es_string_iterator_js__WEBPACK_IMPORTED_MODULE_12___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_string_iterator_js__WEBPACK_IMPORTED_MODULE_12__);
37
- /* harmony import */ var core_js_modules_web_dom_collections_iterator_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! core-js/modules/web.dom-collections.iterator.js */ "./node_modules/core-js/modules/web.dom-collections.iterator.js");
38
- /* harmony import */ var core_js_modules_web_dom_collections_iterator_js__WEBPACK_IMPORTED_MODULE_13___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_web_dom_collections_iterator_js__WEBPACK_IMPORTED_MODULE_13__);
39
- /* harmony import */ var core_js_modules_web_url_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! core-js/modules/web.url.js */ "./node_modules/core-js/modules/web.url.js");
40
- /* harmony import */ var core_js_modules_web_url_js__WEBPACK_IMPORTED_MODULE_14___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_web_url_js__WEBPACK_IMPORTED_MODULE_14__);
41
- /* harmony import */ var core_js_modules_es_array_slice_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! core-js/modules/es.array.slice.js */ "./node_modules/core-js/modules/es.array.slice.js");
42
- /* harmony import */ var core_js_modules_es_array_slice_js__WEBPACK_IMPORTED_MODULE_15___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_array_slice_js__WEBPACK_IMPORTED_MODULE_15__);
43
- /* harmony import */ var core_js_modules_es_function_name_js__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! core-js/modules/es.function.name.js */ "./node_modules/core-js/modules/es.function.name.js");
44
- /* harmony import */ var core_js_modules_es_function_name_js__WEBPACK_IMPORTED_MODULE_16___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_function_name_js__WEBPACK_IMPORTED_MODULE_16__);
45
- /* harmony import */ var core_js_modules_es_array_from_js__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! core-js/modules/es.array.from.js */ "./node_modules/core-js/modules/es.array.from.js");
46
- /* harmony import */ var core_js_modules_es_array_from_js__WEBPACK_IMPORTED_MODULE_17___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_array_from_js__WEBPACK_IMPORTED_MODULE_17__);
47
- /* harmony import */ var core_js_modules_es_symbol_js__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! core-js/modules/es.symbol.js */ "./node_modules/core-js/modules/es.symbol.js");
48
- /* harmony import */ var core_js_modules_es_symbol_js__WEBPACK_IMPORTED_MODULE_18___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_symbol_js__WEBPACK_IMPORTED_MODULE_18__);
49
- /* harmony import */ var core_js_modules_es_symbol_description_js__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! core-js/modules/es.symbol.description.js */ "./node_modules/core-js/modules/es.symbol.description.js");
50
- /* harmony import */ var core_js_modules_es_symbol_description_js__WEBPACK_IMPORTED_MODULE_19___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_symbol_description_js__WEBPACK_IMPORTED_MODULE_19__);
51
- /* harmony import */ var core_js_modules_es_symbol_iterator_js__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! core-js/modules/es.symbol.iterator.js */ "./node_modules/core-js/modules/es.symbol.iterator.js");
52
- /* harmony import */ var core_js_modules_es_symbol_iterator_js__WEBPACK_IMPORTED_MODULE_20___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_symbol_iterator_js__WEBPACK_IMPORTED_MODULE_20__);
53
- /* harmony import */ var _BookReader_PageContainer_js__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ../../BookReader/PageContainer.js */ "./src/BookReader/PageContainer.js");
54
- /* harmony import */ var _view_js__WEBPACK_IMPORTED_MODULE_22__ = __webpack_require__(/*! ./view.js */ "./src/plugins/search/view.js");
55
- /* provided dependency */ var jQuery = __webpack_require__(/*! jquery */ "jquery");
56
- /* provided dependency */ var $ = __webpack_require__(/*! jquery */ "jquery");
57
-
58
-
59
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
60
-
61
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
62
-
63
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
64
-
65
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
66
-
67
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
68
-
69
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
70
-
71
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
72
-
73
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
74
-
75
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
- /* global BookReader */
99
-
100
- /**
101
- * Plugin for Archive.org book search
102
- * NOTE: This script must be loaded AFTER `plugin.mobile_nav.js`
103
- * as it mutates mobile nav drawer
104
- *
105
- * Events fired at various points throughout search processing are published
106
- * on the document DOM element. These can be subscribed to using jQuery's event
107
- * binding method `$.fn.on`. All of the events are prefixed with a BookReader
108
- * namespace. The events are:
109
- *
110
- * @event BookReader:SearchStarted - When a search form is submitted, immediately
111
- * before an AJAX call is made to request search results
112
- * @event BookReader:SearchCallback - When the search AJAX call is returned and at
113
- * least one result is returned. The event callback receives an object
114
- * with the `results`, plugin `options`, and the BookReader `instance`
115
- * @event BookReader:SearchCallbackError - When the AJAX request returns an error.
116
- * Receives the `results` and `instance`
117
- * @event BookReader:SearchCallbackNotIndexed - When a message is received that
118
- * the book has not had OCR text indexed yet. Receives `instance`
119
- * @event BookReader:SearchCallbackEmpty - When no results found. Receives
120
- * `instance`
121
- * @event BookReader:SearchCanceled - When no results found. Receives
122
- * `instance`
123
- */
124
-
125
-
126
- /** @typedef {import('../../BookReader/PageContainer').PageContainer} PageContainer */
127
-
128
- /** @typedef {import('../../BookReader/BookModel').PageIndex} PageIndex */
129
-
130
- jQuery.extend(BookReader.defaultOptions, {
131
- server: 'ia600609.us.archive.org',
132
- bookId: '',
133
- subPrefix: '',
134
- bookPath: '',
135
- enableSearch: true,
136
- searchInsideUrl: '/fulltext/inside.php',
137
- initialSearchTerm: null
138
- });
139
- /** @override */
140
-
141
- BookReader.prototype.setup = function (super_) {
142
- return function (options) {
143
- super_.call(this, options);
144
- this.searchTerm = '';
145
- this.searchResults = null;
146
- this.searchInsideUrl = options.searchInsideUrl;
147
- this.enableSearch = options.enableSearch; // Base server used by some api calls
148
-
149
- this.bookId = options.bookId;
150
- this.server = options.server;
151
- this.subPrefix = options.subPrefix;
152
- this.bookPath = options.bookPath;
153
- this.searchXHR = null;
154
-
155
- this._cancelSearch.bind(this);
156
-
157
- this.cancelSearchRequest.bind(this);
158
- /** @type { {[pageIndex: number]: SearchInsideMatchBox[]} } */
159
-
160
- this._searchBoxesByIndex = {};
161
- this.searchView = undefined;
162
- };
163
- }(BookReader.prototype.setup);
164
- /** @override */
165
-
166
-
167
- BookReader.prototype.init = function (super_) {
168
- return function () {
169
- var _this = this;
170
-
171
- super_.call(this); // give SearchView the most complete bookreader state
172
-
173
- this.searchView = new _view_js__WEBPACK_IMPORTED_MODULE_22__.default({
174
- br: this,
175
- searchCancelledCallback: function searchCancelledCallback() {
176
- _this._cancelSearch();
177
-
178
- _this.trigger('SearchCanceled', {
179
- term: _this.searchTerm,
180
- instance: _this
181
- });
182
- }
183
- });
184
-
185
- if (this.options.enableSearch && this.options.initialSearchTerm) {
186
- /**
187
- * this.search() take two parameter
188
- * 1. this.options.initialSearchTerm - search term
189
- * 2. {
190
- * goToFirstResult: this.options.goToFirstResult,
191
- * suppressFragmentChange: false // always want to change fragment in URL
192
- * }
193
- */
194
- this.search(this.options.initialSearchTerm, {
195
- goToFirstResult: this.options.goToFirstResult,
196
- suppressFragmentChange: false
197
- });
198
- }
199
- };
200
- }(BookReader.prototype.init);
201
- /** @override */
202
-
203
-
204
- BookReader.prototype.buildToolbarElement = function (super_) {
205
- return function () {
206
- var $el = super_.call(this);
207
-
208
- if (!this.enableSearch) {
209
- return;
210
- }
211
-
212
- if (this.searchView.dom.toolbarSearch) {
213
- $el.find('.BRtoolbarSectionInfo').after(this.searchView.dom.toolbarSearch);
214
- }
215
-
216
- return $el;
217
- };
218
- }(BookReader.prototype.buildToolbarElement);
219
- /** @override */
220
-
221
-
222
- BookReader.prototype._createPageContainer = function (super_) {
223
- return function (index) {
224
- var pageContainer = super_.call(this, index);
225
-
226
- if (this.enableSearch && pageContainer.page && index in this._searchBoxesByIndex) {
227
- var pageIndex = pageContainer.page.index;
228
- (0,_BookReader_PageContainer_js__WEBPACK_IMPORTED_MODULE_21__.renderBoxesInPageContainerLayer)('searchHiliteLayer', this._searchBoxesByIndex[pageIndex], pageContainer.page, pageContainer.$container[0]);
229
- }
230
-
231
- return pageContainer;
232
- };
233
- }(BookReader.prototype._createPageContainer);
234
- /**
235
- * @typedef {object} SearchOptions
236
- * @property {boolean} goToFirstResult
237
- * @property {boolean} disablePopup
238
- * @property {(null|function)} error - @deprecated at v.5.0
239
- * @property {(null|function)} success - @deprecated at v.5.0
240
- */
241
-
242
- /**
243
- * Submits search request
244
- *
245
- * @param {string} term
246
- * @param {SearchOptions} overrides
247
- */
248
-
249
-
250
- BookReader.prototype.search = function () {
251
- var _this2 = this;
252
-
253
- var term = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
254
- var overrides = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
255
-
256
- /** @type {SearchOptions} */
257
- var defaultOptions = {
258
- goToFirstResult: false,
259
-
260
- /* jump to the first result (default=false) */
261
- disablePopup: false,
262
-
263
- /* don't show the modal progress (default=false) */
264
- suppressFragmentChange: false,
265
-
266
- /* don't change the URL on initial load */
267
- error: null,
268
-
269
- /* optional error handler (default=null) */
270
- success: null
271
- /* optional success handler (default=null) */
272
-
273
- };
274
- var options = jQuery.extend({}, defaultOptions, overrides);
275
- this.suppressFragmentChange = options.suppressFragmentChange; // strip slashes, since this goes in the url
276
-
277
- this.searchTerm = term.replace(/\//g, ' ');
278
-
279
- if (!options.suppressFragmentChange) {
280
- this.trigger(BookReader.eventNames.fragmentChange);
281
- } // Add quotes to the term. This is to compenstate for the backends default OR query
282
- // term = term.replace(/['"]+/g, '');
283
- // term = '"' + term + '"';
284
- // Remove the port and userdir
285
-
286
-
287
- var serverPath = this.server.replace(/:.+/, '');
288
- var baseUrl = "https://".concat(serverPath).concat(this.searchInsideUrl, "?"); // Remove subPrefix from end of path
289
-
290
- var path = this.bookPath;
291
- var subPrefixWithSlash = "/".concat(this.subPrefix);
292
-
293
- if (this.bookPath.length - this.bookPath.lastIndexOf(subPrefixWithSlash) == subPrefixWithSlash.length) {
294
- path = this.bookPath.substr(0, this.bookPath.length - subPrefixWithSlash.length);
295
- }
296
-
297
- var urlParams = {
298
- item_id: this.bookId,
299
- doc: this.subPrefix,
300
- path: path,
301
- q: term
302
- }; // NOTE that the API does not expect / (slashes) to be encoded. (%2F) won't work
303
-
304
- var paramStr = $.param(urlParams).replace(/%2F/g, '/');
305
- var url = "".concat(baseUrl).concat(paramStr);
306
-
307
- var cleanup = function cleanup() {
308
- _this2.searchXHR = null;
309
-
310
- window.BRSearchInProgress = function () {};
311
- };
312
-
313
- var processSearchResults = function processSearchResults(searchInsideResults) {
314
- if (!_this2.searchXHR) {
315
- return;
316
- }
317
-
318
- var responseHasError = searchInsideResults.error || !searchInsideResults.matches.length;
319
- var hasCustomError = typeof options.error === 'function';
320
- var hasCustomSuccess = typeof options.success === 'function';
321
-
322
- if (responseHasError) {
323
- hasCustomError ? options.error.call(_this2, searchInsideResults, options) : _this2.BRSearchCallbackError(searchInsideResults, options);
324
- } else {
325
- hasCustomSuccess ? options.success.call(_this2, searchInsideResults, options) : _this2.BRSearchCallback(searchInsideResults, options);
326
- }
327
-
328
- cleanup();
329
- };
330
-
331
- var beforeSend = function beforeSend(xhr) {
332
- _this2.searchXHR = xhr;
333
- window.BRSearchInProgress = processSearchResults;
334
- };
335
-
336
- this.trigger('SearchStarted', {
337
- term: this.searchTerm,
338
- instance: this
339
- });
340
- return $.ajax({
341
- url: url,
342
- dataType: 'jsonp',
343
- cache: true,
344
- beforeSend: beforeSend,
345
- jsonpCallback: 'BRSearchInProgress'
346
- }).then(processSearchResults);
347
- };
348
- /**
349
- * cancels AJAX Call
350
- * emits custom event
351
- */
352
-
353
-
354
- BookReader.prototype._cancelSearch = function () {
355
- var _this$searchXHR;
356
-
357
- (_this$searchXHR = this.searchXHR) === null || _this$searchXHR === void 0 ? void 0 : _this$searchXHR.abort();
358
- this.searchView.clearSearchFieldAndResults(false);
359
- this.searchTerm = '';
360
- this.searchXHR = null;
361
- this.searchResults = [];
362
-
363
- window.BRSearchInProgress = function () {};
364
- };
365
- /**
366
- * External function to cancel search
367
- * checks for term & xhr in flight before running
368
- */
369
-
370
-
371
- BookReader.prototype.cancelSearchRequest = function () {
372
- if (this.searchXHR !== null) {
373
- this._cancelSearch();
374
-
375
- this.searchView.toggleSearchPending();
376
- this.trigger('SearchCanceled', {
377
- term: this.searchTerm,
378
- instance: this
379
- });
380
- }
381
- };
382
- /**
383
- * @typedef {object} SearchInsideMatchBox
384
- * @property {number} page
385
- * @property {number} r
386
- * @property {number} l
387
- * @property {number} b
388
- * @property {number} t
389
- * @property {HTMLDivElement} [div]
390
- */
391
-
392
- /**
393
- * @typedef {object} SearchInsideMatch
394
- * @property {string} text
395
- * @property {Array<{ page: number, boxes: SearchInsideMatchBox[] }>} par
396
- */
397
-
398
- /**
399
- * @typedef {object} SearchInsideResults
400
- * @property {string} error
401
- * @property {SearchInsideMatch[]} matches
402
- * @property {boolean} indexed
403
- */
404
-
405
- /**
406
- * Search Results return handler
407
- * @callback
408
- * @param {SearchInsideResults} results
409
- * @param {object} options
410
- * @param {boolean} options.goToFirstResult
411
- */
412
-
413
-
414
- BookReader.prototype.BRSearchCallback = function (results, options) {
415
- this.searchResults = results || [];
416
- this.updateSearchHilites();
417
- this.removeProgressPopup();
418
-
419
- if (options.goToFirstResult) {
420
- var pageIndex = this._models.book.leafNumToIndex(results.matches[0].par[0].page);
421
-
422
- this._searchPluginGoToResult(pageIndex);
423
- }
424
-
425
- this.trigger('SearchCallback', {
426
- results: results,
427
- options: options,
428
- instance: this
429
- });
430
- };
431
- /**
432
- * Main search results error handler
433
- * @callback
434
- * @param {SearchInsideResults} results
435
- */
436
-
437
-
438
- BookReader.prototype.BRSearchCallbackError = function (results) {
439
- this._BRSearchCallbackError(results);
440
- };
441
- /**
442
- * @private draws search results error
443
- * @callback
444
- * @param {SearchInsideResults} results
445
- * @param {jQuery} $el
446
- * @param {boolean} fade
447
- */
448
-
449
-
450
- BookReader.prototype._BRSearchCallbackError = function (results) {
451
- this.searchResults = results;
452
- var basePayload = {
453
- term: this.searchTerm,
454
- instance: this
455
- };
456
-
457
- if (results.error) {
458
- var payload = Object.assign({}, basePayload, {
459
- results: results
460
- });
461
- this.trigger('SearchCallbackError', payload);
462
- } else if (0 == results.matches.length) {
463
- if (false === results.indexed) {
464
- this.trigger('SearchCallbackBookNotIndexed', basePayload);
465
- return;
466
- }
467
-
468
- this.trigger('SearchCallbackEmpty', basePayload);
469
- }
470
- };
471
- /**
472
- * updates search on-page highlights controller
473
- */
474
-
475
-
476
- BookReader.prototype.updateSearchHilites = function () {
477
- var _this$searchResults,
478
- _this3 = this;
479
-
480
- /** @type {SearchInsideMatch[]} */
481
- var matches = ((_this$searchResults = this.searchResults) === null || _this$searchResults === void 0 ? void 0 : _this$searchResults.matches) || [];
482
- /** @type { {[pageIndex: number]: SearchInsideMatch[]} } */
483
-
484
- var boxesByIndex = {}; // Clear any existing svg layers
485
-
486
- this.removeSearchHilites(); // Group by pageIndex
487
-
488
- var _iterator = _createForOfIteratorHelper(matches),
489
- _step;
490
-
491
- try {
492
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
493
- var match = _step.value;
494
-
495
- var _iterator2 = _createForOfIteratorHelper(match.par[0].boxes),
496
- _step2;
497
-
498
- try {
499
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
500
- var box = _step2.value;
501
- var pageIndex = this.leafNumToIndex(box.page);
502
- var pageMatches = boxesByIndex[pageIndex] || (boxesByIndex[pageIndex] = []);
503
- pageMatches.push(box);
504
- }
505
- } catch (err) {
506
- _iterator2.e(err);
507
- } finally {
508
- _iterator2.f();
509
- }
510
- } // update any already created pages
511
-
512
- } catch (err) {
513
- _iterator.e(err);
514
- } finally {
515
- _iterator.f();
516
- }
517
-
518
- var _loop = function _loop() {
519
- var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
520
- pageIndexString = _Object$entries$_i[0],
521
- boxes = _Object$entries$_i[1];
522
-
523
- var pageIndex = parseFloat(pageIndexString);
524
-
525
- var page = _this3._models.book.getPage(pageIndex);
526
-
527
- var pageContainers = _this3.getActivePageContainerElementsForIndex(pageIndex);
528
-
529
- pageContainers.forEach(function (container) {
530
- return (0,_BookReader_PageContainer_js__WEBPACK_IMPORTED_MODULE_21__.renderBoxesInPageContainerLayer)('searchHiliteLayer', boxes, page, container);
531
- });
532
- };
533
-
534
- for (var _i = 0, _Object$entries = Object.entries(boxesByIndex); _i < _Object$entries.length; _i++) {
535
- _loop();
536
- }
537
-
538
- this._searchBoxesByIndex = boxesByIndex;
539
- };
540
- /**
541
- * remove search highlights
542
- */
543
-
544
-
545
- BookReader.prototype.removeSearchHilites = function () {
546
- $(this.getActivePageContainerElements()).find('.searchHiliteLayer').remove();
547
- };
548
- /**
549
- * @private
550
- * Goes to the page specified. If the page is not viewable, tries to load the page
551
- * FIXME Most of this logic is IA specific, and should be less integrated into here
552
- * or at least more configurable.
553
- * @param {PageIndex} pageIndex
554
- */
555
-
556
-
557
- BookReader.prototype._searchPluginGoToResult = /*#__PURE__*/function () {
558
- var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(pageIndex) {
559
- var book, page, makeUnviewableAtEnd, resp, _iterator3, _step3, leafNum;
560
-
561
- return regeneratorRuntime.wrap(function _callee$(_context) {
562
- while (1) {
563
- switch (_context.prev = _context.next) {
564
- case 0:
565
- book = this._models.book;
566
- page = book.getPage(pageIndex);
567
- makeUnviewableAtEnd = false;
568
-
569
- if (page.isViewable) {
570
- _context.next = 10;
571
- break;
572
- }
573
-
574
- _context.next = 6;
575
- return fetch('/services/bookreader/request_page?' + new URLSearchParams({
576
- id: this.options.bookId,
577
- subprefix: this.options.subPrefix,
578
- leafNum: page.leafNum
579
- })).then(function (r) {
580
- return r.json();
581
- });
582
-
583
- case 6:
584
- resp = _context.sent;
585
- _iterator3 = _createForOfIteratorHelper(resp.value);
586
-
587
- try {
588
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
589
- leafNum = _step3.value;
590
- book.getPage(book.leafNumToIndex(leafNum)).makeViewable();
591
- } // not able to show page; make the page viewable anyways so that it can
592
- // actually open. On IA, it has a fallback to a special error page.
593
-
594
- } catch (err) {
595
- _iterator3.e(err);
596
- } finally {
597
- _iterator3.f();
598
- }
599
-
600
- if (!resp.value.length) {
601
- book.getPage(pageIndex).makeViewable();
602
- makeUnviewableAtEnd = true;
603
- }
604
-
605
- case 10:
606
- /* this updates the URL */
607
- this.suppressFragmentChange = false;
608
- this.jumpToIndex(pageIndex); // Reset it to unviewable if it wasn't resolved
609
-
610
- if (makeUnviewableAtEnd) {
611
- book.getPage(pageIndex).makeViewable(false);
612
- }
613
-
614
- case 13:
615
- case "end":
616
- return _context.stop();
617
- }
618
- }
619
- }, _callee, this);
620
- }));
621
-
622
- return function (_x) {
623
- return _ref.apply(this, arguments);
624
- };
625
- }();
626
- /**
627
- * Removes all search pins
628
- */
629
-
630
-
631
- BookReader.prototype.removeSearchResults = function () {
632
- var suppressFragmentChange = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
633
- this.removeSearchHilites(); //be sure to set all box.divs to null
634
-
635
- this.searchTerm = null;
636
- this.searchResults = null;
637
-
638
- if (!suppressFragmentChange) {
639
- this.trigger(BookReader.eventNames.fragmentChange);
640
- }
641
- };
642
- /**
643
- * Returns true if a search highlight is currently being displayed
644
- * @returns {boolean}
645
- */
646
-
647
-
648
- BookReader.prototype.searchHighlightVisible = function () {
649
- var _this4 = this;
650
-
651
- var results = this.searchResults;
652
- var visiblePages = [];
653
- if (null == results) return false;
654
-
655
- if (this.constMode2up == this.mode) {
656
- visiblePages = [this.twoPage.currentIndexL, this.twoPage.currentIndexR];
657
- } else if (this.constMode1up == this.mode) {
658
- visiblePages = [this.currentIndex()];
659
- } else {
660
- return false;
661
- }
662
-
663
- results.matches.some(function (match) {
664
- return match.par[0].boxes.some(function (box) {
665
- var pageIndex = _this4.leafNumToIndex(box.page);
666
-
667
- if (jQuery.inArray(pageIndex, visiblePages) >= 0) {
668
- return true;
669
- }
670
- });
671
- });
672
- return false;
673
- };
674
-
675
- /***/ }),
676
-
677
- /***/ "./src/plugins/search/view.js":
678
- /*!************************************!*\
679
- !*** ./src/plugins/search/view.js ***!
680
- \************************************/
681
- /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
682
-
683
- "use strict";
684
- __webpack_require__.r(__webpack_exports__);
685
- /* harmony import */ var core_js_modules_es_regexp_constructor_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! core-js/modules/es.regexp.constructor.js */ "./node_modules/core-js/modules/es.regexp.constructor.js");
686
- /* harmony import */ var core_js_modules_es_regexp_constructor_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_regexp_constructor_js__WEBPACK_IMPORTED_MODULE_0__);
687
- /* harmony import */ var core_js_modules_es_regexp_exec_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! core-js/modules/es.regexp.exec.js */ "./node_modules/core-js/modules/es.regexp.exec.js");
688
- /* harmony import */ var core_js_modules_es_regexp_exec_js__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_regexp_exec_js__WEBPACK_IMPORTED_MODULE_1__);
689
- /* harmony import */ var core_js_modules_es_regexp_to_string_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! core-js/modules/es.regexp.to-string.js */ "./node_modules/core-js/modules/es.regexp.to-string.js");
690
- /* harmony import */ var core_js_modules_es_regexp_to_string_js__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_regexp_to_string_js__WEBPACK_IMPORTED_MODULE_2__);
691
- /* harmony import */ var core_js_modules_es_array_concat_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! core-js/modules/es.array.concat.js */ "./node_modules/core-js/modules/es.array.concat.js");
692
- /* harmony import */ var core_js_modules_es_array_concat_js__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_array_concat_js__WEBPACK_IMPORTED_MODULE_3__);
693
- /* harmony import */ var core_js_modules_es_array_map_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! core-js/modules/es.array.map.js */ "./node_modules/core-js/modules/es.array.map.js");
694
- /* harmony import */ var core_js_modules_es_array_map_js__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_array_map_js__WEBPACK_IMPORTED_MODULE_4__);
695
- /* harmony import */ var core_js_modules_es_array_slice_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! core-js/modules/es.array.slice.js */ "./node_modules/core-js/modules/es.array.slice.js");
696
- /* harmony import */ var core_js_modules_es_array_slice_js__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_array_slice_js__WEBPACK_IMPORTED_MODULE_5__);
697
- /* harmony import */ var core_js_modules_es_array_find_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! core-js/modules/es.array.find.js */ "./node_modules/core-js/modules/es.array.find.js");
698
- /* harmony import */ var core_js_modules_es_array_find_js__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_array_find_js__WEBPACK_IMPORTED_MODULE_6__);
699
- /* harmony import */ var core_js_modules_web_dom_collections_for_each_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! core-js/modules/web.dom-collections.for-each.js */ "./node_modules/core-js/modules/web.dom-collections.for-each.js");
700
- /* harmony import */ var core_js_modules_web_dom_collections_for_each_js__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_web_dom_collections_for_each_js__WEBPACK_IMPORTED_MODULE_7__);
701
- /* harmony import */ var core_js_modules_es_string_replace_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! core-js/modules/es.string.replace.js */ "./node_modules/core-js/modules/es.string.replace.js");
702
- /* harmony import */ var core_js_modules_es_string_replace_js__WEBPACK_IMPORTED_MODULE_8___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_string_replace_js__WEBPACK_IMPORTED_MODULE_8__);
703
- /* harmony import */ var core_js_modules_es_string_search_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! core-js/modules/es.string.search.js */ "./node_modules/core-js/modules/es.string.search.js");
704
- /* harmony import */ var core_js_modules_es_string_search_js__WEBPACK_IMPORTED_MODULE_9___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_string_search_js__WEBPACK_IMPORTED_MODULE_9__);
705
- /* provided dependency */ var $ = __webpack_require__(/*! jquery */ "jquery");
706
-
707
-
708
-
709
-
710
-
711
-
712
-
713
-
714
-
715
-
716
-
717
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
718
-
719
- 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); } }
720
-
721
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
722
-
723
- var SearchView = /*#__PURE__*/function () {
724
- /**
725
- * @param {object} params
726
- * @param {object} params.br The BookReader instance
727
- * @param {function} params.cancelSearch callback when a user wants to cancel search
728
- *
729
- * @event BookReader:SearchResultsCleared - when the search results nav gets cleared
730
- * @event BookReader:ToggleSearchMenu - when search results menu should toggle
731
- */
732
- function SearchView(_ref) {
733
- var br = _ref.br,
734
- _ref$searchCancelledC = _ref.searchCancelledCallback,
735
- searchCancelledCallback = _ref$searchCancelledC === void 0 ? function () {} : _ref$searchCancelledC;
736
-
737
- _classCallCheck(this, SearchView);
738
-
739
- this.br = br; // Search results are returned as a text blob with the hits wrapped in
740
- // triple mustaches. Hits occasionally include text beyond the search
741
- // term, so everything within the staches is captured and wrapped.
742
-
743
- this.matcher = new RegExp('{{{(.+?)}}}', 'g');
744
- this.matches = [];
745
- this.cacheDOMElements();
746
- this.bindEvents();
747
- this.cancelSearch = searchCancelledCallback;
748
- }
749
-
750
- _createClass(SearchView, [{
751
- key: "cacheDOMElements",
752
- value: function cacheDOMElements() {
753
- this.dom = {}; // Search input within the top toolbar. Will be removed once the mobile menu is replaced.
754
-
755
- this.dom.toolbarSearch = this.buildToolbarSearch();
756
- }
757
- /**
758
- * @param {string} query
759
- */
760
-
761
- }, {
762
- key: "setQuery",
763
- value: function setQuery(query) {
764
- this.br.$('[name="query"]').val(query);
765
- }
766
- }, {
767
- key: "emptyMatches",
768
- value: function emptyMatches() {
769
- this.matches = [];
770
- }
771
- }, {
772
- key: "removeResultPins",
773
- value: function removeResultPins() {
774
- this.br.$('.BRnavpos .BRsearch').remove();
775
- }
776
- }, {
777
- key: "clearSearchFieldAndResults",
778
- value: function clearSearchFieldAndResults() {
779
- var dispatchEventWhenComplete = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
780
- this.br.removeSearchResults();
781
- this.removeResultPins();
782
- this.emptyMatches();
783
- this.setQuery('');
784
- this.teardownSearchNavigation();
785
-
786
- if (dispatchEventWhenComplete) {
787
- this.br.trigger('SearchResultsCleared');
788
- }
789
- }
790
- }, {
791
- key: "toggleSidebar",
792
- value: function toggleSidebar() {
793
- this.br.trigger('ToggleSearchMenu');
794
- }
795
- }, {
796
- key: "renderSearchNavigation",
797
- value: function renderSearchNavigation() {
798
- var selector = 'BRsearch-navigation';
799
- $('.BRnav').before("\n <div class=\"".concat(selector, "\">\n <button class=\"toggle-sidebar\">\n <h4>\n <span class=\"icon icon-search\"></span> Results\n </h4>\n </button>\n <div class=\"pagination\">\n <button class=\"prev\" title=\"Previous result\"><span class=\"icon icon-chevron hflip\"></span></button>\n <span data-id=\"resultsCount\">").concat(this.resultsPosition(), "</span>\n <button class=\"next\" title=\"Next result\"><span class=\"icon icon-chevron\"></button>\n </div>\n <button class=\"clear\" title=\"Clear search results\">\n <span class=\"icon icon-close\"></span>\n </button>\n </div>\n "));
800
- this.dom.searchNavigation = $(".".concat(selector));
801
- }
802
- }, {
803
- key: "resultsPosition",
804
- value: function resultsPosition() {
805
- var positionMessage = "".concat(this.matches.length, " result").concat(this.matches.length === 1 ? '' : 's');
806
-
807
- if (~this.currentMatchIndex) {
808
- positionMessage = "".concat(this.currentMatchIndex + 1, " / ").concat(this.matches.length);
809
- }
810
-
811
- return positionMessage;
812
- }
813
- }, {
814
- key: "bindSearchNavigationEvents",
815
- value: function bindSearchNavigationEvents() {
816
- if (!this.dom.searchNavigation) {
817
- return;
818
- }
819
-
820
- var namespace = 'searchNavigation';
821
- this.dom.searchNavigation.on("click.".concat(namespace), '.clear', this.clearSearchFieldAndResults.bind(this)).on("click.".concat(namespace), '.prev', this.showPrevResult.bind(this)).on("click.".concat(namespace), '.next', this.showNextResult.bind(this)).on("click.".concat(namespace), '.toggle-sidebar', this.toggleSidebar.bind(this)).on("click.".concat(namespace), false);
822
- }
823
- }, {
824
- key: "showPrevResult",
825
- value: function showPrevResult() {
826
- if (this.currentMatchIndex === 0) {
827
- return;
828
- }
829
-
830
- if (this.br.mode === this.br.constModeThumb) {
831
- this.br.switchMode(this.br.constMode1up);
832
- }
833
-
834
- if (!~this.currentMatchIndex) {
835
- this.currentMatchIndex = this.getClosestMatchIndex(function (start, end, comparator) {
836
- return end[0] > comparator;
837
- }) + 1;
838
- }
839
-
840
- this.br.$('.BRnavline .BRsearch').eq(--this.currentMatchIndex).click();
841
- this.updateResultsPosition();
842
- this.updateSearchNavigationButtons();
843
- }
844
- }, {
845
- key: "showNextResult",
846
- value: function showNextResult() {
847
- if (this.currentMatchIndex + 1 === this.matches.length) {
848
- return;
849
- }
850
-
851
- if (this.br.mode === this.br.constModeThumb) {
852
- this.br.switchMode(this.br.constMode1up);
853
- }
854
-
855
- if (!~this.currentMatchIndex) {
856
- this.currentMatchIndex = this.getClosestMatchIndex(function (start, end, comparator) {
857
- return start[start.length - 1] > comparator;
858
- }) - 1;
859
- }
860
-
861
- this.br.$('.BRnavline .BRsearch').eq(++this.currentMatchIndex).click();
862
- this.updateResultsPosition();
863
- this.updateSearchNavigationButtons();
864
- }
865
- /**
866
- * Obtains closest match based on the logical comparison function passed in.
867
- * When the comparison function returns true, the starting (left) half of the
868
- * matches array is used in the binary split, else the ending (right) half is
869
- * used. A recursive call is made to perform the same split and comparison
870
- * on the winning half of the matches. This is traditionally known as binary
871
- * search (https://en.wikipedia.org/wiki/Binary_search_algorithm), and in
872
- * most cases (medium to large search result arrays) should outperform
873
- * traversing the array from start to finish. In the case of small arrays,
874
- * the speed difference is negligible.
875
- *
876
- * @param {function} comparisonFn
877
- * @return {number} matchIndex
878
- */
879
-
880
- }, {
881
- key: "getClosestMatchIndex",
882
- value: function getClosestMatchIndex(comparisonFn) {
883
- var matchPages = this.matches.map(function (m) {
884
- return m.par[0].page;
885
- });
886
- var currentPage = this.br.currentIndex() + 1;
887
-
888
- var closestTo = function closestTo(pool, comparator) {
889
- if (pool.length === 1) {
890
- return pool[0];
891
- }
892
-
893
- var start = pool.slice(0, pool.length / 2);
894
- var end = pool.slice(pool.length / 2);
895
- return closestTo(comparisonFn(start, end, comparator) ? start : end, comparator);
896
- };
897
-
898
- var closestPage = closestTo(matchPages, currentPage);
899
- return this.matches.indexOf(this.matches.find(function (m) {
900
- return m.par[0].page === closestPage;
901
- }));
902
- }
903
- }, {
904
- key: "updateResultsPosition",
905
- value: function updateResultsPosition() {
906
- this.dom.searchNavigation.find('[data-id=resultsCount]').text(this.resultsPosition());
907
- }
908
- }, {
909
- key: "updateSearchNavigationButtons",
910
- value: function updateSearchNavigationButtons() {
911
- this.dom.searchNavigation.find('.prev').attr('disabled', !this.currentMatchIndex);
912
- this.dom.searchNavigation.find('.next').attr('disabled', this.currentMatchIndex + 1 === this.matches.length);
913
- }
914
- }, {
915
- key: "teardownSearchNavigation",
916
- value: function teardownSearchNavigation() {
917
- if (!this.dom.searchNavigation) {
918
- this.dom.searchNavigation = $('.BRsearch-navigation');
919
- }
920
-
921
- if (!this.dom.searchNavigation.length) {
922
- return;
923
- }
924
-
925
- this.dom.searchNavigation.off('.searchNavigation').remove();
926
- this.dom.searchNavigation = null;
927
- this.br.resize();
928
- }
929
- }, {
930
- key: "setCurrentMatchIndex",
931
- value: function setCurrentMatchIndex() {
932
- var matchingSearchResult;
933
-
934
- if (this.br.mode === this.br.constModeThumb) {
935
- this.currentMatchIndex = -1;
936
- return;
937
- }
938
-
939
- if (this.br.mode === this.br.constMode2up) {
940
- matchingSearchResult = this.find2upMatchingSearchResult();
941
- } else {
942
- matchingSearchResult = this.find1upMatchingSearchResult();
943
- }
944
-
945
- this.currentMatchIndex = this.matches.indexOf(matchingSearchResult);
946
- }
947
- }, {
948
- key: "find1upMatchingSearchResult",
949
- value: function find1upMatchingSearchResult() {
950
- var _this = this;
951
-
952
- return this.matches.find(function (m) {
953
- return _this.br.currentIndex() === m.par[0].page - 1;
954
- });
955
- }
956
- }, {
957
- key: "find2upMatchingSearchResult",
958
- value: function find2upMatchingSearchResult() {
959
- var _this2 = this;
960
-
961
- return this.matches.find(function (m) {
962
- return _this2.br._isIndexDisplayed(m.par[0].page - 1);
963
- });
964
- }
965
- }, {
966
- key: "updateSearchNavigation",
967
- value: function updateSearchNavigation() {
968
- if (!this.matches.length) {
969
- return;
970
- }
971
-
972
- this.setCurrentMatchIndex();
973
- this.updateResultsPosition();
974
- this.updateSearchNavigationButtons();
975
- }
976
- /**
977
- * @param {boolean} bool
978
- */
979
-
980
- }, {
981
- key: "togglePinsFor",
982
- value: function togglePinsFor(bool) {
983
- var pinsVisibleState = bool ? 'visible' : 'hidden';
984
- this.br.refs.$BRfooter.find('.BRsearch').css({
985
- visibility: pinsVisibleState
986
- });
987
- }
988
- }, {
989
- key: "buildToolbarSearch",
990
- value: function buildToolbarSearch() {
991
- var toolbarSearch = document.createElement('span');
992
- toolbarSearch.classList.add('BRtoolbarSection', 'BRtoolbarSectionSearch');
993
- toolbarSearch.innerHTML = "\n <form class=\"BRbooksearch desktop\">\n <input type=\"search\" name=\"query\" class=\"BRsearchInput\" value=\"\" placeholder=\"Search inside\"/>\n <button type=\"submit\" class=\"BRsearchSubmit\">\n <img src=\"".concat(this.br.imagesBaseURL, "icon_search_button.svg\" />\n </button>\n </form>\n ");
994
- return toolbarSearch;
995
- }
996
- /**
997
- * @param {array} matches
998
- */
999
-
1000
- }, {
1001
- key: "renderPins",
1002
- value: function renderPins(matches) {
1003
- var _this3 = this;
1004
-
1005
- matches.forEach(function (match) {
1006
- var queryString = match.text;
1007
-
1008
- var pageIndex = _this3.br.leafNumToIndex(match.par[0].page);
1009
-
1010
- var pageNumber = _this3.br.getPageNum(pageIndex);
1011
-
1012
- var uiStringSearch = "Search result"; // i18n
1013
-
1014
- var uiStringPage = "Page"; // i18n
1015
-
1016
- var percentThrough = _this3.br.constructor.util.cssPercentage(pageIndex, _this3.br.getNumLeafs() - 1);
1017
-
1018
- var queryStringWithB = queryString.replace(_this3.matcher, '<b>$1</b>');
1019
- var queryStringWithBTruncated = '';
1020
-
1021
- if (queryString.length > 100) {
1022
- queryStringWithBTruncated = queryString.replace(/^(.{100}[^\s]*).*/, "$1").replace(_this3.matcher, '<b>$1</b>') + '...';
1023
- } // draw marker
1024
-
1025
-
1026
- $('<div>').addClass('BRsearch').css({
1027
- left: percentThrough
1028
- }).attr('title', uiStringSearch).append("\n <div class=\"BRquery\">\n <div>".concat(queryStringWithBTruncated || queryStringWithB, "</div>\n <div>").concat(uiStringPage, " ").concat(pageNumber, "</div>\n </div>\n ")).data({
1029
- pageIndex: pageIndex
1030
- }).appendTo(_this3.br.$('.BRnavline')).on("mouseenter", function (event) {
1031
- // remove from other markers then turn on just for this
1032
- // XXX should be done when nav slider moves
1033
- var marker = event.currentTarget;
1034
- var tooltip = marker.querySelector('.BRquery');
1035
- var tooltipOffset = tooltip.getBoundingClientRect();
1036
- var targetOffset = marker.getBoundingClientRect();
1037
- var boxSizeAdjust = parseInt(getComputedStyle(tooltip).paddingLeft) * 2;
1038
-
1039
- if (tooltipOffset.x - boxSizeAdjust < 0) {
1040
- tooltip.style.setProperty('transform', "translateX(-".concat(targetOffset.left - boxSizeAdjust, "px)"));
1041
- }
1042
-
1043
- $('.BRsearch,.BRchapter').removeClass('front');
1044
- $(event.target).addClass('front');
1045
- }).on("mouseleave", function (event) {
1046
- return $(event.target).removeClass('front');
1047
- }).on("click", function (event) {
1048
- // closures are nested and deep, using an arrow function breaks references.
1049
- // Todo: update to arrow function & clean up closures
1050
- // to remove `bind` dependency
1051
- this.br._searchPluginGoToResult(+$(event.target).data('pageIndex'));
1052
- }.bind(_this3));
1053
- });
1054
- }
1055
- /**
1056
- * @param {boolean} bool
1057
- */
1058
-
1059
- }, {
1060
- key: "toggleSearchPending",
1061
- value: function toggleSearchPending(bool) {
1062
- var _this4 = this;
1063
-
1064
- if (bool) {
1065
- this.br.showProgressPopup("Search results will appear below...", function () {
1066
- return _this4.progressPopupClosed();
1067
- });
1068
- } else {
1069
- this.br.removeProgressPopup();
1070
- }
1071
- }
1072
- /**
1073
- * Primary callback when user cancels search popup
1074
- */
1075
-
1076
- }, {
1077
- key: "progressPopupClosed",
1078
- value: function progressPopupClosed() {
1079
- this.toggleSearchPending();
1080
- this.cancelSearch();
1081
- }
1082
- }, {
1083
- key: "renderErrorModal",
1084
- value: function renderErrorModal() {
1085
- var textIsProcessing = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
1086
- var errorDetails = "".concat(!textIsProcessing ? 'The text may still be processing. ' : '', "Please try again.");
1087
- this.renderModalMessage("\n Sorry, there was an error with your search.\n <br />\n ".concat(errorDetails, "\n "));
1088
- this.delayModalRemovalFor(4000);
1089
- }
1090
- }, {
1091
- key: "renderBookNotIndexedModal",
1092
- value: function renderBookNotIndexedModal() {
1093
- this.renderModalMessage("\n <p>\n This book hasn't been indexed for searching yet.\n We've just started indexing it, so search should be available soon.\n <br />\n Please try again later. Thanks!\n </p>\n ");
1094
- this.delayModalRemovalFor(5000);
1095
- }
1096
- }, {
1097
- key: "renderResultsEmptyModal",
1098
- value: function renderResultsEmptyModal() {
1099
- this.renderModalMessage('No matches were found.');
1100
- this.delayModalRemovalFor(2000);
1101
- }
1102
- /**
1103
- * @param {string} messageHTML The innerHTML string used to popupate the modal contents
1104
- */
1105
-
1106
- }, {
1107
- key: "renderModalMessage",
1108
- value: function renderModalMessage(messageHTML) {
1109
- var modal = document.createElement('div');
1110
- modal.classList.add('BRprogresspopup', 'search_modal');
1111
- modal.innerHTML = messageHTML;
1112
- document.querySelector(this.br.el).append(modal);
1113
- }
1114
- /**
1115
- * @param {number} timeoutMS
1116
- */
1117
-
1118
- }, {
1119
- key: "delayModalRemovalFor",
1120
- value: function delayModalRemovalFor(timeoutMS) {
1121
- setTimeout(this.br.removeProgressPopup.bind(this.br), timeoutMS);
1122
- }
1123
- /**
1124
- * @param {Event} e
1125
- */
1126
-
1127
- }, {
1128
- key: "submitHandler",
1129
- value: function submitHandler(e) {
1130
- e.preventDefault();
1131
- var query = e.target.querySelector('[name="query"]').value;
1132
-
1133
- if (!query.length) {
1134
- return false;
1135
- }
1136
-
1137
- this.br.search(query);
1138
- this.emptyMatches();
1139
- this.toggleSearchPending(true);
1140
- return false;
1141
- }
1142
- /**
1143
- * @param {Event} e
1144
- * @param {object} properties
1145
- * @param {object} properties.results
1146
- * @param {object} properties.options
1147
- */
1148
-
1149
- }, {
1150
- key: "handleSearchCallback",
1151
- value: function handleSearchCallback(e, _ref2) {
1152
- var _this5 = this;
1153
-
1154
- var results = _ref2.results,
1155
- options = _ref2.options;
1156
- this.matches = results.matches;
1157
- this.setCurrentMatchIndex();
1158
- this.teardownSearchNavigation();
1159
- this.renderSearchNavigation();
1160
- this.bindSearchNavigationEvents();
1161
- this.renderPins(results.matches);
1162
- this.toggleSearchPending(false);
1163
-
1164
- if (options.goToFirstResult) {
1165
- $(document).one('BookReader:pageChanged', function () {
1166
- _this5.br.resize();
1167
- });
1168
- } else {
1169
- this.br.resize();
1170
- }
1171
- }
1172
- /**
1173
- * @param {Event} e
1174
- */
1175
-
1176
- }, {
1177
- key: "handleNavToggledCallback",
1178
- value: function handleNavToggledCallback(e) {
1179
- var is_visible = this.br.navigationIsVisible();
1180
- this.togglePinsFor(is_visible);
1181
- }
1182
- }, {
1183
- key: "handleSearchStarted",
1184
- value: function handleSearchStarted() {
1185
- this.emptyMatches();
1186
- this.br.removeSearchHilites();
1187
- this.removeResultPins();
1188
- this.toggleSearchPending(true);
1189
- this.teardownSearchNavigation();
1190
- this.setQuery(this.br.searchTerm);
1191
- }
1192
- /**
1193
- * Event listener for: `BookReader:SearchCallbackError`
1194
- * @param {CustomEvent} event
1195
- */
1196
-
1197
- }, {
1198
- key: "handleSearchCallbackError",
1199
- value: function handleSearchCallbackError() {
1200
- var _event$detail, _event$detail$props, _event$detail$props$r;
1201
-
1202
- var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1203
- this.toggleSearchPending(false);
1204
- var isIndexed = event === null || event === void 0 ? void 0 : (_event$detail = event.detail) === null || _event$detail === void 0 ? void 0 : (_event$detail$props = _event$detail.props) === null || _event$detail$props === void 0 ? void 0 : (_event$detail$props$r = _event$detail$props.results) === null || _event$detail$props$r === void 0 ? void 0 : _event$detail$props$r.indexed;
1205
- this.renderErrorModal(isIndexed);
1206
- }
1207
- }, {
1208
- key: "handleSearchCallbackBookNotIndexed",
1209
- value: function handleSearchCallbackBookNotIndexed() {
1210
- this.toggleSearchPending(false);
1211
- this.renderBookNotIndexedModal();
1212
- }
1213
- }, {
1214
- key: "handleSearchCallbackEmpty",
1215
- value: function handleSearchCallbackEmpty() {
1216
- this.toggleSearchPending(false);
1217
- this.renderResultsEmptyModal();
1218
- }
1219
- }, {
1220
- key: "bindEvents",
1221
- value: function bindEvents() {
1222
- var namespace = 'BookReader:';
1223
- window.addEventListener("".concat(namespace, "SearchCallbackError"), this.handleSearchCallbackError.bind(this));
1224
- $(document).on("".concat(namespace, "SearchCallback"), this.handleSearchCallback.bind(this)).on("".concat(namespace, "navToggled"), this.handleNavToggledCallback.bind(this)).on("".concat(namespace, "SearchStarted"), this.handleSearchStarted.bind(this)).on("".concat(namespace, "SearchCallbackBookNotIndexed"), this.handleSearchCallbackBookNotIndexed.bind(this)).on("".concat(namespace, "SearchCallbackEmpty"), this.handleSearchCallbackEmpty.bind(this)).on("".concat(namespace, "pageChanged"), this.updateSearchNavigation.bind(this));
1225
- this.dom.toolbarSearch.querySelector('form').addEventListener('submit', this.submitHandler.bind(this));
1226
- }
1227
- }]);
1228
-
1229
- return SearchView;
1230
- }();
1231
-
1232
- /* harmony default export */ __webpack_exports__["default"] = (SearchView);
1233
-
1234
- /***/ }),
1235
-
1236
- /***/ "./node_modules/core-js/modules/es.object.entries.js":
1237
- /*!***********************************************************!*\
1238
- !*** ./node_modules/core-js/modules/es.object.entries.js ***!
1239
- \***********************************************************/
1240
- /***/ (function(__unused_webpack_module, __unused_webpack_exports, __webpack_require__) {
1241
-
1242
- var $ = __webpack_require__(/*! ../internals/export */ "./node_modules/core-js/internals/export.js");
1243
- var $entries = __webpack_require__(/*! ../internals/object-to-array */ "./node_modules/core-js/internals/object-to-array.js").entries;
1244
-
1245
- // `Object.entries` method
1246
- // https://tc39.es/ecma262/#sec-object.entries
1247
- $({ target: 'Object', stat: true }, {
1248
- entries: function entries(O) {
1249
- return $entries(O);
1250
- }
1251
- });
1252
-
1253
-
1254
- /***/ })
1255
-
1256
- },
1257
- /******/ function(__webpack_require__) { // webpackRuntimeModules
1258
- /******/ var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId); }
1259
- /******/ var __webpack_exports__ = (__webpack_exec__("./src/plugins/search/plugin.search.js"));
1260
- /******/ }
1261
- ]);
1
+ (self.webpackChunk_internetarchive_bookreader=self.webpackChunk_internetarchive_bookreader||[]).push([[73],{8011:function(e,t,r){"use strict";r(5666),r(4916),r(4765),r(9826),r(5306),r(2222),r(9601),r(9720),r(4747),r(1539),r(8674),r(6992),r(8783),r(3948),r(285),r(7042),r(8309),r(1038),r(2526),r(1817),r(2165);var n=r(9860),a=(r(4603),r(9714),r(1249),r(3609));function i(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}var s,o=function(){function e(t){var r=t.br,n=t.searchCancelledCallback,a=void 0===n?function(){}:n;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.br=r,this.matcher=new RegExp("{{{(.+?)}}}","g"),this.matches=[],this.cacheDOMElements(),this.bindEvents(),this.cancelSearch=a}var t,r;return t=e,(r=[{key:"cacheDOMElements",value:function(){this.dom={},this.dom.toolbarSearch=this.buildToolbarSearch()}},{key:"setQuery",value:function(e){this.br.$('[name="query"]').val(e)}},{key:"emptyMatches",value:function(){this.matches=[]}},{key:"removeResultPins",value:function(){this.br.$(".BRnavpos .BRsearch").remove()}},{key:"clearSearchFieldAndResults",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this.br.removeSearchResults(),this.removeResultPins(),this.emptyMatches(),this.setQuery(""),this.teardownSearchNavigation(),e&&this.br.trigger("SearchResultsCleared")}},{key:"toggleSidebar",value:function(){this.br.trigger("ToggleSearchMenu")}},{key:"renderSearchNavigation",value:function(){var e="BRsearch-navigation";a(".BRnav").before('\n <div class="'.concat(e,'">\n <button class="toggle-sidebar">\n <h4>\n <span class="icon icon-search"></span> Results\n </h4>\n </button>\n <div class="pagination">\n <button class="prev" title="Previous result"><span class="icon icon-chevron hflip"></span></button>\n <span data-id="resultsCount">').concat(this.resultsPosition(),'</span>\n <button class="next" title="Next result"><span class="icon icon-chevron"></button>\n </div>\n <button class="clear" title="Clear search results">\n <span class="icon icon-close"></span>\n </button>\n </div>\n ')),this.dom.searchNavigation=a(".".concat(e))}},{key:"resultsPosition",value:function(){var e="".concat(this.matches.length," result").concat(1===this.matches.length?"":"s");return~this.currentMatchIndex&&(e="".concat(this.currentMatchIndex+1," / ").concat(this.matches.length)),e}},{key:"bindSearchNavigationEvents",value:function(){if(this.dom.searchNavigation){var e="searchNavigation";this.dom.searchNavigation.on("click.".concat(e),".clear",this.clearSearchFieldAndResults.bind(this)).on("click.".concat(e),".prev",this.showPrevResult.bind(this)).on("click.".concat(e),".next",this.showNextResult.bind(this)).on("click.".concat(e),".toggle-sidebar",this.toggleSidebar.bind(this)).on("click.".concat(e),!1)}}},{key:"showPrevResult",value:function(){0!==this.currentMatchIndex&&(this.br.mode===this.br.constModeThumb&&this.br.switchMode(this.br.constMode1up),~this.currentMatchIndex||(this.currentMatchIndex=this.getClosestMatchIndex((function(e,t,r){return t[0]>r}))+1),this.br.$(".BRnavline .BRsearch").eq(--this.currentMatchIndex).click(),this.updateResultsPosition(),this.updateSearchNavigationButtons())}},{key:"showNextResult",value:function(){this.currentMatchIndex+1!==this.matches.length&&(this.br.mode===this.br.constModeThumb&&this.br.switchMode(this.br.constMode1up),~this.currentMatchIndex||(this.currentMatchIndex=this.getClosestMatchIndex((function(e,t,r){return e[e.length-1]>r}))-1),this.br.$(".BRnavline .BRsearch").eq(++this.currentMatchIndex).click(),this.updateResultsPosition(),this.updateSearchNavigationButtons())}},{key:"getClosestMatchIndex",value:function(e){var t=function t(r,n){if(1===r.length)return r[0];var a=r.slice(0,r.length/2),i=r.slice(r.length/2);return t(e(a,i,n)?a:i,n)}(this.matches.map((function(e){return e.par[0].page})),this.br.currentIndex()+1);return this.matches.indexOf(this.matches.find((function(e){return e.par[0].page===t})))}},{key:"updateResultsPosition",value:function(){this.dom.searchNavigation.find("[data-id=resultsCount]").text(this.resultsPosition())}},{key:"updateSearchNavigationButtons",value:function(){this.dom.searchNavigation.find(".prev").attr("disabled",!this.currentMatchIndex),this.dom.searchNavigation.find(".next").attr("disabled",this.currentMatchIndex+1===this.matches.length)}},{key:"teardownSearchNavigation",value:function(){this.dom.searchNavigation||(this.dom.searchNavigation=a(".BRsearch-navigation")),this.dom.searchNavigation.length&&(this.dom.searchNavigation.off(".searchNavigation").remove(),this.dom.searchNavigation=null,this.br.resize())}},{key:"setCurrentMatchIndex",value:function(){var e;this.br.mode!==this.br.constModeThumb?(e=this.br.mode===this.br.constMode2up?this.find2upMatchingSearchResult():this.find1upMatchingSearchResult(),this.currentMatchIndex=this.matches.indexOf(e)):this.currentMatchIndex=-1}},{key:"find1upMatchingSearchResult",value:function(){var e=this;return this.matches.find((function(t){return e.br.currentIndex()===t.par[0].page-1}))}},{key:"find2upMatchingSearchResult",value:function(){var e=this;return this.matches.find((function(t){return e.br._isIndexDisplayed(t.par[0].page-1)}))}},{key:"updateSearchNavigation",value:function(){this.matches.length&&(this.setCurrentMatchIndex(),this.updateResultsPosition(),this.updateSearchNavigationButtons())}},{key:"togglePinsFor",value:function(e){var t=e?"visible":"hidden";this.br.refs.$BRfooter.find(".BRsearch").css({visibility:t})}},{key:"buildToolbarSearch",value:function(){var e=document.createElement("span");return e.classList.add("BRtoolbarSection","BRtoolbarSectionSearch"),e.innerHTML='\n <form class="BRbooksearch desktop">\n <input type="search" name="query" class="BRsearchInput" value="" placeholder="Search inside"/>\n <button type="submit" class="BRsearchSubmit">\n <img src="'.concat(this.br.imagesBaseURL,'icon_search_button.svg" />\n </button>\n </form>\n '),e}},{key:"renderPins",value:function(e){var t=this;e.forEach((function(e){var r=e.text,n=t.br.leafNumToIndex(e.par[0].page),i=t.br.getPageNum(n),s=t.br.constructor.util.cssPercentage(n,t.br.getNumLeafs()-1),o=r.replace(t.matcher,"<b>$1</b>"),c="";r.length>100&&(c=r.replace(/^(.{100}[^\s]*).*/,"$1").replace(t.matcher,"<b>$1</b>")+"..."),a("<div>").addClass("BRsearch").css({left:s}).attr("title","Search result").append('\n <div class="BRquery">\n <div>'.concat(c||o,"</div>\n <div>").concat("Page"," ").concat(i,"</div>\n </div>\n ")).data({pageIndex:n}).appendTo(t.br.$(".BRnavline")).on("mouseenter",(function(e){var t=e.currentTarget,r=t.querySelector(".BRquery"),n=r.getBoundingClientRect(),i=t.getBoundingClientRect(),s=2*parseInt(getComputedStyle(r).paddingLeft);n.x-s<0&&r.style.setProperty("transform","translateX(-".concat(i.left-s,"px)")),a(".BRsearch,.BRchapter").removeClass("front"),a(e.target).addClass("front")})).on("mouseleave",(function(e){return a(e.target).removeClass("front")})).on("click",function(e){this.br._searchPluginGoToResult(+a(e.target).data("pageIndex"))}.bind(t))}))}},{key:"toggleSearchPending",value:function(e){var t=this;e?this.br.showProgressPopup("Search results will appear below...",(function(){return t.progressPopupClosed()})):this.br.removeProgressPopup()}},{key:"progressPopupClosed",value:function(){this.toggleSearchPending(),this.cancelSearch()}},{key:"renderErrorModal",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t="".concat(e?"":"The text may still be processing. ","Please try again.");this.renderModalMessage("\n Sorry, there was an error with your search.\n <br />\n ".concat(t,"\n ")),this.delayModalRemovalFor(4e3)}},{key:"renderBookNotIndexedModal",value:function(){this.renderModalMessage("\n <p>\n This book hasn't been indexed for searching yet.\n We've just started indexing it, so search should be available soon.\n <br />\n Please try again later. Thanks!\n </p>\n "),this.delayModalRemovalFor(5e3)}},{key:"renderResultsEmptyModal",value:function(){this.renderModalMessage("No matches were found."),this.delayModalRemovalFor(2e3)}},{key:"renderModalMessage",value:function(e){var t=document.createElement("div");t.classList.add("BRprogresspopup","search_modal"),t.innerHTML=e,document.querySelector(this.br.el).append(t)}},{key:"delayModalRemovalFor",value:function(e){setTimeout(this.br.removeProgressPopup.bind(this.br),e)}},{key:"submitHandler",value:function(e){e.preventDefault();var t=e.target.querySelector('[name="query"]').value;return!!t.length&&(this.br.search(t),this.emptyMatches(),this.toggleSearchPending(!0),!1)}},{key:"handleSearchCallback",value:function(e,t){var r=this,n=t.results,i=t.options;this.matches=n.matches,this.setCurrentMatchIndex(),this.teardownSearchNavigation(),this.renderSearchNavigation(),this.bindSearchNavigationEvents(),this.renderPins(n.matches),this.toggleSearchPending(!1),i.goToFirstResult?a(document).one("BookReader:pageChanged",(function(){r.br.resize()})):this.br.resize()}},{key:"handleNavToggledCallback",value:function(e){var t=this.br.navigationIsVisible();this.togglePinsFor(t)}},{key:"handleSearchStarted",value:function(){this.emptyMatches(),this.br.removeSearchHilites(),this.removeResultPins(),this.toggleSearchPending(!0),this.teardownSearchNavigation(),this.setQuery(this.br.searchTerm)}},{key:"handleSearchCallbackError",value:function(){var e,t,r,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.toggleSearchPending(!1);var a=null==n||null===(e=n.detail)||void 0===e||null===(t=e.props)||void 0===t||null===(r=t.results)||void 0===r?void 0:r.indexed;this.renderErrorModal(a)}},{key:"handleSearchCallbackBookNotIndexed",value:function(){this.toggleSearchPending(!1),this.renderBookNotIndexedModal()}},{key:"handleSearchCallbackEmpty",value:function(){this.toggleSearchPending(!1),this.renderResultsEmptyModal()}},{key:"bindEvents",value:function(){var e="BookReader:";window.addEventListener("".concat(e,"SearchCallbackError"),this.handleSearchCallbackError.bind(this)),a(document).on("".concat(e,"SearchCallback"),this.handleSearchCallback.bind(this)).on("".concat(e,"navToggled"),this.handleNavToggledCallback.bind(this)).on("".concat(e,"SearchStarted"),this.handleSearchStarted.bind(this)).on("".concat(e,"SearchCallbackBookNotIndexed"),this.handleSearchCallbackBookNotIndexed.bind(this)).on("".concat(e,"SearchCallbackEmpty"),this.handleSearchCallbackEmpty.bind(this)).on("".concat(e,"pageChanged"),this.updateSearchNavigation.bind(this)),this.dom.toolbarSearch.querySelector("form").addEventListener("submit",this.submitHandler.bind(this))}}])&&i(t.prototype,r),e}(),c=r(3609),h=r(3609);function l(e,t,r,n,a,i,s){try{var o=e[i](s),c=o.value}catch(e){return void r(e)}o.done?t(c):Promise.resolve(c).then(n,a)}function u(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=d(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,a=function(){};return{s:a,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,s=!0,o=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return s=e.done,e},e:function(e){o=!0,i=e},f:function(){try{s||null==r.return||r.return()}finally{if(o)throw i}}}}function d(e,t){if(e){if("string"==typeof e)return g(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?g(e,t):void 0}}function g(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}c.extend(BookReader.defaultOptions,{server:"ia600609.us.archive.org",bookId:"",subPrefix:"",bookPath:"",enableSearch:!0,searchInsideUrl:"/fulltext/inside.php",initialSearchTerm:null}),BookReader.prototype.setup=(s=BookReader.prototype.setup,function(e){s.call(this,e),this.searchTerm="",this.searchResults=null,this.searchInsideUrl=e.searchInsideUrl,this.enableSearch=e.enableSearch,this.bookId=e.bookId,this.server=e.server,this.subPrefix=e.subPrefix,this.bookPath=e.bookPath,this.searchXHR=null,this._cancelSearch.bind(this),this.cancelSearchRequest.bind(this),this._searchBoxesByIndex={},this.searchView=void 0}),BookReader.prototype.init=function(e){return function(){var t=this;e.call(this),this.searchView=new o({br:this,searchCancelledCallback:function(){t._cancelSearch(),t.trigger("SearchCanceled",{term:t.searchTerm,instance:t})}}),this.options.enableSearch&&this.options.initialSearchTerm&&this.search(this.options.initialSearchTerm,{goToFirstResult:this.options.goToFirstResult,suppressFragmentChange:!1})}}(BookReader.prototype.init),BookReader.prototype.buildToolbarElement=function(e){return function(){var t=e.call(this);if(this.enableSearch)return this.searchView.dom.toolbarSearch&&t.find(".BRtoolbarSectionInfo").after(this.searchView.dom.toolbarSearch),t}}(BookReader.prototype.buildToolbarElement),BookReader.prototype._createPageContainer=function(e){return function(t){var r=e.call(this,t);if(this.enableSearch&&r.page&&t in this._searchBoxesByIndex){var a=r.page.index;(0,n.Tm)("searchHiliteLayer",this._searchBoxesByIndex[a],r.page,r.$container[0])}return r}}(BookReader.prototype._createPageContainer),BookReader.prototype.search=function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n={goToFirstResult:!1,disablePopup:!1,suppressFragmentChange:!1,error:null,success:null},a=c.extend({},n,r);this.suppressFragmentChange=a.suppressFragmentChange,this.searchTerm=t.replace(/\//g," "),a.suppressFragmentChange||this.trigger(BookReader.eventNames.fragmentChange);var i=this.server.replace(/:.+/,""),s="https://".concat(i).concat(this.searchInsideUrl,"?"),o=this.bookPath,l="/".concat(this.subPrefix);this.bookPath.length-this.bookPath.lastIndexOf(l)==l.length&&(o=this.bookPath.substr(0,this.bookPath.length-l.length));var u={item_id:this.bookId,doc:this.subPrefix,path:o,q:t},d=h.param(u).replace(/%2F/g,"/"),g="".concat(s).concat(d),v=function(){e.searchXHR=null,window.BRSearchInProgress=function(){}},f=function(t){if(e.searchXHR){var r=t.error||!t.matches.length,n="function"==typeof a.error,i="function"==typeof a.success;r?n?a.error.call(e,t,a):e.BRSearchCallbackError(t,a):i?a.success.call(e,t,a):e.BRSearchCallback(t,a),v()}},p=function(t){e.searchXHR=t,window.BRSearchInProgress=f};return this.trigger("SearchStarted",{term:this.searchTerm,instance:this}),h.ajax({url:g,dataType:"jsonp",cache:!0,beforeSend:p,jsonpCallback:"BRSearchInProgress"}).then(f)},BookReader.prototype._cancelSearch=function(){var e;null===(e=this.searchXHR)||void 0===e||e.abort(),this.searchView.clearSearchFieldAndResults(!1),this.searchTerm="",this.searchXHR=null,this.searchResults=[],window.BRSearchInProgress=function(){}},BookReader.prototype.cancelSearchRequest=function(){null!==this.searchXHR&&(this._cancelSearch(),this.searchView.toggleSearchPending(),this.trigger("SearchCanceled",{term:this.searchTerm,instance:this}))},BookReader.prototype.BRSearchCallback=function(e,t){if(this.searchResults=e||[],this.updateSearchHilites(),this.removeProgressPopup(),t.goToFirstResult){var r=this._models.book.leafNumToIndex(e.matches[0].par[0].page);this._searchPluginGoToResult(r)}this.trigger("SearchCallback",{results:e,options:t,instance:this})},BookReader.prototype.BRSearchCallbackError=function(e){this._BRSearchCallbackError(e)},BookReader.prototype._BRSearchCallbackError=function(e){this.searchResults=e;var t={term:this.searchTerm,instance:this};if(e.error){var r=Object.assign({},t,{results:e});this.trigger("SearchCallbackError",r)}else if(0==e.matches.length){if(!1===e.indexed)return void this.trigger("SearchCallbackBookNotIndexed",t);this.trigger("SearchCallbackEmpty",t)}},BookReader.prototype.updateSearchHilites=function(){var e,t=this,r=(null===(e=this.searchResults)||void 0===e?void 0:e.matches)||[],a={};this.removeSearchHilites();var i,s=u(r);try{for(s.s();!(i=s.n()).done;){var o,c=u(i.value.par[0].boxes);try{for(c.s();!(o=c.n()).done;){var h=o.value,l=this.leafNumToIndex(h.page);(a[l]||(a[l]=[])).push(h)}}catch(e){c.e(e)}finally{c.f()}}}catch(e){s.e(e)}finally{s.f()}for(var g=function(){var e,r,a=(e=f[v],r=2,function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,a,i=[],s=!0,o=!1;try{for(r=r.call(e);!(s=(n=r.next()).done)&&(i.push(n.value),!t||i.length!==t);s=!0);}catch(e){o=!0,a=e}finally{try{s||null==r.return||r.return()}finally{if(o)throw a}}return i}}(e,r)||d(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),i=a[0],s=a[1],o=parseFloat(i),c=t._models.book.getPage(o);t.getActivePageContainerElementsForIndex(o).forEach((function(e){return(0,n.Tm)("searchHiliteLayer",s,c,e)}))},v=0,f=Object.entries(a);v<f.length;v++)g();this._searchBoxesByIndex=a},BookReader.prototype.removeSearchHilites=function(){h(this.getActivePageContainerElements()).find(".searchHiliteLayer").remove()},BookReader.prototype._searchPluginGoToResult=function(){var e,t=(e=regeneratorRuntime.mark((function e(t){var r,n,a,i,s,o,c;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=this._models.book,n=r.getPage(t),a=!1,n.isViewable){e.next=10;break}return e.next=6,fetch("/services/bookreader/request_page?"+new URLSearchParams({id:this.options.bookId,subprefix:this.options.subPrefix,leafNum:n.leafNum})).then((function(e){return e.json()}));case 6:i=e.sent,s=u(i.value);try{for(s.s();!(o=s.n()).done;)c=o.value,r.getPage(r.leafNumToIndex(c)).makeViewable()}catch(e){s.e(e)}finally{s.f()}i.value.length||(r.getPage(t).makeViewable(),a=!0);case 10:this.suppressFragmentChange=!1,this.jumpToIndex(t),a&&r.getPage(t).makeViewable(!1);case 13:case"end":return e.stop()}}),e,this)})),function(){var t=this,r=arguments;return new Promise((function(n,a){var i=e.apply(t,r);function s(e){l(i,n,a,s,o,"next",e)}function o(e){l(i,n,a,s,o,"throw",e)}s(void 0)}))});return function(e){return t.apply(this,arguments)}}(),BookReader.prototype.removeSearchResults=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.removeSearchHilites(),this.searchTerm=null,this.searchResults=null,e||this.trigger(BookReader.eventNames.fragmentChange)},BookReader.prototype.searchHighlightVisible=function(){var e=this,t=this.searchResults,r=[];if(null==t)return!1;if(this.constMode2up==this.mode)r=[this.twoPage.currentIndexL,this.twoPage.currentIndexR];else{if(this.constMode1up!=this.mode)return!1;r=[this.currentIndex()]}return t.matches.some((function(t){return t.par[0].boxes.some((function(t){var n=e.leafNumToIndex(t.page);if(c.inArray(n,r)>=0)return!0}))})),!1}},9720:function(e,t,r){var n=r(2109),a=r(4699).entries;n({target:"Object",stat:!0},{entries:function(e){return a(e)}})}},function(e){e(e.s=8011)}]);
1262
2
  //# sourceMappingURL=plugin.search.js.map