verbb / cp-nav

Control Panel Nav is a Craft CMS plugin to help manage your Control Panel navigation.
MIT License
129 stars 11 forks source link

Make correct navigation item be selected in header #10

Closed ErikSwan closed 9 years ago

ErikSwan commented 9 years ago

I've added some JavaScript and a small conditional to correct which navigation item is selected for manually added navigation items. This significantly improves the look and usability for manually added navigation items, and is especially useful if adding nav items for individual entries (a homepage, for example).

Before: homepage_-_young___wilmoth_old

After: homepage_-_young___wilmoth

The preg_replace is necessary to be able to correctly handle both absolute and relative URLs as inputted by the user.

Unfortunately this does have to be done with JavaScript injection right now as the point at which nav items are decided if they are "selected" or not happens after the modifyCpNav hook that is available to plugins.

engram-design commented 9 years ago

Thanks @ErikSwan - great idea! Hadn't actually thought of that, so nice one :)

ErikSwan commented 9 years ago

No problem! This plugin is a must, as in my opinion the default navigation items in the CP are not very intuitive for clients, especially for simpler sites. Thanks for building it!