view src/main/webapp/imageServer/resources/js/plugins/simple-auth.js @ 204:964846688a95 iiif_diva

imageServer view works now with Diva6 and SimpleAuth plugin.
author Robert Casties <casties@mpiwg-berlin.mpg.de>
date Sat, 06 Jul 2019 20:42:28 +0200
parents
children
line wrap: on
line source

!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/build/plugins/",n(n.s=3)}({3:function(e,t,n){"use strict";function r(e){const t=document.createElement(e),n=Array.prototype.slice.call(arguments,1);for(;n.length;){o(t,n.shift())}return t}function o(e,t){if(null!=t)if("object"!=typeof t&&"function"!=typeof t)e.appendChild(document.createTextNode(t));else if(t instanceof window.Node)e.appendChild(t);else if(t instanceof Array){const n=t.length;for(let r=0;r<n;r++)o(e,t[r])}else!function(e,t){for(const n in t)t.hasOwnProperty(n)&&("style"===n?i(e,t.style):e.setAttribute(n,t[n]))}(e,t)}function i(e,t){if(t)if("object"==typeof t)for(const n in t)t.hasOwnProperty(n)&&(e.style[n]=t[n]);else e.style.cssText=t}n.r(t),n.d(t,"default",function(){return s});class s{constructor(e){this.core=e,this.toolbarIcon=this.createIcon(),this.toolbarSide="right",this.authTokenUrl=e.settings.simpleAuthTokenUrl,this.authLoginUrl=e.settings.simpleAuthLoginUrl,this.authToken=null,this.authError=null,this.authTokenId=null,this.serviceOrigin=this.getOrigin(this.authTokenUrl),Diva.Events.subscribe("ManifestFetchError",e=>{if(401==e.status)throw null==this.authToken&&null==this.authError?(this.requestAuthToken(),new Error("cancel error handler")):(this.showLoginMessage(e),new Error("cancel error handler"))},e.settings.ID),window.addEventListener("message",e=>{let t=e.origin,n=e.data;t==this.serviceOrigin&&n.messageId==this.authTokenId&&(n.hasOwnProperty("accessToken")?(this.authToken=n.accessToken,this.authError=null,this.setAuthHeader(n.accessToken),this.core.publicInstance._loadOrFetchObjectData()):n.hasOwnProperty("error")&&(console.debug("ERROR getting access token!"),this.authError=n.error,this.authToken=null,this.setAuthHeader(null),this.core.publicInstance._loadOrFetchObjectData()))})}showLoginMessage(e){const t=["Unauthorized request. Error code: "+e.status+" "+e.statusText];t.push(r("p","The document you are trying to access requires authentication."),r("p","Please ",r("button",this.core.elemAttrs("error-auth-login",{"aria-label":"Log in"}),"log in"))),this.core.showError(t);let n="#"+this.core.settings.selector;document.querySelector(n+"error-auth-login").addEventListener("click",()=>{this.openLoginWindow();let e=document.querySelector(n+"error");e.parentNode.removeChild(e)})}openLoginWindow(){const e=window.open(this.authLoginUrl);if(null==e)return void console.error("login service window did not open :-(");const t=window.setInterval(()=>{e.closed&&(window.clearInterval(t),this.requestAuthToken())},500)}requestAuthToken(){let e=document.getElementById("iiif-token-frame");null==e&&((e=document.createElement("iframe")).id="iiif-token-frame",e.setAttribute("style","display:none; width:30px; height:10px;"),document.body.appendChild(e)),this.authTokenId=Date.now();const t=this.authTokenUrl+"?messageId="+this.authTokenId+"&origin="+this.getOrigin();e.src=t}getOrigin(e){let t=window.location;return e&&((t=document.createElement("a")).href=e),t.protocol+"//"+t.hostname+(t.port?":"+t.port:"")}setAuthHeader(e){null!=e?(this.core.settings.addRequestHeaders=this.core.settings.addRequestHeaders||{},this.core.settings.addRequestHeaders.Authorization="Bearer "+e):null!=this.core.settings.addRequestHeaders&&delete this.core.settings.addRequestHeaders.Authorization}handleClick(){null!=this.authToken&&null==this.authError||this.openLoginWindow()}createIcon(){const e=document.createElement("div");e.classList.add("diva-simpleauth-icon","diva-button");let t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("x","0px"),t.setAttribute("y","0px"),t.setAttribute("viewBox","0 0 25 25"),t.id=`${this.core.settings.selector}download-icon`;let n=document.createElementNS("http://www.w3.org/2000/svg","g");n.id=`${this.core.settings.selector}download-icon-glyph`,n.setAttribute("transform","matrix(1, 0, 0, 1, -11.5, -11.5)"),n.setAttribute("class","diva-pagetool-icon");let r=document.createElementNS("http://www.w3.org/2000/svg","path");return r.setAttribute("d","M36.25,24c0,6.755-5.495,12.25-12.25,12.25S11.75,30.755,11.75,24S17.245,11.75,24,11.75S36.25,17.245,36.25,24z M33,24c0-4.963-4.037-9-9-9s-9,4.037-9,9s4.037,9,9,9S33,28.963,33,24z M29.823,23.414l-5.647,7.428c-0.118,0.152-0.311,0.117-0.428-0.035L18.1,23.433C17.982,23.28,18.043,23,18.235,23H21v-4.469c0-0.275,0.225-0.5,0.5-0.5h5c0.275,0,0.5,0.225,0.5,0.5V23h2.688C29.879,23,29.941,23.263,29.823,23.414z"),n.appendChild(r),t.appendChild(n),e.appendChild(t),e}}s.prototype.pluginName="simple-auth",s.prototype.isPageTool=!1,window.Diva.SimpleAuthPlugin=s}});
//# sourceMappingURL=simple-auth.js.map