3 lines
6.2 KiB
JavaScript
3 lines
6.2 KiB
JavaScript
function receiveSettings(t){if(t.origin===location.origin)return receiveInternalData(t);if(t.origin!==trustpilot_integration_app_url)return;const e=t.data;if("string"==typeof e)if(e.startsWith("sync:")){const t=e.split(":"),s={action:"sync_past_orders"};s[t[0]]=t[1],this.submitPastOrdersCommand(s)}else if(e.startsWith("resync")){const t={action:"resync_past_orders",resync:"resync"};this.submitPastOrdersCommand(t)}else if(e.startsWith("issynced")){const t={action:"is_past_orders_synced",issynced:"issynced"};this.submitPastOrdersCommand(t)}else if(e.startsWith("showPastOrdersInitial:")){const t=e.split(":"),s={action:"show_past_orders_initial"};s[t[0]]=t[1],this.submitPastOrdersCommand(s)}else if(e.startsWith("check_product_skus")){const t=e.split(":"),s={action:"check_product_skus"};s.skuSelector=t[1],this.submitCheckProductSkusCommand(s)}else"update"===e?this.updateplugin():"reload"===e?this.reloadSettings():this.handleJSONMessage(e)}function receiveInternalData(t){const e=t.data,s={};e&&"string"==typeof e&&tryParseJson(e,s)&&("newTrustBox"!=s.type&&"updatePageUrls"!==s.type||submitSettings(s),"loadCategoryProductInfo"===s.type&&requestCategoryInfo())}function handleJSONMessage(t){const e={};if(tryParseJson(t,e))if(e.TrustBoxPreviewMode)this.trustBoxPreviewMode(e);else if(e.window)this.updateIframeSize(e);else if("submit"===e.type)this.submitSettings(e);else if(e.trustbox){document.getElementById("trustbox_preview_frame").contentWindow.postMessage(JSON.stringify(e.trustbox),"*")}}function requestCategoryInfo(){const t=new XMLHttpRequest;t.open("POST",trustpilot_ajax_url),t.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),t.onreadystatechange=function(){4===t.readyState&&(t.status>=400?console.log(`callback error: ${t.response} ${t.status}`):window.postMessage(t.response,window.origin))};const e={action:"get_category_product_info",products:JSON.stringify(list.products.map(t=>t.id_product)),controller:controller,user_id:user_id};t.send("settings="+btoa(encodeSettings(e)))}function trustBoxPreviewMode(t){const e=document.getElementById("trustpilot-trustbox-preview");t.TrustBoxPreviewMode.enable?e.hidden=!1:e.hidden=!0}function submitPastOrdersCommand(t){const e=new XMLHttpRequest;e.open("POST",trustpilot_ajax_url),e.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),e.onreadystatechange=function(){4===e.readyState&&(e.status>=400?console.log(`callback error: ${e.response} ${e.status}`):sendPastOrdersInfo(e.response))},t.token=token,t.controller=controller,t.user_id=user_id,t.context_scope=context_scope,e.send("settings="+btoa(encodeSettings(t)))}function submitCheckProductSkusCommand(t){const e=new XMLHttpRequest;e.open("POST",trustpilot_ajax_url),e.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),e.onreadystatechange=function(){if(4===e.readyState)if(e.status>=400)console.log(`callback error: ${e.response} ${e.status}`);else{const t=document.getElementById("configuration_iframe");t.contentWindow.postMessage(e.response,t.dataset.transfer)}},t.token=token,t.controller=controller,t.user_id=user_id,t.context_scope=context_scope,e.send("settings="+btoa(encodeSettings(t)))}function updateplugin(){const t={action:"update_trustpilot_plugin",token:token,controller:controller,user_id:user_id,context_scope:context_scope},e=new XMLHttpRequest;e.open("POST",trustpilot_ajax_url),e.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),e.send("settings="+btoa(encodeSettings(t)))}function reloadSettings(){const t={action:"reload_trustpilot_settings",token:token,controller:controller,user_id:user_id,context_scope:context_scope},e=new XMLHttpRequest;e.open("POST",trustpilot_ajax_url),e.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),e.onreadystatechange=function(){if(4===e.readyState)if(e.status>=400)console.log(`callback error: ${e.response} ${e.status}`);else{const t=document.getElementById("configuration_iframe").dataset.pluginVersion;JSON.parse(e.response).pluginVersion!==t&&window.location.reload(!0)}},e.send("settings="+btoa(encodeSettings(t)))}function sendPastOrdersInfo(t){const e=document.getElementById("configuration_iframe"),s=e.dataset;void 0===t&&(t=s.pastOrders),e.contentWindow.postMessage(t,s.transfer)}function submitSettings(t){const e={action:"save_changes",token:token,controller:controller,user_id:user_id,context_scope:context_scope};"updatePageUrls"===t.type?e.pageUrls=encodeURIComponent(JSON.stringify(t.pageUrls)):"newTrustBox"===t.type?e.customTrustboxes=encodeURIComponent(JSON.stringify(t)):(e.settings=encodeURIComponent(JSON.stringify(t.settings)),document.getElementById("trustbox_preview_frame").dataset.settings=btoa(e.settings));const s=new XMLHttpRequest;s.open("POST",trustpilot_ajax_url),s.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),s.send("settings="+btoa(encodeSettings(e)))}function encodeSettings(t){let e="";for(const s in t)e+=s+"="+t[s]+"&";return e.substring(0,e.length-1)}function updateIframeSize(t){const e=document.getElementById("configuration_iframe");e&&(e.height=t.window.height+"px")}function sendSettings(){const t=document.getElementById("configuration_iframe"),e=t.dataset,s=JSON.parse(atob(e.settings));if(s.trustbox||(s.trustbox={}),s.trustbox.pageUrls=JSON.parse(atob(e.pageUrls)),s.pluginVersion=e.pluginVersion,s.source=e.source,s.version=e.version,s.basis="plugin",s.productIdentificationOptions=JSON.parse(e.productIdentificationOptions),s.isFromMarketplace=e.isFromMarketplace,s.configurationScopeTree=JSON.parse(atob(e.configurationScopeTree)),s.trustbox.trustboxes&&e.sku)for(trustbox of s.trustbox.trustboxes)trustbox.sku=e.sku;if(s.trustbox.trustboxes&&e.name)for(trustbox of s.trustbox.trustboxes)trustbox.name=e.name;t.contentWindow.postMessage(JSON.stringify(s),e.transfer)}function getTokenAndController(){const t=window.location.search.substring(1).split("&");for(i=0;i<t.length;i++){const e=t[i].split("=");"token"===e[0]&&"undefined"==typeof token&&(token=e[1]),"controller"===e[0]&&"undefined"==typeof controller&&(controller=e[1])}"undefined"!=typeof help_class_name&&(controller=help_class_name)}function tryParseJson(t,e){try{e=Object.assign(e,JSON.parse(t))}catch(t){return!1}return!0}window.addEventListener("message",this.receiveSettings),getTokenAndController();
|
|
//# sourceMappingURL=tp_admin.min.js.map
|