Skip to content

Commit 48352dc

Browse files
caseysoftwareclaude
andcommitted
Load footer scripts queued through the theme (fixes the strength meter)
CAppUI::getTheme() returns a new theme object on every call, and w2p_Theme_Base kept the footer script queue in an instance property. The script added by addFooterJavascriptFile() was therefore gone by the time footer.php called getTheme()->loadFooterJS(), so no queued footer script was ever output. That is why the password strength indicator did nothing on the user add/edit form and the change-password dialog. The queue is now a static property, so it is shared for the request. (Caching the theme on CAppUI was not an option: CAppUI is serialized into the session and the theme class is not loaded when it is unserialized.) Scripts are output in the order they were added, and the duplicate check compares the full URL that is actually stored. Refs #386 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016CP89WVmGZ1VVCCZMS6ntN
1 parent bf1b5c7 commit 48352dc

1 file changed

Lines changed: 20 additions & 12 deletions

File tree

‎classes/w2p/Theme/Base.class.php‎

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ abstract class w2p_Theme_Base
99
protected $_AppUI = null;
1010
protected $_m = null;
1111
protected $_uistyle = 'web2project';
12-
protected $footerJavascriptFiles = array();
12+
/**
13+
* Scripts queued for the page footer. CAppUI::getTheme() builds a new theme
14+
* object on every call, so the queue is shared by all instances for the
15+
* request; an instance property would be lost before footer.php runs.
16+
*
17+
* @var array<int, string>
18+
*/
19+
protected static $footerJavascriptFiles = array();
1320

1421
public function __construct($AppUI, $m = '') {
1522
$this->_AppUI = $AppUI;
@@ -133,15 +140,16 @@ public function getModuleJS($module, $file = null, $load_all = false)
133140

134141
public function addFooterJavascriptFile($pathTo)
135142
{
136-
if (!in_array($pathTo, $this->footerJavascriptFiles)) {
137-
$base = W2P_BASE_URL;
138-
if (substr($base, -1) != '/') {
139-
$base .= '/';
140-
}
141-
if (strpos($pathTo, $base) === false) {
142-
$pathTo = $base . $pathTo;
143-
}
144-
$this->footerJavascriptFiles[] = $pathTo;
143+
$base = W2P_BASE_URL;
144+
if (substr($base, -1) != '/') {
145+
$base .= '/';
146+
}
147+
if (strpos($pathTo, $base) === false) {
148+
$pathTo = $base . $pathTo;
149+
}
150+
// Compare the full URL, which is what the queue holds.
151+
if (!in_array($pathTo, static::$footerJavascriptFiles)) {
152+
static::$footerJavascriptFiles[] = $pathTo;
145153
}
146154
}
147155

@@ -160,8 +168,8 @@ public function loadFooterJS()
160168
$s .= '});';
161169
$s .= '</script>';
162170

163-
if (is_array($this->footerJavascriptFiles) and !empty($this->footerJavascriptFiles)) {
164-
while ($jsFile = array_pop($this->footerJavascriptFiles)) {
171+
if (!empty(static::$footerJavascriptFiles)) {
172+
while ($jsFile = array_shift(static::$footerJavascriptFiles)) {
165173
$s .= "<script type='text/javascript' src='" . $jsFile . "'></script>";
166174
}
167175
}

0 commit comments

Comments
 (0)