CDropDownMenu is a extension to CMenu that allows Drop-Downs via the superfish jquery plugin.
Documentation ¶
Requirements ¶
- Yii
Installation ¶
- Extract the release file under
protected/extensions
Usage ¶
See the following code example:
$this->widget('ext.CDropDownMenu.CDropDownMenu',array(
'style' => 'vertical', // or default or navbar
'items'=>array(
array(
'label'=>Yii::t('Login'),
'url'=>array('//user/user/login'),
'visible'=>Yii::app()->user->isGuest,
),
array(
'label'=>Yii::t('Register'),
'url'=>array('//registration/registration/registration'),
'visible'=>Yii::app()->user->isGuest,
),
array(
'label'=>Yii::t('Demo'),
'url'=>array('//demo/index'),
'visible'=>Yii::app()->user->isGuest,
),
array(
'label'=>Yii::t('Demo'),
'visible'=>!Yii::app()->user->isGuest,
'items' => array(
array(
'label'=>Yii::t('Browse demos'),
'url'=>array('//demo/index'),
),
array(
'label'=>Yii::t('Create new Demo'),
'url'=>array('//demo/create'),
),
array(
'label'=>Yii::t('Demos'),
'url'=>array('//demo/index', 'owner' => true),
),
),
array('label'=>'Logout ('.Yii::app()->user->name.')',
'url'=>array('/site/logout'),
'visible'=>!Yii::app()->user->isGuest)
)
)
)
);
Attention: please be sure to not use this Widget inside the div id="mainmenu" of standard-generated webapps because there seems to be some css inconsistency between yii's default css and superfish's default css.
Also be sure to read the API Documentation of CMenu to fully understand how this Menu works.
Options passed to superfish need to be inserted into the js/superfish.js file.
Change Log ¶
June 2, 2011 ¶
- added style = 'navbar' and style = 'vertical'
- Codecleanup
January 25, 2010 ¶
- Version 0.2 released
- possible to pass 'cssFile' option
- bugfix: added div clear:both after menu
- possibility to move extension anywhere in file system path
- added shadow.png and arrows.png from default
- made the default css-file a lot more beautiful
January 20, 2010 ¶
- Initial release.
How can I center in my page a CDropDownMenu?
How can I center in my page a CDropDownMenu?
Ability to set superfish options
Perhaps replace CDropDownMenu.js with PHP code:
//Yii::app()->clientScript->registerScriptFile($baseUrl . '/' . 'CDropDownMenu.js',CClientScript::POS_HEAD); $sfOptions = '{delay:300,speed:"fast"}'; Yii::app()->clientScript->registerScript('sf-menu', '$("ul.sf-menu").superfish('.$sfOptions.');', CClientScript::POS_READY);
Hope for a new release...
Yep, would be great to have a workin superfish plugin... this way is quite not usable...
Thank you
this bugfix and some more default styles will be released in the next version soon
Missing Closing Div
Hi and thanks for your contribution.
I just wanted to report that your code appears to have a missing closing div element.
$this->registerClientScript();
echo '<div style="clear:both;">';
The last line should read:
echo '<div style="clear:both;"></div>';
Kind regards.
excellent
the use of hoverIntent.js is a big improvement over any other javascript menus.
Thanks for creating this in Yii!
thanks for Your Contributions
@ got2doodle: yes, of course. Any Contribution is wanted !
@ jonah: already fixed this in the new Version i am releasing soon (among other additions...)
Excellent
I would only recommend this change on line 47 of CDropDownMenu:
$basePath=dirname(__FILE__).DIRECTORY_SEPARATOR.'vendors';
This way the vendor folder can be located in the same directory as the extension no matter where the extension is located
Nice extension
I modified CDropDownMenu.php so that I could pass the name of the css file that I want to use. Let me know if you want the modified code.
doodle
Problems with using this extension
Unfortunatelly, this extension does not work as supposed!
Extension author assumed that it's files (CDropDownMenu.php file and vendors folder) will be put directly in extensions folder, not in own subfolder which introduces mess inside. Attempts to use subfolder makes extension to not work at all, because paths inside it (especially to vendors folder, which should be published via assetsManager) are hardcoded -> very bad developer attitiude! One must do manual extension code rewrite to be able to put it in subfolder of extensions folder. Please not that Yii definitive guide strongly advises to use subfolder per each extension being used in page!
Even if ones decides to use extension directly in extensions folder, it works, but looks ugly! Seems like CSS styling does not work. Double checked that superfish.css is properly published and linked to page and that menu structure does not collide with original div id="mainmenu", but with no results.
Overall note: Idea of use superfish.js is great but one need to search for another Yii extensions or write own to use it inside Yii app as this one requires to much work to made it working.
Beautiful
Well, it needs fine-tuning to make it look good...but functionally beautiful.
Thanks for keeping it so clean!
changing the background color
How do I change the lightgray background color of the menu? Changing the color in superfish.css has no effect.
@abhimir
It will take effect if you delete content of assets folder.
Suggestion
Suggestion for next release for configuring superfish options:
comment this first line and add the second
//$cs->registerScriptFile($baseUrl . '/js/' . 'CDropDownMenu.js',$this->position); $cs->registerScript('superfish',$this->getJs(),CClientScript::POS_READY);
add this public var:
public $options;
and finally this function
protected function getJs(){ $js_options = CJavaScript::encode($this->options); return <<<EOF $(document).ready(function() { $('ul.sf-menu').superfish($js_options); }); EOF; }
Suggestion
add:
public $options; public $activeCssClass = 'current';
Move files:
directory /js, /images/, /js into subfolder /assets/*
Delete file:
/assets/js/CDropDownMenu.js
Relace #1:
//$basePath = Yii::getPathOfAlias('ext.CDropDownMenu'); //$baseUrl = Yii::app()->getAssetManager()->publish($basePath);
$dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets'; $baseUrl = Yii::app()->getAssetManager()->publish($dir);
Replace #2:
//$cs->registerScriptFile($baseUrl . '/js/' . 'CDropDownMenu.js',$this->position);
$cs->registerScript('superfish', '$("ul.sf-menu").superfish('.CJavaScript::encode($this->options).'); ',$this->position);
Add:
protected function renderMenuItem($item) { $options=isset($item['linkOptions']) ? $item['linkOptions'] : array(); $class = array(); if($item['active'] && $this->activeCssClass!='') $class[]=$this->activeCssClass; if($class!==array()) { if(empty($options['class'])) $options['class']=implode(' ',$class); else $options['class'].=' '.implode(' ',$class); } $item['linkOptions'] = $options; return parent::renderMenuItem($item); }
Demo and git
Is there any Demo and git repository?
Css images path error
In my assets folders, the 'images' folder is not inside the 'css' folder.
So this code in superfish.css does not find the required file:
background: url('images/arrows-ffffff.png') no-repeat -10px -100px;
Change it to:
background: url('../images/arrows-ffffff.png') no-repeat -10px -100px;
Do the same for:
background: url('../images/shadow.png') no-repeat -10px -100px;
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.