Skip to content

Commit cad43d2

Browse files
committed
better comments on floating panel
1 parent aba4c94 commit cad43d2

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

floating-panel-settings.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,33 @@
55
// This file handles settings persistence and profile management for the floating panel.
66
// It includes methods for loading/saving panel settings, debouncing saves, and profile switching.
77
// These functions extend the window.MaxExtensionFloatingPanel namespace.
8+
//
9+
// Key Components:
10+
// 1. Settings Management - Loading and saving panel configuration per website
11+
// 2. Storage Integration - Communication with the config.js service worker
12+
// 3. Profile Management - Loading available profiles and handling profile switching
13+
// 4. Initialization - Setup of the floating panel system
14+
//
15+
// Key Methods:
16+
// - loadPanelSettings(): Fetches settings from service worker for current hostname
17+
// - savePanelSettings(): Stores current panel settings via service worker
18+
// - debouncedSavePanelSettings(): Throttles saves to improve performance
19+
// - loadAvailableProfiles(): Gets profile list from service worker
20+
// - getCurrentProfile(): Fetches and sets current active profile
21+
// - switchToProfile(): Changes active profile and updates panel content
22+
// - initialize(): Sets up the floating panel (creates UI and loads settings)
23+
//
24+
// Implementation Details:
25+
// - All settings are stored with the prefix 'floating_panel_' followed by hostname
26+
// - Settings are loaded asynchronously via chrome.runtime.sendMessage
27+
// - The panel uses a debounce mechanism (150ms) to avoid excessive storage writes
28+
// - Each website has its own panel settings (position, size, visibility)
29+
// - Profile switching refreshes the buttons shown in the panel
30+
//
31+
// Dependencies:
32+
// - floating-panel.js: Provides the namespace and shared properties
33+
// - floating-panel-ui.js: Provides UI update methods
34+
// - config.js (Service Worker): Handles persistent storage operations
835

936
'use strict';
1037

floating-panel-ui.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,33 @@
55
// This file contains all UI-related functionality for the floating panel,
66
// including creation, layout, drag behavior, and button moving logic.
77
// It extends the window.MaxExtensionFloatingPanel namespace with the corresponding methods.
8+
//
9+
// Key Components:
10+
// 1. Panel Creation - Creates the panel with header, content area, and profile switcher
11+
// 2. Drag Behavior - Makes the panel draggable by the header or footer
12+
// 3. Panel Visibility - Toggles the panel and handles state persistence
13+
// 4. Button Movement - Moves buttons between the original container and floating panel
14+
// 5. Profile Switching UI - Creates and manages the profile dropdown in the panel footer
15+
//
16+
// Key Methods:
17+
// - createFloatingPanel(): Creates the panel DOM structure with styling
18+
// - makeDraggable(): Adds drag functionality to specified elements
19+
// - togglePanel(): Handles panel visibility toggling and button movement
20+
// - moveButtonsToPanel(): Moves buttons from their original container to the panel
21+
// - restorePanelState(): Ensures panel visibility matches saved settings
22+
// - positionPanelAtCursor(): Positions the panel relative to mouse cursor
23+
// - createPanelToggleButton(): Creates the button that summons the floating panel
24+
//
25+
// Known Issues & Fixes:
26+
// - The togglePanel() method avoids loadPanelSettings() when initially creating the panel
27+
// to prevent race conditions that could cause the panel to disappear after summoning
28+
// - restorePanelState() only toggles the panel if its current state doesn't match the desired state
29+
// to prevent unintended toggling when loading settings
30+
//
31+
// Dependencies:
32+
// - floating-panel.js: Provides the namespace and shared properties
33+
// - floating-panel-settings.js: Provides settings management methods
34+
// - utils.js: For logging functionality
835

936
'use strict';
1037

floating-panel.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,27 @@
55
// This file implements the entry point for the OneClickPrompts floating panel.
66
// It defines the window.MaxExtensionFloatingPanel namespace (with common properties)
77
// and loads additional functionality split into two files: floating-panel-ui.js and floating-panel-settings.js.
8+
//
9+
// Structure:
10+
// 1. Namespace: window.MaxExtensionFloatingPanel - Global object containing all floating panel functionality
11+
// 2. Properties:
12+
// - panelElement: Reference to the panel DOM element
13+
// - isPanelVisible: Boolean tracking current visibility state
14+
// - currentProfileName: Currently active profile name
15+
// - availableProfiles: Array of all available profile names
16+
// - storageKeyPrefix: Prefix used for storing settings ('floating_panel_')
17+
// - defaultPanelSettings: Default configuration for new panels
18+
// - currentPanelSettings: Current active settings for the panel
19+
// - savePositionTimer: Used for debounced settings saves
20+
//
21+
// Dependencies:
22+
// - floating-panel-ui.js: Contains UI creation and interaction methods
23+
// - floating-panel-settings.js: Contains settings and profile management
24+
// - config.js (Service Worker): Handles persistent storage of panel settings
25+
//
26+
// Communication:
27+
// The floating panel uses chrome.runtime.sendMessage to communicate with the config.js
28+
// service worker for storing and retrieving settings based on the website hostname.
829
//
930
// IMPORTANT: DO NOT REMOVE COMMENTS. All old names are preserved.
1031

0 commit comments

Comments
 (0)