Skip to content

Commit

Permalink
Updates to release v1.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Sep 19, 2018
1 parent aa097f1 commit b1af977
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 114 deletions.
7 changes: 7 additions & 0 deletions CHANGE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Change Log: `yii2-nav-x`
========================

## Version 1.2.2

**Date:** 19-Sep-2018

- Enhancements to support Bootstrap v4.x.
- Move all source code to `src` directory.

## Version 1.2.1

**Date:** 13-May-2017
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2014 - 2017, Kartik Visweswaran
Copyright (c) 2014 - 2018, Kartik Visweswaran
Krajee.com
All rights reserved.

Expand Down
29 changes: 0 additions & 29 deletions NavXAsset.php

This file was deleted.

13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ yii2-nav-x
[![Monthly Downloads](https://poser.pugx.org/kartik-v/yii2-nav-x/d/monthly)](https://packagist.org/packages/kartik-v/yii2-nav-x)
[![Daily Downloads](https://poser.pugx.org/kartik-v/yii2-nav-x/d/daily)](https://packagist.org/packages/kartik-v/yii2-nav-x)

An extended bootstrap Nav widget for Yii Framework 2 with submenu drilldown. This widget extends the `\yii\bootstrap\Nav` widget
with some additional controls and adding the CSS Styles for enabling a submenu drilldown. The dropdown menu style is optimized for both
desktop and mobile devices. The drilldown is triggered on `active` instead of `hover` so that it works equally well on mobile devices. The
extension uses the `\kartik\dropdown\DropdownX` extension by default for rendering dropdown navigation, but this can be overridden.
An extended bootstrap Nav widget for Yii Framework 2 with submenu drilldown. This widget extends the `\yii\bootstrap\Nav` widget for Bootstrap 3.x and
`\yii\bootstrap4\Nav` widget for Bootstrap 4.x with some additional controls and adding the CSS Styles for enabling a submenu drilldown. The dropdown menu style
is optimized for both desktop and mobile devices. The drilldown is triggered on `active` instead of `hover` so that it works equally well on mobile devices. The
extension uses the one of the following Dropdown Class extensions by default for rendering dropdown navigation, but this can be overridden:

- `\kartik\dropdown\DropdownX` for Bootstrap 3.x
- `\kartik\bs4dropdown\Dropdown` for Bootstrap 4.x

### Demo
You can see detailed [documentation](http://demos.krajee.com/nav-x) on usage of the extension.
Expand Down Expand Up @@ -61,4 +64,4 @@ echo NavX::widget([

## License

**yii2-nav-x** is released under the BSD 3-Clause License. See the bundled `LICENSE.md` for details.
**yii2-nav-x** is released under the BSD-3-Clause License. See the bundled `LICENSE.md` for details.
29 changes: 0 additions & 29 deletions assets/css/nav-x.css

This file was deleted.

11 changes: 0 additions & 11 deletions assets/css/nav-x.min.css

This file was deleted.

4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
}
],
"require": {
"kartik-v/yii2-dropdown-x": "*"
"kartik-v/yii2-krajee-base": ">=1.9"
},
"autoload": {
"psr-4": {
"kartik\\nav\\": ""
"kartik\\nav\\": "src"
}
},
"extra": {
Expand Down
116 changes: 116 additions & 0 deletions src/NavX.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php

/**
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2018
* @package yii2-nav-x
* @version 1.2.2
*/

namespace kartik\nav;

use kartik\base\Widget;

/**
* An extended nav menu for Bootstrap 3.x and 4.x - that offers submenu drilldown
*
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @since 1.0
*/
class NavX extends Widget
{
/**
* @var array list of items in the nav widget. Each array element represents a single
* menu item which can be either a string or an array with the following structure:
*
* - label: string, required, the nav item label.
* - url: optional, the item's URL. Defaults to "#".
* - visible: bool, optional, whether this menu item is visible. Defaults to true.
* - linkOptions: array, optional, the HTML attributes of the item's link.
* - options: array, optional, the HTML attributes of the item container (LI).
* - active: bool, optional, whether the item should be on active state or not.
* - dropDownOptions: array, optional, the HTML options that will passed to the [[Dropdown]] widget.
* - items: array|string, optional, the configuration array for creating a [[Dropdown]] widget,
* or a string representing the dropdown menu. Note that Bootstrap does not support sub-dropdown menus.
* - encode: bool, optional, whether the label will be HTML-encoded. If set, supersedes the $encodeLabels option for only this item.
*
* If a menu item is a string, it will be rendered directly without HTML encoding.
*/
public $items = [];

/**
* @var bool whether the nav items labels should be HTML-encoded.
*/
public $encodeLabels = true;

/**
* @var bool whether to automatically activate items according to whether their route setting
* matches the currently requested route.
* @see isItemActive
*/
public $activateItems = true;

/**
* @var bool whether to activate parent menu items when one of the corresponding child menu items is active.
*/
public $activateParents = false;

/**
* @var string the route used to determine if a menu item is active or not.
* If not set, it will use the route of the current request.
* @see params
* @see isItemActive
*/
public $route;

/**
* @var array the parameters used to determine if a menu item is active or not.
* If not set, it will use `$_GET`.
* @see route
* @see isItemActive
*/
public $params;

/**
* @var string name of a class to use for rendering dropdowns within this widget. Defaults to [[Dropdown]].
*/
public $dropdownClass;

/**
* @var array the dropdown widget options
*/
public $dropdownOptions = [];

/**
* @inheritdoc
*/
public function init()
{
if (!class_exists($this->dropdownClass)) {
throw new InvalidConfigException("The dropdownClass '{$this->dropdownClass}' was not found. Please ensure the '{$this->dropdownClass}' extension is installed and accessible.");
}
parent::init();
}

/**
* @inheritdoc
*/
public function run()
{
$opts = [
'items' => $this->items,
'encodeLabels' => $this->encodeLabels,
'activateItems' => $this->activateItems,
'activateParents' => $this->activateParents,
'dropdownOptions' => $this->dropdownOptions,
'options' => $this->options,
'clientOptions' => $this->pluginOptions,
];
$props = ['route', 'params', 'dropdownClass'];
foreach ($props as $prop) {
if (isset($this->$prop)) {
$opts[$prop] = $this->$prop;
}
}
echo $this->isBs4() ? NavXBs4::widget($opts) : NavXBs3::widget($opts);
}
}
27 changes: 27 additions & 0 deletions src/NavXBs3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/**
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2018
* @package yii2-nav-x
* @version 1.2.2
*/

namespace kartik\nav;

use yii\base\InvalidConfigException;
use yii\bootstrap\Nav;

/**
* An extended nav menu for Bootstrap 3.x and 4.x - that offers submenu drilldown
*
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @since 1.0
*/
class NavXBs3 extends Nav
{
use NavXTrait;
/**
* @var string the class name to render the Dropdown items. Defaults to `\kartik\dropdown\DropdownX`.
*/
public $dropdownClass = 'kartik\dropdown\DropdownX';
}
27 changes: 27 additions & 0 deletions src/NavXBs4.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/**
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2018
* @package yii2-nav-x
* @version 1.2.2
*/

namespace kartik\nav;

use yii\base\InvalidConfigException;
use yii\bootstrap4\Nav;

/**
* An extended nav menu for Bootstrap 3.x and 4.x - that offers submenu drilldown
*
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @since 1.0
*/
class NavXBs4 extends Nav
{
use NavXTrait;
/**
* @var string the class name to render the Dropdown items. Defaults to `\kartik\dropdown\DropdownX`.
*/
public $dropdownClass = 'kartik\bs4dropdown\Dropdown';
}
55 changes: 18 additions & 37 deletions NavX.php → src/NavXTrait.php
Original file line number Diff line number Diff line change
@@ -1,69 +1,50 @@
<?php

/**
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2017
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2018
* @package yii2-nav-x
* @version 1.2.1
* @version 1.2.2
*/

namespace kartik\nav;

use yii\base\InvalidConfigException;
use yii\bootstrap\Nav;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;

/**
* An extended nav menu for Bootstrap 3 - that offers submenu drilldown
* Trait for [[NavX]] methods
*
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @since 1.0
*/
class NavX extends Nav
trait NavXTrait
{
/**
* @var string the class name to render the Dropdown items. Defaults to `\kartik\dropdown\DropdownX`.
*/
public $dropdownClass = '\kartik\dropdown\DropdownX';

/**
* @var array the dropdown widget options
*/
public $dropdownOptions = [];

/**
* @inheritdoc
* @throws InvalidConfigException
*/
public function init()
{
if (!class_exists($this->dropdownClass)) {
throw new InvalidConfigException("The dropdownClass '{$this->dropdownClass}' does not exist or is not accessible.");
}
NavXAsset::register($this->getView());
parent::init();
}

/**
* @inheritdoc
* Renders the given items as a dropdown.
* This method is called to create sub-menus.
* @param array $items the given items. Please refer to [[Dropdown::items]] for the array structure.
* @param array $parentItem the parent item information. Please refer to [[items]] for the structure of this array.
* @return string the rendering result.
* @throws \Exception
*/
protected function renderDropdown($items, $parentItem)
{
/**
* @var \yii\bootstrap\Dropdown $ddWidget
*/
$ddWidget = $this->dropdownClass;
/** @var \yii\base\Widget $dropdownClass */
$dropdownClass = $this->dropdownClass;
$ddOptions = array_replace_recursive($this->dropdownOptions, [
'options' => ArrayHelper::getValue($parentItem, 'dropDownOptions', []),
'items' => $items,
'encodeLabels' => $this->encodeLabels,
'clientOptions' => false,
'view' => $this->getView(),
]);
return $ddWidget::widget($ddOptions);
return $dropdownClass::widget($ddOptions);
}

/**
* @inheritdoc
* Check to see if a child item is active optionally activating the parent.
* @param array $items @see items
* @param bool $active should the parent be active too
* @return array @see items
*/
protected function isChildActive($items, &$active)
{
Expand Down

0 comments on commit b1af977

Please sign in to comment.