@internetarchive/bookreader 5.0.0-24-sortingstate → 5.0.0-25-02

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