public static N2.Web.Tree LITagModifier(this N2.Web.Tree tree, Action <HierarchyNode <ContentItem>, TagBuilder> tagModifier) { return(tree.Tag((n, t) => { if (t.TagName.Equals("li", StringComparison.InvariantCultureIgnoreCase)) { tagModifier(n, t); } })); }
/// <summary> /// Add attibtues the root of a treeview /// </summary> /// <param name="tree"></param> /// <param name="htmlAttributes"></param> /// <returns></returns> public static N2.Web.Tree HtmlAttibutes(this N2.Web.Tree tree, object htmlAttributes) { tree.Tag((node, builder) => { if (builder.TagName.Equals("ul", StringComparison.InvariantCultureIgnoreCase) && (node.Parent == null || node.Parent.Current == null)) { builder.MergeAttributes(new RouteValueDictionary(htmlAttributes), true); } }); return(tree); }
protected override void CreateChildControls() { IContentAdapterProvider adapters = Engine.Resolve <IContentAdapterProvider>(); if (Nodes == null) { Nodes = new BranchHierarchyBuilder(SelectedItem, RootNode, true) .Children((item) => adapters.ResolveAdapter <NodeAdapter>(item).GetChildren(item, Interfaces.Managing)) .Build(); } var tree = new N2.Web.Tree(Nodes) .OpenTo(SelectedItem) .Filters(Filter) .LinkProvider(item => BuildLink(adapters.ResolveAdapter <NodeAdapter>(item), item, item.Path == SelectedItem.Path, Target)) .ToControl(); AppendExpanderNodeRecursive(tree, Filter, Target, adapters); Controls.Add(tree); base.CreateChildControls(); }
protected override void CreateChildControls() { IContentAdapterProvider adapters = Engine.Resolve<IContentAdapterProvider>(); if (Nodes == null) Nodes = new BranchHierarchyBuilder(SelectedItem, RootNode, true) .Children((item) => adapters.ResolveAdapter<NodeAdapter>(item).GetChildren(item, Interfaces.Managing)) .Build(); var tree = new N2.Web.Tree(Nodes) .OpenTo(SelectedItem) .Filters(Filter) .LinkProvider(item => BuildLink(adapters.ResolveAdapter<NodeAdapter>(item), item, item.Path == SelectedItem.Path, Target)) .ToControl(); AppendExpanderNodeRecursive(tree, Filter, Target, adapters); Controls.Add(tree); base.CreateChildControls(); }
private static void ClassifyAnchors(ContentItem startsFrom, ContentItem current, N2.Web.Tree tree) { IList <ContentItem> ancestors = GenericFind <ContentItem, ContentItem> .ListParents(current, startsFrom, true); if (ancestors.Contains(startsFrom)) { ancestors.Remove(startsFrom); } tree.LinkWriter((n, w) => { var link = n.Current.Link(); var @class = n.Current == current ? "current" : ancestors.Contains(n.Current) ? "trail" : ""; if (n.Children.Count > 0) { @class += " dropdown-toggle"; link.Attribute("data-toggle", "dropdown"); } link.Class(@class).WriteTo(w); }); tree.ULTagModifier((n, t) => { if (n.Parent != null && n.Parent.Current != null) { t.MergeAttribute("class", "dropdown-menu"); } }); tree.LITagModifier((n, t) => { //if children, indicate with a dropdown class var @class = n.Children.Count > 0 ? "dropdown" : string.Empty; @class += " " + (n.Current == current ? "active" : ancestors.Contains(n.Current) ? "active trail" : ""); t.MergeAttribute("class", @class.Trim()); }); }
public static Tree OpenTo(this Tree treeBuilder, ContentItem item) { var items = new HashSet <ContentItem>(Find.EnumerateParents(item)); return(treeBuilder.ClassProvider(null, n => items.Contains(n.Current) || n.Current == item ? "open" : string.Empty)); }