From 02cc7035e865f4026a6918a6ea23eea06b3cbde5 Mon Sep 17 00:00:00 2001 From: Ilya Kreymer Date: Thu, 31 Oct 2019 17:09:42 -0700 Subject: [PATCH] query: fix query for IE11, don't use ES6 syntax, add URL polyfill (#514) --- pywb/static/query.js | 47 ++++++++++++++++++++++++-------------- pywb/templates/query.html | 1 + static/url-polyfill.min.js | 2 ++ 3 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 static/url-polyfill.min.js diff --git a/pywb/static/query.js b/pywb/static/query.js index 55ab8443..f736b002 100644 --- a/pywb/static/query.js +++ b/pywb/static/query.js @@ -291,7 +291,9 @@ RenderCalendar.prototype.makeCDXRequest = function() { var spinner = document.getElementById( renderCal.domStructureIds.updatesSpinner ); - if (spinner) spinner.remove(); + if (spinner && spinner.parentNode) { + spinner.parentNode.removeChild(spinner); + } } }; queryWorker.postMessage({ @@ -330,7 +332,9 @@ RenderCalendar.prototype.makeCDXRequest = function() { var spinner = document.getElementById( renderCal.domStructureIds.updatesSpinner ); - if (spinner) spinner.remove(); + if (spinner && spinner.parentNode) { + spinner.parentNode.removeChild(spinner); + } } }); }; @@ -545,24 +549,32 @@ RenderCalendar.prototype.renderDateCalPart = function( if (memoizedYMDT[timeInfo.year] == null) { // we have not seen this year month day before // create the year month day structure (occurs once per result year) - memoizedYMDT[timeInfo.year] = { - [timeInfo.month]: { - [timeInfo.day]: { - [timeInfo.time]: 1 - } - } - }; + + var timeVal = {}; + timeVal[timeInfo.time] = 1; + + var dayVal = {}; + dayVal[timeInfo.day] = timeVal; + + var monthVal = {}; + monthVal[timeInfo.month] = dayVal; + + memoizedYMDT[timeInfo.year] = monthVal; + this.addRegYearListItem(timeInfo, active); this.addRegYearMonthListItem(timeInfo, active); return this.addRegYearMonthDayListItem(cdxObj, timeInfo, 1, active); } else if (memoizedYMDT[timeInfo.year][timeInfo.month] == null) { // we have seen the year before but not the month and day // create the month day structure (occurs for every new month encountered for an existing year) - memoizedYMDT[timeInfo.year][timeInfo.month] = { - [timeInfo.day]: { - [timeInfo.time]: 1 - } - }; + var timeVal = {}; + timeVal[timeInfo.time] = 1; + + var dayVal = {}; + dayVal[timeInfo.day] = timeVal; + + memoizedYMDT[timeInfo.year][timeInfo.month] = dayVal; + this.addRegYearMonthListItem(timeInfo, active); return this.addRegYearMonthDayListItem(cdxObj, timeInfo, 1, active); } @@ -571,9 +583,10 @@ RenderCalendar.prototype.renderDateCalPart = function( var month = memoizedYMDT[timeInfo.year][timeInfo.month]; if (month[timeInfo.day] == null) { // never seen this day (case 1) - month[timeInfo.day] = { - [timeInfo.time]: count - }; + var timeVal = {}; + timeVal[timeInfo.time] = count; + + month[timeInfo.day] = timeVal; } else if (month[timeInfo.day][timeInfo.time] == null) { // we have seen this day before but not at this time (case 2) month[timeInfo.day][timeInfo.time] = count; diff --git a/pywb/templates/query.html b/pywb/templates/query.html index e4038831..6a710fbf 100644 --- a/pywb/templates/query.html +++ b/pywb/templates/query.html @@ -7,6 +7,7 @@ {% block head %} {{ super() }} + {% endblock %} diff --git a/static/url-polyfill.min.js b/static/url-polyfill.min.js new file mode 100644 index 00000000..0e01abcb --- /dev/null +++ b/static/url-polyfill.min.js @@ -0,0 +1,2 @@ +(function(t){var e=function(){try{return!!Symbol.iterator}catch(e){return false}};var r=e();var n=function(t){var e={next:function(){var e=t.shift();return{done:e===void 0,value:e}}};if(r){e[Symbol.iterator]=function(){return e}}return e};var i=function(e){return encodeURIComponent(e).replace(/%20/g,"+")};var o=function(e){return decodeURIComponent(String(e).replace(/\+/g," "))};var a=function(){var a=function(e){Object.defineProperty(this,"_entries",{writable:true,value:{}});var t=typeof e;if(t==="undefined"){}else if(t==="string"){if(e!==""){this._fromString(e)}}else if(e instanceof a){var r=this;e.forEach(function(e,t){r.append(t,e)})}else if(e!==null&&t==="object"){if(Object.prototype.toString.call(e)==="[object Array]"){for(var n=0;nt[0]){return+1}else{return 0}});if(r._entries){r._entries={}}for(var e=0;e1?o(i[1]):"")}}})}})(typeof global!=="undefined"?global:typeof window!=="undefined"?window:typeof self!=="undefined"?self:this);(function(h){var e=function(){try{var e=new h.URL("b","http://a");e.pathname="c%20d";return e.href==="http://a/c%20d"&&e.searchParams}catch(e){return false}};var t=function(){var t=h.URL;var e=function(e,t){if(typeof e!=="string")e=String(e);var r=document,n;if(t&&(h.location===void 0||t!==h.location.href)){r=document.implementation.createHTMLDocument("");n=r.createElement("base");n.href=t;r.head.appendChild(n);try{if(n.href.indexOf(t)!==0)throw new Error(n.href)}catch(e){throw new Error("URL unable to set base "+t+" due to "+e)}}var i=r.createElement("a");i.href=e;if(n){r.body.appendChild(i);i.href=i.href}if(i.protocol===":"||!/:/.test(i.href)){throw new TypeError("Invalid URL")}Object.defineProperty(this,"_anchorElement",{value:i});var o=new h.URLSearchParams(this.search);var a=true;var s=true;var f=this;["append","delete","set"].forEach(function(e){var t=o[e];o[e]=function(){t.apply(o,arguments);if(a){s=false;f.search=o.toString();s=true}}});Object.defineProperty(this,"searchParams",{value:o,enumerable:true});var c=void 0;Object.defineProperty(this,"_updateSearchParams",{enumerable:false,configurable:false,writable:false,value:function(){if(this.search!==c){c=this.search;if(s){a=false;this.searchParams._fromString(this.search);a=true}}}})};var r=e.prototype;var n=function(t){Object.defineProperty(r,t,{get:function(){return this._anchorElement[t]},set:function(e){this._anchorElement[t]=e},enumerable:true})};["hash","host","hostname","port","protocol"].forEach(function(e){n(e)});Object.defineProperty(r,"search",{get:function(){return this._anchorElement["search"]},set:function(e){this._anchorElement["search"]=e;this._updateSearchParams()},enumerable:true});Object.defineProperties(r,{toString:{get:function(){var e=this;return function(){return e.href}}},href:{get:function(){return this._anchorElement.href.replace(/\?$/,"")},set:function(e){this._anchorElement.href=e;this._updateSearchParams()},enumerable:true},pathname:{get:function(){return this._anchorElement.pathname.replace(/(^\/?)/,"/")},set:function(e){this._anchorElement.pathname=e},enumerable:true},origin:{get:function(){var e={"http:":80,"https:":443,"ftp:":21}[this._anchorElement.protocol];var t=this._anchorElement.port!=e&&this._anchorElement.port!=="";return this._anchorElement.protocol+"//"+this._anchorElement.hostname+(t?":"+this._anchorElement.port:"")},enumerable:true},password:{get:function(){return""},set:function(e){},enumerable:true},username:{get:function(){return""},set:function(e){},enumerable:true}});e.createObjectURL=function(e){return t.createObjectURL.apply(t,arguments)};e.revokeObjectURL=function(e){return t.revokeObjectURL.apply(t,arguments)};h.URL=e};if(!e()){t()}if(h.location!==void 0&&!("origin"in h.location)){var r=function(){return h.location.protocol+"//"+h.location.hostname+(h.location.port?":"+h.location.port:"")};try{Object.defineProperty(h.location,"origin",{get:r,enumerable:true})}catch(e){setInterval(function(){h.location.origin=r()},100)}}})(typeof global!=="undefined"?global:typeof window!=="undefined"?window:typeof self!=="undefined"?self:this); +