Added support to DynamicNodeWalker so that .Next() and .Previous() can be called on nodes which did not come from a DynamicNodeList (e.g. a node you have from @Model) - assuming it has a parent

This commit is contained in:
agrath@gmail.com
2011-03-08 19:22:41 -13:00
parent fa5b85557f
commit d7e83cb1ee

View File

@@ -52,10 +52,15 @@ namespace umbraco.MacroEngines
}
public static DynamicNode Next(this DynamicNode context, int number)
{
if (context.ownerList == null && context.Parent != null)
{
var list = context.Parent.ChildrenAsList.ConvertAll(n => new DynamicNode(n));
context.ownerList = new DynamicNodeList(list);
}
if (context.ownerList != null)
{
List<DynamicNode> container = context.ownerList.Items.ToList();
int currentIndex = container.IndexOf(context);
int currentIndex = container.FindIndex(n => n.Id == context.Id);
if (currentIndex != -1)
{
return container.ElementAtOrDefault(currentIndex + (number + 1));
@@ -76,10 +81,15 @@ namespace umbraco.MacroEngines
}
public static DynamicNode Previous(this DynamicNode context, int number)
{
if (context.ownerList == null && context.Parent != null)
{
var list = context.Parent.ChildrenAsList.ConvertAll(n => new DynamicNode(n));
context.ownerList = new DynamicNodeList(list);
}
if (context.ownerList != null)
{
List<DynamicNode> container = context.ownerList.Items.ToList();
int currentIndex = container.IndexOf(context);
int currentIndex = container.FindIndex(n => n.Id == context.Id);
if (currentIndex != -1)
{
return container.ElementAtOrDefault(currentIndex + (number - 1));