2011-01-11 69 views
1

這是我用我的Joomla網站顯示手風琴腳本:增加了變量的JavaScript的Joomla

<?php 
defined('JPATH_BASE') or die(); 
gantry_import('core.gantryfeature'); 
class GantryFeatureAccordion extends GantryFeature { 
    var $_feature_name = 'accordion'; 
    function init() { 
     global $gantry; 
     if ($this->get('enabled')) { 
      $gantry->addScript('accordion.js'); 
      $gantry->addInlineScript($this->_accordion()); 
     } 
    } 
    function render($position="") { 
    ob_start(); 
    ?> 
     <div id="accordion"> 
      <dl> 
      <?php foreach (glob("templates/rt_gantry_j15/features/accordion/*.php") as $filename) {include($filename);} ?> 
      </dl> 
     </div> 
    <?php 
    return ob_get_clean(); 
    } 
    function _accordion() { 
     global $gantry; 
     $js = " 
      jQuery.noConflict(); 
       (function($){ 
       $(document).ready(function() { 
        $('#accordion').easyAccordion({ 
         slideNum: true,     
         autoStart: true, 
         slideInterval: 4000 
        }); 
       }); 
      })(jQuery); 
     "; 
     return $js; 
    } 
} 

我想在templateDetails.XML文件作爲用戶輸入來調用這三個值。

    slideNum: true,     
        autoStart: true, 
        slideInterval: 4000 

像這樣在templateDetails.xml文件:

<param name="accordion" type="chain" label="ACCORDION" description="ACCORDION_DESC"> 
    <param name="slideNum" type="text" default="true" label="SlideNumber" class="text-short" /> 
    <param name="autoStart" type="text" default="true" label="AutoStart" class="text-short" /> 
    <param name="slideinterval" type="text" default="4000" label="SlideInterval" class="text-short" /> 
</param> 

我怎麼可以這樣做?相同的確切語法是什麼?

我對編程和JavaScript特別感興趣。

請幫忙。

回答

2

試試這個:

$cfgParams = &JComponentHelper::getParams('com_mycomponent'); 
    $js = " 
     jQuery.noConflict(); 
      (function($){ 
      $(document).ready(function() { 
       $('#accordion').easyAccordion({ 
        slideNum: ".$cfgParams->get('slideNum', 'true').",     
        autoStart: ".$cfgParams->get('autoStart', 'true').", 
        slideInterval: ".$cfgParams->get('slideInterval', '4000')." 
       }); 
      }); 
     })(jQuery); 
    "; 
+0

你很酷。謝謝回覆。這可以用來解決問題。再次感謝。 – 2011-01-11 16:12:32