@internetarchive/bookreader 5.0.0-54 → 5.0.0-55
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.
- package/BookReader/BookReader.css +1 -1
- package/BookReader/BookReader.js +1 -1
- package/BookReader/BookReader.js.map +1 -1
- package/BookReader/ia-bookreader-bundle.js +188 -92
- package/BookReader/ia-bookreader-bundle.js.map +1 -1
- package/BookReader/plugins/plugin.resume.js +1 -1
- package/BookReader/plugins/plugin.resume.js.map +1 -1
- package/CHANGELOG.md +5 -0
- package/package.json +7 -7
- package/src/BookReader/options.js +6 -0
- package/src/BookReader.js +32 -37
- package/src/css/_icons.scss +1 -1
- package/src/util/docCookies.js +21 -2
- package/tests/jest/BookReader.test.js +7 -30
- package/tests/jest/util/docCookies.test.js +9 -0
@@ -1,2 +1,2 @@
|
|
1
|
-
"use strict";(self.webpackChunk_internetarchive_bookreader=self.webpackChunk_internetarchive_bookreader||[]).push([[951],{5842:function(e,o,n){var t={};function r(e){return e
|
1
|
+
"use strict";(self.webpackChunk_internetarchive_bookreader=self.webpackChunk_internetarchive_bookreader||[]).push([[951],{5842:function(e,o,n){var t={};function r(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:document;try{return e.cookie,!1}catch(e){return!0}}n.r(t),n.d(t,{areCookiesBlocked:function(){return r},getItem:function(){return u},removeItem:function(){return c},setItem:function(){return i}}),n(1058),n(4916),n(4723),n(5306),n(4603),n(9714);var a=r();function u(e){return a||!e?null:decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*"+encodeURIComponent(e).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=\\s*([^;]*).*$)|^.*$"),"$1"))||null}function i(e,o,n,t,r,u){return!a&&(document.cookie=encodeURIComponent(e)+"="+encodeURIComponent(o)+(n?"; expires=".concat(n.toUTCString()):"")+(r?"; domain=".concat(r):"")+(t?"; path=".concat(t):"")+(u?"; secure":""),!0)}function c(e,o,n){return!a&&!!hasItem(e)&&(document.cookie=encodeURIComponent(e)+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT"+(n?"; domain=".concat(n):"")+(o?"; path=".concat(o):""),!0)}var s,d=n(3609);BookReader.docCookies=t,d.extend(BookReader.defaultOptions,{enablePageResume:!0,resumeCookiePath:null}),BookReader.prototype.init=(s=BookReader.prototype.init,function(){var e=this;s.call(this),this.options.enablePageResume&&this.bind(BookReader.eventNames.fragmentChange,(function(){var o=e.paramsFromCurrent();e.updateResumeValue(o.index)}))}),BookReader.prototype.getResumeValue=function(){var e=BookReader.docCookies.getItem("br-resume");return null!==e?parseInt(e):null},BookReader.prototype.getCookiePath=function(e){return e.match(".+?(?=/page/|/mode/|$)")[0]},BookReader.prototype.updateResumeValue=function(e,o){var n=new Date(+new Date+12096e5),t=this.options.resumeCookiePath||this.getCookiePath(window.location.pathname);BookReader.docCookies.setItem(o||"br-resume",e,n,t,null,!1)}},4723:function(e,o,n){var t=n(6916),r=n(7007),a=n(9670),u=n(7466),i=n(1340),c=n(4488),s=n(8173),d=n(1530),l=n(7651);r("match",(function(e,o,n){return[function(o){var n=c(this),r=null==o?void 0:s(o,e);return r?t(r,o,n):new RegExp(o)[e](i(n))},function(e){var t=a(this),r=i(e),c=n(o,t,r);if(c.done)return c.value;if(!t.global)return l(t,r);var s=t.unicode;t.lastIndex=0;for(var m,p=[],k=0;null!==(m=l(t,r));){var h=i(m[0]);p[k]=h,""===h&&(t.lastIndex=d(r,u(t.lastIndex),s)),k++}return 0===k?null:p}]}))}},function(e){e(e.s=5842)}]);
|
2
2
|
//# sourceMappingURL=plugin.resume.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"plugins/plugin.resume.js","mappings":"
|
1
|
+
{"version":3,"file":"plugins/plugin.resume.js","mappings":"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","sources":["webpack://@internetarchive/bookreader/./src/util/docCookies.js","webpack://@internetarchive/bookreader/./src/plugins/plugin.resume.js","webpack://@internetarchive/bookreader/./node_modules/core-js/modules/es.string.match.js"],"sourcesContent":["/**\n * Helper module use to get, set and remove item from cookie\n *\n * See more:\n * https://developer.mozilla.org/en-US/docs/Web/API/document.cookie\n * https://developer.mozilla.org/User:fusionchess\n * https://github.com/madmurphy/cookies.js\n * This framework is released under the GNU Public License, version 3 or later.\n * http://www.gnu.org/licenses/gpl-3.0-standalone.html\n */\n\n/**\n * Check to see if the browser has cookies enabled.\n * Accessing document.cookies errors if eg iframe with sandbox enabled.\n * @returns {boolean}\n */\nexport function areCookiesBlocked(doc = document) {\n try {\n doc.cookie;\n return false;\n } catch (e) {\n return true;\n }\n}\n\nconst COOKIES_BLOCKED = areCookiesBlocked();\n\n/**\n * Get specific key's value stored in cookie\n *\n * @param {string} sKey\n *\n * @returns {string|null}\n */\nexport function getItem(sKey) {\n if (COOKIES_BLOCKED || !sKey) return null;\n\n return decodeURIComponent(\n // eslint-disable-next-line no-useless-escape\n document.cookie.replace(new RegExp('(?:(?:^|.*;)\\\\s*' + encodeURIComponent(sKey).replace(/[\\-\\.\\+\\*]/g, '\\\\$&') + '\\\\s*\\\\=\\\\s*([^;]*).*$)|^.*$'), '$1')) || null;\n}\n\n/**\n * Set specific key's value in cookie\n *\n * @param {string} sKey cookie name\n * @param {string} sValue cookie value\n * @param {string} [vEnd] expire|max-age\n * @param {string} [sPath] path of current item\n * @param {string} [sDomain] domain name\n * @param {boolean} [bSecure]\n *\n * @returns {boolean}\n */\nexport function setItem(sKey, sValue, vEnd, sPath, sDomain, bSecure) {\n if (COOKIES_BLOCKED) return false;\n\n document.cookie = encodeURIComponent(sKey) + '=' + encodeURIComponent(sValue)\n + (vEnd ? `; expires=${vEnd.toUTCString()}` : '')\n + (sDomain ? `; domain=${sDomain}` : '')\n + (sPath ? `; path=${sPath}` : '')\n + (bSecure ? `; secure` : '');\n\n return true;\n}\n\n/**\n * BROKEN Remove specific key's value from cookie\n * @fixme hasItem isn't even implemented! This will always error.\n * @param {string} sKey cookie name\n * @param {string} [sPath] path of current item\n * @param {string} [sDomain]\n *\n * @returns {boolean}\n */\nexport function removeItem(sKey, sPath, sDomain) {\n if (COOKIES_BLOCKED) return false;\n // eslint-disable-next-line\n if (!hasItem(sKey)) return false;\n\n document.cookie = encodeURIComponent(sKey) + `=; expires=Thu, 01 Jan 1970 00:00:00 GMT`\n + (sDomain ? `; domain=${sDomain}` : '')\n + (sPath ? `; path=${sPath}` : '');\n\n return true;\n}\n","import * as docCookies from '../util/docCookies.js';\n\n/* global BookReader */\n\n/** @deprecated Exposed for backward compatibility */\nBookReader.docCookies = docCookies;\n\n/**\n * Plugin to remember the current page number in a cookie\n */\njQuery.extend(BookReader.defaultOptions, {\n enablePageResume: true,\n /** @type {string|null} eg '/', '/details/id' */\n resumeCookiePath: null,\n});\n\n/** @override */\nBookReader.prototype.init = (function(super_) {\n return function() {\n super_.call(this);\n if (this.options.enablePageResume) {\n this.bind(BookReader.eventNames.fragmentChange, () => {\n const params = this.paramsFromCurrent();\n this.updateResumeValue(params.index);\n });\n }\n };\n})(BookReader.prototype.init);\n\n/**\n * Gets page resume value, for remembering reader's page\n * Can be overridden for different implementation\n *\n * @return {number|null}\n */\nBookReader.prototype.getResumeValue = function() {\n const val = BookReader.docCookies.getItem('br-resume');\n if (val !== null) return parseInt(val);\n else return null;\n};\n\n/**\n * Return cookie path using pathname up to /page/... or /mode/...\n * using window.location.pathname for urlPathPart:\n * - matches encoding\n * - ignores querystring part\n * - ignores fragment part (after #)\n * @param {string} urlPathPart - window.location.pathname\n */\nBookReader.prototype.getCookiePath = function(urlPathPart) {\n return urlPathPart.match('.+?(?=/page/|/mode/|$)')[0];\n};\n\n/**\n * Sets page resume value, for remembering reader's page\n * Can be overridden for different implementation\n *\n * @param {Number} index leaf index\n * @param {string} [cookieName]\n */\nBookReader.prototype.updateResumeValue = function(index, cookieName) {\n const ttl = new Date(+new Date + 12096e5); // 2 weeks\n // For multiple files in item, leave resumeCookiePath blank\n // It's likely we can remove resumeCookiePath using getCookiePath()\n const path = this.options.resumeCookiePath\n || this.getCookiePath(window.location.pathname);\n BookReader.docCookies.setItem(cookieName || 'br-resume', index, ttl, path, null, false);\n};\n","'use strict';\nvar call = require('../internals/function-call');\nvar fixRegExpWellKnownSymbolLogic = require('../internals/fix-regexp-well-known-symbol-logic');\nvar anObject = require('../internals/an-object');\nvar toLength = require('../internals/to-length');\nvar toString = require('../internals/to-string');\nvar requireObjectCoercible = require('../internals/require-object-coercible');\nvar getMethod = require('../internals/get-method');\nvar advanceStringIndex = require('../internals/advance-string-index');\nvar regExpExec = require('../internals/regexp-exec-abstract');\n\n// @@match logic\nfixRegExpWellKnownSymbolLogic('match', function (MATCH, nativeMatch, maybeCallNative) {\n return [\n // `String.prototype.match` method\n // https://tc39.es/ecma262/#sec-string.prototype.match\n function match(regexp) {\n var O = requireObjectCoercible(this);\n var matcher = regexp == undefined ? undefined : getMethod(regexp, MATCH);\n return matcher ? call(matcher, regexp, O) : new RegExp(regexp)[MATCH](toString(O));\n },\n // `RegExp.prototype[@@match]` method\n // https://tc39.es/ecma262/#sec-regexp.prototype-@@match\n function (string) {\n var rx = anObject(this);\n var S = toString(string);\n var res = maybeCallNative(nativeMatch, rx, S);\n\n if (res.done) return res.value;\n\n if (!rx.global) return regExpExec(rx, S);\n\n var fullUnicode = rx.unicode;\n rx.lastIndex = 0;\n var A = [];\n var n = 0;\n var result;\n while ((result = regExpExec(rx, S)) !== null) {\n var matchStr = toString(result[0]);\n A[n] = matchStr;\n if (matchStr === '') rx.lastIndex = advanceStringIndex(S, toLength(rx.lastIndex), fullUnicode);\n n++;\n }\n return n === 0 ? null : A;\n }\n ];\n});\n"],"names":["areCookiesBlocked","doc","document","cookie","e","COOKIES_BLOCKED","getItem","sKey","decodeURIComponent","replace","RegExp","encodeURIComponent","setItem","sValue","vEnd","sPath","sDomain","bSecure","toUTCString","removeItem","hasItem","super_","BookReader","docCookies","jQuery","extend","defaultOptions","enablePageResume","resumeCookiePath","prototype","init","call","this","options","bind","eventNames","fragmentChange","params","paramsFromCurrent","updateResumeValue","index","getResumeValue","val","parseInt","getCookiePath","urlPathPart","match","cookieName","ttl","Date","path","window","location","pathname","fixRegExpWellKnownSymbolLogic","anObject","toLength","toString","requireObjectCoercible","getMethod","advanceStringIndex","regExpExec","MATCH","nativeMatch","maybeCallNative","regexp","O","matcher","undefined","string","rx","S","res","done","value","global","fullUnicode","unicode","lastIndex","result","A","n","matchStr"],"sourceRoot":""}
|
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
# 5.0.0-55
|
2
|
+
- Fix BookReader going to 1up in fullscreen on desktop @mheiman
|
3
|
+
- Support BookReader running in sandboxed (cookie-less) iframe @cdrini
|
4
|
+
- Update IA dependencies to avoid duplicate dependencies @cdrini
|
5
|
+
|
1
6
|
# 5.0.0-54
|
2
7
|
- Dev: Dispatch custom event from bookreader for ia-book-actions @nsharma123
|
3
8
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@internetarchive/bookreader",
|
3
|
-
"version": "5.0.0-
|
3
|
+
"version": "5.0.0-55",
|
4
4
|
"description": "The Internet Archive BookReader.",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -25,7 +25,7 @@
|
|
25
25
|
"homepage": "https://github.com/internetarchive/bookreader#readme",
|
26
26
|
"private": false,
|
27
27
|
"dependencies": {
|
28
|
-
"@internetarchive/ia-activity-indicator": "^0.0.
|
28
|
+
"@internetarchive/ia-activity-indicator": "^0.0.4",
|
29
29
|
"@internetarchive/ia-item-navigator": "^1.0.3",
|
30
30
|
"@internetarchive/ia-sharing-options": "^1.0.2",
|
31
31
|
"@internetarchive/icon-bookmark": "^1.3.4",
|
@@ -36,7 +36,7 @@
|
|
36
36
|
"@internetarchive/icon-search": "^1.3.4",
|
37
37
|
"@internetarchive/icon-share": "^1.3.4",
|
38
38
|
"@internetarchive/icon-visual-adjustment": "^1.3.4",
|
39
|
-
"@internetarchive/modal-manager": "^0.2.
|
39
|
+
"@internetarchive/modal-manager": "^0.2.8",
|
40
40
|
"@internetarchive/shared-resize-observer": "^0.2.0",
|
41
41
|
"lit": "^2.5.0"
|
42
42
|
},
|
@@ -47,7 +47,7 @@
|
|
47
47
|
"@babel/plugin-proposal-decorators": "7.17.9",
|
48
48
|
"@babel/preset-env": "7.16.11",
|
49
49
|
"@open-wc/testing-helpers": "^2.1.4",
|
50
|
-
"@types/jest": "^29.
|
50
|
+
"@types/jest": "^29.4.0",
|
51
51
|
"@webcomponents/webcomponentsjs": "^2.6.0",
|
52
52
|
"babel-loader": "8.2.5",
|
53
53
|
"codecov": "^3.8.3",
|
@@ -60,8 +60,8 @@
|
|
60
60
|
"hammerjs": "^2.0.8",
|
61
61
|
"http-server": "14.1.1",
|
62
62
|
"iso-language-codes": "1.1.0",
|
63
|
-
"jest": "^29.
|
64
|
-
"jest-environment-jsdom": "^29.
|
63
|
+
"jest": "^29.4.3",
|
64
|
+
"jest-environment-jsdom": "^29.4.3",
|
65
65
|
"jquery": "3.6.1",
|
66
66
|
"jquery-colorbox": "1.6.4",
|
67
67
|
"jquery-ui": "1.12.1",
|
@@ -72,7 +72,7 @@
|
|
72
72
|
"node-fetch": "3.2.10",
|
73
73
|
"regenerator-runtime": "0.13.9",
|
74
74
|
"sass": "1.52.1",
|
75
|
-
"sinon": "^
|
75
|
+
"sinon": "^15.0.1",
|
76
76
|
"soundmanager2": "2.97.20170602",
|
77
77
|
"svgo": "2.8.0",
|
78
78
|
"testcafe": "^2.0.1",
|
@@ -328,3 +328,9 @@ export const DEFAULT_OPTIONS = {
|
|
328
328
|
|
329
329
|
/** @typedef {typeof DEFAULT_OPTIONS} BookReaderOptions */
|
330
330
|
|
331
|
+
/**
|
332
|
+
* Thrown when an error occurs while parsing options.
|
333
|
+
* Potentially recoverable and non-halting.
|
334
|
+
*/
|
335
|
+
export class OptionsParseError extends Error {
|
336
|
+
}
|
package/src/BookReader.js
CHANGED
@@ -31,7 +31,7 @@ import PACKAGE_JSON from '../package.json';
|
|
31
31
|
import * as utils from './BookReader/utils.js';
|
32
32
|
import { exposeOverrideable } from './BookReader/utils/classes.js';
|
33
33
|
import { Navbar } from './BookReader/Navbar/Navbar.js';
|
34
|
-
import { DEFAULT_OPTIONS } from './BookReader/options.js';
|
34
|
+
import { DEFAULT_OPTIONS, OptionsParseError } from './BookReader/options.js';
|
35
35
|
/** @typedef {import('./BookReader/options.js').BookReaderOptions} BookReaderOptions */
|
36
36
|
/** @typedef {import('./BookReader/options.js').ReductionFactor} ReductionFactor */
|
37
37
|
/** @typedef {import('./BookReader/BookModel.js').PageIndex} PageIndex */
|
@@ -452,61 +452,56 @@ BookReader.prototype.readQueryString = function() {
|
|
452
452
|
* Determines the initial mode for starting if a mode is not already
|
453
453
|
* present in the params argument
|
454
454
|
* @param {object} params
|
455
|
-
* @return {
|
455
|
+
* @return {1 | 2 | 3} the initial mode
|
456
456
|
*/
|
457
457
|
BookReader.prototype.getInitialMode = function(params) {
|
458
|
-
let nextMode;
|
459
|
-
|
460
458
|
// if mobile breakpoint, we always show this.constMode1up mode
|
461
|
-
const
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
// In full mode OR device width, we set the default based on width
|
470
|
-
nextMode = this.constMode1up;
|
459
|
+
const windowWidth = $(window).width();
|
460
|
+
const isMobile = windowWidth && windowWidth <= this.onePageMinBreakpoint;
|
461
|
+
|
462
|
+
let initialMode;
|
463
|
+
if (params.mode) {
|
464
|
+
initialMode = params.mode;
|
465
|
+
} else if (isMobile) {
|
466
|
+
initialMode = this.constMode1up;
|
471
467
|
} else {
|
472
|
-
|
468
|
+
initialMode = this.constMode2up;
|
473
469
|
}
|
474
470
|
|
475
|
-
if (!this.canSwitchToMode(
|
476
|
-
|
471
|
+
if (!this.canSwitchToMode(initialMode)) {
|
472
|
+
initialMode = this.constMode1up;
|
477
473
|
}
|
478
474
|
|
479
475
|
// override defaults mode via `options.defaults` metadata
|
480
476
|
if (this.options.defaults) {
|
481
|
-
|
477
|
+
try {
|
478
|
+
initialMode = _modeStringToNumber(this.options.defaults);
|
479
|
+
} catch (e) {
|
480
|
+
// Can ignore this error
|
481
|
+
}
|
482
482
|
}
|
483
483
|
|
484
|
-
return
|
484
|
+
return initialMode;
|
485
485
|
};
|
486
486
|
|
487
487
|
/**
|
488
|
-
*
|
489
|
-
* @
|
488
|
+
* Converts a mode string to a the mode numeric constant
|
489
|
+
* @param {'mode/1up'|'mode/2up'|'mode/thumb'} modeString
|
490
|
+
* @return {1 | 2 | 3}
|
490
491
|
*/
|
491
|
-
|
492
|
-
|
492
|
+
export function _modeStringToNumber(modeString) {
|
493
|
+
const MAPPING = {
|
494
|
+
'mode/1up': 1,
|
495
|
+
'mode/2up': 2,
|
496
|
+
'mode/thumb': 3,
|
497
|
+
};
|
493
498
|
|
494
|
-
|
495
|
-
|
496
|
-
nextMode = this.constMode1up;
|
497
|
-
break;
|
498
|
-
case 'mode/2up':
|
499
|
-
nextMode = this.constMode2up;
|
500
|
-
break;
|
501
|
-
case 'mode/thumb':
|
502
|
-
nextMode = this.constModeThumb;
|
503
|
-
break;
|
504
|
-
default:
|
505
|
-
break;
|
499
|
+
if (!(modeString in MAPPING)) {
|
500
|
+
throw new OptionsParseError(`Invalid mode string: ${modeString}`);
|
506
501
|
}
|
507
502
|
|
508
|
-
return
|
509
|
-
}
|
503
|
+
return MAPPING[modeString];
|
504
|
+
}
|
510
505
|
|
511
506
|
/**
|
512
507
|
* This is called by the client to initialize BookReader.
|
package/src/css/_icons.scss
CHANGED
package/src/util/docCookies.js
CHANGED
@@ -9,6 +9,22 @@
|
|
9
9
|
* http://www.gnu.org/licenses/gpl-3.0-standalone.html
|
10
10
|
*/
|
11
11
|
|
12
|
+
/**
|
13
|
+
* Check to see if the browser has cookies enabled.
|
14
|
+
* Accessing document.cookies errors if eg iframe with sandbox enabled.
|
15
|
+
* @returns {boolean}
|
16
|
+
*/
|
17
|
+
export function areCookiesBlocked(doc = document) {
|
18
|
+
try {
|
19
|
+
doc.cookie;
|
20
|
+
return false;
|
21
|
+
} catch (e) {
|
22
|
+
return true;
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
const COOKIES_BLOCKED = areCookiesBlocked();
|
27
|
+
|
12
28
|
/**
|
13
29
|
* Get specific key's value stored in cookie
|
14
30
|
*
|
@@ -17,7 +33,7 @@
|
|
17
33
|
* @returns {string|null}
|
18
34
|
*/
|
19
35
|
export function getItem(sKey) {
|
20
|
-
if (!sKey) return null;
|
36
|
+
if (COOKIES_BLOCKED || !sKey) return null;
|
21
37
|
|
22
38
|
return decodeURIComponent(
|
23
39
|
// eslint-disable-next-line no-useless-escape
|
@@ -34,9 +50,11 @@ export function getItem(sKey) {
|
|
34
50
|
* @param {string} [sDomain] domain name
|
35
51
|
* @param {boolean} [bSecure]
|
36
52
|
*
|
37
|
-
* @returns {
|
53
|
+
* @returns {boolean}
|
38
54
|
*/
|
39
55
|
export function setItem(sKey, sValue, vEnd, sPath, sDomain, bSecure) {
|
56
|
+
if (COOKIES_BLOCKED) return false;
|
57
|
+
|
40
58
|
document.cookie = encodeURIComponent(sKey) + '=' + encodeURIComponent(sValue)
|
41
59
|
+ (vEnd ? `; expires=${vEnd.toUTCString()}` : '')
|
42
60
|
+ (sDomain ? `; domain=${sDomain}` : '')
|
@@ -56,6 +74,7 @@ export function setItem(sKey, sValue, vEnd, sPath, sDomain, bSecure) {
|
|
56
74
|
* @returns {boolean}
|
57
75
|
*/
|
58
76
|
export function removeItem(sKey, sPath, sDomain) {
|
77
|
+
if (COOKIES_BLOCKED) return false;
|
59
78
|
// eslint-disable-next-line
|
60
79
|
if (!hasItem(sKey)) return false;
|
61
80
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
import BookReader from '@/src/BookReader.js';
|
2
|
+
import BookReader, {_modeStringToNumber} from '@/src/BookReader.js';
|
3
3
|
import '@/src/plugins/plugin.resume.js';
|
4
4
|
import '@/src/plugins/url/plugin.url.js';
|
5
5
|
|
@@ -279,35 +279,12 @@ describe('nextReduce', () => {
|
|
279
279
|
expect(nextReduce(2, 'auto', SAMPLE_FACTORS).reduce).toBe(0.5);
|
280
280
|
});
|
281
281
|
});
|
282
|
+
});
|
282
283
|
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
expect(nextModeNumber).toBe(1);
|
289
|
-
});
|
290
|
-
|
291
|
-
test('replace current mode with options.default is set mode/2up', () => {
|
292
|
-
br.options.defaults = 'mode/2up';
|
293
|
-
|
294
|
-
const nextModeNumber = br.overridesBookMode();
|
295
|
-
expect(nextModeNumber).toBe(2);
|
296
|
-
});
|
297
|
-
|
298
|
-
test('replace current mode with options.default is set mode/thumb', () => {
|
299
|
-
br.options.defaults = 'mode/thumb';
|
300
|
-
|
301
|
-
const nextModeNumber = br.overridesBookMode();
|
302
|
-
expect(nextModeNumber).toBe(3);
|
303
|
-
});
|
304
|
-
|
305
|
-
test('test if options.default is NOT set', () => {
|
306
|
-
br.options.defaults = null;
|
307
|
-
|
308
|
-
// use mode/2up as default when no options.default metadata found
|
309
|
-
const nextModeNumber = br.overridesBookMode();
|
310
|
-
expect(nextModeNumber).toBe(2);
|
311
|
-
});
|
284
|
+
describe('_modeStringToNumber', () => {
|
285
|
+
test('Returns correct number', () => {
|
286
|
+
expect(_modeStringToNumber('mode/1up')).toBe(1);
|
287
|
+
expect(_modeStringToNumber('mode/2up')).toBe(2);
|
288
|
+
expect(_modeStringToNumber('mode/thumb')).toBe(3);
|
312
289
|
});
|
313
290
|
});
|
@@ -13,3 +13,12 @@ describe('Helper function: set and get cookie item', () => {
|
|
13
13
|
expect(docCookies.getItem('test-cookie')).toEqual('jack-sparow');
|
14
14
|
});
|
15
15
|
});
|
16
|
+
|
17
|
+
describe('isCookiesBlocked', () => {
|
18
|
+
test('return true if cookies are blocked', () => {
|
19
|
+
expect(docCookies.areCookiesBlocked({ get cookie() { throw new Error(); }})).toBeTruthy();
|
20
|
+
});
|
21
|
+
test('return false if cookies are not blocked', () => {
|
22
|
+
expect(docCookies.areCookiesBlocked({ cookie: 'blah' })).toBeFalsy();
|
23
|
+
});
|
24
|
+
});
|