UNPKG

@kbee-app/embedded

Version:

Embed a Kbee knowledge base into your website

2 lines 7.53 kB
!function(){var t={},e={};try{!function(t,n){if("+"!==new t("q=%2B").get("q")||"+"!==new t({q:"+"}).get("q")||"+"!==new t([["q","+"]]).get("q")||"q=%0A"!==new t("q=\n").toString()||"q=+%26"!==new t({q:" &"}).toString()||"q=%25zx"!==new t({q:"%zx"}).toString())throw t;e.URLSearchParams=t}(URLSearchParams)}catch(URLSearchParams){!function(t,n,r){"use strict";var a=t.create,i=t.defineProperty,o=/[!'\(\)~]|%20|%00/g,c=/%(?![0-9a-fA-F]{2})/g,s=/\+/g,u={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"},h={append:function(t,e){d(this._ungap,t,e)},delete:function(t){delete this._ungap[t]},get:function(t){return this.has(t)?this._ungap[t][0]:null},getAll:function(t){return this.has(t)?this._ungap[t].slice(0):[]},has:function(t){return t in this._ungap},set:function(t,e){this._ungap[t]=[n(e)]},forEach:function(t,e){var r=this;for(var a in r._ungap)r._ungap[a].forEach(i,a);function i(i){t.call(e,i,n(a),r)}},toJSON:function(){return{}},toString:function(){var t=[];for(var e in this._ungap)for(var n=y(e),r=0,a=this._ungap[e];r<a.length;r++)t.push(n+"="+y(a[r]));return t.join("&")}};for(var l in h)i(f.prototype,l,{configurable:!0,writable:!0,value:h[l]});function f(t){var e=a(null);switch(i(this,"_ungap",{value:e}),!0){case!t:break;case"string"==typeof t:"?"===t.charAt(0)&&(t=t.slice(1));for(var n=t.split("&"),o=0,c=n.length;o<c;o++){var s=(u=n[o]).indexOf("=");-1<s?d(e,g(u.slice(0,s)),g(u.slice(s+1))):u.length&&d(e,g(u),"")}break;case r(t):for(o=0,c=t.length;o<c;o++){var u;d(e,(u=t[o])[0],u[1])}break;case"forEach"in t:t.forEach(p,e);break;default:for(var h in t)d(e,h,t[h])}}function p(t,e){d(this,e,t)}function d(t,e,n){var a=r(n)?n.join(","):n;e in t?t[e].push(a):t[e]=[a]}function g(t){return decodeURIComponent(t.replace(c,"%25").replace(s," "))}function y(t){return encodeURIComponent(t).replace(o,w)}function w(t){return u[t]}e.URLSearchParams=f}(Object,String,Array.isArray)}!function(t){var e=!1;try{e=!!Symbol.iterator}catch(r){}function n(t,n){var r=[];return t.forEach(n,r),e?r[Symbol.iterator]():{next:function(){var t=r.shift();return{done:void 0===t,value:t}}}}"forEach"in t||(t.forEach=function(t,e){var n=this,r=Object.create(null);this.toString().replace(/=[\s\S]*?(?:&|$)/g,"=").split("=").forEach((function(a){!a.length||a in r||(r[a]=n.getAll(a)).forEach((function(r){t.call(e,r,a,n)}))}))}),"keys"in t||(t.keys=function(){return n(this,(function(t,e){this.push(e)}))}),"values"in t||(t.values=function(){return n(this,(function(t,e){this.push(t)}))}),"entries"in t||(t.entries=function(){return n(this,(function(t,e){this.push([e,t])}))}),!e||Symbol.iterator in t||(t[Symbol.iterator]=t.entries),"sort"in t||(t.sort=function(){for(var t,e,n,r=this.entries(),a=r.next(),i=a.done,o=[],c=Object.create(null);!i;)e=(n=a.value)[0],o.push(e),e in c||(c[e]=[]),c[e].push(n[1]),i=(a=r.next()).done;for(o.sort(),t=0;t<o.length;t++)this.delete(o[t]);for(t=0;t<o.length;t++)e=o[t],this.append(e,c[e].shift())}),function(e){var n=e.defineProperty,r=e.getOwnPropertyDescriptor,a=function(e){var n=e.append;e.append=t.append,URLSearchParams.call(e,e._usp.search.slice(1)),e.append=n},i=function(t,e){if(!(t instanceof e))throw new TypeError("'searchParams' accessed on an object that does not implement interface "+e.name)},o=function(o){var c,s,u=o.prototype,h=r(u,"searchParams"),l=r(u,"href"),f=r(u,"search");!h&&f&&f.set&&(s=function(e){function r(n,r){t.append.call(this,n,r),n=this.toString(),e.set.call(this._usp,n?"?"+n:"")}function a(n){t.delete.call(this,n),n=this.toString(),e.set.call(this._usp,n?"?"+n:"")}function i(n,r){t.set.call(this,n,r),n=this.toString(),e.set.call(this._usp,n?"?"+n:"")}return function(t,e){return t.append=r,t.delete=a,t.set=i,n(t,"_usp",{configurable:!0,writable:!0,value:e})}}(f),c=function(t,e){return n(t,"_searchParams",{configurable:!0,writable:!0,value:s(e,t)}),e},e.defineProperties(u,{href:{get:function(){return l.get.call(this)},set:function(t){var e=this._searchParams;l.set.call(this,t),e&&a(e)}},search:{get:function(){return f.get.call(this)},set:function(t){var e=this._searchParams;f.set.call(this,t),e&&a(e)}},searchParams:{get:function(){return i(this,o),this._searchParams||c(this,new URLSearchParams(this.search.slice(1)))},set:function(t){i(this,o),c(this,t)}}}))};try{o(HTMLAnchorElement),/^function|object$/.test(typeof URL)&&URL.prototype&&o(URL)}catch(c){}}(Object)}(e.URLSearchParams.prototype),t=e.URLSearchParams;var n={};function r(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t)){var n=[],r=!0,a=!1,i=void 0;try{for(var o,c=t[Symbol.iterator]();!(r=(o=c.next()).done)&&(n.push(o.value),!e||n.length!==e);r=!0);}catch(s){a=!0,i=s}finally{try{r||null==c.return||c.return()}finally{if(a)throw i}}return n}}(t,e)||function(t,e){if(t){if("string"==typeof t)return a(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?a(t,e):void 0}}(t,e)||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.")}()}function a(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}n.render=function(e){var n=e.target,a=e.token,i=e.apiKey,o=e.spaceUrl;function c(){var e=window.location.pathname,c=new t(window.location.search),s=r((c.get("kbee")?decodeURI(c.get("kbee")):"").split("#"),2),u=s[0],h=s[1],l="string"==typeof n?document.querySelector(n):n;if("string"==typeof n&&!l)throw new Error('Target element with selector "'.concat(n,'" does not exist'));if(!(l instanceof Element||l instanceof HTMLDocument))throw new Error("Target element is not a valid DOM element");if(!o)throw new Error('"spaceUrl" is required');if(!a&&!i)throw new Error('One of "token" or "apiKey" is required');if(o=o.replace(/\/$/,""),a)d(a);else{var f='{"url": "'.concat(o.split("://")[1],'","key":"').concat(i,'"}'),p=new XMLHttpRequest;p.addEventListener("readystatechange",(function(){if(4===this.readyState)try{d(JSON.parse(this.responseText).jwt)}catch(t){l.innerHTML='Could not authenticate. Please make sure you <a href="https://help.kbee.app/page/1yogD_TtpKLjdmVhFGxJyIaRZPuyPcbwtTH1rHsZhcUQ/Embed_Kbee_on_your_page#h.a4zbywr9omu7">whitelist your domain</a>.'}})),p.open("POST","".concat(o,"/api/generateJWT")),p.send(f)}function d(n){l.innerHTML='<iframe src="'.concat(o).concat(u,"?jwt=").concat(n,"#").concat(h,'" style="width:100%;height:100%;border:none"/>');var a=l.querySelector("iframe").contentWindow;window.addEventListener("popstate",(function(){var e=new t(window.location.search),a=r((e.get("kbee")?decodeURI(e.get("kbee")):"").split("#"),2),i=a[0],c=a[1];l.querySelector("iframe").src="".concat(o).concat(i,"?jwt=").concat(n,"#").concat(c)})),window.addEventListener("message",(function(i){if(i.source===a&&!(i.data.indexOf("jwt=")>-1)){var c=new t(window.location.search),s=i.data;if(i.data.startsWith("__initial__")){var u=r(i.data.split("__initial__"),2),h=r((s=u[1]).split("#"),2),f=h[0],p=h[1];l.querySelector("iframe").src="".concat(o).concat(f,"?jwt=").concat(n,"#").concat(p)}c.set("kbee",s);var d="".concat(e,"?").concat(c.toString());window.history.pushState({},"",d)}}))}}e.bypassDocumentLoadEvent?c():document.addEventListener("DOMContentLoaded",c)},window.Kbee={render:n.render}}(); //# sourceMappingURL=kbee-embedded.js.map