Changed around line 1
- const main = () => {
- // Get UI elements
- const statusDiv = document.getElementById("status");
- const contextDiv = document.getElementById("contextData");
- const buttons = ["contextBtn", "urlBtn", "closeBtn", "testBtn"].map((id) =>
- document.getElementById(id),
- );
+ class App {
+ constructor() {
+ this.statusDiv = document.getElementById("status");
+ this.contextDiv = document.getElementById("contextData");
+ this.buttons = ["contextBtn", "urlBtn", "closeBtn", "testBtn"].map((id) =>
+ document.getElementById(id)
+ );
+ this.isSDKLoaded = false;
+ }
- let isSDKLoaded = false;
+ setStatus(message) {
+ if (this.statusDiv) {
+ this.statusDiv.innerText = message;
+ }
+ }
- // Enable all buttons
- function enableButtons() {
- buttons.forEach((btn) => (btn.disabled = false));
+ enableButtons() {
+ this.buttons.forEach((btn) => {
+ if (btn) btn.disabled = false;
+ });
- // Initialize frame
- async function init() {
+ async start() {
- isSDKLoaded = true;
- statusDiv.innerText = "Frame is ready!";
- enableButtons();
-
- // Set up button click listener
+ this.isSDKLoaded = true;
+ this.setStatus("Frame is ready!");
+ this.enableButtons();
+
- statusDiv.innerText = "Primary button was clicked!";
+ this.setStatus("Primary button was clicked!");
- statusDiv.innerText = "Error initializing frame: " + error.message;
+ this.setStatus(`Error initializing frame: ${error.message}`);
- // Get and display frame context
- async function getContext() {
- if (!isSDKLoaded) return;
+ async getContext() {
+ if (!this.isSDKLoaded) return;
- contextDiv.innerHTML = `
-
Frame Context:
-
${JSON.stringify(context, null, 2)}
- `;
+ if (this.contextDiv) {
+ this.contextDiv.innerHTML = `
+
Frame Context:
+
${JSON.stringify(context, null, 2)}
+ `;
+ }
- statusDiv.innerText = "Error getting context: " + error.message;
+ this.setStatus(`Error getting context: ${error.message}`);
- // Open external URL
- function openUrl() {
- if (!isSDKLoaded) return;
+ openUrl() {
+ if (!this.isSDKLoaded) return;
- statusDiv.innerText = "Opening URL...";
+ this.setStatus("Opening URL...");
- statusDiv.innerText = "Error opening URL: " + error.message;
+ this.setStatus(`Error opening URL: ${error.message}`);
- // Close the frame
- function closeFrame() {
- if (!isSDKLoaded) return;
+ closeFrame() {
+ if (!this.isSDKLoaded) return;
- statusDiv.innerText = "Closing frame...";
+ this.setStatus("Closing frame...");
- statusDiv.innerText = "Error closing frame: " + error.message;
+ this.setStatus(`Error closing frame: ${error.message}`);
- // Test the primary button functionality
- function testPrimaryButton() {
- if (!isSDKLoaded) return;
+ testPrimaryButton() {
+ if (!this.isSDKLoaded) return;
- statusDiv.innerText = "Primary button set - try clicking it!";
+ this.setStatus("Primary button set - try clicking it!");
- statusDiv.innerText = "Error setting primary button: " + error.message;
+ this.setStatus(`Error setting primary button: ${error.message}`);
- };
+ }
- // Initialize the app when the DOM is fully loaded
- main();
- jframe.sdk.actions.ready();
+ window.app = new App();
+ window.app.start();