### Setup Document Templates in C# Source: https://www.nutrient.io/guides/ai-document-processing/classify-documents This C# code demonstrates how to create a list of DocumentTemplate objects, adding predefined templates for Invoice, Resume, PurchaseOrder, and PayrollStatement. This setup is crucial for document classification and data extraction tasks. ```csharp static List setupDocumentTemplates(){ List templates = new List(); templates.Add(DocumentTemplates.Invoice); // Add invoice template. templates.Add(DocumentTemplates.Resume); // Add resume template. templates.Add(DocumentTemplates.PurchaseOrder); // Add purchase order template. templates.Add(DocumentTemplates.PayrollStatement); // Add payroll statement template. return templates; } ``` -------------------------------- ### Configure Nutrient AI Assistant Widget (JavaScript) Source: https://www.nutrient.io/guides/ai-document-processing/custom-templates This JavaScript code dynamically configures and injects the Kapa.ai widget into the Nutrient platform. It determines the correct configuration (disclaimer, example questions) based on the current URL path, allowing for context-specific AI assistance. The script sets numerous attributes to customize the widget's appearance and behavior. ```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); } ``` -------------------------------- ### Open ChatGPT Prompt - JavaScript Source: https://www.nutrient.io/guides/ai-document-processing/custom-templates Opens a new tab with a ChatGPT prompt pre-filled. The prompt includes the current Nutrient documentation URL and a request for assistance. This leverages the `encodeURIComponent` function to properly format the URL and prompt for the query parameter. ```javascript function v(i) { const t = "https://www.nutrient.io"; const o = window.location.pathname; const 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"); } ``` -------------------------------- ### Initialize Sidebar Navigation for Document Processing Guides (JavaScript) Source: https://www.nutrient.io/guides/ai-document-processing/intro This JavaScript code initializes the sidebar navigation for the AI Document Processing guides. It handles expanding parent folders, highlighting the active link, and adds click handlers for toggling folder visibility. It uses DOM manipulation to manage the UI state based on the current page path. It ensures that the sidebar is interactive and reflects the user's current location within the documentation. ```javascript (function() { const sidenavParent = null; /* global sidenavParent */ function normalizeUrl(url) { return url.replace(/\/$/, ""); } function getActiveParent(links, normalizedCurrentPath) { let bestMatch = null; let maxMatchLength = 0; for (const link of links) { const linkHref = normalizeUrl(link.getAttribute("href")); // Check if current path starts with link href (more precise than includes) if (normalizedCurrentPath.startsWith(linkHref)) { if (linkHref.length > maxMatchLength) { maxMatchLength = linkHref.length; bestMatch = link; } } } return bestMatch; } document.addEventListener("DOMContentLoaded", () => { // Make all folders collapsed initially document.querySelectorAll(".folder-content").forEach((content) => { content.classList.add("folder-hidden"); }); // Pathname (ex. /guides/android/viewer/zooming) const currentPath = window.location.pathname; const normalizedCurrentPath = normalizeUrl(currentPath); const links = document.querySelectorAll(".sidebar a"); // Find exact URL match first let exactMatch = Array.from(links).find((link) => { const linkHref = normalizeUrl(link.getAttribute("href")); return linkHref === normalizedCurrentPath; }); // If no exact match, try fallback strategies let parentMatch = null; if (!exactMatch) { if (sidenavParent) { exactMatch = document.querySelector( `.sidebar a[href*="${sidenavParent}"]`, ); } else { parentMatch = getActiveParent(links, normalizedCurrentPath); } } // Apply styles and expand folders based on matches if (exactMatch || parentMatch) { // Only add active class for exact matches if (exactMatch) { exactMatch.classList.add("active"); } // Expand parent folders for either match type let parent = (exactMatch || parentMatch).closest(".folder-content"); while (parent) { parent.classList.remove("folder-hidden"); const folderId = parent.id; const header = document.querySelector(`[data-target="${folderId}"]`); if (header) { // Add active class to parent folder headers header.classList.add("active"); const icon = header.querySelector(".folder-chevron"); icon?.classList.toggle("rotate-icon"); } parent = header?.closest(".folder-content"); } } // Click handlers for folder toggles document.querySelectorAll(".folder-header").forEach((header) => { header.addEventListener("click", () => { const targetId = header.getAttribute("data-target"); const content = document.getElementById(targetId); const chevron = header.querySelector(".folder-chevron"); if (content) { content.classList.toggle("folder-hidden"); chevron?.classList.toggle("rotate-icon"); } }); }); }); })(); ``` -------------------------------- ### Open ChatGPT with Context - JavaScript Source: https://www.nutrient.io/sdk/ai-document-processing/getting-started Opens ChatGPT in a new tab with a pre-filled prompt that includes the current documentation URL and a request for assistance. This allows users to quickly get help regarding the viewed documentation. ```javascript function v(i){ const t = "https://www.nutrient.io"; const o = window.location.pathname; const 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"); } ``` -------------------------------- ### Initialize Document Action Components - JavaScript Source: https://www.nutrient.io/sdk/ai-document-processing/getting-started Initializes two main components, 'I' and 'A', upon the DOM being fully loaded. These functions likely handle the setup and behavior of markdown action containers and related UI elements. ```javascript document.addEventListener("DOMContentLoaded", () => { I(); A(); }); ``` -------------------------------- ### Open ChatGPT with Context (JavaScript) Source: https://www.nutrient.io/guides/ai-document-processing/preconfigured-templates Opens ChatGPT in a new tab, pre-populated with a query related to the current Nutrient documentation page. The query asks for assistance in understanding and using the documentation, making it ready for concept explanation, examples, or debugging. ```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 Claude AI with Context (JavaScript) Source: https://www.nutrient.io/guides/ai-document-processing/preconfigured-templates Opens Claude AI in a new tab, pre-populated with a query related to the current Nutrient documentation page. The query asks for assistance in understanding and using the documentation, enabling quick help with concepts, examples, or debugging. ```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"); } ``` -------------------------------- ### Open Grok AI with Context (JavaScript) Source: https://www.nutrient.io/guides/ai-document-processing/preconfigured-templates Opens Grok AI in a new tab, pre-populated with a query related to the current Nutrient documentation page. The query requests help understanding and using the documentation, facilitating rapid assistance with concepts, examples, or debugging. ```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.`, s = `https://grok.com/c?q=${encodeURIComponent(r)}`; window.open(s, "_blank"); } ``` -------------------------------- ### Visual Website Optimizer Configuration (JavaScript) Source: https://www.nutrient.io/guides/ai-document-processing/custom-templates Initializes the Visual Website Optimizer (VWO) with a specified account ID and version. It includes configurations for settings tolerance, hiding elements, and handling platform-specific settings from local storage. The code aims to load VWO settings and potentially scripts asynchronously. ```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 ``` -------------------------------- ### Copy Page Content to Clipboard (JavaScript) Source: https://www.nutrient.io/guides/ai-document-processing/preconfigured-templates Handles the logic for copying the entire page's markdown content to the clipboard. It uses the `fetchMarkdown` function to get the content and then the `copyToClipboard` function to perform the copy operation. Includes visual feedback for success or error. ```javascript async function w(i = {}) { const {buttonSelector: t = ".copy-page-btn", dropdownSelector: o = ".copy-dropdown-item", successText: e = "Copied", errorText: r = "Error", resetDelay: a = 2000} = i; try { if (/^((?!chrome|android).)*safari/i.test(navigator.userAgent) && navigator.clipboard && window.isSecureContext) { const n = new ClipboardItem({"text/plain": fetch(`${window.location.pathname.replace(/\/$/, "")}.md`).then(c => { if (!c.ok) throw new Error("Failed to fetch"); return c.text(); }).then(c => new Blob([c], {type: "text/plain"}))}); await navigator.clipboard.write([n]); } else { const n = await y(); await b(n); } h(t, o, e, "btn-success", a); } catch (s) { console.error("Error copying content:", s); h(t, o, r, "btn-error", a); } } ``` -------------------------------- ### Open Grok AI Prompt - JavaScript Source: https://www.nutrient.io/guides/ai-document-processing/custom-templates Opens a new tab with a Grok AI prompt pre-filled. This function constructs a query for Grok AI, including the current Nutrient documentation URL and a request for help. It ensures the prompt is correctly encoded for the URL using `encodeURIComponent`. ```javascript function C(i) { const t = "https://www.nutrient.io"; const o = window.location.pathname; const 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 Grok AI with Documentation Context Source: https://www.nutrient.io/guides/ai-document-processing/concepts Opens Grok AI in a new tab, initiating a conversation with a prompt tailored to the current Nutrient documentation page. The prompt requests help with understanding, examples, or debugging related to the 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.`,s=`https://grok.com/c?q=${encodeURIComponent(r)}`; window.open(s,"_blank") } ``` -------------------------------- ### Open Claude AI Prompt - JavaScript Source: https://www.nutrient.io/guides/ai-document-processing/custom-templates Opens a new tab with a Claude AI prompt pre-filled. Similar to the ChatGPT function, it constructs a helpful prompt based on the current documentation URL and directs the user to Claude AI for assistance. Uses `encodeURIComponent` for safe URL construction. ```javascript function x(i) { const t = "https://www.nutrient.io"; const o = window.location.pathname; const 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://claude.ai/new?q=${encodeURIComponent(r)}`; window.open(s, "_blank"); } ``` -------------------------------- ### Generate ChatGPT Query URL Source: https://www.nutrient.io/guides/ai-document-processing/intro Constructs a URL to open ChatGPT with a pre-filled query related to the current documentation page. The query asks for help understanding and using the documentation. It encodes the query to be safely included in a URL. ```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# Document Processing and Result Analysis Source: https://www.nutrient.io/guides/ai-document-processing/custom-templates Demonstrates how to process a document and analyze the extraction results using the DocumentProcessor class. It involves building a ProcessorComponent and then using the Process method to get ProcessorResult, which contains extracted fields and their validation states. Dependencies include the DocumentProcessor, ProcessorComponent, and ProcessorResult classes. ```csharp // Build the component. ProcessorComponent component = buildComponent(); // Process a document. ProcessorResult result = new DocumentProcessor().Process("orpalis_certificate.jpg", component); // Output results. if (result.ExtractedFields != null) { foreach (var item in result.ExtractedFields) { Console.WriteLine($"Field name: '{item.FieldName}' - Field value: '{item.Value}' - Validation state: ({item.ValidationState})"); } } ``` -------------------------------- ### Open Page in ChatGPT - JavaScript Source: https://www.nutrient.io/guides/ai-document-processing/classify-documents Opens the current Nutrient.io documentation page in ChatGPT, pre-populated with a prompt asking for assistance related to 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") } ``` -------------------------------- ### Configure Nutrient AI Chatbot Widget - JavaScript Source: https://www.nutrient.io/guides/ai-document-processing/intro This JavaScript code dynamically configures and injects the Kapa.ai chatbot widget into a webpage. It determines the widget's settings (like disclaimers and example questions) based on the current URL path, allowing for context-specific AI assistance. The script targets different website sections like '/workflow-automation' and '/low-code' to customize the AI's behavior. ```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, 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); } ``` -------------------------------- ### Sidebar Navigation Initialization - JavaScript Source: https://www.nutrient.io/guides/ai-document-processing/custom-templates This JavaScript code initializes the sidebar navigation for a documentation site. It handles expanding folders, highlighting active links based on the current URL, and managing click events for folder toggles. It supports exact URL matching and fallback strategies for finding the active parent. ```javascript (function(){ const sidenavParent = null; /* global sidenavParent */ function normalizeUrl(url) { return url.replace(/\/$/, ""); } function getActiveParent(links, normalizedCurrentPath) { let bestMatch = null; let maxMatchLength = 0; for (const link of links) { const linkHref = normalizeUrl(link.getAttribute("href")); if (normalizedCurrentPath.startsWith(linkHref)) { if (linkHref.length > maxMatchLength) { maxMatchLength = linkHref.length; bestMatch = link; } } } return bestMatch; } document.addEventListener("DOMContentLoaded", () => { document.querySelectorAll(".folder-content").forEach((content) => { content.classList.add("folder-hidden"); }); const currentPath = window.location.pathname; const normalizedCurrentPath = normalizeUrl(currentPath); const links = document.querySelectorAll(".sidebar a"); let exactMatch = Array.from(links).find((link) => { const linkHref = normalizeUrl(link.getAttribute("href")); return linkHref === normalizedCurrentPath; }); let parentMatch = null; if (!exactMatch) { if (sidenavParent) { exactMatch = document.querySelector( `.sidebar a[href*=\"${sidenavParent}\"]`, ); } else { parentMatch = getActiveParent(links, normalizedCurrentPath); } } if (exactMatch || parentMatch) { if (exactMatch) { exactMatch.classList.add("active"); } let parent = (exactMatch || parentMatch).closest(".folder-content"); while (parent) { parent.classList.remove("folder-hidden"); const folderId = parent.id; const header = document.querySelector(`[data-target=\"${ folderId }\"]`); if (header) { header.classList.add("active"); const icon = header.querySelector(".folder-chevron"); icon?.classList.toggle("rotate-icon"); } parent = header?.closest(".folder-content"); } } document.querySelectorAll(".folder-header").forEach((header) => { header.addEventListener("click", () => { const targetId = header.getAttribute("data-target"); const content = document.getElementById(targetId); const chevron = header.querySelector(".folder-chevron"); if (content) { content.classList.toggle("folder-hidden"); chevron?.classList.toggle("rotate-icon"); } }); }); }); })(); ``` -------------------------------- ### Visual Website Optimizer (VWO) Initialization (JavaScript) Source: https://www.nutrient.io/sdk/ai-document-processing/getting-started This JavaScript code snippet initializes the Visual Website Optimizer (VWO) for A/B testing and personalization. It configures account ID, version, and settings, and includes logic for loading VWO settings from local storage or session storage. It prevents the body from being hidden to avoid flashes of unstyled content. ```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 ``` -------------------------------- ### Initialize Document Load Event Listeners (JavaScript) Source: https://www.nutrient.io/guides/ai-document-processing/preconfigured-validators Attaches event listeners to be executed once the DOM is fully loaded. It calls `I()` and `A()` which are presumed to handle further UI initializations or setup related to document interactions. ```javascript document.addEventListener("DOMContentLoaded",()=>{ I(), A() }); function I(){ document.querySelectorAll('a[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 ``` -------------------------------- ### Animate Dropdown Classes on Mutation Source: https://www.nutrient.io/guides/ai-document-processing/intro Observes class attribute changes on dropdown wrappers and applies/removes animation classes based on the presence of the 'block' class. Uses MutationObserver and debouncing with setTimeout for performance. ```javascript document.addEventListener("DOMContentLoaded",()=>{ document.querySelectorAll(".main-nav-dropdown-wrapper").forEach(e=>{ let t; new MutationObserver(a=>{ a.forEach(s=>{ s.type==="attributes"&&s.attributeName==="class"&&(clearTimeout(t),t=setTimeout(()=>{ e.classList.contains("block")?e.classList.add("dropdown-animate"):e.classList.remove("dropdown-animate") },10)) }) }).observe(e,{ attributes:!0 }) }) }); ``` -------------------------------- ### Initialize Sidebar Navigation for Nutrient IO Guides Source: https://www.nutrient.io/guides/ai-document-processing/concepts This JavaScript code initializes the sidebar navigation for the Nutrient IO documentation. It handles expanding folders based on the current page URL, applies active classes to matched links, and sets up click handlers for toggling folder visibility. It supports exact URL matches and fallback strategies for parent folder matching. ```javascript (function(){const sidenavParent = null; /* global sidenavParent */ function normalizeUrl(url) { return url.replace(/\/$/, ""); } function getActiveParent(links, normalizedCurrentPath) { let bestMatch = null; let maxMatchLength = 0; for (const link of links) { const linkHref = normalizeUrl(link.getAttribute("href")); if (normalizedCurrentPath.startsWith(linkHref)) { if (linkHref.length > maxMatchLength) { maxMatchLength = linkHref.length; bestMatch = link; } } } return bestMatch; } document.addEventListener("DOMContentLoaded", () => { document.querySelectorAll(".folder-content").forEach((content) => { content.classList.add("folder-hidden"); }); const currentPath = window.location.pathname; const normalizedCurrentPath = normalizeUrl(currentPath); const links = document.querySelectorAll(".sidebar a"); let exactMatch = Array.from(links).find((link) => { const linkHref = normalizeUrl(link.getAttribute("href")); return linkHref === normalizedCurrentPath; }); let parentMatch = null; if (!exactMatch) { if (sidenavParent) { exactMatch = document.querySelector( `.sidebar a[href*="${sidenavParent}"]`, ); } else { parentMatch = getActiveParent(links, normalizedCurrentPath); } } if (exactMatch || parentMatch) { if (exactMatch) { exactMatch.classList.add("active"); } let parent = (exactMatch || parentMatch).closest(".folder-content"); while (parent) { parent.classList.remove("folder-hidden"); const folderId = parent.id; const header = document.querySelector(`[data-target="${folderId}"]`); if (header) { header.classList.add("active"); const icon = header.querySelector(".folder-chevron"); icon?.classList.toggle("rotate-icon"); } parent = header?.closest(".folder-content"); } } document.querySelectorAll(".folder-header").forEach((header) => { header.addEventListener("click", () => { const targetId = header.getAttribute("data-target"); const content = document.getElementById(targetId); const chevron = header.querySelector(".folder-chevron"); if (content) { content.classList.toggle("folder-hidden"); chevron?.classList.toggle("rotate-icon"); } }); }); }); })(); ``` -------------------------------- ### Open ChatGPT with Documentation Context Source: https://www.nutrient.io/guides/ai-document-processing/concepts Opens ChatGPT in a new tab, pre-populated with a prompt that includes the current Nutrient documentation URL. The prompt asks ChatGPT to help understand and explain the documentation, implying it should be ready to answer questions or debug based on the content. ```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") } ``` -------------------------------- ### Clean up Mega Menu Attributes if Menu Absent Source: https://www.nutrient.io/guides/ai-document-processing/intro Removes 'data-collapse-toggle' and 'aria-controls' attributes from a mega menu toggle element if the corresponding mega menu element is not found. This ensures proper ARIA behavior. ```javascript (function(){ const o=document.querySelector("[data-collapse-toggle='mega-menu']"),a=document.getElementById("mega-menu"); o&&!a&&(o.removeAttribute("data-collapse-toggle"),o.removeAttribute("aria-controls")) })(); ``` -------------------------------- ### Open ChatGPT with Context - JavaScript Source: https://www.nutrient.io/guides/ai-document-processing/about/system-compatibility Opens a new browser tab with ChatGPT, pre-populated with a query that includes the current page's URL. The query prompts the AI to help understand and explain the documentation found at the given URL. ```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") } ``` -------------------------------- ### Initialize Main Event Listeners Source: https://www.nutrient.io/guides/ai-document-processing/intro Initializes various event listeners for the page, including those for AI document actions and potentially other UI interactions. This function ensures that event handlers are set up after the DOM is fully loaded. ```javascript document.addEventListener("DOMContentLoaded",()=>{ I(), A() }); ``` -------------------------------- ### Open Grok AI with Context - JavaScript Source: https://www.nutrient.io/sdk/ai-document-processing/getting-started Opens Grok AI in a new tab with a pre-populated prompt that includes the current documentation URL and a request for detailed explanations or help. This integrates the documentation with AI-powered assistance. ```javascript function C(i){ const t = "https://www.nutrient.io"; const o = window.location.pathname; const 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"); } ``` -------------------------------- ### Initialize Documentation Action Listeners Source: https://www.nutrient.io/guides/ai-document-processing/intro Sets up event listeners for interactive elements related to documentation actions, such as expanding/collapsing action menus and handling keyboard navigation within these menus. This function is called once the DOM is ready. ```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 Raw Markdown File Source: https://www.nutrient.io/guides/ai-document-processing/intro Opens the raw Markdown file for the current page in a new browser tab. It constructs the URL by appending '.md' to the current path, ensuring it handles trailing slashes correctly. ```javascript function k(i){ const t=window.location.pathname, e=`${t.endsWith("/")?t.slice(0,-1):t}.md`; window.open(e,"_blank") } ``` -------------------------------- ### Conditionally Display Team Badge Based on Cookie Source: https://www.nutrient.io/guides/ai-document-processing/intro Checks for a 'nutrient_team' cookie. If the cookie's value is 'true' or '1', it displays the '.team-badge' element; otherwise, it hides it. This is likely used for showing internal/beta features. ```javascript function o(){ const e=document.cookie.split(";").find(t=>t.trim().startsWith("nutrient_team=")); if(e){ const t=e.split("=")[1]; return t==="true"||t==="1") } return!1 } function i(){ const n=document.querySelector(".team-badge"); if(n){ const e=o(); n.style.display=e?"":"none" } } function a(){ document.readyState==="loading"?document.addEventListener("DOMContentLoaded",i):i() } a(); ``` -------------------------------- ### Recalculate Layout on Resize Source: https://www.nutrient.io/guides/ai-document-processing/intro Sets up an event listener for window resize events, debounced using requestAnimationFrame, to recalculate and update layout-related CSS variables. Ensures layout consistency across different screen sizes. ```javascript let r=!1; window.addEventListener("resize", ()=>{ r||(r=!0,requestAnimationFrame(()=>{ r=!1, t() })) }); ``` -------------------------------- ### JavaScript: Load External Script Dynamically Source: https://www.nutrient.io/guides/ai-document-processing/intro Dynamically loads an external JavaScript file. It handles loading via XMLHttpRequest for cross-origin requests or via a script tag. Includes error handling and callbacks for success and failure. ```javascript function loadScript(e, t) { var r = document.createElement('script'); r.src = e; r.async = true; r.onload = function() { if (t) { t.call(window); } }; r.onerror = function() { // Handle error }; document.head.appendChild(r); } ``` ```javascript 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() ``` -------------------------------- ### Open Claude AI with Context - JavaScript Source: https://www.nutrient.io/sdk/ai-document-processing/getting-started Opens Claude AI in a new tab with a pre-filled prompt containing the current documentation URL and a request for assistance. This facilitates quick help and clarification on the documentation content. ```javascript function x(i){ const t = "https://www.nutrient.io"; const o = window.location.pathname; const 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://claude.ai/new?q=${encodeURIComponent(r)}`; window.open(s, "_blank"); } ``` -------------------------------- ### Generate Claude AI Query URL Source: https://www.nutrient.io/guides/ai-document-processing/intro Constructs a URL to open Claude AI with a pre-filled query about the current documentation page. The query prompts Claude to provide assistance based on the viewed documentation. The query is URL-encoded. ```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") } ```