Skip to content

Commit

Permalink
add caption (#249)
Browse files Browse the repository at this point in the history
* add caption

* make option

* update readme

* update readme nav
  • Loading branch information
cugrif authored and dustingraham committed Jul 24, 2019
1 parent d740616 commit 45165b5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ __For Laravel 4.x, check [version 1.5.0](https://github.com/lavary/laravel-menu/
* [Active Item](#active-item)
- [RESTful URLs](#restful-urls)
- [URL Wildcards](#url-wildcards)
- [Disable activation](#disable-activation)
* [Inserting a Separator](#inserting-a-separator)
* [Append and Prepend](#append-and-prepend)
* [Before and After](#before-and-after)
Expand Down Expand Up @@ -775,6 +776,15 @@ $menu->add('Articles', 'articles')->active('this-is-another-url/*');

So `this-is-another-url`, `this-is-another-url/and-another` will both activate `Articles` item.

#### Disable activation
Sometimes you may need to disable auto activation for single items.
You can pass **disableActivationByURL** in options like this:
```php
$menu->add('Anchor', ['disableActivationByURL' => true, 'url' => '#']);
```
This prevents auto activation by matching URL.
But activation for items with active children keeps working.

## Inserting a Separator

You can insert a separator after each item using `divide()` method:
Expand Down
16 changes: 15 additions & 1 deletion src/Lavary/Menu/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ class Item
*/
public $isActive = false;

/**
* If true this prevents auto activation by matching URL
* Activation by active children keeps working.
*
* @var bool
*/
private $disableActivationByURL = false;

/**
* Creates a new Item instance.
*
Expand All @@ -125,6 +133,9 @@ public function __construct($builder, $id, $title, $options)
} else {
$path = Arr::only($options, array('url', 'route', 'action', 'secure'));
}
if (isset($options['disableActivationByURL']) && true == $options['disableActivationByURL']) {
$this->disableActivationByURL = true;
}

if (!is_null($path)) {
$path['prefix'] = $this->builder->getLastGroupPrefix();
Expand All @@ -141,7 +152,7 @@ public function __construct($builder, $id, $title, $options)
/**
* Creates a sub Item.
*
* @param string $title
* @param string $title
* @param string|array $options
* @return Item
*/
Expand Down Expand Up @@ -352,6 +363,9 @@ public function all()
*/
public function checkActivationStatus()
{
if (true === $this->disableActivationByURL) {
return;
}
if (true == $this->builder->conf['restful']) {
$path = ltrim(parse_url($this->url(), PHP_URL_PATH), '/');
$rpath = ltrim(parse_url(Request::path(), PHP_URL_PATH), '/');
Expand Down

0 comments on commit 45165b5

Please sign in to comment.