PageSourceSearch

https://www.fullerton.edu/_resources/js/yana-embed.js?v=1.0

js fullerton.edu collected 2026-10-01 07:38:20 UTC 4,433 bytes, 139 lines download raw bytes

1// ==========================================================
2// iTuffy Embedded Launcher + Widget
3// ==========================================================
4
5// Display text and styling config for the launcher button
6var appName = 'Ask iTuffy';
7var headerTextColor = '#000';
8
9var bottomButtonColor = '#EB7500';
10var bottomButtonHeight = '35px';
11var bottomButtonWidth = '131px';
12
13/**
14 * Initializes the custom iTuffy launcher button.
15 * - Prevents duplicate button creation
16 * - Appends a styled fixed-position button to the page
17 * - Binds click handler to open chatbot
18 */
19function init() {
20    // Prevent duplicate launcher if script runs more than once
21    if (document.getElementById('btnAskiTuffy')) return;
22
23    var yanaBlock = document.body;
24
25    // Create launcher button
26    var launcher = document.createElement('button');
27    launcher.setAttribute('id', 'btnAskiTuffy');
28    launcher.setAttribute('type', 'button');
29    launcher.setAttribute('aria-label', appName);
30    launcher.textContent = appName;
31
32    // Inline styling for launcher positioning and appearance
33    launcher.style.position = 'fixed';
34    launcher.style.bottom = '0';
35    launcher.style.right = '120px';
36    launcher.style.width = bottomButtonWidth;
37    launcher.style.height = bottomButtonHeight;
38    launcher.style.borderRadius = '4px 4px 0 0';
39    launcher.style.backgroundColor = bottomButtonColor;
40    launcher.style.color = headerTextColor;
41    launcher.style.zIndex = '1';
42    launcher.style.cursor = 'pointer';
43    launcher.style.border = 'none';
44    launcher.style.padding = '8px';
45    launcher.style.margin = '0';
46    launcher.style.textAlign = 'center';
47    launcher.style.font = 'inherit';
48    launcher.style.lineHeight = '1';
49
50    // Attach click handler to control chatbot
51    launcher.addEventListener('click', iTuffyOpenClose);
52
53    // Add button to page
54    yanaBlock.appendChild(launcher);
55}
56
57/**
58 * Ensure init runs when DOM is ready
59 */
60if (document.readyState !== 'loading') {
61    init();
62} else {
63    document.addEventListener('DOMContentLoaded', init);
64}
65
66/**
67 * Handles launcher click behavior.
68 *
69 * Behavior:
70 * 1. First click:
71 *    - Initializes Yana chatbot via iTuffyStarter()
72 *    - Marks launcher as "started"
73 *    - Opens chatbot after short delay (SDK needs time to initialize)
74 *
75 * 2. Subsequent clicks:
76 *    - Checks if chatbot is currently open using isPopupOpen()
77 *    - If closed → opens chatbot
78 *    - If already open → does nothing (launcher is "open-only")
79 *
80 * Notes:
81 * - We DO NOT call isPopupOpen() before initialization (avoids SDK bug)
82 * - We guard all SDK calls to prevent runtime errors if not ready
83 */
84function iTuffyOpenClose() {
85    var btnAskiTuffy = document.getElementById("btnAskiTuffy");
86    if (!btnAskiTuffy) return;
87
88    // Track whether chatbot has been initialized
89    var hasStarted = btnAskiTuffy.getAttribute("ituffy-started") === "true";
90
91    // ------------------------------------------------------
92    // FIRST CLICK → initialize chatbot
93    // ------------------------------------------------------
94    if (!hasStarted) {
95        // Mark as started BEFORE initializing to avoid race conditions
96        btnAskiTuffy.setAttribute("ituffy-started", "true");
97
98        // Initialize Yana chatbot with config
99        iTuffyStarter();
100
101        console.log("iTuffy is starting/opening...");
102
103        // Delay open slightly to allow SDK initialization
104        setTimeout(function () {
105            if (typeof YanaChatbotClient !== 'undefined' &&
106                typeof YanaChatbotClient.open === 'function') {
107
108                YanaChatbotClient.open();
109
110                console.log(YanaChatbotClient);
111            }
112        }, 400);
113
114        return;
115    }
116
117    // ------------------------------------------------------
118    // SUBSEQUENT CLICKS → open if not already open
119    // ------------------------------------------------------
120
121    var isOpen = false;
122
123    // Safely check chatbot state (only after initialization)
124    if (typeof YanaChatbotClient !== 'undefined' &&
125        typeof YanaChatbotClient.isPopupOpen === 'function') {
126
127        isOpen = YanaChatbotClient.isPopupOpen() === true;
128    }
129
130    console.log("is iTuffy open?", isOpen);
131
132    // Open chatbot only if currently closed/minimized
133    if (!isOpen &&
134        typeof YanaChatbotClient !== 'undefined' &&
135        typeof YanaChatbotClient.open === 'function') {
136
137        YanaChatbotClient.open();
138    }
139}

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.