1(function () { 2 "use strict"; 3 4 /** 5 * All of the code for your public-facing JavaScript source 6 * should reside in this file. 7 * 8 * Note: It has been assumed you will write jQuery code here, so the 9 * $ function reference has been prepared for usage within the scope 10 * of this function. 11 * 12 * This enables you to define handlers, for when the DOM is ready: 13 * 14 * $(function() { 15 * 16 * }); 17 * 18 * When the window is loaded: 19 * 20 * $( window ).load(function() { 21 * 22 * }); 23 * 24 * ...and/or other possibilities. 25 * 26 * Ideally, it is not considered best practise to attach more than a 27 * single DOM-ready or window-load handler for a particular page. 28 * Although scripts in the WordPress core, Plugins and Themes may be 29 * practising this, we should strive to set a better example in our own work. 30 */ 31 window.addEventListener("load", function () { 32 function camelCaseToDash(myStr) { 33 return myStr.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(); 34 } 35 36 if ( 37 !lc_public_js || 38 !lc_public_js.text_widget_location_id || 39 lc_public_js.text_widget_error == "1" 40 ) { 41 console.error( 42 "invalid API key or location ID, please provide correct API key and resave it under LeadConnector setting menu" 43 ); 44 return; 45 } 46 47 var textWidget = document.createElement("chat-widget"); 48 textWidget.setAttribute( 49 "location-id", 50 lc_public_js.text_widget_location_id 51 ); 52 if ( 53 !!lc_public_js.text_widget_settings && 54 !!(lc_public_js.text_widget_settings instanceof Object) 55 ) { 56 var textWidgetSettings = lc_public_js.text_widget_settings; 57 var allAttrs = Object.keys(textWidgetSettings); 58 59 for (var attrIndex = allAttrs.length - 1; attrIndex >= 0; attrIndex--) { 60 try { 61 var attributeName = allAttrs[attrIndex]; 62 attributeName = camelCaseToDash(attributeName); 63 var attributeValue = textWidgetSettings[allAttrs[attrIndex]]; 64 if ("widget-primary-color" === attributeName) { 65 attributeName = "style"; 66 attributeValue = 67 "--chat-widget-primary-color:" + 68 attributeValue + 69 "; --chat-widget-active-color:" + 70 attributeValue + 71 " ;--chat-widget-bubble-color: " + 72 attributeValue; 73 } 74 } catch (e) { 75 console.log(e, "Fail to parse settings"); 76 continue; 77 } 78 79 textWidget.setAttribute(attributeName, attributeValue); 80 } 81 } else { 82 if (!!lc_public_js.text_widget_heading) { 83 textWidget.setAttribute("heading", lc_public_js.text_widget_heading); 84 } 85 if (!!lc_public_js.text_widget_sub_heading) { 86 textWidget.setAttribute( 87 "sub-heading", 88 lc_public_js.text_widget_sub_heading 89 ); 90 } 91 textWidget.setAttribute( 92 "use-email-field", 93 lc_public_js.text_widget_use_email_field == "1" ? "true" : "false" 94 ); 95 } 96 97 document.body.appendChild(textWidget); 98 99 if (!!lc_public_js.text_widget_cdn_base_url) { 100 setTimeout(() => { 101 if (!window.leadConnector || !window.leadConnector.chatWidget) { 102 try { 103 var moduleScript = document.createElement("script"); 104 var cdnURL = lc_public_js.text_widget_cdn_base_url; 105 moduleScript.src = cdnURL + "loader.js"; 106 moduleScript.setAttribute( 107 "data-cdn-url", 108 cdnURL.replace(/\/$/, "") 109 ); 110 document.body.appendChild(moduleScript); 111 } catch (err) { 112 console.warn(err); 113 } 114 } 115 }, 10 * 1000); 116 } 117 }); 118})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.