PATH:
home
/
letacommog
/
letaweb
/
protected
/
extensions
/
SmartMenu
<?php class CSmartMenuWidget extends CWidget { public $scriptUrl; public $themeUrl; public $theme = 'sm-simple'; public $scriptFile = array('jquery.smartmenus.min.js'); public $cssFile = array('sm-core-css.css'); public $bootstrap = false; protected $bootstrapScriptFile = 'addons/bootstrap/jquery.smartmenus.bootstrap.min.js'; protected $bootstrapCssFile = 'addons/bootstrap/jquery.smartmenus.bootstrap.css'; public $items = array(); public $htmlOptions = array(); public $tagName = 'div'; public $options = array(); public $absoluteLink = false; public function init() { $this->resolvePackagePath(); $this->registerCoreScripts(); parent::init(); } public function run() { $id = $this->getId(); $this->htmlOptions['id'] = $id; if (!isset($this->htmlOptions['class']) || strlen($this->htmlOptions['class']) === 0) { $this->htmlOptions['class'] = 'sm'; } elseif (strlen($this->htmlOptions['class'])) { $this->htmlOptions['class'] .= ' sm'; } if (is_string($this->theme) && strlen($this->theme)) { $this->htmlOptions['class'] .= ' '.$this->theme; } if ($this->bootstrap) { $cs = Yii::app()->getClientScript(); $cs->registerCssFile($this->scriptUrl.'/'.$this->bootstrapCssFile); $this->registerScriptFile($this->bootstrapScriptFile); } $options = CJavaScript::encode($this->options); $this->renderMenuItems($this->items); $placeholder = "$('#${id}').smartmenus($options)"; Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id, "$placeholder;"); } protected function renderMenuItems($items) { echo CHtml::openTag('ul', $this->htmlOptions); foreach ($items as $item) { $this->renderMenuItem($item); } echo CHtml::closeTag('ul'); } protected function renderSubMenuItems($items) { echo CHtml::openTag('ul')."\n"; foreach ($items as $item) { $this->renderMenuItem($item); } echo CHtml::closeTag('ul'); } protected function renderMenuItem($item) { echo CHtml::openTag('li')."\n"; $href = $item['link']; if (!$this->absoluteLink) { $href = Yii::app()->createUrl($item['link']); } echo CHtml::openTag('a', array('class' => $item['class'], 'href' => $href))."\n"; echo $item['name']; echo CHtml::closeTag('a'); if (isset($item['items']) && count($item['items'])) { $this->renderSubMenuItems($item['items']); } echo CHtml::closeTag('li'); } protected function resolvePackagePath() { if ($this->scriptUrl === null || $this->themeUrl === null) { $basePath = Yii::getPathOfAlias('application.extensions.SmartMenu.assets'); $baseUrl = Yii::app()->getAssetManager()->publish($basePath); if ($this->scriptUrl === null) { $this->scriptUrl = $baseUrl.''; } if ($this->themeUrl === null) { $this->themeUrl = $baseUrl.'/css'; } } } protected function registerCoreScripts() { $cs = Yii::app()->getClientScript(); if (is_string($this->cssFile)) { $cs->registerCssFile($this->themeUrl.'/'.$this->cssFile); } elseif (is_array($this->cssFile)) { foreach ($this->cssFile as $cssFile) { $cs->registerCssFile($this->themeUrl.'/'.$cssFile); } } if (is_string($this->theme)) { $cs->registerCssFile($this->themeUrl.'/'.$this->theme.'/'.$this->theme.'.css'); } elseif (is_array($this->cssFile)) { foreach ($this->cssFile as $cssFile) { $cs->registerCssFile($this->themeUrl.'/'.$this->theme.'/'.$cssFile); } } $cs->registerCoreScript('jquery'); if (is_string($this->scriptFile)) { $this->registerScriptFile($this->scriptFile); } elseif (is_array($this->scriptFile)) { foreach ($this->scriptFile as $scriptFile) { $this->registerScriptFile($scriptFile); } } } protected function registerScriptFile($fileName, $position = CClientScript::POS_HEAD) { Yii::app()->getClientScript()->registerScriptFile($this->scriptUrl.'/'.$fileName, $position); } }
[+]
..
[+]
assets
[-] CSmartMenuWidget.php
[edit]