mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-24 05:23:33 +08:00
Adding the ability to put (CSS) classes on menu items.
Making use of it by adding a "collapsed" class to the admin menu's settings top-level item to have it collapse by default (with some adjustment to the admin.js) work item: 17599 --HG-- branch : 1.x
This commit is contained in:
@@ -21,7 +21,7 @@ namespace Orchard.Core.Settings {
|
|||||||
builder.AddImageSet("settings")
|
builder.AddImageSet("settings")
|
||||||
.Add(T("Settings"), "99",
|
.Add(T("Settings"), "99",
|
||||||
menu => menu.Add(T("General"), "0", item => item.Action("Index", "Admin", new { area = "Settings", groupInfoId = "Index" })
|
menu => menu.Add(T("General"), "0", item => item.Action("Index", "Admin", new { area = "Settings", groupInfoId = "Index" })
|
||||||
.Permission(StandardPermissions.SiteOwner)));
|
.Permission(StandardPermissions.SiteOwner)), new [] {"collapsed"});
|
||||||
|
|
||||||
var site = _siteService.GetSiteSettings();
|
var site = _siteService.GetSiteSettings();
|
||||||
if (site == null)
|
if (site == null)
|
||||||
|
@@ -23,7 +23,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((settings.remember && "closed" === $.orchard.setting(__cookieName, { key: settings.key + "-" + controller.text(), path: settings.path }))
|
if ((settings.remember && "closed" === $.orchard.setting(__cookieName, { key: settings.key + "-" + controller.text(), path: settings.path }))
|
||||||
|| settings.collapse) {
|
|| settings.collapse
|
||||||
|
|| (controller.closest("li").hasClass("collapsed") && !(settings.remember && "open" === $.orchard.setting(__cookieName, { key: settings.key + "-" + controller.text(), path: settings.path })))) {
|
||||||
glyph.addClass("closed").data("controllees").hide();
|
glyph.addClass("closed").data("controllees").hide();
|
||||||
}
|
}
|
||||||
else if (settings.collapse) {
|
else if (settings.collapse) {
|
||||||
|
@@ -192,7 +192,7 @@ namespace Orchard.UI.Navigation {
|
|||||||
/// <param name="menuItem">The menu item to build the shape for.</param>
|
/// <param name="menuItem">The menu item to build the shape for.</param>
|
||||||
/// <returns>The menu item shape.</returns>
|
/// <returns>The menu item shape.</returns>
|
||||||
protected dynamic BuildMenuItemShape(dynamic shapeFactory, dynamic parentShape, dynamic menu, MenuItem menuItem) {
|
protected dynamic BuildMenuItemShape(dynamic shapeFactory, dynamic parentShape, dynamic menu, MenuItem menuItem) {
|
||||||
return shapeFactory.MenuItem()
|
var menuItemShape = shapeFactory.MenuItem()
|
||||||
.Text(menuItem.Text)
|
.Text(menuItem.Text)
|
||||||
.IdHint(menuItem.IdHint)
|
.IdHint(menuItem.IdHint)
|
||||||
.Href(menuItem.Href)
|
.Href(menuItem.Href)
|
||||||
@@ -203,6 +203,11 @@ namespace Orchard.UI.Navigation {
|
|||||||
.Item(menuItem)
|
.Item(menuItem)
|
||||||
.Menu(menu)
|
.Menu(menu)
|
||||||
.Parent(parentShape);
|
.Parent(parentShape);
|
||||||
|
|
||||||
|
foreach (var className in menuItem.Classes)
|
||||||
|
menuItemShape.Classes.Add(className);
|
||||||
|
|
||||||
|
return menuItemShape;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -214,7 +219,7 @@ namespace Orchard.UI.Navigation {
|
|||||||
/// <param name="menuItem">The menu item to build the shape for.</param>
|
/// <param name="menuItem">The menu item to build the shape for.</param>
|
||||||
/// <returns>The menu item shape.</returns>
|
/// <returns>The menu item shape.</returns>
|
||||||
protected dynamic BuildLocalMenuItemShape(dynamic shapeFactory, dynamic parentShape, dynamic menu, MenuItem menuItem) {
|
protected dynamic BuildLocalMenuItemShape(dynamic shapeFactory, dynamic parentShape, dynamic menu, MenuItem menuItem) {
|
||||||
return shapeFactory.LocalMenuItem()
|
var menuItemShape = shapeFactory.LocalMenuItem()
|
||||||
.Text(menuItem.Text)
|
.Text(menuItem.Text)
|
||||||
.IdHint(menuItem.IdHint)
|
.IdHint(menuItem.IdHint)
|
||||||
.Href(menuItem.Href)
|
.Href(menuItem.Href)
|
||||||
@@ -225,6 +230,11 @@ namespace Orchard.UI.Navigation {
|
|||||||
.Item(menuItem)
|
.Item(menuItem)
|
||||||
.Menu(menu)
|
.Menu(menu)
|
||||||
.Parent(parentShape);
|
.Parent(parentShape);
|
||||||
|
|
||||||
|
foreach (var className in menuItem.Classes)
|
||||||
|
menuItemShape.Classes.Add(className);
|
||||||
|
|
||||||
|
return menuItemShape;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnResultExecuted(ResultExecutedContext filterContext) { }
|
public void OnResultExecuted(ResultExecutedContext filterContext) { }
|
||||||
|
@@ -6,6 +6,8 @@ using Orchard.Security.Permissions;
|
|||||||
|
|
||||||
namespace Orchard.UI.Navigation {
|
namespace Orchard.UI.Navigation {
|
||||||
public class MenuItem {
|
public class MenuItem {
|
||||||
|
private IList<string> _classes = new List<string>();
|
||||||
|
|
||||||
public MenuItem() {
|
public MenuItem() {
|
||||||
Permissions = Enumerable.Empty<Permission>();
|
Permissions = Enumerable.Empty<Permission>();
|
||||||
LinkToFirstChild = true;
|
LinkToFirstChild = true;
|
||||||
@@ -22,5 +24,13 @@ namespace Orchard.UI.Navigation {
|
|||||||
public RouteValueDictionary RouteValues { get; set; }
|
public RouteValueDictionary RouteValues { get; set; }
|
||||||
public IEnumerable<MenuItem> Items { get; set; }
|
public IEnumerable<MenuItem> Items { get; set; }
|
||||||
public IEnumerable<Permission> Permissions { get; set; }
|
public IEnumerable<Permission> Permissions { get; set; }
|
||||||
|
public IList<string> Classes {
|
||||||
|
get { return _classes; }
|
||||||
|
set {
|
||||||
|
if (value == null)
|
||||||
|
return;
|
||||||
|
_classes = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -9,27 +9,33 @@ namespace Orchard.UI.Navigation {
|
|||||||
private readonly IList<string> _imageSets = new List<string>();
|
private readonly IList<string> _imageSets = new List<string>();
|
||||||
IEnumerable<MenuItem> Contained { get; set; }
|
IEnumerable<MenuItem> Contained { get; set; }
|
||||||
|
|
||||||
public NavigationBuilder Add(LocalizedString caption, string position, Action<NavigationItemBuilder> itemBuilder) {
|
public NavigationBuilder Add(LocalizedString caption, string position, Action<NavigationItemBuilder> itemBuilder, IEnumerable<string> classes = null) {
|
||||||
var childBuilder = new NavigationItemBuilder();
|
var childBuilder = new NavigationItemBuilder();
|
||||||
|
|
||||||
childBuilder.Caption(caption);
|
childBuilder.Caption(caption);
|
||||||
childBuilder.Position(position);
|
childBuilder.Position(position);
|
||||||
itemBuilder(childBuilder);
|
itemBuilder(childBuilder);
|
||||||
Contained = (Contained ?? Enumerable.Empty<MenuItem>()).Concat(childBuilder.Build());
|
Contained = (Contained ?? Enumerable.Empty<MenuItem>()).Concat(childBuilder.Build());
|
||||||
|
|
||||||
|
if (classes != null) {
|
||||||
|
foreach (var className in classes)
|
||||||
|
childBuilder.AddClass(className);
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NavigationBuilder Add(LocalizedString caption, Action<NavigationItemBuilder> itemBuilder) {
|
public NavigationBuilder Add(LocalizedString caption, Action<NavigationItemBuilder> itemBuilder, IEnumerable<string> classes = null) {
|
||||||
return Add(caption, null, itemBuilder);
|
return Add(caption, null, itemBuilder, classes);
|
||||||
}
|
}
|
||||||
public NavigationBuilder Add(Action<NavigationItemBuilder> itemBuilder) {
|
public NavigationBuilder Add(Action<NavigationItemBuilder> itemBuilder, IEnumerable<string> classes = null) {
|
||||||
return Add(null, null, itemBuilder);
|
return Add(null, null, itemBuilder, classes);
|
||||||
}
|
}
|
||||||
public NavigationBuilder Add(LocalizedString caption, string position) {
|
public NavigationBuilder Add(LocalizedString caption, string position, IEnumerable<string> classes = null) {
|
||||||
return Add(caption, position, x=> { });
|
return Add(caption, position, x=> { }, classes);
|
||||||
}
|
}
|
||||||
public NavigationBuilder Add(LocalizedString caption) {
|
public NavigationBuilder Add(LocalizedString caption, IEnumerable<string> classes = null) {
|
||||||
return Add(caption, null, x => { });
|
return Add(caption, null, x => { }, classes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NavigationBuilder AddImageSet(string imageSet) {
|
public NavigationBuilder AddImageSet(string imageSet) {
|
||||||
|
@@ -32,6 +32,18 @@ namespace Orchard.UI.Navigation {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NavigationItemBuilder AddClass(string className) {
|
||||||
|
if (!_item.Classes.Contains(className))
|
||||||
|
_item.Classes.Add(className);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NavigationItemBuilder RemoveClass(string className) {
|
||||||
|
if (_item.Classes.Contains(className))
|
||||||
|
_item.Classes.Remove(className);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public NavigationItemBuilder LinkToFirstChild(bool value) {
|
public NavigationItemBuilder LinkToFirstChild(bool value) {
|
||||||
_item.LinkToFirstChild = value;
|
_item.LinkToFirstChild = value;
|
||||||
return this;
|
return this;
|
||||||
|
@@ -77,6 +77,7 @@ namespace Orchard.UI.Navigation {
|
|||||||
LocalNav = item.LocalNav,
|
LocalNav = item.LocalNav,
|
||||||
Text = item.Text,
|
Text = item.Text,
|
||||||
IdHint = item.IdHint,
|
IdHint = item.IdHint,
|
||||||
|
Classes = item.Classes,
|
||||||
Url = item.Url,
|
Url = item.Url,
|
||||||
LinkToFirstChild = item.LinkToFirstChild,
|
LinkToFirstChild = item.LinkToFirstChild,
|
||||||
Href = item.Href
|
Href = item.Href
|
||||||
@@ -145,6 +146,7 @@ namespace Orchard.UI.Navigation {
|
|||||||
var joined = new MenuItem {
|
var joined = new MenuItem {
|
||||||
Text = items.First().Text,
|
Text = items.First().Text,
|
||||||
IdHint = items.Select(x => x.IdHint).FirstOrDefault(x => !string.IsNullOrWhiteSpace(x)),
|
IdHint = items.Select(x => x.IdHint).FirstOrDefault(x => !string.IsNullOrWhiteSpace(x)),
|
||||||
|
Classes = items.Select(x => x.Classes).FirstOrDefault(x => x != null && x.Count > 0),
|
||||||
Url = items.Select(x => x.Url).FirstOrDefault(x => !string.IsNullOrWhiteSpace(x)),
|
Url = items.Select(x => x.Url).FirstOrDefault(x => !string.IsNullOrWhiteSpace(x)),
|
||||||
Href = items.Select(x => x.Href).FirstOrDefault(x => !string.IsNullOrWhiteSpace(x)),
|
Href = items.Select(x => x.Href).FirstOrDefault(x => !string.IsNullOrWhiteSpace(x)),
|
||||||
LinkToFirstChild = items.First().LinkToFirstChild,
|
LinkToFirstChild = items.First().LinkToFirstChild,
|
||||||
|
Reference in New Issue
Block a user