@competitionlabs/gamification-widget-loader 1.0.3 → 1.0.5
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/dist/loader.js +1 -1
- package/package.json +1 -1
package/dist/loader.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(){"use strict";const
|
|
1
|
+
(function(){"use strict";const h=function(i){return typeof Element<"u"&&i instanceof Element},p=function(i){let a=0,t;for(t in i)i.hasOwnProperty(t)&&a++;return a===0&&h(i)&&(a=1),a},w=function({sizeof:i}){return class{constructor(){this.xhr=new XMLHttpRequest}createCORSRequest(t,e){return"withCredentials"in this.xhr?this.xhr.open(t,e,!0):typeof XDomainRequest<"u"?(this.xhr=new XDomainRequest,e=e.indexOf("https")>-1&&location.protocol!=="https:"?e.replace("https","http"):e,this.xhr.open(t,e)):this.xhr=null,this.xhr}abort(){return this.xhr&&this.xhr.readyState!==void 0&&this.xhr.readyState!==4&&this.xhr.abort(),this}getData(t){const e=this;try{if(t.type=t.type!==void 0&&typeof t.type=="string"&&t.type.length>0?t.type:"POST",t.data=t.data!==void 0&&typeof t.data=="object"?t.data:{},t.url=t.url!==void 0&&typeof t.url=="string"&&t.url.length>0?t.url:"",t.success=t.success!==void 0?t.success:function(){},t.error=t.error!==void 0?t.error:function(){},t.headers=t.headers!==void 0?t.headers:{},t.extraCallback=t.extraCallback!==void 0?t.extraCallback:function(){},e.xhr=this.createCORSRequest(t.type,t.url),e.xhr.onload=function(){t.extraCallback(t,e.xhr),t.success(e.xhr.responseText,t,e.xhr)},e.xhr.onerror=function(){t.error(e.xhr.status)},typeof XDomainRequest>"u")if(i(t.headers)>0)for(const n in t.headers)e.xhr.setRequestHeader(n,t.headers[n]);else(t.type==="POST"||t.type==="PUT"||t.type==="DELETE")&&i(t.headers)===0?e.xhr.setRequestHeader("Content-Type","application/json"):e.xhr.setRequestHeader("Content-Type","text/plain");return e.xhr.send(JSON.stringify(t.data)),e.xhr}catch{}}}};(function(){const i=w({sizeof:p});var a=function(){this.ajax=new i,this.settings={apiKey:"",spaceName:"my_space_name",enforceGameLookup:!0,language:"en",currency:"",enableNotifications:!1,memberId:"",uri:{gatewayDomain:"",gatewayWSDomain:"",translationPath:"",widgetData:"/api/v1/:space/widget"},uomSymbol:"",isWidgetMinimized:!0,bindContainer:null,miniBindContainer:null,loadTranslationsForceCustomPath:!0,widgetStatus:"Live",resources:[],assetsBasePath:"/build"},this.initialiseWidget=function(t){var f,l,g;const e=this,n={...t.data[0],widgets:{type_1:{script:"https://s3.eu-west-1.amazonaws.com/demo.gamify.mt/gamification-widget/competitionlabs-gamification-widget-v3/themes/default/javascript/gamification-ux-package.v3-selfinit.js",css:["https://s3.eu-west-1.amazonaws.com/demo.gamify.mt/gamification-widget/competitionlabs-gamification-widget-v3/themes/default/css/styles.css"],translations:{ja:"https://s3.eu-west-1.amazonaws.com/demo.gamify.mt/gamification-widget/competitionlabs-gamification-widget-v3/themes/default/i18n/translation_ja.json",en:"https://s3.eu-west-1.amazonaws.com/demo.gamify.mt/gamification-widget/competitionlabs-gamification-widget-v3/themes/default/i18n/translation_en.json"}},type_2:{script:"https://s3.eu-west-1.amazonaws.com/demo.gamify.mt/gamification-widget/competitionlabs-gamification-widget-v3/themes/type_2/javascript/gamification-ux-package.v3-selfinit.js",css:["https://s3.eu-west-1.amazonaws.com/demo.gamify.mt/gamification-widget/competitionlabs-gamification-widget-v3/themes/type_2/css/styles.css"],translations:{ja:"https://s3.eu-west-1.amazonaws.com/demo.gamify.mt/gamification-widget/competitionlabs-gamification-widget-v3/themes/type_2/i18n/translation_ja.json",en:"https://s3.eu-west-1.amazonaws.com/demo.gamify.mt/gamification-widget/competitionlabs-gamification-widget-v3/themes/type_2/i18n/translation_en.json"}}}},c=n.layout.toLowerCase(),s=(f=n.widgets)==null?void 0:f[c];if(!s)throw new Error(`CompetitionLabs widget configuration does not contain assets for ${n.layout}`);const m=((l=s.translations)==null?void 0:l[e.settings.language])||((g=s.translations)==null?void 0:g.en)||"";(Array.isArray(s.css)?s.css:[]).forEach(function(o){if(!Array.from(document.head.querySelectorAll('link[rel="stylesheet"]')).some(r=>r.href===new URL(o,document.baseURI).href)){const r=document.createElement("link");r.rel="stylesheet",r.href=o,document.head.appendChild(r)}});const y={enableNotifications:e.settings.enableNotifications,memberId:e.settings.memberId,uri:{...e.settings.uri,translationPath:m},uomSymbol:e.settings.uomSymbol,spaceName:e.settings.spaceName,apiKey:e.settings.apiKey,isWidgetMinimized:e.settings.isWidgetMinimized,bindContainer:e.settings.bindContainer,miniBindContainer:e.settings.miniBindContainer,language:e.settings.language,loadTranslationsForceCustomPath:e.settings.loadTranslationsForceCustomPath,resources:[...e.settings.resources],widgetStatus:e.settings.widgetStatus,widgetData:Array.isArray(t==null?void 0:t.data)?t.data:[n]},u=function(){if(typeof window._clWidgetV32026SelfInit!="function")throw new Error("CompetitionLabs widget script did not create window._clWidgetV32026SelfInit");typeof window._clWidgetV32026<"u"&&window._clWidgetV32026.destroy(),window._clWidgetV32026=new window._clWidgetV32026SelfInit({...y}),window._clWidgetV32026.init()};if(!s.script)throw new Error(`CompetitionLabs widget configuration does not contain a script for ${n.layout}`);if(typeof window._clWidgetV32026SelfInit<"u")u();else{const o=document.createElement("script");o.type="text/javascript",o.src=s.script,o.onload=function(){u()},o.onerror=function(){throw new Error(`CompetitionLabs widget script failed to load: ${s.script}`)},document.body.appendChild(o)}},this.getWidgetData=function(t){const e=this,n=`${e.settings.uri.gatewayDomain}${e.settings.uri.widgetData.replace(":space",e.settings.spaceName)}?status=${e.settings.widgetStatus}`;e.ajax.abort().getData({type:"GET",url:n,headers:{"X-API-KEY":e.settings.apiKey},success:function(c,s,m){if(m.status===200){const d=JSON.parse(c);e.initialiseWidget(d),typeof t=="function"&&t(d)}},error:function(){typeof t=="function"&&t()}})},this.init=function(t){const e=this;console.log("Initting Data"),e.getWidgetData(t)}};window.clLoaderV3=new a})()})();
|