Permalink
Browse files

Accordeon menu extesion version 1.0

  • Loading branch information...
1 parent 3b3d467 commit d9f8ec15ffce488a0b51b07b4017e0470cd97769 @belichuk committed Aug 22, 2012
View
@@ -1,3 +0,0 @@
-assets/
-protected/runtime/
-themes/classic/views/
View
110 EMenu.php
@@ -0,0 +1,110 @@
+<?
+class EMenu extends CWidget
+{
+ public $tag = 'ul';
+ public $subtag = 'li';
+ public $id = "";
+ public $items = array();
+
+
+ public function init()
+ {
+ if( empty($this->items) )
+ return;
+
+ $menuClass = 'accordion-menu';
+ $content = '';
+ $assets = $this->publishAssets();
+ $css = $assets . '/css/accordionmenu.css';
+ $js = $assets . '/js/accordionmenu.min.js';
+ $cs = Yii::app()->clientScript;
+
+ $cs->registerCSSFile( $css );
+ $cs->registerScriptFile( $js );
+ $cs->registerScript(
+ 'accordionMenu',
+ "$('.".$menuClass."').accordionMenu();",
+ CClientScript::POS_READY
+ );
+
+ $route = array(
+ 'controller' => Yii::app()->controller->id,
+ 'action' => Yii::app()->controller->action->id
+ );
+
+ foreach ($this->items as $item) {
+ $content .= $this->renderTag($item, 1, $route);
+ }
+
+ $htmlOptions = array(
+ 'id' => empty($this->id) ? null : $this->id,
+ 'class' => $menuClass
+ );
+
+ echo CHtml::tag($this->tag, $htmlOptions, $content);
+ }
+
+ private function renderTag($item, $level=1, $route = array())
+ {
+ $menu = '';
+ $submenu = '';
+ $toggle = '';
+ $nextlevel = $level + 1;
+
+ if( isset($item['sub']) && is_array($item['sub']) ){
+ foreach ($item['sub'] as $sub) {
+ $submenu .= $this->renderTag($sub, $nextlevel, $route);
+ }
+ $toggle = CHtml::tag('span', array('class'=>'arrow'), '');
+ }
+
+ $content = CHtml::link($item['name'], $item['link']);
+ $subclass = 'level'.$level;
+ $toggleclass = 'toggler';
+
+ if( !empty($item['active']) ){
+ $active = explode('/', $item['active']);
+ if( ($level == 1) && ($route['controller'] == $active[0]) ){
+ $subclass .= ' current active';
+ $toggleclass .= ' active';
+ }
+
+ if( array_diff($route, $active) == array() )
+ $subclass .= ' active';
+ }
+
+ if( $level == 1 ){
+ $icon_class = isset($item['icon']) ? $item['icon'] : 'none';
+ $icon_class = 'menu_icon ' . 'icon-' . $icon_class;
+ $icon = CHtml::tag('span', array('class'=> $icon_class), '');
+ $toggleOptions = array(
+ 'class' => $toggleclass
+ );
+ $toggleContent = $icon . $toggle . $content;
+ $content = CHtml::tag('div', $toggleOptions, $toggleContent);
+ }
+
+ if( !empty($submenu) ){
+ $htmlOptions = array('class' => 'level'.$nextlevel);
+ $submenu = CHtml::tag($this->tag, $htmlOptions, $submenu);
+ $content .= $submenu;
+ }
+
+ $menu .= CHtml::tag($this->subtag, array('class'=>$subclass), $content);
+ return $menu;
+ }
+
+ private function publishAssets()
+ {
+ $package = array(
+ 'basePath'=> 'ext.menu.assets',
+ 'depends' => array('jquery')
+ );
+ $assets = Yii::app()->clientScript
+ ->addPackage('emenu', $package)
+ ->registerPackage('emenu')
+ ->getPackageBaseUrl('emenu');
+ return $assets;
+ }
+
+}
View
@@ -1,4 +1 @@
-menu
-====
-
Accordion menu extension for Yii
@@ -0,0 +1,81 @@
+/************ Accordion menu ************/
+ul.accordion-menu{
+ margin: 0;
+ padding: 0;
+ list-style: none;
+ border-radius: 4px 4px 4px 4px;
+ padding: 15px 0;
+ margin: 3px 6px;
+ background: url("../images/menu_separate.png") repeat-x scroll 0 15px #686d73;
+}
+ul.accordion-menu li{
+ background: url("../images/menu_separate.png") repeat-x scroll 0 bottom transparent;
+ color: #DCE3EA;
+ text-shadow:1px 0 0 rgba(255, 255, 255, 0.1);
+}
+ul.accordion-menu li a{
+ line-height: 20px;
+ color: inherit !important;
+ display: block;
+ text-decoration: none !important;
+}
+
+ul.accordion-menu li.level1 div.toggler:hover,
+ul.level2 li:hover{
+ background: #4C99D2;
+ color: #FFF !important;
+ text-shadow: none;
+ background: -o-linear-gradient(top, #60afee 0%, #5596d6 100%);
+ background: -webkit-linear-gradient(top, #60afee 0%, #5596d6 100%);
+ background: -moz-linear-gradient(top, #60afee 0%, #5596d6 100%);
+ background: linear-gradient(to bottom, #60afee 0%, #5596d6 100%);
+}
+ul.accordion-menu li.current div.toggler{
+ background: #E5E5E5;
+ background: -o-linear-gradient(top, #fff 10%, #E5E5E5 100%);
+ background: -webkit-linear-gradient(top, #fff 10%, #E5E5E5 100%);
+ background: -moz-linear-gradient(top, #fff 10%, #E5E5E5 100%);
+ background: linear-gradient(to bottom, #fff 10%, #E5E5E5 100%);
+ box-shadow: 0 -1px 0 rgba(20,20,25,0.1);
+ text-shadow: 0 1px 0 rgba(255,255,255,0.7);
+ color: #92979E;
+
+}
+ul.accordion-menu li div.toggler{
+ height: 20px;
+ padding: 7px 15px;
+}
+ul.accordion-menu li.current span.arrow{ background-position: -9px -6px;}
+ul.accordion-menu li.current.active span.arrow{background-position: -9px -36px;}
+ul.accordion-menu li.active span.arrow{background-position: -9px -96px;}
+ul.accordion-menu li span.arrow{
+ background-image: url("../images/menu_arrows.png");
+ clear:right;
+ float: right;
+ width: 20px;
+ height: 20px;
+ background-repeat: no-repeat;
+ background-position: -8px -66px;
+ cursor: pointer;
+}
+ul.accordion-menu li span.menu_icon{
+ float: left;
+ height: 14px;
+ width: 14px;
+ margin:2px 4px 0 0;
+}
+ul.accordion-menu li ul.level2{
+ margin: 0;
+ padding: 0;
+ list-style: none;
+ background: url("../images/menu_separate.png") repeat-x scroll 0 top transparent;
+}
+ul.accordion-menu li ul.level2 li{
+ height: 20px;
+ padding: 6px 0 5px 45px;
+}
+ul.accordion-menu li ul.level2 li.active a{
+ font-weight: bold;
+ text-shadow: none;
+}
+/********** End accordion menu **********/
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -0,0 +1,66 @@
+/* License http://www.gnu.org/licenses/gpl.html GNU/GPL */
+
+
+(function (d) {
+ var a = function () {};
+ d.extend(a.prototype, {
+ name: "accordionMenu",
+ options: {
+ display: null,
+ collapseall: false,
+ toggler : "li.level1 div.toggler",
+ submenu : "ul.level2",
+ arrow : "li.level1 div.toggler span.arrow"
+ },
+ initialize: function (a, b) {
+ var b = d.extend({}, this.options, b),
+ c = a.find(b.toggler),
+ r = a.find(b.arrow);
+
+ r.each(function (h) {
+ var a = d(this),
+ c = a.parent().next(b.submenu).wrap("<div>").parent();
+
+ c.data("height", c.height());
+ a.parent().hasClass("active") || h == b.display ? c.show() : c.hide().css("height", 0);
+
+ a.bind("click", function () {
+ f(h)
+ })
+ });
+ var f = function (b) {
+
+ var a = d(r.get(b)).parent(),
+ e = d([]);
+
+ a.hasClass("active") && (e = a, a = d([]));
+ b.collapseall && (e = c.filter(".active"));
+
+ a.next().stop().show().animate({
+ height: a.next().data("height")
+ });
+ e.next().stop().animate({
+ height: 0
+ }, function () {
+ e.next().hide()
+ });
+
+ a.addClass("active").parent().addClass("active");
+ e.removeClass("active").parent().removeClass("active")
+ }
+ }
+ });
+ d.fn[a.prototype.name] = function () {
+ var g = arguments,
+ b = g[0] ? g[0] : null;
+ return this.each(function () {
+ var c = d(this);
+ if (a.prototype[b] && c.data(a.prototype.name) && b != "initialize") c.data(a.prototype.name)[b].apply(c.data(a.prototype.name), Array.prototype.slice.call(g, 1));
+ else if (!b || d.isPlainObject(b)) {
+ var f = new a;
+ a.prototype.initialize && f.initialize.apply(f, d.merge([c], g));
+ c.data(a.prototype.name, f)
+ } else d.error("Method " + b + " does not exist on jQuery." + a.name)
+ })
+ }
+})(jQuery);

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit d9f8ec1

Please sign in to comment.