Kaynağa Gözat

Studio top menu: the module JS object is created from an options marker

The script block held a bare code marker, which SonarCloud read as a
stray expression. The template now carries the statement itself and only
the options come from PHP (BxBaseStudioModules::getJsParams()).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Andrey Yasko 1 ay önce
ebeveyn
işleme
c07de045f8

+ 2 - 3
studio/template/menu_top.html

@@ -3,9 +3,8 @@
 var oBxDolStudioMenuTop = new BxDolStudioMenuTop({
     sActionUrl: '<bx_url_studio />ajax.php'
 });
-if(typeof oBxDolStudioModule == 'undefined') {
-    __js_code_module__
-}
+if(typeof oBxDolStudioModule == 'undefined')
+    var oBxDolStudioModule = new BxDolStudioModule(__js_options_module__);
 -->
 </script>
 <div class="bx-std-menu-top-wrp">

+ 1 - 1
studio/template/scripts/BxBaseStudioMenuTop.php

@@ -81,7 +81,7 @@ class BxBaseStudioMenuTop extends BxDolStudioMenuTop
         $oTemplate->addCss($this->getCss());
         return $oTemplate->parseHtmlByName('menu_top.html', array(
             'bx_repeat:menus' => $aTmplVars,
-            'js_code_module' => BxTemplStudioModules::getInstance()->getJsCode(array(), false) // pages with their own instance define it again below
+            'js_options_module' => json_encode(BxTemplStudioModules::getInstance()->getJsParams()) // pages with their own instance define it again below
         ));
     }
 }

+ 9 - 4
studio/template/scripts/BxBaseStudioModules.php

@@ -35,15 +35,20 @@ class BxBaseStudioModules extends BxDolStudioModules
         return $this->sJsObject;
     }
 
+    public function getJsParams($aParams = array())
+    {
+        return array_merge(array(
+            'sActionUrl' => BX_DOL_URL_STUDIO . $this->sActionUri,
+            'sActionsPrefix' => $this->sParamPrefix,
+        ), $aParams);
+    }
+
     public function getJsCode($aParams = array(), $mixedWrap = true)
     {
         $sJsObject = $this->getJsObject();
         $sJsClass = $this->getJsClass();
 
-        $aParams = array_merge(array(
-            'sActionUrl' => BX_DOL_URL_STUDIO . $this->sActionUri,
-            'sActionsPrefix' => $this->sParamPrefix,
-        ), $aParams);
+        $aParams = $this->getJsParams($aParams);
 
         $sContent = bx_replace_markers("var {object} = new {class}({params});", array(
             'object' => $sJsObject,