Commits

Christoffer Niska committed a8bf141

fixed an issue with navbar and collapse

  • Participants
  • Parent commits 657c5d1
  • Branches 1.0.0-wip

Comments (0)

Files changed (3)

File widgets/TbAlert.php

 	 */
 	public $htmlOptions = array();
 
+	private static $_containerId = 0;
+
 	/**
 	 * Initializes the widget.
 	 */
 		echo '</div>';
 
 		$selector = "#{$id} .alert";
-		$id .= '_'.uniqid(true, true);
+		$id .= '_'.self::$_containerId++;
 
 		/** @var CClientScript $cs */
 		$cs = Yii::app()->getClientScript();

File widgets/TbCollapse.php

     */
     public $htmlOptions = array();
 
+	private static $_containerId = 0;
+
     /**
      * Initializes the widget.
      */
             $cs->registerScript(__CLASS__.'#'.$id.'_'.$name, "jQuery('#{$id}').on('{$name}', {$handler});");
         }
     }
+
+	/**
+	 * Returns the next collapse container ID.
+	 * @return string the id
+	 * @static
+	 */
+	public static function getNextContainerId()
+	{
+		return 'collapse_'.self::$_containerId++;
+	}
 }
 

File widgets/TbNavbar.php

  * @since 0.9.7
  */
 
+Yii::import('bootstrap.widgets.TbCollapse');
+
 /**
  * Bootstrap navigation bar widget.
  */
 	 */
 	public function run()
 	{
-		$containerCssClass = $this->fluid ? 'container-fluid' : 'container';
+		echo CHtml::openTag('div', $this->htmlOptions);
+		echo '<div class="navbar-inner"><div class="'.$this->getContainerCssClass().'">';
 
-		echo CHtml::openTag('div', $this->htmlOptions);
-		echo '<div class="navbar-inner"><div class="'.$containerCssClass.'">';
+		$collapseId = TbCollapse::getNextContainerId();
 
-        if ($this->collapse)
+        if ($this->collapse !== false)
         {
-            echo '<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">';
+            echo '<a class="btn btn-navbar" data-toggle="collapse" data-target="#'.$collapseId.'">';
 			echo '<span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>';
 			echo '</a>';
 		}
         if ($this->brand !== false)
             echo CHtml::openTag('a', $this->brandOptions).$this->brand.'</a>';
 
-		if ($this->collapse)
+		if ($this->collapse !== false)
         {
             $this->controller->beginWidget('bootstrap.widgets.TbCollapse', array(
+				'id'=>$collapseId,
 				'toggle'=>false, // navbars should be collapsed by default
                 'htmlOptions'=>array('class'=>'nav-collapse'),
             ));
 			}
 		}
 
-		if ($this->collapse)
+		if ($this->collapse !== false)
             $this->controller->endWidget();
 
 		echo '</div></div></div>';
 	}
+
+	/**
+	 * Returns the navbar container CSS class.
+	 * @return string the class
+	 */
+	protected function getContainerCssClass()
+	{
+		return $this->fluid ? 'container-fluid' : 'container';
+	}
 }