### Share to Grok AI (JavaScript) Source: https://www.nutrient.io/guides/maui/prebuilt-solutions/example-projects Opens a new browser tab with the Grok AI interface, initiating a conversation about the current documentation page. The pre-populated query asks Grok for assistance with the documentation's concepts, examples, and debugging. ```javascript function C(i) {\n const t = "https://www.nutrient.io",\n o = window.location.pathname,\n r = `I'm looking at this Nutrient documentation: ${`${t}${o}`} Help me understand how to use it. Be ready to explain concepts, give examples, or help debug based on it.`, \n s = `https://grok.com/c?q=${encodeURIComponent(r)}`;\n window.open(s, "_blank");\n} ``` -------------------------------- ### C# Example: Opening Document from Assets with Configuration (Nutrient MAUI SDK) Source: https://www.nutrient.io/guides/maui/migration-guides/maui-1-1-migration-guide Illustrates how to open a PDF document from the application's Assets folder using the `LoadDocumentFromAssetsAsync` method in Nutrient MAUI SDK. It shows the creation of a viewer configuration, setting the toolbar placement, and handling potential exceptions during the loading process. The `PSPDFKitController.CreateViewerConfiguration()` method is used to instantiate the configuration object. ```csharp string assetDocumentPath = "subFolder/document.pdf"; // Path to the document in the Assets folder. try{ var config = PSPDFKitController.CreateViewerConfiguration(); config.ToolbarPlacement = ToolbarPlacement.Bottom; await PSPDFKitController.LoadDocumentFromAssetsAsync(assetDocumentPath, config); } catch (Exception ex){ // Handle exception. } ``` -------------------------------- ### Share to ChatGPT (JavaScript) Source: https://www.nutrient.io/guides/maui/prebuilt-solutions/example-projects Opens a new browser tab with a ChatGPT chat interface pre-populated with a query related to the current documentation page. The query asks for assistance in understanding and using the documentation, including concepts, examples, and debugging. ```javascript function v(i) {\n const t = "https://www.nutrient.io",\n o = window.location.pathname,\n r = `I'm looking at this Nutrient documentation: ${`${t}${o}`} Help me understand how to use it. Be ready to explain concepts, give examples, or help debug based on it.`, \n s = `https://chatgpt.com/?q=${encodeURIComponent(r)}`;\n window.open(s, "_blank");\n} ``` -------------------------------- ### Open ChatGPT with Query (JavaScript) Source: https://www.nutrient.io/guides/maui/migration-guides/maui-1-1-migration-guide Opens a new browser tab with a pre-filled ChatGPT query. The query is constructed to ask for help understanding the current Nutrient IO documentation page, including its URL. This function is useful for users who want to quickly get AI assistance related to the documentation they are viewing. ```javascript function v(i){ const t="https://www.nutrient.io", o=window.location.pathname, r=`I'm looking at this Nutrient documentation: ${`${t}${o}`} Help me understand how to use it. Be ready to explain concepts, give examples, or help debug based on it.`, s=`https://chatgpt.com/?q=${encodeURIComponent(r)}`; window.open(s,"_blank") } ``` -------------------------------- ### JavaScript VWO Initialization and Script Loading Source: https://www.nutrient.io/guides/maui/user-interface/main-toolbar/activate-or-deactivate-tools This snippet details the VWO initialization process. It includes functions for loading scripts, retrieving settings, and initiating the VWO setup. The loading mechanism supports both XHR for fetching script content and direct script tag insertion. Error handling for network requests and expired settings is also implemented. Initialization is deferred to ensure it doesn't block page rendering. ```javascript (function() { var w = window; var d = document; var cK = "_vwo_config_"; var stT = localStorage; var account_id = 12345; var version = "1.0.0"; var code = { load: function(e, t) { var r = this; if (t.useXHR) { var o = new XMLHttpRequest; o.open('GET', e, true); o.withCredentials = !t.dSC; o.responseType = t.responseType || 'text'; o.onload = function() { if (t.onloadCb) { return t.onloadCb(o, e); } if (o.status === 200 || o.status === 304) { _vwo_code.addScript({ text: o.responseText }); } else { _vwo_code.finish('&e=loading_failure:' + e); } }; o.onerror = function() { if (t.onerrorCb) { return t.onerrorCb(e); } _vwo_code.finish('&e=loading_failure:' + e); }; o.send(); } else { this.addScript({ src: e }); } }, getSettings: function() { try { var e = stT.getItem(cK); if (!e) { return; } e = JSON.parse(e); if (Date.now() > e.e) { stT.removeItem(cK); return; } return e.s; } catch (e) { return; } }, init: function() { if (d.URL.indexOf('__vwo_disable__') > -1) return; var e = this.settings_tolerance(); w._vwo_settings_timer = setTimeout(function() { _vwo_code.finish(); stT.removeItem(cK); }, e); var o = window._vis_opt_url || d.URL, s = 'https://dev.visualwebsiteoptimizer.com/j.php?a=' + account_id + '&u=' + encodeURIComponent(o) + '&vn=' + version; if (w.location.search.indexOf('_vwo_xhr') !== -1) { this.addScript({ src: s }); } else { this.load(s + '&x=true'); } }, addScript: function(options) { var script = d.createElement('script'); if (options.src) { script.src = options.src; script.async = true; } if (options.text) { script.text = options.text; } d.body.appendChild(script); }, finish: function(e) { console.log('VWO finished: ', e || ''); } }; w._vwo_code = code; if (d.readyState === 'loading') { d.addEventListener('DOMContentLoaded', function() { code.init(); }); } else { if ('requestIdleCallback' in w) { requestIdleCallback(function() { code.init(); }, { timeout: 1000 }); } else { setTimeout(function() { code.init(); }, 0); } } })(); ``` -------------------------------- ### Open ChatGPT Query - JavaScript Source: https://www.nutrient.io/guides/maui/print Opens ChatGPT in a new tab with a pre-filled query related to the current documentation page. The query asks for help understanding and using the documentation, requesting explanations, examples, or debugging assistance. ```javascript function v(i){ const t="https://www.nutrient.io", o=window.location.pathname, r=`I'm looking at this Nutrient documentation: ${`${t}${o}`} Help me understand how to use it. Be ready to explain concepts, give examples, or help debug based on it.`,s=`https://chatgpt.com/?q=${encodeURIComponent(r)}`; window.open(s,"_blank") } ``` -------------------------------- ### Open ChatGPT for Context (JavaScript) Source: https://www.nutrient.io/guides/maui/intro Opens ChatGPT in a new tab with a pre-formatted query. The query includes the current documentation URL and a prompt asking for help understanding or debugging the documentation. ```javascript function v(i){ const t="https://www.nutrient.io", o=window.location.pathname, r=`I'm looking at this Nutrient documentation: ${`${t}${o}`} Help me understand how to use it. Be ready to explain concepts, give examples, or help debug based on it.`, s=`https://chatgpt.com/?q=${encodeURIComponent(r)}`; window.open(s,"_blank") } ``` -------------------------------- ### Open ChatGPT with Context - JavaScript Source: https://www.nutrient.io/guides/maui/json/schema/form-fields Opens ChatGPT in a new tab, pre-filled with a prompt that includes the current documentation URL and a request for assistance. This allows users to quickly get help related to the documentation they are viewing. ```javascript function v(i) { const t = "https://www.nutrient.io", o = window.location.pathname, r = `I'm looking at this Nutrient documentation: ${`${t}${o}`} Help me understand how to use it. Be ready to explain concepts, give examples, or help debug based on it.`,s = `https://chatgpt.com/?q=${encodeURIComponent(r)}`; window.open(s, "_blank") } ``` -------------------------------- ### Open Grok with Context (JavaScript) Source: https://www.nutrient.io/guides/maui/signatures/electronic-signatures Opens Grok.com in a new tab with a pre-filled query. The query includes the current Nutrient.io documentation URL and asks for help with understanding, examples, or debugging based on the provided documentation. ```javascript function C(i){ const t = "https://www.nutrient.io", o = window.location.pathname, r = `I'm looking at this Nutrient documentation: ${`${t}${o}`} Help me understand how to use it. Be ready to explain concepts, give examples, or help debug based on it.`; const s = `https://grok.com/c?q=${encodeURIComponent(r)}`; window.open(s, "_blank"); } ``` -------------------------------- ### Open ChatGPT with Context Source: https://www.nutrient.io/guides/maui/open-a-document Opens ChatGPT in a new tab, pre-filled with a prompt that includes the current documentation URL and a request for assistance. The prompt asks the AI to explain, provide examples, or help debug based on the documentation. ```javascript function v(i){ const t="https://www.nutrient.io", o=window.location.pathname, r=`I'm looking at this Nutrient documentation: ${`${t}${o}`} Help me understand how to use it. Be ready to explain concepts, give examples, or help debug based on it.`; s=`https://chatgpt.com/?q=${encodeURIComponent(r)}`; window.open(s,"_blank") } ``` -------------------------------- ### C# SDK Annotation Example Source: https://www.nutrient.io/guides/maui/annotations/instant-json Example demonstrating how to create and convert an annotation object to JSON using the C# SDK. ```APIDOC ## C# SDK Annotation Generation ### Description This code snippet shows how to use the PSPDFKit SDK in C# to create a `Line` annotation, set its properties, and then convert it to its JSON representation. ### Method SDK Method Call ### Endpoint N/A (SDK specific) ### Parameters N/A (SDK specific) ### Request Example ```csharp var annotation = _annotationManager.AnnotationFactory.CreateAnnotation(); annotation.StartPoint = new System.Drawing.PointF(10, 10); annotation.EndPoint = new System.Drawing.PointF(100, 100); annotation.BoundingBox = new Sdk.Models.Geometry.Rectangle() { Left = 0, Top = 0, Width = 100, Height = 100 }; var annotationJson = annotation.ToJson(); ``` ### Response #### Success Response - **annotationJson** (string) - The generated JSON string of the annotation. #### Response Example ```json { "startPoint": [10, 10], "endPoint": [100, 100], "strokeColor": "#2293FB", "strokeWidth": 5, "blendMode": "normal", "bbox": [0, 0, 100, 100], "createdAt": "2024-02-09T10:21:17.1203525+00:00", "opacity": 1, "pageIndex": 0, "updatedAt": "2024-02-09T10:21:17.1203525+00:00", "v": 2, "type": "pspdfkit/shape/line" } ``` ``` -------------------------------- ### Share to Claude AI (JavaScript) Source: https://www.nutrient.io/guides/maui/prebuilt-solutions/example-projects Opens a new browser tab with the Claude AI interface, pre-filled with a query about the current documentation page. Similar to the ChatGPT function, it prompts Claude to help understand and use the documentation. ```javascript function x(i) {\n const t = "https://www.nutrient.io",\n o = window.location.pathname,\n r = `I'm looking at this Nutrient documentation: ${`${t}${o}`} Help me understand how to use it. Be ready to explain concepts, give examples, or help debug based on it.`, \n s = `https://claude.ai/new?q=${encodeURIComponent(r)}`;\n window.open(s, "_blank");\n} ``` -------------------------------- ### Start Local Server for Document Export (Python) Source: https://www.nutrient.io/guides/maui/save-a-document/to-remote-server This Python script, `exportServer.py`, is used to start a local server, facilitating the export of documents to a remote server. Users need to install Python and then run the script from the terminal. The server can then be accessed using `localhost:5000` as the server path for saving documents. ```python # Assuming exportServer.py is in Resources/Server/ # To start the server: # 1. Install Python (https://www.python.org/downloads/) # 2. Run the server using the 'python exportServer.py' command. # Then use 'localhost:5000' as the server path. ``` -------------------------------- ### Deserialize Annotation from JSON (C#) Source: https://www.nutrient.io/guides/maui/annotations/instant-json Example C# code demonstrating how to deserialize an annotation object from a JSON string using Newtonsoft.Json.Linq.JObject and the PSPDFKit API. ```csharp var annotation = _annotationFactory.CreateAnnotation(JObject.Parse(annotationJson)); ``` -------------------------------- ### Open Document from Array Buffer in C# Source: https://www.nutrient.io/guides/maui/open-a-document/from-arraybuffer This C# example illustrates how to load a PDF document into the PDFView control using a byte array. It assumes the document has already been read into a byte array variable named `documentAsBuffer`. ```csharp byte[] documentAsBuffer = /* document read as byte array */; ``` -------------------------------- ### VWO Script Loading and Initialization (JavaScript) Source: https://www.nutrient.io/guides/maui/prebuilt-solutions/example-projects This snippet demonstrates how VWO loads scripts and initializes its tracking. It uses `XMLHttpRequest` for asynchronous script loading and handles different scenarios like `onload` and `onerror` events. The `init` function orchestrates the loading process, including fetching settings and constructing the script URL. ```javascript var code = { settings_tolerance: function() { var e = stT.getItem(cK); if (!e) { return 10000; } try { e = JSON.parse(e); } catch (t) { return 10000; } return e.s; }, addScript: function(t) { if (t.text) { var script = d.createElement('script'); script.type = 'text/javascript'; try { script.appendChild(d.createTextNode(t.text)); } catch (e) { script.text = t.text; } d.head.appendChild(script); } else { var script = d.createElement('script'); script.type = 'text/javascript'; script.src = t.src; script.async = false; d.head.appendChild(script); } }, load: function(e, t) { if (t.useXHR) { var o = new XMLHttpRequest(); o.open('GET', e, true); o.withCredentials = !t.dSC; o.responseType = t.responseType || 'text'; o.onload = function() { if (t.onloadCb) { return t.onloadCb(o, e); } if (o.status === 200 || o.status === 304) { _vwo_code.addScript({ text: o.responseText }); } else { _vwo_code.finish('&e=loading_failure:' + e); } }; o.onerror = function() { if (t.onerrorCb) { return t.onerrorCb(e); } _vwo_code.finish('&e=loading_failure:' + e); }; o.send(); } else { this.addScript({ src: e }); } }, getSettings: function() { try { var e = stT.getItem(cK); if (!e) { return; } e = JSON.parse(e); if (Date.now() > e.e) { stT.removeItem(cK); return; } return e.s; } catch (e) { return; } }, init: function() { if (d.URL.indexOf('__vwo__disable__') > -1) return; var e = this.settings_tolerance(); w._vwo_settings_timer = setTimeout(function() { _vwo_code.finish(); stT.removeItem(cK); }, e); var o = window._vis_opt_url || d.URL, s = 'https://dev.visualwebsiteoptimizer.com/j.php?a=' + account_id + '&u=' + encodeURIComponent(o) + '&vn=' + version; if (w.location.search.indexOf('_vwo_xhr') !== -1) { this.addScript({ src: s }); } else { this.load(s + '&x=true'); } } }; w._vwo_code = code; if (d.readyState === 'loading') { d.addEventListener('DOMContentLoaded', function() { code.init(); }); } else { if ('requestIdleCallback' in w) { requestIdleCallback(function() { code.init(); }, { timeout: 1000 }); } else { setTimeout(function() { code.init(); }, 0); } } })(); ``` -------------------------------- ### Open ChatGPT with Context (JavaScript) Source: https://www.nutrient.io/guides/maui/conversion/to-pdfa Opens ChatGPT in a new tab, pre-populated with a query related to the current Nutrient.io documentation page. The query asks for help understanding and using the documentation, indicating readiness to explain concepts, provide examples, or debug. The URL is constructed using `encodeURIComponent` for the query parameter. ```javascript function v(i){ const t="https://www.nutrient.io", o=window.location.pathname, r=`I'm looking at this Nutrient documentation: ${`${t}${o}`} Help me understand how to use it. Be ready to explain concepts, give examples, or help debug based on it.`; const s=`https://chatgpt.com/?q=${encodeURIComponent(r)}`; window.open(s,"_blank") } ``` -------------------------------- ### Open Claude AI with Context (JavaScript) Source: https://www.nutrient.io/guides/maui/annotations/instant-json Opens Claude AI in a new tab with a pre-filled prompt similar to the ChatGPT function. It includes the current documentation URL and requests assistance, enabling users to get contextual help from Claude. ```javascript function x(i){ const t="https://www.nutrient.io", o=window.location.pathname, r=`I'm looking at this Nutrient documentation: ${`${t}${o}`} Help me understand how to use it. Be ready to explain concepts, give examples, or help debug based on it.`,s=`https://claude.ai/new?q=${encodeURIComponent(r)}`; window.open(s,"_blank") } ``` -------------------------------- ### Initialize VWO Script Source: https://www.nutrient.io/guides/maui/prebuilt-solutions/example-projects This JavaScript code block initializes the Visual Website Optimizer (VWO) tracking script. It sets up configuration variables such as account ID, version, and settings tolerance. It also includes logic for handling stored settings and defines functions for adding scripts and loading settings, preparing the environment for A/B testing or other VWO features. ```javascript window._vwo_code || (function() { var account_id = 892495, version = 2.1, settings_tolerance = 2000, hide_element = '', // Don't hide body to prevent flash hide_element_style = '', /* DO NOT EDIT BELOW THIS LINE */ f = false, w = window, d = document, v = d.querySelector('#vwoCode'), cK = '_vwo_' + account_id + '_settings', cc = {}; try { var c = JSON.parse(localStorage.getItem('_vwo_' + account_id + '_config')); cc = c && typeof c === 'object' ? c : {}; } catch (e) {} var stT = cc.stT == 'session' ? w.sessionStorage : w.localStorage; code = { nonce: v && v.nonce, library_tolerance: function() { return typeof library_tolerance !== 'undefined' ? library_tolerance : undefined; }, settings_tolerance: function() { return cc.sT || settings_tolerance; }, hide_element_style: function() { return '{' + (cc.hES || hide_element_style) + '}'; }, hide_element: function() { // Always return empty to prevent hiding return ''; }, getVersion: function() { return version; }, finish: function(e) { if (!f) { f = true; var t = d.getElementById('_vis_opt_path_hides'); if (t) t.parentNode.removeChild(t); if (e) (new Image).src = 'https://dev.visualwebsiteoptimizer.com/ee.gif?a=' + account_id + e; } }, finished: function() { return f; }, addScript: function(e) { var t = d.createElement('script'); t.type = 'text/javascript'; if (e.src) { t.src = e.src; t.async = true; // Make async } else { t.text = e.text; } v && t.setAttribute('nonce', v.nonce); d.getElementsByTagName('head')[0].appendChild(t); }, load: function(e, t) { var n = this.getSettings(), i = d.createElement('script'), r = this; t = t || {}; if (n) { i.textContent = n; d.getElementsByTagName('head')[0].appendChild(i); if (!w.VWO || VWO.caE) stT.removeI ``` -------------------------------- ### Generate Annotation JSON using C# SDK Source: https://www.nutrient.io/guides/maui/annotations/instant-json Demonstrates how to create a line annotation object using the PSPDFKit SDK in C# and convert it to its JSON representation. This involves setting properties like start and end points, bounding box, and color before calling the ToJson() method. ```csharp var annotation = _annotationManager.AnnotationFactory.CreateAnnotation(); annotation.StartPoint = new System.Drawing.PointF(10, 10); annotation.EndPoint = new System.Drawing.PointF(100, 100); annotation.BoundingBox = new Sdk.Models.Geometry.Rectangle() { Left = 0, Top = 0, Width = 100, Height = 100 }; var annotationJson = annotation.ToJson(); ``` ```json { "startPoint": [10, 10], "endPoint": [100, 100], "strokeColor": "#2293FB", "strokeWidth": 5, "blendMode": "normal", "bbox": [0, 0, 100, 100], "createdAt": "2024-02-09T10:21:17.1203525+00:00", "opacity": 1, "pageIndex": 0, "updatedAt": "2024-02-09T10:21:17.1203525+00:00", "v": 2, "type": "pspdfkit/shape/line" } ``` -------------------------------- ### Configure and Load Nutrient AI Widget (JavaScript) Source: https://www.nutrient.io/guides/maui/troubleshooting/what-is-a-bundle-id This JavaScript code dynamically creates and configures a Kapa.ai chat widget. It sets various attributes to customize the widget's appearance, behavior, and integration with the Nutrient platform, including disclaimer messages and example questions specific to the current page context. ```javascript const n = { paths: { workflowPaths: ["/workflow-automation", "/guides/workflow-automation"], lowCodePaths: ["/low-code", "/guides/low-code", "/guides/document-converter", "/guides/document-editor", "/guides/document-searchability", "/guides/document-automation-server/"] }, workflow: { modalDisclaimer: "This is a custom LLM for Nutrient with access to product information, the help center, as well as other resources. For best results please mention the product name when asking technical questions.", exampleQuestions: "What types of Workflow templates are available?,How to create a Workflow Form?" }, lowCode: { modalDisclaimer: "This is a custom LLM for Nutrient with access to product information, the help center, as well as other resources. For best results please mention the product name when asking technical questions.", exampleQuestions: "Convert Documents to PDF with Power Automate?, How to secure Documents using Power Automate?" }, default: { modalDisclaimer: "This is a custom LLM for Nutrient with access to product information, [guides]((https://www.nutrient.io/sdk/developers)), API reference as well as other resources. For best results please mention the product name when asking technical questions.", exampleQuestions: "How do I get started with the Web SDK?,What AI features does Nutrient offer?" } }; function d() { const a = window.location.pathname; const t = Object.entries(n.paths).find(([o, r]) => r.some(s => a.startsWith(s))); const e = t ? t[0].replace("Paths", "") : "default"; return e === "workflow" ? n.workflow : e === "lowCode" ? n.lowCode : n.default; } function u() { const a = d(); const t = document.createElement("script"); t.async = !0; t.src = "https://widget.kapa.ai/kapa-widget.bundle.js"; t.setAttribute("data-website-id", "ec76a086-c5ce-409a-91bb-bee358fdb208"); t.setAttribute("data-project-color", "#1A1414"); t.setAttribute("data-text-color", "#1A1414"); t.setAttribute("data-modal-override-open-id", "nutrient-sdk-docs-ai"); t.setAttribute("data-button-hide", "false"); t.setAttribute("data-modal-open-by-default", "true"); t.setAttribute("data-user-analytics-fingerprint-enabled", "true"); t.setAttribute("data-project-name", "Nutrient"); t.setAttribute("data-modal-title", "Nutrient AI"); t.setAttribute("data-modal-disclaimer", a.modalDisclaimer); t.setAttribute("data-modal-example-questions", a.exampleQuestions); t.setAttribute("data-modal-disclaimer-bg-color", "#EFEBE7"); t.setAttribute("data-modal-disclaimer-text-color", "#67594B"); t.setAttribute("data-modal-disclaimer-font-size", "14px"); t.setAttribute("data-modal-disclaimer-padding", "0.875rem"); t.setAttribute("data-query-input-font-size", "1rem"); t.setAttribute("data-query-input-text-color", "#1A1414"); t.setAttribute("data-query-input-placeholder-text-color", "#67594B"); t.setAttribute("data-query-input-border-color", "#1A1414"); t.setAttribute("data-query-input-focus-border-color", "#DE9DCC"); t.setAttribute("data-submit-query-button-bg-color", "#1A1414"); t.setAttribute("data-example-question-button-height", "40px"); t.setAttribute("data-example-question-button-padding-x", "1.5rem"); t.setAttribute("data-example-question-button-padding-y", "0.75rem"); t.setAttribute("data-example-question-button-border", "1px solid #C2B8AE !important"); t.setAttribute("data-example-question-button-border-radius", "8px"); t.setAttribute("data-example-question-button-text-color", "#1A1414"); t.setAttribute("data-example-question-button-box-shadow", "none"); t.setAttribute("data-example-question-button-font-size", "0.875rem"); t.setAttribute("data-example-question-button-hover-bg-color", "#EFEBE7"); t.setAttribute("data-modal-z-index", "999999"); t.setAttribute("data-modal-border-radius", "1.5rem"); t.setAttribute("data-modal-header-bg-color", "#DE9DCC"); t.setAttribute("data-modal-header-border-bottom", "none"); t.setAttribute("data-modal-header-padding", "1.5rem"); t.setAttribute("data-modal-title-font-weight", "400"); t.setAttribute("data-modal-title-font-size", "1.5rem"); t.setAttribute("data-modal-title-color", "#1A1414"); t.setAttribute("data-button-text", "ASK AI"); t.setAttribute("data-button-height", "5rem"); t.setAttribute("data-button-width", "5rem"); t.setAttribute("data-button-bg-color", "#1A1414"); t.setAttribute("data-button-border-radius", "1rem"); t.setAttribute("data-button-text-shadow", "none"); t.setAttribute("data-button-text-font-weight", "400"); t.setAttribute("data-button-text-font-size", "0.75rem"); t.setAttribute("data-button-image-height", "1.5rem"); t.setAttribute("data-button-image-width", "1.5rem"); t.setAttribute("data-thread-clear-button-height", "40px"); t.setAttribute("data-thread-clear-button-padding-x", "16px"); t.setAttribute("data-thread-clear-button-padding-y", "8px"); t.setAttribute("data-thread-clear-button-border", "none"); t.setAttribute("data-thread-clear-button-border-radius", "8px"); t.setAttribute("data-thread-clear-button-bg-color", "#EFEBE7"); t.setAttribute("data-thread-clear-button-hover-bg-color", "#E2DBD9"); t.setAttribute("data-thread-clear-button-text-color", "#1A1414"); t.setAttribute("data-thread-clear-button-font-size", "12px"); t.setAttribute("data-thread-clear-button-icon-size", "24px"); document.body.appendChild(t); } u(); ``` -------------------------------- ### Configure Nutrient AI Widget Script Source: https://www.nutrient.io/guides/maui/json Dynamically creates and configures a script element to load the Kapa.ai widget. It sets various attributes for customization, including website ID, project colors, modal behavior, disclaimer text, and example questions, all based on the current page's context. ```javascript function d(){ const a=window.location.pathname, t=Object.entries(n.paths).find(( [o,r] )=>r.some(s=>a.startsWith(s))), e=t?t[0].replace("Paths",""):"default"; return e==="workflow"?n.workflow:e==="lowCode"?n.lowCode:n.default } function u(){ const a=d(), t=document.createElement("script"); t.async=!0, t.src="https://widget.kapa.ai/kapa-widget.bundle.js", t.setAttribute("data-website-id","ec76a086-c5ce-409a-91bb-bee358fdb208"), t.setAttribute("data-project-color","#1A1414"), t.setAttribute("data-text-color","#1A1414"), t.setAttribute("data-modal-override-open-id","nutrient-sdk-docs-ai"), t.setAttribute("data-button-hide","false"), t.setAttribute("data-modal-open-by-default","true"), t.setAttribute("data-user-analytics-fingerprint-enabled","true"), t.setAttribute("data-project-name","Nutrient"), t.setAttribute("data-modal-title","Nutrient AI"), t.setAttribute("data-modal-disclaimer",a.modalDisclaimer), t.setAttribute("data-modal-example-questions",a.exampleQuestions), t.setAttribute("data-modal-disclaimer-bg-color","#EFEBE7"), t.setAttribute("data-modal-disclaimer-text-color","#67594B"), t.setAttribute("data-modal-disclaimer-font-size","14px"), t.setAttribute("data-modal-disclaimer-padding","0.875rem"), t.setAttribute("data-query-input-font-size","1rem"), t.setAttribute("data-query-input-text-color","#1A1414"), t.setAttribute("data-query-input-placeholder-text-color","#67594B"), t.setAttribute("data-query-input-border-color","#1A1414"), t.setAttribute("data-query-input-focus-border-color","#DE9DCC"), t.setAttribute("data-submit-query-button-bg-color","#1A1414"), t.setAttribute("data-example-question-button-height","40px"), t.setAttribute("data-example-question-button-padding-x","1.5rem"), t.setAttribute("data-example-question-button-padding-y","0.75rem"), t.setAttribute("data-example-question-button-border","1px solid #C2B8AE !important"), t.setAttribute("data-example-question-button-border-radius","8px"), t.setAttribute("data-example-question-button-text-color","#1A1414"), t.setAttribute("data-example-question-button-box-shadow","none"), t.setAttribute("data-example-question-button-font-size","0.875rem"), t.setAttribute("data-example-question-button-hover-bg-color","#EFEBE7"), t.setAttribute("data-modal-z-index","999999"), t.setAttribute("data-modal-border-radius","1.5rem"), t.setAttribute("data-modal-header-bg-color","#DE9DCC"), t.setAttribute("data-modal-header-border-bottom","none"), t.setAttribute("data-modal-header-padding","1.5rem"), t.setAttribute("data-modal-title-font-weight","400"), t.setAttribute("data-modal-title-font-size","1.5rem"), t.setAttribute("data-modal-title-color","#1A1414"), t.setAttribute("data-button-text","ASK AI"), t.setAttribute("data-button-height","5rem"), t.setAttribute("data-button-width","5rem"), t.setAttribute("data-button-bg-color","#1A1414"), t.setAttribute("data-button-border-radius","1rem"), t.setAttribute("data-button-text-shadow","none"), t.setAttribute("data-button-text-font-weight","400"), t.setAttribute("data-button-text-font-size","0.75rem"), t.setAttribute("data-button-image-height","1.5rem"), t.setAttribute("data-button-image-width","1.5rem"), t.setAttribute("data-thread-clear-button-height","40px"), t.setAttribute("data-thread-clear-button-padding-x","16px"), t.setAttribute("data-thread-clear-button-padding-y","8px"), t.setAttribute("data-thread-clear-button-border","none"), t.setAttribute("data-thread-clear-button-border-radius","8px"), t.setAttribute("data-thread-clear-button-bg-color","#EFEBE7"), t.setAttribute("data-thread-clear-button-hover-bg-color","#E2DBD9"), t.setAttribute("data-thread-clear-button-text-color","#1A1414"), t.setAttribute("data-thread-clear-button-font-size","12px"), t.setAttribute("data-thread-clear-button-icon-size","24px"); document.body.appendChild(t) } ``` -------------------------------- ### VWO Initialization and Script Loading (JavaScript) Source: https://www.nutrient.io/guides/maui/annotations/create-edit-and-remove/create This snippet initializes VWO by fetching settings, constructing the VWO script URL, and loading it. It handles different browser environments and DOM readiness states. Dependencies include `account_id` and `version` which should be defined elsewhere. It outputs by potentially executing VWO's functionality on the page. ```javascript (function() { var d = document; var w = window; var cK = "_vwo_config_"; var stT = window.localStorage; var _vwo_code = window._vwo_code || {}; var account_id = 12345; // Replace with actual account ID var version = "2.0"; // Replace with actual version var code = { settings_tolerance: function() { var e = stT.getItem(cK); if (!e) { return 30000; } try { e = JSON.parse(e); if (Date.now() > e.e) { stT.removeItem(cK); return 30000; } return e.t; } catch (e) { return 30000; } }, addScript: function(t) { var e = d.createElement('script'); e.async = true; if (t.text) { e.textContent = t.text; } else { e.src = t.src; } d.body.appendChild(e); }, load: function(e, t) { t = t || {}; if (t.useXHR) { var o = new XMLHttpRequest(); o.open('GET', e, true); o.withCredentials = !t.dSC; o.responseType = t.responseType || 'text'; o.onload = function() { if (t.onloadCb) { return t.onloadCb(o, e); } if (o.status === 200 || o.status === 304) { _vwo_code.addScript({ text: o.responseText }); } else { _vwo_code.finish('&e=loading_failure:' + e); } }; o.onerror = function() { if (t.onerrorCb) { return t.onerrorCb(e); } _vwo_code.finish('&e=loading_failure:' + e); }; o.send(); } else { this.addScript({ src: e }); } }, getSettings: function() { try { var e = stT.getItem(cK); if (!e) { return; } e = JSON.parse(e); if (Date.now() > e.e) { stT.removeItem(cK); return; } return e.s; } catch (e) { return; } }, init: function() { if (d.URL.indexOf('__vwo_disable__') > -1) return; var e = this.settings_tolerance(); w._vwo_settings_timer = setTimeout(function() { _vwo_code.finish(); stT.removeItem(cK); }, e); var o = window._vis_opt_url || d.URL, s = 'https://dev.visualwebsiteoptimizer.com/j.php?a=' + account_id + '&u=' + encodeURIComponent(o) + '&vn=' + version; if (w.location.search.indexOf('_vwo_xhr') !== -1) { this.addScript({ src: s }); } else { this.load(s + '&x=true'); } } }; w._vwo_code = code; // Defer initialization to prevent render blocking if (d.readyState === 'loading') { d.addEventListener('DOMContentLoaded', function() { code.init(); }); } else { // If DOM is already loaded, use requestIdleCallback or setTimeout if ('requestIdleCallback' in w) { requestIdleCallback(function() { code.init(); }, { timeout: 1000 }); } else { setTimeout(function() { code.init(); }, 0); } } })(); ``` -------------------------------- ### Markdown Actions Toggle (JavaScript) Source: https://www.nutrient.io/guides/maui/migration-guides/maui-1-1-migration-guide Handles the functionality for toggling the visibility and accessibility of markdown action menus. It adds click and keydown event listeners to elements that trigger these menus (identified by IDs starting with 'markdown-actions-container-'). It manages ARIA attributes for expanded states and focuses on the first option when the menu opens. ```javascript function I(){ document.querySelectorAll('[id^="markdown-actions-container-"]').forEach(t=>{ const o=t.getAttribute("aria-controls"); if(!o)return; const e=document.getElementById(o), r=t.querySelector(".arrow-dropdown-icon"); if(!e)return; t.addEventListener("click",function(n){ n.stopPropagation(), t.getAttribute("aria-expanded")==="true"?s():a() }), t.addEventListener("keydown",function(n){ if(n.key==="Enter"||n.key===" ")n.preventDefault(), t.getAttribute("aria-expanded")==="true"?s():a(); else if(n.key==="ArrowDown"){ n.preventDefault(), a(); const c=e.querySelector(".markdown-actions-option"); c&&c.focus() }}), e.addEventListener("click",function(n){ n.target.closest(".markdown-actions-option")&&(n.preventD ``` -------------------------------- ### Open Markdown File (JavaScript) Source: https://www.nutrient.io/guides/maui/prebuilt-solutions/example-projects Opens the raw markdown file of the current page in a new browser tab. It constructs the URL by appending '.md' to the current path, ensuring the user can view the source content directly. ```javascript function k(i) {\n const t = window.location.pathname,\n e = `${t.endsWith(\"/\") ? t.slice(0, -1) : t}.md`;\n window.open(e, "_blank");\n} ``` -------------------------------- ### Open Claude AI with Context - JavaScript Source: https://www.nutrient.io/guides/maui/migration-guides/maui-1-2-migration-guide Opens Claude AI in a new tab, pre-populated with a query based on the current Nutrient documentation page. The query prompts Claude to explain or debug the documentation content. It constructs the URL with encoded query parameters. ```javascript function x(i){ const t="https://www.nutrient.io", o=window.location.pathname, r=`I'm looking at this Nutrient documentation: ${`${t}${o}`} Help me understand how to use it. Be ready to explain concepts, give examples, or help debug based on it.`; s=`https://claude.ai/new?q=${encodeURIComponent(r)}`; window.open(s, "_blank") } ``` -------------------------------- ### VWO Script Initialization and Loading Logic Source: https://www.nutrient.io/guides/maui/conversion/to-pdfa This JavaScript snippet details the core logic for initializing the VWO tracking script. It includes functions for loading settings from local storage, making HTTP requests (using `XMLHttpRequest`), and handling the response to either add the script or report a loading failure. The `init` function orchestrates the loading process, considering query parameters and deferring execution to prevent render blocking. ```javascript var code = { settings_tolerance: function() { var e = stT.getItem(cK); if (!e) { return 300000 } try { e = JSON.parse(e); if (Date.now() > e.e) { return 300000 } return e.s } catch (e) { return 300000 } }, addScript: function(t) { var e = d.createElement('script'); if (t.src) { e.src = t.src } if (t.text) { e.text = t.text } d.body.appendChild(e) }, load: function(e, t) { t = t || {}; if (stT.getItem(cK)) { var r = JSON.parse(stT.getItem(cK)); if (r.s) { this.addScript({ text: r.s }); r.e = Date.now() + 1000 * 60 * 5; stT.setItem(cK, JSON.stringify(r)); return } } else { var o = new XMLHttpRequest; o.open('GET', e, true); o.withCredentials = !t.dSC; o.responseType = t.responseType || 'text'; o.onload = function() { if (t.onloadCb) { return t.onloadCb(o, e) } if (o.status === 200 || o.status === 304) { _vwo_code.addScript({ text: o.responseText }) } else { _vwo_code.finish('&e=loading_failure:' + e) } }; o.onerror = function() { if (t.onerrorCb) { return t.onerrorCb(e) } _vwo_code.finish('&e=loading_failure:' + e) }; o.send() } }, getSettings: function() { try { var e = stT.getItem(cK); if (!e) { return } e = JSON.parse(e); if (Date.now() > e.e) { stT.removeItem(cK); return } return e.s } catch (e) { return } }, init: function() { if (d.URL.indexOf('__vwo__disable__') > -1) return; var e = this.settings_tolerance(); w._vwo_settings_timer = setTimeout(function() { _vwo_code.finish(); stT.removeItem(cK) }, e); var o = window._vis_opt_url || d.URL, s = 'https://dev.visualwebsiteoptimizer.com/j.php?a=' + account_id + '&u=' + encodeURIComponent(o) + '&vn=' + version; if (w.location.search.indexOf('_vwo_xhr') !== -1) { this.addScript({ src: s }) } else { this.load(s + '&x=true') } } }; w._vwo_code = code; if (d.readyState === 'loading') { d.addEventListener('DOMContentLoaded', function() { code.init(); }); } else { if ('requestIdleCallback' in w) { requestIdleCallback(function() { code.init(); }, { timeout: 1000 }); } else { setTimeout(function() { code.init(); }, 0); } } })(); ```