@internetarchive/bookreader 5.0.0-28 → 5.0.0-28-remove-url-defaults
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.
@@ -1,2 +1,2 @@
|
|
1
|
-
(self.webpackChunk_internetarchive_bookreader=self.webpackChunk_internetarchive_bookreader||[]).push([[336],{1226:function(t,e,r){"use strict";function n(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function a(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}r(5827),r(4916),r(5306),r(2222),r(6992),r(1539),r(8783),r(3948),r(285),r(489),r(2419),r(4819),r(5003),r(2526),r(1817),r(2165),r(4747),r(7941),r(9826),r(8309),r(9600),r(1249),r(7327),r(9714),r(8559),r(4723),r(3123),r(9720),r(4765),r(7042),r(1038);var i,l=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};o(this,t),this.bookReaderOptions=e,this.urlSchema=[{name:"page",position:"path",default:"n0"},{name:"mode",position:"path",default:"2up"},{name:"search",position:"path",deprecated_for:"q"},{name:"q",position:"query_param"},{name:"sort",position:"query_param"},{name:"view",position:"query_param"},{name:"admin",position:"query_param"}],this.urlState={},this.urlMode=this.bookReaderOptions.urlMode||"hash",this.urlHistoryBasePath=this.bookReaderOptions.urlHistoryBasePath||"/",this.urlLocationPollId=null,this.oldLocationHash=null,this.oldUserHash=null}var e,r;return e=t,(r=[{key:"urlStateToUrlString",value:function(t){var e=this,r=new URLSearchParams,n={};Object.keys(t).forEach((function(o){var a,i,l,u,s=e.urlSchema.find((function(t){return t.name===o}));null!==(a=s)&&void 0!==a&&a.deprecated_for&&(s=e.urlSchema.find((function(t){return t.name===s.deprecated_for}))),"path"==(null===(i=s)||void 0===i?void 0:i.position)?n[null===(l=s)||void 0===l?void 0:l.name]=t[o]:r.append((null===(u=s)||void 0===u?void 0:u.name)||o,t[o])}));var o=this.urlSchema.filter((function(t){return"path"==t.position})).map((function(t){return n[t.name]?"".concat(t.name,"/").concat(n[t.name]):""})).join("/"),a="".concat(o.replace(/\/$/,"")),i="".concat(a,"?").concat(r.toString());return r.toString()?i:"".concat(a)}},{key:"urlStringToUrlState",value:function(t){var e={},r=new URL(t,"http://example.com"),o=Object.fromEntries(r.searchParams.entries()),a=r.pathname.match(/[^\\/]+\/[^\\/]+/g),i=a?Object.fromEntries(a.map((function(t){return t.split("/")}))):{},l=function(t,e){return Object.keys(t).some((function(t){return t==e}))};return this.urlSchema.filter((function(t){return"path"==t.position})).forEach((function(t){if(!i[t.name]&&t.default)return e[t.name]=t.default;var r=l(i,t.name);l(t,"deprecated_for")&&r?e[t.deprecated_for]=i[t.name]:r&&(e[t.name]=i[t.name])})),Object.entries(o).forEach((function(t){var r,o,a=(o=2,function(t){if(Array.isArray(t))return t}(r=t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,a=[],i=!0,l=!1;try{for(r=r.call(t);!(i=(n=r.next()).done)&&(a.push(n.value),!e||a.length!==e);i=!0);}catch(t){l=!0,o=t}finally{try{i||null==r.return||r.return()}finally{if(l)throw o}}return a}}(r,o)||function(t,e){if(t){if("string"==typeof t)return n(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(t,e):void 0}}(r,o)||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],l=a[1];e[i]=l})),e}},{key:"setUrlParam",value:function(t,e){this.urlState[t]=e,this.pushToAddressBar()}},{key:"removeUrlParam",value:function(t){delete this.urlState[t],this.pushToAddressBar()}},{key:"getUrlParam",value:function(t){return this.urlState[t]}},{key:"pushToAddressBar",value:function(){var t=this.urlStateToUrlString(this.urlState);if("history"==this.urlMode){if(window.history&&window.history.replaceState){var e="".concat(this.urlHistoryBasePath).concat(t);window.history.replaceState({},null,e)}}else window.location.replace("#"+t);this.oldLocationHash=t}},{key:"listenForHashChanges",value:function(){var t=this;this.oldLocationHash=window.location.hash.substr(1),this.urlLocationPollId&&(clearInterval(this.urlLocationPollId),this.urlLocationPollId=null),this.urlLocationPollId=setInterval((function(){var e=window.location.hash.substr(1);e!=t.oldLocationHash&&(t.urlState=t.urlStringToUrlState(e))}),500)}},{key:"pullFromAddressBar",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:window.location,e="history"===this.urlMode?t.pathname.substr(this.urlHistoryBasePath.length)+t.search:t.hash.substr(1);this.urlState=this.urlStringToUrlState(e)}}])&&a(e.prototype,r),t}();function u(t){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function s(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function c(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function h(t,e,r){return(h="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,r){var n=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=p(t)););return t}(t,e);if(n){var o=Object.getOwnPropertyDescriptor(n,e);return o.get?o.get.call(r):o.value}})(t,e,r||t)}function f(t,e){return(f=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function d(t,e){if(e&&("object"===u(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function p(t){return(p=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}r(3609).extend(BookReader.defaultOptions,{enableUrlPlugin:!0,bookId:"",defaults:null,updateWindowTitle:!1,urlMode:"hash",urlHistoryBasePath:"/",urlTrackedParams:["page","search","mode","region","highlight","view"],urlTrackIndex0:!1}),BookReader.prototype.setup=(i=BookReader.prototype.setup,function(t){i.call(this,t),this.bookId=t.bookId,this.defaults=t.defaults,this.locationPollId=null,this.oldLocationHash=null,this.oldUserHash=null}),BookReader.prototype.init=function(t){return function(){var e=this;this.options.enableUrlPlugin&&(this.bind(BookReader.eventNames.PostInit,(function(){var t=e.options,r=t.updateWindowTitle,n=t.urlMode;r&&(document.title=e.shortTitle(e.bookTitle,50)),"hash"===n&&e.urlStartLocationPolling()})),this.bind(BookReader.eventNames.fragmentChange,this.urlUpdateFragment.bind(this))),t.call(this)}}(BookReader.prototype.init),BookReader.prototype.shortTitle=function(t){return this.bookTitle.length<t?this.bookTitle:"".concat(this.bookTitle.substr(0,t-3),"...")},BookReader.prototype.urlStartLocationPolling=function(){var t=this;this.oldLocationHash=this.urlReadFragment(),this.locationPollId&&(clearInterval(this.locationPollId),this.locationPollId=null),this.locationPollId=setInterval((function(){var e=t.urlReadFragment();if(e!=t.oldLocationHash&&e!=t.oldUserHash){var r=t.paramsFromFragment(e),n=function(){return t.updateFromParams(r)};t.trigger(BookReader.eventNames.stop),t.animating?(t.autoStop&&t.autoStop(),t.animationFinishedCallback=n):n(),t.oldUserHash=e}}),500)},BookReader.prototype.urlUpdateFragment=function(){var t=this.paramsFromCurrent(),e=this.options,r=e.urlMode,n=e.urlTrackIndex0,o=e.urlTrackedParams;n||void 0===t.index||0!==t.index||(delete t.index,delete t.page);var a=o.reduce((function(e,r){return r in t&&(e[r]=t[r]),e}),{}),i=this.fragmentFromParams(a,r),l=this.urlReadFragment(),u=this.getLocationSearch(),s=this.queryStringFromParams(a,u,r);if(l!==i||u!==s)if("history"===r){if(window.history&&window.history.replaceState){var c=this.options.urlHistoryBasePath.replace(/\/+$/,""),h=""===i?"":"/".concat(i),f="".concat(c).concat(h).concat(s);window.history.replaceState({},null,f),this.oldLocationHash=i+s}}else{var d=this.urlParamsFiltersOnlySearch(this.readQueryString());window.location.replace("#"+i+d),this.oldLocationHash=i+d}},BookReader.prototype.urlParamsFiltersOnlySearch=function(t){var e=new URLSearchParams(t);return e.has("q")?"?".concat(new URLSearchParams({q:e.get("q")})):""},BookReader.prototype.urlReadFragment=function(){var t=this.options,e=t.urlMode,r=t.urlHistoryBasePath;return"history"===e?window.location.pathname.substr(r.length):window.location.hash.substr(1)},BookReader.prototype.urlReadHashFragment=function(){return window.location.hash.substr(1)};var m=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&f(t,e)}(i,BookReader);var e,r,n,o,a=(n=i,o=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,e=p(n);if(o){var r=p(this).constructor;t=Reflect.construct(e,arguments,r)}else t=e.apply(this,arguments);return d(this,t)});function i(){return s(this,i),a.apply(this,arguments)}return e=i,(r=[{key:"init",value:function(){var t=this;this.options.enableUrlPlugin&&(this.urlPlugin=new l(this.options),this.bind(BookReader.eventNames.PostInit,(function(){"hash"===t.options.urlMode&&t.urlPlugin.listenForHashChanges()}))),h(p(i.prototype),"init",this).call(this)}}])&&c(e.prototype,r),i}();window.BookReader=m},9720:function(t,e,r){var n=r(2109),o=r(4699).entries;n({target:"Object",stat:!0},{entries:function(t){return o(t)}})},8559:function(t,e,r){var n=r(2109),o=r(408),a=r(6135);n({target:"Object",stat:!0},{fromEntries:function(t){var e={};return o(t,(function(t,r){a(e,t,r)}),{AS_ENTRIES:!0}),e}})},4723:function(t,e,r){"use strict";var n=r(7007),o=r(9670),a=r(7466),i=r(1340),l=r(4488),u=r(1530),s=r(7651);n("match",(function(t,e,r){return[function(e){var r=l(this),n=null==e?void 0:e[t];return void 0!==n?n.call(e,r):new RegExp(e)[t](i(r))},function(t){var n=o(this),l=i(t),c=r(e,n,l);if(c.done)return c.value;if(!n.global)return s(n,l);var h=n.unicode;n.lastIndex=0;for(var f,d=[],p=0;null!==(f=s(n,l));){var m=i(f[0]);d[p]=m,""===m&&(n.lastIndex=u(l,a(n.lastIndex),h)),p++}return 0===p?null:d}]}))}},function(t){t(t.s=1226)}]);
|
1
|
+
(self.webpackChunk_internetarchive_bookreader=self.webpackChunk_internetarchive_bookreader||[]).push([[336],{1226:function(t,e,r){"use strict";function n(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function a(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}r(5827),r(4916),r(5306),r(2222),r(6992),r(1539),r(8783),r(3948),r(285),r(489),r(2419),r(4819),r(5003),r(2526),r(1817),r(2165),r(4747),r(7941),r(9826),r(8309),r(9600),r(1249),r(7327),r(9714),r(8559),r(4723),r(3123),r(9720),r(4765),r(7042),r(1038);var i,l=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};o(this,t),this.bookReaderOptions=e,this.urlSchema=[{name:"page",position:"path",default:"n0"},{name:"mode",position:"path",default:"2up"},{name:"search",position:"path",deprecated_for:"q"},{name:"q",position:"query_param"},{name:"sort",position:"query_param"},{name:"view",position:"query_param"},{name:"admin",position:"query_param"}],this.urlState={},this.urlMode=this.bookReaderOptions.urlMode||"hash",this.urlHistoryBasePath=this.bookReaderOptions.urlHistoryBasePath||"/",this.urlLocationPollId=null,this.oldLocationHash=null,this.oldUserHash=null}var e,r;return e=t,(r=[{key:"urlStateToUrlString",value:function(t){var e=this,r=new URLSearchParams,n={};Object.keys(t).forEach((function(o){var a,i,l,u,s=e.urlSchema.find((function(t){return t.name===o}));null!==(a=s)&&void 0!==a&&a.deprecated_for&&(s=e.urlSchema.find((function(t){return t.name===s.deprecated_for}))),"path"==(null===(i=s)||void 0===i?void 0:i.position)?n[null===(l=s)||void 0===l?void 0:l.name]=t[o]:r.append((null===(u=s)||void 0===u?void 0:u.name)||o,t[o])}));var o=this.urlSchema.filter((function(t){return"path"==t.position})).map((function(t){return n[t.name]?"".concat(t.name,"/").concat(n[t.name]):""})).join("/"),a="".concat(o.replace(/\/+/g,"/").replace(/\/+$/,"")),i="".concat(a,"?").concat(r.toString());return r.toString()?i:"".concat(a)}},{key:"urlStringToUrlState",value:function(t){var e={},r=new URL(t,"http://example.com"),o=Object.fromEntries(r.searchParams.entries()),a=r.pathname.match(/[^\\/]+\/[^\\/]+/g),i=a?Object.fromEntries(a.map((function(t){return t.split("/")}))):{},l=function(t,e){return Object.keys(t).some((function(t){return t==e}))};return this.urlSchema.filter((function(t){return"path"==t.position})).forEach((function(t){var r=l(i,t.name);l(t,"deprecated_for")&&r?e[t.deprecated_for]=i[t.name]:r&&(e[t.name]=i[t.name])})),Object.entries(o).forEach((function(t){var r,o,a=(o=2,function(t){if(Array.isArray(t))return t}(r=t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,a=[],i=!0,l=!1;try{for(r=r.call(t);!(i=(n=r.next()).done)&&(a.push(n.value),!e||a.length!==e);i=!0);}catch(t){l=!0,o=t}finally{try{i||null==r.return||r.return()}finally{if(l)throw o}}return a}}(r,o)||function(t,e){if(t){if("string"==typeof t)return n(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(t,e):void 0}}(r,o)||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],l=a[1];e[i]=l})),e}},{key:"setUrlParam",value:function(t,e){this.urlState[t]=e,this.pushToAddressBar()}},{key:"removeUrlParam",value:function(t){delete this.urlState[t],this.pushToAddressBar()}},{key:"getUrlParam",value:function(t){return this.urlState[t]}},{key:"pushToAddressBar",value:function(){var t=this.urlStateToUrlString(this.urlState),e="/"!==t?t:"";if("history"==this.urlMode){if(window.history&&window.history.replaceState){var r="".concat(this.urlHistoryBasePath).concat(e);window.history.replaceState({},null,r)}}else window.location.replace("#"+e);this.oldLocationHash=t}},{key:"listenForHashChanges",value:function(){var t=this;this.oldLocationHash=window.location.hash.substr(1),this.urlLocationPollId&&(clearInterval(this.urlLocationPollId),this.urlLocationPollId=null),this.urlLocationPollId=setInterval((function(){var e=window.location.hash.substr(1);e!=t.oldLocationHash&&(t.urlState=t.urlStringToUrlState(e))}),500)}},{key:"pullFromAddressBar",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:window.location,e="history"===this.urlMode?t.pathname.substr(this.urlHistoryBasePath.length)+t.search:t.hash.substr(1);this.urlState=this.urlStringToUrlState(e)}}])&&a(e.prototype,r),t}();function u(t){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function s(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function c(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function h(t,e,r){return(h="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,r){var n=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=p(t)););return t}(t,e);if(n){var o=Object.getOwnPropertyDescriptor(n,e);return o.get?o.get.call(r):o.value}})(t,e,r||t)}function f(t,e){return(f=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function d(t,e){if(e&&("object"===u(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function p(t){return(p=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}r(3609).extend(BookReader.defaultOptions,{enableUrlPlugin:!0,bookId:"",defaults:null,updateWindowTitle:!1,urlMode:"hash",urlHistoryBasePath:"/",urlTrackedParams:["page","search","mode","region","highlight","view"],urlTrackIndex0:!1}),BookReader.prototype.setup=(i=BookReader.prototype.setup,function(t){i.call(this,t),this.bookId=t.bookId,this.defaults=t.defaults,this.locationPollId=null,this.oldLocationHash=null,this.oldUserHash=null}),BookReader.prototype.init=function(t){return function(){var e=this;this.options.enableUrlPlugin&&(this.bind(BookReader.eventNames.PostInit,(function(){var t=e.options,r=t.updateWindowTitle,n=t.urlMode;r&&(document.title=e.shortTitle(e.bookTitle,50)),"hash"===n&&e.urlStartLocationPolling()})),this.bind(BookReader.eventNames.fragmentChange,this.urlUpdateFragment.bind(this))),t.call(this)}}(BookReader.prototype.init),BookReader.prototype.shortTitle=function(t){return this.bookTitle.length<t?this.bookTitle:"".concat(this.bookTitle.substr(0,t-3),"...")},BookReader.prototype.urlStartLocationPolling=function(){var t=this;this.oldLocationHash=this.urlReadFragment(),this.locationPollId&&(clearInterval(this.locationPollId),this.locationPollId=null),this.locationPollId=setInterval((function(){var e=t.urlReadFragment();if(e!=t.oldLocationHash&&e!=t.oldUserHash){var r=t.paramsFromFragment(e),n=function(){return t.updateFromParams(r)};t.trigger(BookReader.eventNames.stop),t.animating?(t.autoStop&&t.autoStop(),t.animationFinishedCallback=n):n(),t.oldUserHash=e}}),500)},BookReader.prototype.urlUpdateFragment=function(){var t=this.paramsFromCurrent(),e=this.options,r=e.urlMode,n=e.urlTrackIndex0,o=e.urlTrackedParams;n||void 0===t.index||0!==t.index||(delete t.index,delete t.page);var a=o.reduce((function(e,r){return r in t&&(e[r]=t[r]),e}),{}),i=this.fragmentFromParams(a,r),l=this.urlReadFragment(),u=this.getLocationSearch(),s=this.queryStringFromParams(a,u,r);if(l!==i||u!==s)if("history"===r){if(window.history&&window.history.replaceState){var c=this.options.urlHistoryBasePath.replace(/\/+$/,""),h=""===i?"":"/".concat(i),f="".concat(c).concat(h).concat(s);window.history.replaceState({},null,f),this.oldLocationHash=i+s}}else{var d=this.urlParamsFiltersOnlySearch(this.readQueryString());window.location.replace("#"+i+d),this.oldLocationHash=i+d}},BookReader.prototype.urlParamsFiltersOnlySearch=function(t){var e=new URLSearchParams(t);return e.has("q")?"?".concat(new URLSearchParams({q:e.get("q")})):""},BookReader.prototype.urlReadFragment=function(){var t=this.options,e=t.urlMode,r=t.urlHistoryBasePath;return"history"===e?window.location.pathname.substr(r.length):window.location.hash.substr(1)},BookReader.prototype.urlReadHashFragment=function(){return window.location.hash.substr(1)};var y=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&f(t,e)}(i,BookReader);var e,r,n,o,a=(n=i,o=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,e=p(n);if(o){var r=p(this).constructor;t=Reflect.construct(e,arguments,r)}else t=e.apply(this,arguments);return d(this,t)});function i(){return s(this,i),a.apply(this,arguments)}return e=i,(r=[{key:"init",value:function(){var t=this;this.options.enableUrlPlugin&&(this.urlPlugin=new l(this.options),this.bind(BookReader.eventNames.PostInit,(function(){"hash"===t.options.urlMode&&t.urlPlugin.listenForHashChanges()}))),h(p(i.prototype),"init",this).call(this)}}])&&c(e.prototype,r),i}();window.BookReader=y},9720:function(t,e,r){var n=r(2109),o=r(4699).entries;n({target:"Object",stat:!0},{entries:function(t){return o(t)}})},8559:function(t,e,r){var n=r(2109),o=r(408),a=r(6135);n({target:"Object",stat:!0},{fromEntries:function(t){var e={};return o(t,(function(t,r){a(e,t,r)}),{AS_ENTRIES:!0}),e}})},4723:function(t,e,r){"use strict";var n=r(7007),o=r(9670),a=r(7466),i=r(1340),l=r(4488),u=r(1530),s=r(7651);n("match",(function(t,e,r){return[function(e){var r=l(this),n=null==e?void 0:e[t];return void 0!==n?n.call(e,r):new RegExp(e)[t](i(r))},function(t){var n=o(this),l=i(t),c=r(e,n,l);if(c.done)return c.value;if(!n.global)return s(n,l);var h=n.unicode;n.lastIndex=0;for(var f,d=[],p=0;null!==(f=s(n,l));){var y=i(f[0]);d[p]=y,""===y&&(n.lastIndex=u(l,a(n.lastIndex),h)),p++}return 0===p?null:d}]}))}},function(t){t(t.s=1226)}]);
|
2
2
|
//# sourceMappingURL=plugin.url.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"plugins/plugin.url.js","mappings":"mvBAAO,ICkCgCA,EDlC1BC,EAAb,WACE,aAA0B,IAAdC,EAAc,uDAAJ,GAAI,UACxBC,KAAKC,kBAAoBF,EAGzBC,KAAKE,UAAY,CACf,CAAEC,KAAM,OAAQC,SAAU,OAAQC,QAAS,MAC3C,CAAEF,KAAM,OAAQC,SAAU,OAAQC,QAAS,OAC3C,CAAEF,KAAM,SAAUC,SAAU,OAAQE,eAAgB,KACpD,CAAEH,KAAM,IAAKC,SAAU,eACvB,CAAED,KAAM,OAAQC,SAAU,eAC1B,CAAED,KAAM,OAAQC,SAAU,eAC1B,CAAED,KAAM,QAASC,S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KC,EACU,KAAbA,IAAiBX,EAAGO,UAAYjB,EAAmBW,EAAGb,EAASY,EAAGO,WAAYF,IAClFK,IAEF,OAAa,IAANA,EAAU,KAAOD,S","sources":["webpack://@internetarchive/bookreader/./src/plugins/url/UrlPlugin.js","webpack://@internetarchive/bookreader/./src/plugins/url/plugin.url.js","webpack://@internetarchive/bookreader/./node_modules/core-js/modules/es.object.entries.js","webpack://@internetarchive/bookreader/./node_modules/core-js/modules/es.object.from-entries.js","webpack://@internetarchive/bookreader/./node_modules/core-js/modules/es.string.match.js"],"sourcesContent":["export class UrlPlugin {\n constructor(options = {}) {\n this.bookReaderOptions = options;\n\n // the canonical order of elements is important in the path and query string\n this.urlSchema = [\n { name: 'page', position: 'path', default: 'n0' },\n { name: 'mode', position: 'path', default: '2up' },\n { name: 'search', position: 'path', deprecated_for: 'q' },\n { name: 'q', position: 'query_param' },\n { name: 'sort', position: 'query_param' },\n { name: 'view', position: 'query_param' },\n { name: 'admin', position: 'query_param' },\n ];\n\n this.urlState = {};\n this.urlMode = this.bookReaderOptions.urlMode || 'hash';\n this.urlHistoryBasePath = this.bookReaderOptions.urlHistoryBasePath || '/';\n this.urlLocationPollId = null;\n this.oldLocationHash = null;\n this.oldUserHash = null;\n }\n\n /**\n * Parse JSON object URL state to string format\n * Arrange path names in an order that it is positioned on the urlSchema\n * @param {Object} urlState\n * @returns {string}\n */\n urlStateToUrlString(urlState) {\n const searchParams = new URLSearchParams();\n const pathParams = {};\n\n Object.keys(urlState).forEach(key => {\n let schema = this.urlSchema.find(schema => schema.name === key);\n if (schema?.deprecated_for) {\n schema = this.urlSchema.find(schemaKey => schemaKey.name === schema.deprecated_for);\n }\n if (schema?.position == 'path') {\n pathParams[schema?.name] = urlState[key];\n } else {\n searchParams.append(schema?.name || key, urlState[key]);\n }\n });\n\n const strPathParams = this.urlSchema\n .filter(s => s.position == 'path')\n .map(schema => pathParams[schema.name] ? `${schema.name}/${pathParams[schema.name]}` : '')\n .join('/');\n\n const strStrippedTrailingSlash = `${strPathParams.replace(/\\/$/, '')}`;\n const concatenatedPath = `${strStrippedTrailingSlash}?${searchParams.toString()}`;\n return searchParams.toString() ? concatenatedPath : `${strStrippedTrailingSlash}`;\n }\n\n /**\n * Parse string URL and add it in the current urlState\n * Example:\n * /page/n7/mode/2up => {page: 'n7', mode: '2up'}\n * /page/n7/mode/2up/search/hello => {page: 'n7', mode: '2up', q: 'hello'}\n * @param {string} urlString\n * @returns {object}\n */\n urlStringToUrlState(urlString) {\n const urlState = {};\n\n // Fetch searchParams from given {str}\n // Note: whole URL path is needed for URL parsing\n const urlPath = new URL(urlString, 'http://example.com');\n const urlSearchParamsObj = Object.fromEntries(urlPath.searchParams.entries());\n const splitUrlMatches = urlPath.pathname.match(/[^\\\\/]+\\/[^\\\\/]+/g);\n const urlStrSplitSlashObj = splitUrlMatches ? Object.fromEntries(splitUrlMatches.map(x => x.split('/'))) : {};\n\n const doesKeyExists = (_object, _key) => {\n return Object.keys(_object).some(value => value == _key);\n };\n\n // Add path objects to urlState\n this.urlSchema\n .filter(schema => schema.position == 'path')\n .forEach(schema => {\n if (!urlStrSplitSlashObj[schema.name] && schema.default) {\n return urlState[schema.name] = schema.default;\n }\n const hasPropertyKey = doesKeyExists(urlStrSplitSlashObj, schema.name);\n const hasDeprecatedKey = doesKeyExists(schema, 'deprecated_for') && hasPropertyKey;\n\n if (hasDeprecatedKey) {\n urlState[schema.deprecated_for] = urlStrSplitSlashObj[schema.name];\n return;\n }\n\n if (hasPropertyKey) {\n urlState[schema.name] = urlStrSplitSlashObj[schema.name];\n return;\n }\n });\n\n // Add searchParams to urlState\n Object.entries(urlSearchParamsObj).forEach(([key, value]) => {\n urlState[key] = value;\n });\n\n return urlState;\n }\n\n /**\n * Add or update key-value to the urlState\n * @param {string} key\n * @param {string} val\n */\n setUrlParam(key, value) {\n this.urlState[key] = value;\n\n this.pushToAddressBar();\n }\n\n /**\n * Delete key-value to the urlState\n * @param {string} key\n */\n removeUrlParam(key) {\n delete this.urlState[key];\n\n this.pushToAddressBar();\n }\n\n /**\n * Get key-value from the urlState\n * @param {string} key\n * @return {string}\n */\n getUrlParam(key) {\n return this.urlState[key];\n }\n\n /**\n * Push URL params to addressbar\n */\n pushToAddressBar() {\n const urlStrPath = this.urlStateToUrlString(this.urlState);\n if (this.urlMode == 'history') {\n if (window.history && window.history.replaceState) {\n const newUrlPath = `${this.urlHistoryBasePath}${urlStrPath}`;\n window.history.replaceState({}, null, newUrlPath);\n }\n } else {\n window.location.replace('#' + urlStrPath);\n }\n this.oldLocationHash = urlStrPath;\n }\n\n /**\n * Get the url and check if it has changed\n * If it was changeed, update the urlState\n */\n listenForHashChanges() {\n this.oldLocationHash = window.location.hash.substr(1);\n if (this.urlLocationPollId) {\n clearInterval(this.urlLocationPollId);\n this.urlLocationPollId = null;\n }\n\n // check if the URL changes\n const updateHash = () => {\n const newFragment = window.location.hash.substr(1);\n const hasFragmentChange = newFragment != this.oldLocationHash;\n\n if (!hasFragmentChange) { return; }\n\n this.urlState = this.urlStringToUrlState(newFragment);\n };\n this.urlLocationPollId = setInterval(updateHash, 500);\n }\n\n /**\n * Will read either the hash or URL and return the bookreader fragment\n */\n pullFromAddressBar (location = window.location) {\n const path = this.urlMode === 'history'\n ? (location.pathname.substr(this.urlHistoryBasePath.length) + location.search)\n : location.hash.substr(1);\n this.urlState = this.urlStringToUrlState(path);\n }\n}\n","/* global BookReader */\n\nimport { UrlPlugin } from \"./UrlPlugin\";\n\n/**\n * Plugin for URL management in BookReader\n * Note read more about the url \"fragment\" here:\n * https://openlibrary.org/dev/docs/bookurls\n */\n\njQuery.extend(BookReader.defaultOptions, {\n enableUrlPlugin: true,\n bookId: '',\n /** @type {string} Defaults can be a urlFragment string */\n defaults: null,\n updateWindowTitle: false,\n\n /** @type {'history' | 'hash'} */\n urlMode: 'hash',\n\n /**\n * When using 'history' mode, this part of the URL is kept constant\n * @example /details/plato/\n */\n urlHistoryBasePath: '/',\n\n /** Only these params will be reflected onto the URL */\n urlTrackedParams: ['page', 'search', 'mode', 'region', 'highlight', 'view'],\n\n /** If true, don't update the URL when `page == n0 (eg \"/page/n0\")` */\n urlTrackIndex0: false,\n});\n\n/** @override */\nBookReader.prototype.setup = (function(super_) {\n return function(options) {\n super_.call(this, options);\n\n this.bookId = options.bookId;\n this.defaults = options.defaults;\n\n this.locationPollId = null;\n this.oldLocationHash = null;\n this.oldUserHash = null;\n };\n})(BookReader.prototype.setup);\n\n/** @override */\nBookReader.prototype.init = (function(super_) {\n return function() {\n\n if (this.options.enableUrlPlugin) {\n this.bind(BookReader.eventNames.PostInit, () => {\n const { updateWindowTitle, urlMode } = this.options;\n if (updateWindowTitle) {\n document.title = this.shortTitle(this.bookTitle, 50);\n }\n if (urlMode === 'hash') {\n this.urlStartLocationPolling();\n }\n });\n\n this.bind(BookReader.eventNames.fragmentChange,\n this.urlUpdateFragment.bind(this)\n );\n }\n super_.call(this);\n };\n})(BookReader.prototype.init);\n\n/**\n * Returns a shortened version of the title with the maximum number of characters\n * @param {number} maximumCharacters\n * @return {string}\n */\nBookReader.prototype.shortTitle = function(maximumCharacters) {\n if (this.bookTitle.length < maximumCharacters) {\n return this.bookTitle;\n }\n\n const title = `${this.bookTitle.substr(0, maximumCharacters - 3)}...`;\n return title;\n};\n\n/**\n * Starts polling of window.location to see hash fragment changes\n */\nBookReader.prototype.urlStartLocationPolling = function() {\n this.oldLocationHash = this.urlReadFragment();\n\n if (this.locationPollId) {\n clearInterval(this.locationPollId);\n this.locationPollId = null;\n }\n\n const updateHash = () => {\n const newFragment = this.urlReadFragment();\n const hasFragmentChange = (newFragment != this.oldLocationHash) && (newFragment != this.oldUserHash);\n\n if (!hasFragmentChange) { return; }\n\n const params = this.paramsFromFragment(newFragment);\n\n const updateParams = () => this.updateFromParams(params);\n\n this.trigger(BookReader.eventNames.stop);\n if (this.animating) {\n // Queue change if animating\n if (this.autoStop) this.autoStop();\n this.animationFinishedCallback = updateParams;\n } else {\n // update immediately\n updateParams();\n }\n this.oldUserHash = newFragment;\n };\n\n this.locationPollId = setInterval(updateHash, 500);\n};\n\n/**\n * Update URL from the current parameters.\n * Call this instead of manually using window.location.replace\n */\nBookReader.prototype.urlUpdateFragment = function() {\n const allParams = this.paramsFromCurrent();\n const { urlMode, urlTrackIndex0, urlTrackedParams } = this.options;\n\n if (!urlTrackIndex0\n && (typeof(allParams.index) !== 'undefined')\n && allParams.index === 0) {\n delete allParams.index;\n delete allParams.page;\n }\n\n const params = urlTrackedParams.reduce((validParams, paramName) => {\n if (paramName in allParams) {\n validParams[paramName] = allParams[paramName];\n }\n return validParams;\n }, {});\n\n const newFragment = this.fragmentFromParams(params, urlMode);\n const currFragment = this.urlReadFragment();\n const currQueryString = this.getLocationSearch();\n const newQueryString = this.queryStringFromParams(params, currQueryString, urlMode);\n if (currFragment === newFragment && currQueryString === newQueryString) {\n return;\n }\n\n if (urlMode === 'history') {\n if (window.history && window.history.replaceState) {\n const baseWithoutSlash = this.options.urlHistoryBasePath.replace(/\\/+$/, '');\n const newFragmentWithSlash = newFragment === '' ? '' : `/${newFragment}`;\n\n const newUrlPath = `${baseWithoutSlash}${newFragmentWithSlash}${newQueryString}`;\n window.history.replaceState({}, null, newUrlPath);\n this.oldLocationHash = newFragment + newQueryString;\n\n }\n } else {\n const newQueryStringSearch = this.urlParamsFiltersOnlySearch(this.readQueryString());\n window.location.replace('#' + newFragment + newQueryStringSearch);\n this.oldLocationHash = newFragment + newQueryStringSearch;\n\n }\n};\n\n/**\n * @private\n * Filtering query parameters to select only book search param (?q=foo)\n This needs to be updated/URL system modified if future query params are to be added\n * @param {string} url\n * @return {string}\n * */\nBookReader.prototype.urlParamsFiltersOnlySearch = function(url) {\n const params = new URLSearchParams(url);\n return params.has('q') ? `?${new URLSearchParams({ q: params.get('q') })}` : '';\n};\n\n\n/**\n * Will read either the hash or URL and return the bookreader fragment\n * @return {string}\n */\nBookReader.prototype.urlReadFragment = function() {\n const { urlMode, urlHistoryBasePath } = this.options;\n if (urlMode === 'history') {\n return window.location.pathname.substr(urlHistoryBasePath.length);\n } else {\n return window.location.hash.substr(1);\n }\n};\n\n/**\n * Will read the hash return the bookreader fragment\n * @return {string}\n */\nBookReader.prototype.urlReadHashFragment = function() {\n return window.location.hash.substr(1);\n};\nexport class BookreaderUrlPlugin extends BookReader {\n init() {\n if (this.options.enableUrlPlugin) {\n this.urlPlugin = new UrlPlugin(this.options);\n this.bind(BookReader.eventNames.PostInit, () => {\n const { urlMode } = this.options;\n\n if (urlMode === 'hash') {\n this.urlPlugin.listenForHashChanges();\n }\n });\n }\n\n super.init();\n }\n}\n\nwindow.BookReader = BookreaderUrlPlugin;\nexport default BookreaderUrlPlugin;\n","var $ = require('../internals/export');\nvar $entries = require('../internals/object-to-array').entries;\n\n// `Object.entries` method\n// https://tc39.es/ecma262/#sec-object.entries\n$({ target: 'Object', stat: true }, {\n entries: function entries(O) {\n return $entries(O);\n }\n});\n","var $ = require('../internals/export');\nvar iterate = require('../internals/iterate');\nvar createProperty = require('../internals/create-property');\n\n// `Object.fromEntries` method\n// https://github.com/tc39/proposal-object-from-entries\n$({ target: 'Object', stat: true }, {\n fromEntries: function fromEntries(iterable) {\n var obj = {};\n iterate(iterable, function (k, v) {\n createProperty(obj, k, v);\n }, { AS_ENTRIES: true });\n return obj;\n }\n});\n","'use strict';\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 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 : regexp[MATCH];\n return matcher !== undefined ? matcher.call(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":["super_","UrlPlugin","options","this","bookReaderOptions","urlSchema","name","position","default","deprecated_for","urlState","urlMode","urlHistoryBasePath","urlLocationPollId","oldLocationHash","oldUserHash","searchParams","URLSearchParams","pathParams","Object","keys","forEach","key","schema","find","schemaKey","append","strPathParams","filter","s","map","join","strStrippedTrailingSlash","replace","concatenatedPath","toString","urlString","urlPath","URL","urlSearchParamsObj","fromEntries","entries","splitUrlMatches","pathname","match","urlStrSplitSlashObj","x","split","doesKeyExists","_object","_key","some","value","hasPropertyKey","pushToAddressBar","urlStrPath","urlStateToUrlString","window","history","replaceState","newUrlPath","location","hash","substr","clearInterval","setInterval","newFragment","urlStringToUrlState","path","length","search","extend","BookReader","defaultOptions","enableUrlPlugin","bookId","defaults","updateWindowTitle","urlTrackedParams","urlTrackIndex0","prototype","setup","call","locationPollId","init","bind","eventNames","PostInit","document","title","shortTitle","bookTitle","urlStartLocationPolling","fragmentChange","urlUpdateFragment","maximumCharacters","urlReadFragment","params","paramsFromFragment","updateParams","updateFromParams","trigger","stop","animating","autoStop","animationFinishedCallback","allParams","paramsFromCurrent","index","page","reduce","validParams","paramName","fragmentFromParams","currFragment","currQueryString","getLocationSearch","newQueryString","queryStringFromParams","baseWithoutSlash","newFragmentWithSlash","newQueryStringSearch","urlParamsFiltersOnlySearch","readQueryString","url","has","q","get","urlReadHashFragment","BookreaderUrlPlugin","urlPlugin","listenForHashChanges","$","$entries","target","stat","O","iterate","createProperty","iterable","obj","k","v","AS_ENTRIES","fixRegExpWellKnownSymbolLogic","anObject","toLength","requireObjectCoercible","advanceStringIndex","regExpExec","MATCH","nativeMatch","maybeCallNative","regexp","matcher","undefined","RegExp","string","rx","S","res","done","global","fullUnicode","unicode","lastIndex","result","A","n","matchStr"],"sourceRoot":""}
|
1
|
+
{"version":3,"file":"plugins/plugin.url.js","mappings":"mvBAAO,ICkCgCA,EDlC1BC,EAAb,WACE,aAA0B,IAAdC,EAAc,uDAAJ,GAAI,UACxBC,KAAKC,kBAAoBF,EAGzBC,KAAKE,UAAY,CACf,CAAEC,KAAM,OAAQC,SAAU,OAAQC,QAAS,MAC3C,CAAEF,KAAM,OAAQC,SAAU,OAAQC,QAAS,OAC3C,CAAEF,KAAM,SAAUC,SAAU,OAAQE,eAAgB,KACpD,CAAEH,KAAM,IAAKC,SAAU,eACvB,CAAED,KAAM,OAAQC,SAAU,eAC1B,CAAED,KAAM,OAAQC,SAAU,eAC1B,CAAED,KAAM,QAASC,SAAU,gBAG7BJ,KAAKO,SAAW,GAChBP,KAAKQ,QAAUR,KAAKC,kBAAkBO,SAAW,OACjDR,KAAKS,mBAAqBT,KAAKC,kBAAkBQ,oBAAuB,IACxET,KAAKU,kBAAoB,KACzBV,KAAKW,gBAAkB,KACvBX,KAAKY,YAAc,K,QApBvB,O,EAAA,G,EAAA,kCA6BE,SAAoBL,GAAU,WACtBM,EAAe,IAAIC,gBACnBC,EAAa,GAEnBC,OAAOC,KAAKV,GAAUW,SAAQ,SAAAC,GAAO,QAKH,EAEzB,EANHC,EAAS,EAAKlB,UAAUmB,MAAK,SAAAD,GAAM,OAAIA,EAAOjB,OAASgB,KAC3D,UAAIC,SAAJ,OAAI,EAAQd,iBACVc,EAAS,EAAKlB,UAAUmB,MAAK,SAAAC,GAAS,OAAIA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ACnBgH,EAAyB,EAAQ,MACjCC,EAAqB,EAAQ,MAC7BC,EAAa,EAAQ,MAGzBL,EAA8B,SAAS,SAAUM,EAAOC,EAAaC,GACnE,MAAO,CAGL,SAAeC,GACb,IAAIjB,EAAIW,EAAuBhJ,MAC3BuJ,EAAoBC,MAAVF,OAAsBE,EAAYF,EAAOH,GACvD,YAAmBK,IAAZD,EAAwBA,EAAQxE,KAAKuE,EAAQjB,GAAK,IAAIoB,OAAOH,GAAQH,GAAOnH,EAASqG,KAI9F,SAAUqB,GACR,IAAIC,EAAKb,EAAS9I,MACd4J,EAAI5H,EAAS0H,GACbG,EAAMR,EAAgBD,EAAaO,EAAIC,GAE3C,GAAIC,EAAIC,KAAM,OAAOD,EAAI5G,MAEzB,IAAK0G,EAAGI,OAAQ,OAAOb,EAAWS,EAAIC,GAEtC,IAAII,EAAcL,EAAGM,QACrBN,EAAGO,UAAY,EAIf,IAHA,IAEIC,EAFAC,EAAI,GACJC,EAAI,EAEgC,QAAhCF,EAASjB,EAAWS,EAAIC,KAAc,CAC5C,IAAIU,EAAWtI,EAASmI,EAAO,IAC/BC,EAAEC,GAAKC,EACU,KAAbA,IAAiBX,EAAGO,UAAYjB,EAAmBW,EAAGb,EAASY,EAAGO,WAAYF,IAClFK,IAEF,OAAa,IAANA,EAAU,KAAOD,S","sources":["webpack://@internetarchive/bookreader/./src/plugins/url/UrlPlugin.js","webpack://@internetarchive/bookreader/./src/plugins/url/plugin.url.js","webpack://@internetarchive/bookreader/./node_modules/core-js/modules/es.object.entries.js","webpack://@internetarchive/bookreader/./node_modules/core-js/modules/es.object.from-entries.js","webpack://@internetarchive/bookreader/./node_modules/core-js/modules/es.string.match.js"],"sourcesContent":["export class UrlPlugin {\n constructor(options = {}) {\n this.bookReaderOptions = options;\n\n // the canonical order of elements is important in the path and query string\n this.urlSchema = [\n { name: 'page', position: 'path', default: 'n0' },\n { name: 'mode', position: 'path', default: '2up' },\n { name: 'search', position: 'path', deprecated_for: 'q' },\n { name: 'q', position: 'query_param' },\n { name: 'sort', position: 'query_param' },\n { name: 'view', position: 'query_param' },\n { name: 'admin', position: 'query_param' },\n ];\n\n this.urlState = {};\n this.urlMode = this.bookReaderOptions.urlMode || 'hash';\n this.urlHistoryBasePath = this.bookReaderOptions.urlHistoryBasePath || '/';\n this.urlLocationPollId = null;\n this.oldLocationHash = null;\n this.oldUserHash = null;\n }\n\n /**\n * Parse JSON object URL state to string format\n * Arrange path names in an order that it is positioned on the urlSchema\n * @param {Object} urlState\n * @returns {string}\n */\n urlStateToUrlString(urlState) {\n const searchParams = new URLSearchParams();\n const pathParams = {};\n\n Object.keys(urlState).forEach(key => {\n let schema = this.urlSchema.find(schema => schema.name === key);\n if (schema?.deprecated_for) {\n schema = this.urlSchema.find(schemaKey => schemaKey.name === schema.deprecated_for);\n }\n if (schema?.position == 'path') {\n pathParams[schema?.name] = urlState[key];\n } else {\n searchParams.append(schema?.name || key, urlState[key]);\n }\n });\n\n const strPathParams = this.urlSchema\n .filter(s => s.position == 'path')\n .map(schema => pathParams[schema.name] ? `${schema.name}/${pathParams[schema.name]}` : '')\n .join('/');\n\n // replace consecutive slashes with a single slash + remove trailing slashes\n const strStrippedTrailingSlash = `${strPathParams.replace(/\\/+/g, '/').replace(/\\/+$/, '')}`;\n const concatenatedPath = `${strStrippedTrailingSlash}?${searchParams.toString()}`;\n return searchParams.toString() ? concatenatedPath : `${strStrippedTrailingSlash}`;\n }\n\n /**\n * Parse string URL and add it in the current urlState\n * Example:\n * /page/n7/mode/2up => {page: 'n7', mode: '2up'}\n * /page/n7/mode/2up/search/hello => {page: 'n7', mode: '2up', q: 'hello'}\n * @param {string} urlString\n * @returns {object}\n */\n urlStringToUrlState(urlString) {\n const urlState = {};\n\n // Fetch searchParams from given {str}\n // Note: whole URL path is needed for URL parsing\n const urlPath = new URL(urlString, 'http://example.com');\n const urlSearchParamsObj = Object.fromEntries(urlPath.searchParams.entries());\n const splitUrlMatches = urlPath.pathname.match(/[^\\\\/]+\\/[^\\\\/]+/g);\n const urlStrSplitSlashObj = splitUrlMatches ? Object.fromEntries(splitUrlMatches.map(x => x.split('/'))) : {};\n\n const doesKeyExists = (_object, _key) => {\n return Object.keys(_object).some(value => value == _key);\n };\n\n // Add path objects to urlState\n this.urlSchema\n .filter(schema => schema.position == 'path')\n .forEach(schema => {\n const hasPropertyKey = doesKeyExists(urlStrSplitSlashObj, schema.name);\n const hasDeprecatedKey = doesKeyExists(schema, 'deprecated_for') && hasPropertyKey;\n\n if (hasDeprecatedKey) {\n urlState[schema.deprecated_for] = urlStrSplitSlashObj[schema.name];\n return;\n }\n\n if (hasPropertyKey) {\n urlState[schema.name] = urlStrSplitSlashObj[schema.name];\n return;\n }\n });\n\n // Add searchParams to urlState\n Object.entries(urlSearchParamsObj).forEach(([key, value]) => {\n urlState[key] = value;\n });\n\n return urlState;\n }\n\n /**\n * Add or update key-value to the urlState\n * @param {string} key\n * @param {string} val\n */\n setUrlParam(key, value) {\n this.urlState[key] = value;\n\n this.pushToAddressBar();\n }\n\n /**\n * Delete key-value to the urlState\n * @param {string} key\n */\n removeUrlParam(key) {\n delete this.urlState[key];\n\n this.pushToAddressBar();\n }\n\n /**\n * Get key-value from the urlState\n * @param {string} key\n * @return {string}\n */\n getUrlParam(key) {\n return this.urlState[key];\n }\n\n /**\n * Push URL params to addressbar\n */\n pushToAddressBar() {\n const urlStrPath = this.urlStateToUrlString(this.urlState);\n const concatenatedPath = urlStrPath !== '/' ? urlStrPath : '';\n if (this.urlMode == 'history') {\n if (window.history && window.history.replaceState) {\n const newUrlPath = `${this.urlHistoryBasePath}${concatenatedPath}`;\n window.history.replaceState({}, null, newUrlPath);\n }\n } else {\n window.location.replace('#' + concatenatedPath);\n }\n this.oldLocationHash = urlStrPath;\n }\n\n /**\n * Get the url and check if it has changed\n * If it was changeed, update the urlState\n */\n listenForHashChanges() {\n this.oldLocationHash = window.location.hash.substr(1);\n if (this.urlLocationPollId) {\n clearInterval(this.urlLocationPollId);\n this.urlLocationPollId = null;\n }\n\n // check if the URL changes\n const updateHash = () => {\n const newFragment = window.location.hash.substr(1);\n const hasFragmentChange = newFragment != this.oldLocationHash;\n\n if (!hasFragmentChange) { return; }\n\n this.urlState = this.urlStringToUrlState(newFragment);\n };\n this.urlLocationPollId = setInterval(updateHash, 500);\n }\n\n /**\n * Will read either the hash or URL and return the bookreader fragment\n */\n pullFromAddressBar (location = window.location) {\n const path = this.urlMode === 'history'\n ? (location.pathname.substr(this.urlHistoryBasePath.length) + location.search)\n : location.hash.substr(1);\n this.urlState = this.urlStringToUrlState(path);\n }\n}\n","/* global BookReader */\n\nimport { UrlPlugin } from \"./UrlPlugin\";\n\n/**\n * Plugin for URL management in BookReader\n * Note read more about the url \"fragment\" here:\n * https://openlibrary.org/dev/docs/bookurls\n */\n\njQuery.extend(BookReader.defaultOptions, {\n enableUrlPlugin: true,\n bookId: '',\n /** @type {string} Defaults can be a urlFragment string */\n defaults: null,\n updateWindowTitle: false,\n\n /** @type {'history' | 'hash'} */\n urlMode: 'hash',\n\n /**\n * When using 'history' mode, this part of the URL is kept constant\n * @example /details/plato/\n */\n urlHistoryBasePath: '/',\n\n /** Only these params will be reflected onto the URL */\n urlTrackedParams: ['page', 'search', 'mode', 'region', 'highlight', 'view'],\n\n /** If true, don't update the URL when `page == n0 (eg \"/page/n0\")` */\n urlTrackIndex0: false,\n});\n\n/** @override */\nBookReader.prototype.setup = (function(super_) {\n return function(options) {\n super_.call(this, options);\n\n this.bookId = options.bookId;\n this.defaults = options.defaults;\n\n this.locationPollId = null;\n this.oldLocationHash = null;\n this.oldUserHash = null;\n };\n})(BookReader.prototype.setup);\n\n/** @override */\nBookReader.prototype.init = (function(super_) {\n return function() {\n\n if (this.options.enableUrlPlugin) {\n this.bind(BookReader.eventNames.PostInit, () => {\n const { updateWindowTitle, urlMode } = this.options;\n if (updateWindowTitle) {\n document.title = this.shortTitle(this.bookTitle, 50);\n }\n if (urlMode === 'hash') {\n this.urlStartLocationPolling();\n }\n });\n\n this.bind(BookReader.eventNames.fragmentChange,\n this.urlUpdateFragment.bind(this)\n );\n }\n super_.call(this);\n };\n})(BookReader.prototype.init);\n\n/**\n * Returns a shortened version of the title with the maximum number of characters\n * @param {number} maximumCharacters\n * @return {string}\n */\nBookReader.prototype.shortTitle = function(maximumCharacters) {\n if (this.bookTitle.length < maximumCharacters) {\n return this.bookTitle;\n }\n\n const title = `${this.bookTitle.substr(0, maximumCharacters - 3)}...`;\n return title;\n};\n\n/**\n * Starts polling of window.location to see hash fragment changes\n */\nBookReader.prototype.urlStartLocationPolling = function() {\n this.oldLocationHash = this.urlReadFragment();\n\n if (this.locationPollId) {\n clearInterval(this.locationPollId);\n this.locationPollId = null;\n }\n\n const updateHash = () => {\n const newFragment = this.urlReadFragment();\n const hasFragmentChange = (newFragment != this.oldLocationHash) && (newFragment != this.oldUserHash);\n\n if (!hasFragmentChange) { return; }\n\n const params = this.paramsFromFragment(newFragment);\n\n const updateParams = () => this.updateFromParams(params);\n\n this.trigger(BookReader.eventNames.stop);\n if (this.animating) {\n // Queue change if animating\n if (this.autoStop) this.autoStop();\n this.animationFinishedCallback = updateParams;\n } else {\n // update immediately\n updateParams();\n }\n this.oldUserHash = newFragment;\n };\n\n this.locationPollId = setInterval(updateHash, 500);\n};\n\n/**\n * Update URL from the current parameters.\n * Call this instead of manually using window.location.replace\n */\nBookReader.prototype.urlUpdateFragment = function() {\n const allParams = this.paramsFromCurrent();\n const { urlMode, urlTrackIndex0, urlTrackedParams } = this.options;\n\n if (!urlTrackIndex0\n && (typeof(allParams.index) !== 'undefined')\n && allParams.index === 0) {\n delete allParams.index;\n delete allParams.page;\n }\n\n const params = urlTrackedParams.reduce((validParams, paramName) => {\n if (paramName in allParams) {\n validParams[paramName] = allParams[paramName];\n }\n return validParams;\n }, {});\n\n const newFragment = this.fragmentFromParams(params, urlMode);\n const currFragment = this.urlReadFragment();\n const currQueryString = this.getLocationSearch();\n const newQueryString = this.queryStringFromParams(params, currQueryString, urlMode);\n if (currFragment === newFragment && currQueryString === newQueryString) {\n return;\n }\n\n if (urlMode === 'history') {\n if (window.history && window.history.replaceState) {\n const baseWithoutSlash = this.options.urlHistoryBasePath.replace(/\\/+$/, '');\n const newFragmentWithSlash = newFragment === '' ? '' : `/${newFragment}`;\n\n const newUrlPath = `${baseWithoutSlash}${newFragmentWithSlash}${newQueryString}`;\n window.history.replaceState({}, null, newUrlPath);\n this.oldLocationHash = newFragment + newQueryString;\n\n }\n } else {\n const newQueryStringSearch = this.urlParamsFiltersOnlySearch(this.readQueryString());\n window.location.replace('#' + newFragment + newQueryStringSearch);\n this.oldLocationHash = newFragment + newQueryStringSearch;\n\n }\n};\n\n/**\n * @private\n * Filtering query parameters to select only book search param (?q=foo)\n This needs to be updated/URL system modified if future query params are to be added\n * @param {string} url\n * @return {string}\n * */\nBookReader.prototype.urlParamsFiltersOnlySearch = function(url) {\n const params = new URLSearchParams(url);\n return params.has('q') ? `?${new URLSearchParams({ q: params.get('q') })}` : '';\n};\n\n\n/**\n * Will read either the hash or URL and return the bookreader fragment\n * @return {string}\n */\nBookReader.prototype.urlReadFragment = function() {\n const { urlMode, urlHistoryBasePath } = this.options;\n if (urlMode === 'history') {\n return window.location.pathname.substr(urlHistoryBasePath.length);\n } else {\n return window.location.hash.substr(1);\n }\n};\n\n/**\n * Will read the hash return the bookreader fragment\n * @return {string}\n */\nBookReader.prototype.urlReadHashFragment = function() {\n return window.location.hash.substr(1);\n};\nexport class BookreaderUrlPlugin extends BookReader {\n init() {\n if (this.options.enableUrlPlugin) {\n this.urlPlugin = new UrlPlugin(this.options);\n this.bind(BookReader.eventNames.PostInit, () => {\n const { urlMode } = this.options;\n\n if (urlMode === 'hash') {\n this.urlPlugin.listenForHashChanges();\n }\n });\n }\n\n super.init();\n }\n}\n\nwindow.BookReader = BookreaderUrlPlugin;\nexport default BookreaderUrlPlugin;\n","var $ = require('../internals/export');\nvar $entries = require('../internals/object-to-array').entries;\n\n// `Object.entries` method\n// https://tc39.es/ecma262/#sec-object.entries\n$({ target: 'Object', stat: true }, {\n entries: function entries(O) {\n return $entries(O);\n }\n});\n","var $ = require('../internals/export');\nvar iterate = require('../internals/iterate');\nvar createProperty = require('../internals/create-property');\n\n// `Object.fromEntries` method\n// https://github.com/tc39/proposal-object-from-entries\n$({ target: 'Object', stat: true }, {\n fromEntries: function fromEntries(iterable) {\n var obj = {};\n iterate(iterable, function (k, v) {\n createProperty(obj, k, v);\n }, { AS_ENTRIES: true });\n return obj;\n }\n});\n","'use strict';\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 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 : regexp[MATCH];\n return matcher !== undefined ? matcher.call(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":["super_","UrlPlugin","options","this","bookReaderOptions","urlSchema","name","position","default","deprecated_for","urlState","urlMode","urlHistoryBasePath","urlLocationPollId","oldLocationHash","oldUserHash","searchParams","URLSearchParams","pathParams","Object","keys","forEach","key","schema","find","schemaKey","append","strPathParams","filter","s","map","join","strStrippedTrailingSlash","replace","concatenatedPath","toString","urlString","urlPath","URL","urlSearchParamsObj","fromEntries","entries","splitUrlMatches","pathname","match","urlStrSplitSlashObj","x","split","doesKeyExists","_object","_key","some","value","hasPropertyKey","pushToAddressBar","urlStrPath","urlStateToUrlString","window","history","replaceState","newUrlPath","location","hash","substr","clearInterval","setInterval","newFragment","urlStringToUrlState","path","length","search","extend","BookReader","defaultOptions","enableUrlPlugin","bookId","defaults","updateWindowTitle","urlTrackedParams","urlTrackIndex0","prototype","setup","call","locationPollId","init","bind","eventNames","PostInit","document","title","shortTitle","bookTitle","urlStartLocationPolling","fragmentChange","urlUpdateFragment","maximumCharacters","urlReadFragment","params","paramsFromFragment","updateParams","updateFromParams","trigger","stop","animating","autoStop","animationFinishedCallback","allParams","paramsFromCurrent","index","page","reduce","validParams","paramName","fragmentFromParams","currFragment","currQueryString","getLocationSearch","newQueryString","queryStringFromParams","baseWithoutSlash","newFragmentWithSlash","newQueryStringSearch","urlParamsFiltersOnlySearch","readQueryString","url","has","q","get","urlReadHashFragment","BookreaderUrlPlugin","urlPlugin","listenForHashChanges","$","$entries","target","stat","O","iterate","createProperty","iterable","obj","k","v","AS_ENTRIES","fixRegExpWellKnownSymbolLogic","anObject","toLength","requireObjectCoercible","advanceStringIndex","regExpExec","MATCH","nativeMatch","maybeCallNative","regexp","matcher","undefined","RegExp","string","rx","S","res","done","global","fullUnicode","unicode","lastIndex","result","A","n","matchStr"],"sourceRoot":""}
|
package/package.json
CHANGED
@@ -48,7 +48,8 @@ export class UrlPlugin {
|
|
48
48
|
.map(schema => pathParams[schema.name] ? `${schema.name}/${pathParams[schema.name]}` : '')
|
49
49
|
.join('/');
|
50
50
|
|
51
|
-
|
51
|
+
// replace consecutive slashes with a single slash + remove trailing slashes
|
52
|
+
const strStrippedTrailingSlash = `${strPathParams.replace(/\/+/g, '/').replace(/\/+$/, '')}`;
|
52
53
|
const concatenatedPath = `${strStrippedTrailingSlash}?${searchParams.toString()}`;
|
53
54
|
return searchParams.toString() ? concatenatedPath : `${strStrippedTrailingSlash}`;
|
54
55
|
}
|
@@ -79,9 +80,6 @@ export class UrlPlugin {
|
|
79
80
|
this.urlSchema
|
80
81
|
.filter(schema => schema.position == 'path')
|
81
82
|
.forEach(schema => {
|
82
|
-
if (!urlStrSplitSlashObj[schema.name] && schema.default) {
|
83
|
-
return urlState[schema.name] = schema.default;
|
84
|
-
}
|
85
83
|
const hasPropertyKey = doesKeyExists(urlStrSplitSlashObj, schema.name);
|
86
84
|
const hasDeprecatedKey = doesKeyExists(schema, 'deprecated_for') && hasPropertyKey;
|
87
85
|
|
@@ -139,13 +137,14 @@ export class UrlPlugin {
|
|
139
137
|
*/
|
140
138
|
pushToAddressBar() {
|
141
139
|
const urlStrPath = this.urlStateToUrlString(this.urlState);
|
140
|
+
const concatenatedPath = urlStrPath !== '/' ? urlStrPath : '';
|
142
141
|
if (this.urlMode == 'history') {
|
143
142
|
if (window.history && window.history.replaceState) {
|
144
|
-
const newUrlPath = `${this.urlHistoryBasePath}${
|
143
|
+
const newUrlPath = `${this.urlHistoryBasePath}${concatenatedPath}`;
|
145
144
|
window.history.replaceState({}, null, newUrlPath);
|
146
145
|
}
|
147
146
|
} else {
|
148
|
-
window.location.replace('#' +
|
147
|
+
window.location.replace('#' + concatenatedPath);
|
149
148
|
}
|
150
149
|
this.oldLocationHash = urlStrPath;
|
151
150
|
}
|
@@ -61,7 +61,7 @@ describe('UrlPlugin tests', () => {
|
|
61
61
|
{page: 'n7', mode: '2up', q: 'hello', view: 'theather', foo: 'bar', sort: 'title_asc'}
|
62
62
|
);
|
63
63
|
expect(urlPlugin.urlStringToUrlState(url1)).toEqual(
|
64
|
-
{
|
64
|
+
{mode: '2up', ref: 'ol', ui: 'embed', wrapper: 'false', view: 'theater'}
|
65
65
|
);
|
66
66
|
});
|
67
67
|
|
@@ -99,15 +99,26 @@ describe('UrlPlugin tests', () => {
|
|
99
99
|
});
|
100
100
|
|
101
101
|
describe('pullFromAddressBar and pushToAddressBar - hash mode', () => {
|
102
|
+
test('url first load - empty state', () => {
|
103
|
+
urlPlugin.urlState = {};
|
104
|
+
urlPlugin.urlMode = 'hash';
|
105
|
+
|
106
|
+
urlPlugin.pullFromAddressBar({ pathname: '', search: '', hash: '#' });
|
107
|
+
expect(urlPlugin.urlState).toEqual({});
|
108
|
+
|
109
|
+
urlPlugin.pushToAddressBar();
|
110
|
+
expect(window.location.hash).toEqual('');
|
111
|
+
});
|
112
|
+
|
102
113
|
test('url without mode state value - use default', () => {
|
103
114
|
urlPlugin.urlState = {};
|
104
115
|
urlPlugin.urlMode = 'hash';
|
105
116
|
|
106
117
|
urlPlugin.pullFromAddressBar({ pathname: '', search: '', hash: '#page/12' });
|
107
|
-
expect(urlPlugin.urlState).toEqual({page: '12'
|
118
|
+
expect(urlPlugin.urlState).toEqual({page: '12'});
|
108
119
|
|
109
120
|
urlPlugin.pushToAddressBar();
|
110
|
-
expect(window.location.hash).toEqual('#page/12
|
121
|
+
expect(window.location.hash).toEqual('#page/12');
|
111
122
|
});
|
112
123
|
|
113
124
|
test('url with query param', () => {
|
@@ -115,24 +126,36 @@ describe('UrlPlugin tests', () => {
|
|
115
126
|
urlPlugin.urlMode = 'hash';
|
116
127
|
|
117
128
|
urlPlugin.pullFromAddressBar({ pathname: '', search: '', hash: '#page/12?q=hello&view=theater' });
|
118
|
-
expect(urlPlugin.urlState).toEqual({page: '12',
|
129
|
+
expect(urlPlugin.urlState).toEqual({page: '12', q: 'hello', view: 'theater'});
|
119
130
|
|
120
131
|
urlPlugin.pushToAddressBar();
|
121
|
-
expect(window.location.hash).toEqual('#page/12
|
132
|
+
expect(window.location.hash).toEqual('#page/12?q=hello&view=theater');
|
122
133
|
});
|
123
134
|
});
|
124
135
|
|
125
136
|
describe('pullFromAddressBar and pushToAddressBar - history mode', () => {
|
126
|
-
test('url
|
137
|
+
test('url first load - empty state', () => {
|
138
|
+
urlPlugin.urlState = {};
|
139
|
+
urlPlugin.urlHistoryBasePath = '/details/foo';
|
140
|
+
urlPlugin.urlMode = 'history';
|
141
|
+
|
142
|
+
urlPlugin.pullFromAddressBar({ pathname: '', search: '', hash: '' });
|
143
|
+
expect(urlPlugin.urlState).toEqual({});
|
144
|
+
|
145
|
+
urlPlugin.pushToAddressBar();
|
146
|
+
expect(window.location.pathname).toEqual('/details/foo');
|
147
|
+
});
|
148
|
+
|
149
|
+
test('url without mode state value', () => {
|
127
150
|
urlPlugin.urlState = {};
|
128
151
|
urlPlugin.urlHistoryBasePath = '/details/foo/';
|
129
152
|
urlPlugin.urlMode = 'history';
|
130
153
|
|
131
154
|
urlPlugin.pullFromAddressBar({ pathname: '/details/foo/page/12', search: '', hash: '' });
|
132
|
-
expect(urlPlugin.urlState).toEqual({page: '12'
|
155
|
+
expect(urlPlugin.urlState).toEqual({page: '12'});
|
133
156
|
|
134
157
|
urlPlugin.pushToAddressBar();
|
135
|
-
expect(window.location.pathname).toEqual('/details/foo/page/12
|
158
|
+
expect(window.location.pathname).toEqual('/details/foo/page/12');
|
136
159
|
});
|
137
160
|
|
138
161
|
test('url with query param', () => {
|
@@ -141,11 +164,11 @@ describe('UrlPlugin tests', () => {
|
|
141
164
|
urlPlugin.urlMode = 'history';
|
142
165
|
|
143
166
|
urlPlugin.pullFromAddressBar({ pathname: '/details/foo/page/12', search: '?q=hello&view=theater', hash: '' });
|
144
|
-
expect(urlPlugin.urlState).toEqual({page: '12',
|
167
|
+
expect(urlPlugin.urlState).toEqual({page: '12', q: 'hello', view: 'theater'});
|
145
168
|
|
146
169
|
urlPlugin.pushToAddressBar();
|
147
170
|
const locationUrl = `${window.location.pathname}${window.location.search}`;
|
148
|
-
expect(locationUrl).toEqual('/details/foo/page/12
|
171
|
+
expect(locationUrl).toEqual('/details/foo/page/12?q=hello&view=theater');
|
149
172
|
});
|
150
173
|
});
|
151
174
|
|