├── .github
├── CONTRIBUTING.md
├── ISSUE_TEMPLATE.md
├── PULL_REQUEST_TEMPLATE.md
└── stale.yml
├── CHANGE.md
├── LICENSE.md
├── README.md
├── composer.json
└── src
├── NavX.php
├── NavXBs3.php
├── NavXBs4.php
├── NavXBs5.php
└── NavXTrait.php
/.github/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | Contributing to yii2-nav-x
2 | ==========================
3 | Looking to contribute something to yii2-nav-x? **Here's how you can help.**
4 |
5 | Please take a moment to review this document in order to make the contribution
6 | process easy and effective for everyone involved.
7 |
8 | Following these guidelines helps to communicate that you respect the time of
9 | the developers managing and developing this open source project. In return,
10 | they should reciprocate that respect in addressing your issue or assessing
11 | patches and features.
12 |
13 | Using the issue tracker
14 | -----------------------
15 | When [reporting bugs][reporting-bugs] or
16 | [requesting features][requesting-features], the
17 | [issue tracker on GitHub][issue-tracker] is the recommended channel to use.
18 |
19 | The issue tracker **is not** a place for support requests. Refer the
20 | [extension documentation and demos](http://demos.krajee.com/nav-x) and/or refer to the
21 | [webtips Q & A forum](http://webtips.krajee.com/questions) which are the better places to get help.
22 |
23 | Reporting bugs with yii2-nav-x
24 | -----------------------------
25 | We really appreciate clear bug reports that _consistently_ show an issue
26 | _within yii2-nav-x_.
27 |
28 | The ideal bug report follows these guidelines:
29 |
30 | 1. **Use the [GitHub issue search][issue-search]** — Check if the issue
31 | has already been reported.
32 | 2. **Check if the issue has been fixed** — Try to reproduce the problem
33 | using the code in the `master` branch.
34 | 3. **Isolate the problem** — Try to share a demo or a test case that
35 | consistently reproduces the problem.
36 |
37 | Please try to be as detailed as possible in your bug report, especially if an
38 | isolated test case cannot be made. Some useful questions to include the answer
39 | to are:
40 |
41 | - What steps can be used to reproduce the issue?
42 | - What is the bug and what is the expected outcome?
43 | - What browser(s) and Operating System have you tested with?
44 | - Does the bug happen consistently across all tested browsers?
45 | - What version of jQuery are you using? And what version of yii2-nav-x?
46 | - Are you using yii2-nav-x with other plugins?
47 |
48 | All of these questions will help others fix and identify any potential bugs.
49 |
50 | Requesting features in yii2-nav-x
51 | ------------------------------------------
52 | Before starting work on a major feature for yii2-nav-x, **read the
53 | [documentation](http://demos.krajee.com/nav-x) first** or you may risk spending a considerable amount of
54 | time on something which the project developers are not interested in bringing into the project.
55 |
56 | ### Submitting a pull request
57 |
58 | We use GitHub's pull request system for submitting patches. Here are some
59 | guidelines to follow when creating the pull request for your fix.
60 |
61 | 1. Make sure to create a ticket for your pull request. This will serve as the
62 | bug ticket, and any discussion about the bug will take place there. Your pull
63 | request will be focused on the specific changes that fix the bug.
64 | 2. Make sure to reference the ticket you are fixing within your pull request.
65 | This will allow us to close off the ticket once we merge the pull request, or
66 | follow up on the ticket if there are any related blocking issues.
67 | 3. Explain why the specific change was made. Not everyone who is reviewing your
68 | pull request will be familiar with the problem it is fixing.
69 | 4. Run your tests first. If your tests aren't passing, the pull request won't
70 | be able to be merged. If you're breaking existing tests, make sure that you
71 | aren't causing any breaking changes.
72 | 5. Only include source changes. While it's not required, only including changes
73 | from the `src` directory will prevent merge conflicts from occuring. Making
74 | this happen can be as a simple as not committing changes from the `dist`
75 | directory.
76 |
77 | By following these steps, you will make it easier for your pull request to be
78 | reviewed and eventually merged.
79 |
80 | Triaging issues and pull requests
81 | ---------------------------------
82 | Anyone can help the project maintainers triage issues and review pull requests.
83 |
84 | ### Handling new issues
85 |
86 | yii2-nav-x regularly receives new issues which need to be tested and organized.
87 |
88 | When a new issue that comes in that is similar to another existing issue, it
89 | should be checked to make sure it is not a duplicate. Duplicates issues should
90 | be marked by replying to the issue with "Duplicate of #[issue number]" where
91 | `[issue number]` is the url or issue number for the existing issue. This will
92 | allow the project maintainers to quickly close off additional issues and keep
93 | the discussion focused within a single issue.
94 |
95 | If you can test issues that are reported to yii2-nav-x that contain test cases and
96 | confirm under what conditions bugs happen, that will allow others to identify
97 | what causes a bug quicker.
98 |
99 | ### Reviewing pull requests
100 |
101 | It is very common for pull requests to be opened for issues that contain a clear
102 | solution to the problem. These pull requests should be rigorously reviewed by
103 | the community before being accepted. If you are not sure about a piece of
104 | submitted code, or know of a better way to do something, do not hesitate to make
105 | a comment on the pull request.
106 |
107 | ### Reviving old tickets
108 |
109 | If you come across tickets which have not been updated for a while, you are
110 | encouraged to revive them. While this can be as simple as saying `:+1:`, it is
111 | best if you can include more information on the issue. Common bugs and feature
112 | requests are more likely to be fixed, whether it is by the community or the
113 | developers, so keeping tickets up to date is encouraged.
114 |
115 | Licensing
116 | ---------
117 |
118 | It should also be made clear that **all code contributed to yii2-nav-x** must be
119 | licensable under the [BSD-3 license][licensing]. Code that cannot be released
120 | under this license **cannot be accepted** into the project.
121 |
122 | [issue-search]: https://github.com/kartik-v/yii2-nav-x/search?q=&type=Issues
123 | [issue-tracker]: https://github.com/kartik-v/yii2-nav-x/issues
124 | [licensing]: https://github.com/kartik-v/yii2-nav-x/blob/master/LICENSE.md
125 | [reporting-bugs]: #reporting-bugs-with-yii2-nav-x
126 | [requesting-features]: #requesting-features-in-yii2-nav-x
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ## Prerequisites
2 |
3 | - [ ] I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
4 | - [ ] The issue still exists against the latest `master` branch of yii2-nav-x.
5 | - [ ] This is not an usage question. I confirm having gone through and read the [documentation and demos](http://demos.krajee.com/nav-x).
6 | - [ ] This is not a general programming / coding question. (Those should be directed to the [webtips Q & A forum](http://webtips.krajee.com/questions)).
7 | - [ ] I have attempted to find the simplest possible steps to reproduce the issue.
8 | - [ ] I have included a failing test as a pull request (Optional).
9 |
10 | ## Steps to reproduce the issue
11 |
12 | 1.
13 | 2.
14 | 3.
15 |
16 | ## Expected behavior and actual behavior
17 |
18 | When I follow those steps, I see...
19 |
20 | I was expecting...
21 |
22 | ## Environment
23 |
24 | #### Browsers
25 |
26 | - [ ] Google Chrome
27 | - [ ] Mozilla Firefox
28 | - [ ] Internet Explorer
29 | - [ ] Safari
30 |
31 | #### Operating System
32 |
33 | - [ ] Windows
34 | - [ ] Mac OS X
35 | - [ ] Linux
36 | - [ ] Mobile
37 |
38 | #### Libraries
39 |
40 | - jQuery version:
41 | - yii2-nav-x version:
42 |
43 | ## Isolating the problem
44 |
45 | - [ ] This bug happens [on the demos page](https://demos.krajee.com/nav-x)
46 | - [ ] The bug happens consistently across all tested browsers
47 | - [ ] This bug happens when using yii2-nav-x without other plugins.
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ## Scope
2 | This pull request includes a
3 |
4 | - [ ] Bug fix
5 | - [ ] New feature
6 | - [ ] Translation
7 |
8 | ## Changes
9 | The following changes were made (this change is also documented in the [change log](https://github.com/kartik-v/yii2-nav-x/blob/master/CHANGE.md)):
10 |
11 | -
12 | -
13 | -
14 |
15 | ## Related Issues
16 | If this is related to an existing ticket, include a link to it as well.
--------------------------------------------------------------------------------
/.github/stale.yml:
--------------------------------------------------------------------------------
1 | # Number of days of inactivity before an issue becomes stale
2 | daysUntilStale: 60
3 | # Number of days of inactivity before a stale issue is closed
4 | daysUntilClose: 7
5 | # Issues with these labels will never be considered stale
6 | exemptLabels:
7 | - bug
8 | - enhancement
9 | - pinned
10 | - security
11 | # Label to use when marking an issue as stale
12 | staleLabel: wontfix
13 | # Comment to post when marking an issue as stale. Set to `false` to disable
14 | markComment: >
15 | This issue has been automatically marked as stale because it has not had
16 | recent activity. It will be closed if no further activity occurs. Thank you
17 | for your contributions.
18 | # Comment to post when closing a stale issue. Set to `false` to disable
19 | closeComment: false
--------------------------------------------------------------------------------
/CHANGE.md:
--------------------------------------------------------------------------------
1 | Change Log: `yii2-nav-x`
2 | ========================
3 |
4 | ## Version 1.2.6
5 |
6 | *Date:* 24-Jan-2022
7 |
8 | - Enhance & standardize php docs for new website https://docs.krajee.com.
9 |
10 | ## Version 1.2.5
11 |
12 | *Date:* 02-Nov-2021
13 |
14 | - (enh #22): Enhancements to support Bootstrap v5.x.
15 |
16 | ## Version 1.2.4
17 |
18 | **Date:** 19-Sep-2018
19 |
20 | - Maintain dependency on kartik-v/yii2-dropdown-x for Backward compatibility.
21 |
22 | ## Version 1.2.3
23 |
24 | **Date:** 19-Sep-2018
25 |
26 | - Correct README for dependencies.
27 |
28 | ## Version 1.2.2
29 |
30 | **Date:** 19-Sep-2018
31 |
32 | - Enhancements to support Bootstrap v4.x.
33 | - Move all source code to `src` directory.
34 |
35 | ## Version 1.2.1
36 |
37 | **Date:** 13-May-2017
38 |
39 | - Chronological ordering of issues for change log.
40 | - Add github contribution and PR templates.
41 | - (enh #14, #15, #16): Better styling for submenu items for smaller device screens.
42 | - Add branch alias for dev-master latest release.
43 | - (enh #12): Refactor NavX code based on latest `yii\bootstrap\Nav`.
44 |
45 | ## Version 1.2.0
46 |
47 | **Date:** 07-Dec-2014
48 |
49 | - (enh #7): Enhance multi level navigation beyond 2 levels.
50 |
51 | ## Version 1.1.0
52 |
53 | **Date:** 08-Nov-2014
54 |
55 | - Set release to stable
56 | - Enhance dependency validation using common code base.
57 |
58 | ## Version 1.0.0
59 |
60 | **Date:** 08-May-2014
61 |
62 | - PSR4 alias change
63 | - (bug #6): Enhance the extension to have the right dependency on `yii\bootstrap` assets.
64 | - Initial release
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | Copyright (c) 2014 - 2022, Kartik Visweswaran
2 | Krajee.com
3 | All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without modification,
6 | are permitted provided that the following conditions are met:
7 |
8 | * Redistributions of source code must retain the above copyright notice, this
9 | list of conditions and the following disclaimer.
10 |
11 | * Redistributions in binary form must reproduce the above copyright notice, this
12 | list of conditions and the following disclaimer in the documentation and/or
13 | other materials provided with the distribution.
14 |
15 | * Neither the names of Kartik Visweswaran or Krajee nor the names of its
16 | contributors may be used to endorse or promote products derived from
17 | this software without specific prior written permission.
18 |
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | yii2-nav-x
7 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | [](https://packagist.org/packages/kartik-v/yii2-nav-x)
16 | [](https://packagist.org/packages/kartik-v/yii2-nav-x)
17 | [](https://packagist.org/packages/kartik-v/yii2-nav-x)
18 | [](https://packagist.org/packages/kartik-v/yii2-nav-x)
19 | [](https://packagist.org/packages/kartik-v/yii2-nav-x)
20 | [](https://packagist.org/packages/kartik-v/yii2-nav-x)
21 |
22 |
23 |
24 | 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
25 | `\yii\bootstrap4\Nav` widget for Bootstrap 4.x `\yii\bootstrap5\Nav` widget for Bootstrap 5.x with some additional controls and adding the CSS Styles for enabling a submenu drilldown. The dropdown menu style
26 | 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
27 | extension uses the one of the following Dropdown Class extensions by default for rendering dropdown navigation, but this can be overridden:
28 |
29 | - `\kartik\dropdown\DropdownX` for Bootstrap 3.x
30 | - `\kartik\bs4dropdown\Dropdown` for Bootstrap 4.x
31 | - `\kartik\bs5dropdown\Dropdown` for Bootstrap 5.x
32 |
33 | ### Demo
34 | You can see detailed [documentation](http://demos.krajee.com/nav-x) on usage of the extension.
35 |
36 | ## Installation
37 |
38 | Install the dependencies depending on the Bootstrap version used in your app:
39 |
40 | 1. For Bootstrap 3.x install `kartik-v/yii2-dropdown-x`
41 |
42 | ```
43 | $ php composer.phar require kartik-v/yii2-dropdown-x "@dev"
44 | ```
45 |
46 | 2. For Bootstrap 4.x install `kartik-v/yii2-bootstrap4-dropdown`
47 | ```
48 | $ php composer.phar require kartik-v/yii2-bootstrap4-dropdown "@dev"
49 | ```
50 |
51 | 3. For Bootstrap 5.x install `kartik-v/yii2-bootstrap5-dropdown`
52 | ```
53 | $ php composer.phar require kartik-v/yii2-bootstrap5-dropdown "@dev"
54 | ```
55 |
56 | The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
57 |
58 | > NOTE: Check the [composer.json](https://github.com/kartik-v/yii2-nav-x/blob/master/composer.json) for this extension's requirements and dependencies. Read this [web tip /wiki](http://webtips.krajee.com/setting-composer-minimum-stability-application/) on setting the `minimum-stability` settings for your application's composer.json.
59 |
60 | Either run
61 |
62 | ```
63 | $ php composer.phar require kartik-v/yii2-nav-x "@dev"
64 | ```
65 |
66 | or add
67 |
68 | ```
69 | "kartik-v/yii2-nav-x": "@dev"
70 | ```
71 |
72 | to the ```require``` section of your `composer.json` file.
73 |
74 | ## Usage
75 |
76 | ### NavX
77 |
78 | ```php
79 | use kartik\nav\NavX;
80 | echo NavX::widget([
81 | 'options' => ['class' => 'nav nav-pills'],
82 | 'items' => [
83 | ['label' => 'Action', 'url' => '#'],
84 | ['label' => 'Submenu', 'items' => [
85 | ['label' => 'Action', 'url' => '#'],
86 | ['label' => 'Another action', 'url' => '#'],
87 | ['label' => 'Something else here', 'url' => '#'],
88 | ]],
89 | ['label' => 'Something else here', 'url' => '#'],
90 | '',
91 | ['label' => 'Separated link', 'url' => '#'],
92 | ],
93 | 'encodeLabels' => false
94 | ]);
95 | ```
96 |
97 | ## License
98 |
99 | **yii2-nav-x** is released under the BSD-3-Clause License. See the bundled `LICENSE.md` for details.
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "kartik-v/yii2-nav-x",
3 | "description": "An extended bootstrap Nav widget for Yii 2 with submenu drilldown.",
4 | "keywords": [
5 | "yii2",
6 | "extension",
7 | "widget",
8 | "context",
9 | "menu",
10 | "mouse",
11 | "click"
12 | ],
13 | "homepage": "https://github.com/kartik-v/yii2-nav-x",
14 | "type": "yii2-extension",
15 | "license": "BSD-3-Clause",
16 | "authors": [
17 | {
18 | "name": "Kartik Visweswaran",
19 | "email": "kartikv2@gmail.com",
20 | "homepage": "http://www.krajee.com/"
21 | }
22 | ],
23 | "require": {
24 | "kartik-v/yii2-krajee-base": ">=3.0"
25 | },
26 | "suggest": {
27 | "kartik-v/yii2-dropdown-x": "For enabling dropdown support when using with Bootstrap v3.x",
28 | "kartik-v/yii2-bootstrap4-dropdown": "For enabling dropdown support when using with Bootstrap v4.x",
29 | "kartik-v/yii2-bootstrap5-dropdown": "For enabling dropdown support when using with Bootstrap v5.x"
30 | },
31 | "autoload": {
32 | "psr-4": {
33 | "kartik\\nav\\": "src"
34 | }
35 | },
36 | "extra": {
37 | "branch-alias": {
38 | "dev-master": "1.2.x-dev"
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/NavX.php:
--------------------------------------------------------------------------------
1 | ['class' => 'nav nav-pills'],
24 | * 'items' => [
25 | * ['label' => 'Action', 'url' => '#'],
26 | * ['label' => 'Submenu', 'items' => [
27 | * ['label' => 'Action', 'url' => '#'],
28 | * ['label' => 'Another action', 'url' => '#'],
29 | * ['label' => 'Something else here', 'url' => '#'],
30 | * ]],
31 | * ['label' => 'Something else here', 'url' => '#'],
32 | * '',
33 | * ['label' => 'Separated link', 'url' => '#'],
34 | * ],
35 | * 'encodeLabels' => false
36 | * ]);
37 | * ```
38 | *
39 | * @author Kartik Visweswaran
40 | * @since 1.0
41 | */
42 | class NavX extends Widget
43 | {
44 | /**
45 | * @var array list of items in the nav widget. Each array element represents a single
46 | * menu item which can be either a string or an array with the following structure:
47 | *
48 | * - `label`: _string_, required, the nav item label.
49 | * - `url`: _string_, the item's link URL. Defaults to `#`.
50 | * - `visible`: _bool_, optional, whether this menu item is visible. Defaults to `true`.
51 | * - `linkOptions`: _array_, the HTML attributes of the item's link.
52 | * - `options`: _array_, optional, the HTML attributes of the item container (LI).
53 | * - `active`: _bool_, optional, whether the item should be on active state or not.
54 | * - `dropDownOptions`: _array_, optional, the HTML options that will passed to the `Dropdown` widget as set in [[dropdownClass]].
55 | * - `items`: _array_|_string_, optional, the configuration array for creating a `Dropdown` widget as set in [[dropdownClass]]
56 | * or a raw HTML markup representing the dropdown menu.
57 | * - `encode`: _bool_, optional, whether the label will be HTML-encoded. If set, supersedes the $encodeLabels option for only this item.
58 | *
59 | * If a menu item is a string, it will be rendered directly without HTML encoding.
60 | */
61 | public $items = [];
62 |
63 | /**
64 | * @var bool whether the nav items labels should be HTML-encoded.
65 | */
66 | public $encodeLabels = true;
67 |
68 | /**
69 | * @var bool whether to automatically activate items according to whether their route setting
70 | * matches the currently requested route.
71 | * @see NavXBs3::isItemActive for Bootstrap 3.x
72 | * @see NavXBs4::isItemActive for Bootstrap 4.x
73 | * @see NavXBs5::isItemActive for Bootstrap 5.x
74 | */
75 | public $activateItems = true;
76 |
77 | /**
78 | * @var bool whether to activate parent menu items when one of the corresponding child menu items is active.
79 | */
80 | public $activateParents = false;
81 |
82 | /**
83 | * @var string the route used to determine if a menu item is active or not.
84 | * If not set, it will use the route of the current request.
85 | * @see params
86 | * @see NavXBs3::isItemActive for Bootstrap 3.x
87 | * @see NavXBs4::isItemActive for Bootstrap 4.x
88 | * @see NavXBs5::isItemActive for Bootstrap 5.x
89 | */
90 | public $route;
91 |
92 | /**
93 | * @var array the parameters used to determine if a menu item is active or not.
94 | * If not set, it will use `$_GET`.
95 | * @see route
96 | * @see NavXBs3::isItemActive for Bootstrap 3.x
97 | * @see NavXBs4::isItemActive for Bootstrap 4.x
98 | * @see NavXBs5::isItemActive for Bootstrap 5.x
99 | */
100 | public $params;
101 |
102 | /**
103 | * @var string name of a class to use for rendering dropdowns within this widget. Defaults to one of the
104 | * following classes based on the bootstrap version ([[bsVersion]]) set:
105 | *
106 | * - [[kartik\dropdown\DropdownX]] for Bootstrap 3.x
107 | * - [[kartik\bs4dropdown\Dropdown]] for Bootstrap 4.x
108 | * - [[kartik\bs5dropdown\Dropdown]] for Bootstrap 5.x
109 | *
110 | */
111 | public $dropdownClass;
112 |
113 | /**
114 | * @var array the dropdown widget options
115 | */
116 | public $dropdownOptions = [];
117 |
118 | /**
119 | * @inheritdoc
120 | */
121 | public function run()
122 | {
123 | $opts = [
124 | 'items' => $this->items,
125 | 'encodeLabels' => $this->encodeLabels,
126 | 'activateItems' => $this->activateItems,
127 | 'activateParents' => $this->activateParents,
128 | 'dropdownOptions' => $this->dropdownOptions,
129 | 'options' => $this->options,
130 | 'clientOptions' => $this->pluginOptions,
131 | ];
132 | $props = ['route', 'params', 'dropdownClass'];
133 | foreach ($props as $prop) {
134 | if (isset($this->$prop)) {
135 | $opts[$prop] = $this->$prop;
136 | }
137 | }
138 | /**
139 | * @var Widget $widget
140 | */
141 | $ver = $this->getBsVer();
142 | $widget = '\\'.__NAMESPACE__.'\\NavXBs'.$ver;
143 | if (!class_exists($widget)) {
144 | throw new InvalidConfigException("The NavX widget has not been implemented for Bootstrap {$ver}.x release.");
145 | }
146 | echo $widget::widget($opts);
147 | }
148 | }
149 |
--------------------------------------------------------------------------------
/src/NavXBs3.php:
--------------------------------------------------------------------------------
1 |
21 | * @since 1.0
22 | */
23 | class NavXBs3 extends Nav
24 | {
25 | use NavXTrait;
26 |
27 | /**
28 | * @var string the class name to render the Dropdown items. Defaults to `\kartik\dropdown\DropdownX`.
29 | */
30 | public $dropdownClass = 'kartik\\dropdown\\DropdownX';
31 |
32 | /**
33 | * Renders the given items as a dropdown. This method is called to create sub-menus.
34 | * @param array $items the given items. Please refer to `items` property in the `Dropdown` widget (as set in [[dropdownClass]]) for the array structure.
35 | * @param array $parentItem the parent item information. Please refer to [[items]] for the structure of this array.
36 | * @return string the rendering result.
37 | * @throws Exception
38 | */
39 | protected function renderDropdown($items, $parentItem)
40 | {
41 | /** @var DropdownX $dropdownClass */
42 | $dropdownClass = $this->dropdownClass;
43 | $ddOptions = array_replace_recursive($this->dropdownOptions, [
44 | 'options' => ArrayHelper::getValue($parentItem, 'dropDownOptions', []),
45 | 'items' => $items,
46 | 'encodeLabels' => $this->encodeLabels,
47 | 'clientOptions' => false,
48 | 'view' => $this->getView(),
49 | ]);
50 | return $dropdownClass::widget($ddOptions);
51 | }
52 |
53 | /**
54 | * Check to see if a child item is active optionally activating the parent.
55 | * @param array $items the items configuration similar to [[items]]
56 | * @param bool $active should the parent be active too
57 | * @return array
58 | * @see items
59 | */
60 | protected function isChildActive($items, &$active)
61 | {
62 | foreach ($items as $i => $child) {
63 | if (ArrayHelper::remove($items[$i], 'active', false) || $this->isItemActive($child)) {
64 | Html::addCssClass($items[$i]['options'], 'active');
65 | if ($this->activateParents) {
66 | $active = true;
67 | }
68 | }
69 | if (isset($items[$i]['items']) && is_array($items[$i]['items'])) {
70 | $childActive = false;
71 | $items[$i]['items'] = $this->isChildActive($items[$i]['items'], $childActive);
72 | if ($childActive) {
73 | Html::addCssClass($items[$i]['options'], 'active');
74 | $active = true;
75 | }
76 | }
77 | }
78 | return $items;
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/src/NavXBs4.php:
--------------------------------------------------------------------------------
1 |
22 | * @since 1.0
23 | */
24 | class NavXBs4 extends Nav
25 | {
26 | use NavXTrait;
27 |
28 | /**
29 | * @var string the class name to render the Dropdown items. Defaults to `kartik\bs4dropdown\Dropdown`.
30 | */
31 | public $dropdownClass = 'kartik\bs4dropdown\Dropdown';
32 |
33 | /**
34 | * @inheritdoc
35 | * @throws InvalidConfigException
36 | */
37 | public function init()
38 | {
39 | $this->checkDependency();
40 | parent::init();
41 | }
42 |
43 | /**
44 | * Renders the given items as a dropdown. This method is called to create sub-menus.
45 | * @param array $items the given items. Please refer to `items` property in the `Dropdown` widget (as set in [[dropdownClass]]) for the array structure.
46 | * @param array $parentItem the parent item information. Please refer to [[items]] for the structure of this array.
47 | * @return string the rendering result.
48 | * @throws Exception
49 | */
50 | protected function renderDropdown($items, $parentItem)
51 | {
52 | /** @var Dropdown $dropdownClass */
53 | $dropdownClass = $this->dropdownClass;
54 | $ddOptions = array_replace_recursive($this->dropdownOptions, [
55 | 'options' => ArrayHelper::getValue($parentItem, 'dropDownOptions', []),
56 | 'items' => $items,
57 | 'encodeLabels' => $this->encodeLabels,
58 | 'clientOptions' => false,
59 | 'view' => $this->getView(),
60 | ]);
61 |
62 | return $dropdownClass::widget($ddOptions);
63 | }
64 |
65 | /**
66 | * Check to see if a child item is active optionally activating the parent.
67 | * @param array $items the items configuration similar to [[items]]
68 | * @param bool $active should the parent be active too
69 | * @return array
70 | * @see items
71 | */
72 | protected function isChildActive($items, &$active)
73 | {
74 | foreach ($items as $i => $child) {
75 | if (ArrayHelper::remove($items[$i], 'active', false) || $this->isItemActive($child)) {
76 | Html::addCssClass($items[$i]['linkOptions'], 'active');
77 | if ($this->activateParents) {
78 | $active = true;
79 | }
80 | }
81 | if (isset($items[$i]['items']) && is_array($items[$i]['items'])) {
82 | $childActive = false;
83 | $items[$i]['items'] = $this->isChildActive($items[$i]['items'], $childActive);
84 | if ($childActive) {
85 | Html::addCssClass($items[$i]['linkOptions'], 'active');
86 | $active = true;
87 | }
88 | }
89 | }
90 |
91 | return $items;
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/src/NavXBs5.php:
--------------------------------------------------------------------------------
1 |
21 | * @since 1.0
22 | */
23 | class NavXBs5 extends Nav
24 | {
25 | use NavXTrait;
26 |
27 | /**
28 | * @var string the class name to render the Dropdown items. Defaults to `kartik\bs5dropdown\Dropdown`.
29 | */
30 | public $dropdownClass = 'kartik\bs5dropdown\Dropdown';
31 |
32 | /**
33 | * Renders the given items as a dropdown. This method is called to create sub-menus.
34 | * @param array $items the given items. Please refer to `items` property in the `Dropdown` widget (as set in [[dropdownClass]]) for the array structure.
35 | * @param array $parentItem the parent item information. Please refer to [[items]] for the structure of this array.
36 | * @return string the rendering result.
37 | * @throws Exception
38 | */
39 | protected function renderDropdown(array $items, array $parentItem): string
40 | {
41 | /** @var Dropdown $dropdownClass */
42 | $dropdownClass = $this->dropdownClass;
43 | $ddOptions = array_replace_recursive($this->dropdownOptions, [
44 | 'options' => ArrayHelper::getValue($parentItem, 'dropDownOptions', []),
45 | 'items' => $items,
46 | 'encodeLabels' => $this->encodeLabels,
47 | 'clientOptions' => false,
48 | 'view' => $this->getView(),
49 | ]);
50 |
51 | return $dropdownClass::widget($ddOptions);
52 | }
53 |
54 | /**
55 | * Check to see if a child item is active optionally activating the parent.
56 | * @param array $items the items configuration similar to [[items]]
57 | * @param bool $active should the parent be active too
58 | * @return array
59 | * @throws Exception
60 | * @see items
61 | */
62 | protected function isChildActive(array $items, bool &$active): array
63 | {
64 | foreach ($items as $i => $child) {
65 | $child = (array)$child;
66 | if (ArrayHelper::remove($items[$i], 'active', false) || $this->isItemActive($child)) {
67 | Html::addCssClass($items[$i]['linkOptions'], 'active');
68 | if ($this->activateParents) {
69 | $active = true;
70 | }
71 | }
72 | if (isset($items[$i]['items']) && is_array($items[$i]['items'])) {
73 | $childActive = false;
74 | $items[$i]['items'] = $this->isChildActive($items[$i]['items'], $childActive);
75 | if ($childActive) {
76 | Html::addCssClass($items[$i]['linkOptions'], 'active');
77 | $active = true;
78 | }
79 | }
80 | }
81 |
82 | return $items;
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/NavXTrait.php:
--------------------------------------------------------------------------------
1 |
17 | * @since 1.0
18 | */
19 | trait NavXTrait
20 | {
21 | /**
22 | * @var array the dropdown widget options
23 | */
24 | public $dropdownOptions = [];
25 |
26 | /**
27 | * @inheritdoc
28 | * @throws InvalidConfigException
29 | */
30 | public function init()
31 | {
32 | $this->checkDependency();
33 | parent::init();
34 | }
35 |
36 | /**
37 | * Check dependency
38 | * @throws InvalidConfigException
39 | */
40 | protected function checkDependency()
41 | {
42 | if (!class_exists($this->dropdownClass)) {
43 | throw new InvalidConfigException("The dropdownClass '{$this->dropdownClass}' was not found. Please ensure the '{$this->dropdownClass}' extension is installed and accessible.");
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------