You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enhance documentation for JavaScript Patterns and Tab Pages with best practices on selector scoping, menu placement, and initialization timing to prevent conflicts when adding tabs to existing Unraid pages.
When your plugin adds a tab to an existing Unraid page (like adding a tab to the Docker menu), your JavaScript runs in the same context as that page's JavaScript. Unscoped selectors can accidentally target elements from the parent page, causing visual glitches or broken functionality.
583
+
584
+
Common classes like `.auto_start`, `.advanced`, `.basic`, and `.updatecolumn` are used by multiple Unraid pages. jQuery plugins like `switchButton` should never be re-initialized on elements that are already set up.
585
+
586
+
```javascript
587
+
// BAD - Selects ALL .auto_start elements on the page
588
+
// If Docker tab already initialized these, you'll break them
See [Tab Pages - Adding Tabs to Existing Pages](tab-pages.md#adding-tabs-to-existing-pages) for more details.
619
+
580
620
### Namespace Your Timers
581
621
582
622
Unraid's core JavaScript uses a global `timers` object to manage intervals and timeouts. If your plugin declares `var timers = {}`, you'll overwrite Unraid's object and break functionality like auto-refresh and status polling. Always use a plugin-specific name like `myPluginTimers` to avoid this collision.
Copy file name to clipboardExpand all lines: docs/ui/tab-pages.md
+75Lines changed: 75 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -190,6 +190,81 @@ TODO: Document the Menu numbering system for related pages
190
190
- Consider user workflow when ordering tabs
191
191
- Save tab state for better UX
192
192
193
+
## Adding Tabs to Existing Pages
194
+
195
+
Plugins can add new tabs to existing Unraid pages (like the Docker page) using the `Menu` header in `.page` files. This creates a seamless integrated experience but requires careful attention to avoid conflicts.
196
+
197
+
### Menu Placement
198
+
199
+
To add a tab to an existing menu, use the menu name with an optional sort order:
200
+
201
+
```
202
+
# Add to Docker page as second tab
203
+
Menu="Docker:2"
204
+
Title="Compose"
205
+
Type="php"
206
+
```
207
+
208
+
### Selector Scoping
209
+
210
+
{: .warning }
211
+
> When your plugin adds a tab to an existing Unraid page, your JavaScript will run in the same context as the parent page's JavaScript. You **must** scope your CSS selectors to avoid conflicts.
212
+
213
+
Common classes like `.auto_start`, `.advanced`, `.basic`, and `.updatecolumn` are used by multiple Unraid pages. If your plugin uses these same classes and initializes jQuery plugins on them (like `switchButton`), you'll inadvertently reinitialize or modify elements that belong to the parent page.
214
+
215
+
**Problem - Unscoped selectors:**
216
+
217
+
```javascript
218
+
// BAD - This selects ALL .auto_start on the page, including Docker tab's checkboxes
When adding a tab to an existing page, that page's JavaScript typically runs first and initializes its own UI components. Your plugin's async content loading can conflict if not properly scoped:
0 commit comments