Skip to content

Commit 3fb853d

Browse files
authored
Fix order of registered JS code block or files
1 parent 2cb9807 commit 3fb853d

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/renderers/BaseRenderer.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ abstract class BaseRenderer extends BaseObject implements RendererInterface
183183
*/
184184
public $jsExtraSettings = [];
185185

186+
/**
187+
* @var array List of the locations of registered JavaScript code block or files in right order.
188+
*/
189+
public $jsPositions = [View::POS_HEAD, View::POS_BEGIN, View::POS_END, View::POS_READY, View::POS_LOAD];
190+
186191
/**
187192
* @inheritdoc
188193
*/
@@ -370,8 +375,8 @@ public function render()
370375
// Collect all js scripts which has to be appended to page before initialization widget
371376
$jsInit = [];
372377
if (is_array($view->js)) {
373-
foreach ($view->js as $position => $scripts) {
374-
foreach ((array)$scripts as $key => $js) {
378+
foreach ($this->jsPositions as $position) {
379+
foreach (ArrayHelper::getValue($view->js, $position, []) as $key => $js) {
375380
if (isset($jsBefore[$position][$key])) {
376381
continue;
377382
}
@@ -386,8 +391,8 @@ public function render()
386391

387392
$jsTemplates = [];
388393
if (is_array($view->js)) {
389-
foreach ($view->js as $position => $scripts) {
390-
foreach ((array)$scripts as $key => $js) {
394+
foreach ($this->jsPositions as $position) {
395+
foreach (ArrayHelper::getValue($view->js, $position, []) as $key => $js) {
391396
if (isset($jsBefore[$position][$key])) {
392397
continue;
393398
}

0 commit comments

Comments
 (0)