mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 21:01:35 +08:00
Implementing a positioned wrapper for text elements
When adding a text directly to a zone, the position will now be taken into account. This is also useful for the Capture feature. Conflicts: src/Orchard/Orchard.Framework.csproj
This commit is contained in:
parent
66ff5d36e9
commit
0bf76dc7ac
src
@ -301,9 +301,12 @@ namespace Orchard.Core.Shapes {
|
||||
var progress = 1;
|
||||
var flatPositionComparer = new FlatPositionComparer();
|
||||
var ordering = unordered.Select(item => {
|
||||
var position = (item == null || item.GetType().GetProperty("Metadata") == null || item.Metadata.GetType().GetProperty("Position") == null)
|
||||
? null
|
||||
: item.Metadata.Position;
|
||||
string position = null;
|
||||
var itemPosition = item as IPositioned;
|
||||
if (itemPosition != null) {
|
||||
position = itemPosition.Position;
|
||||
}
|
||||
|
||||
return new { item, position };
|
||||
}).ToList();
|
||||
|
||||
|
@ -21,14 +21,6 @@ namespace Orchard.ContentManagement {
|
||||
|
||||
public virtual ContentItem ContentItem { get; set; }
|
||||
|
||||
//interesting thought, should/could parts also have zones (would then have zones on the page, content item and parts...)?
|
||||
private readonly IZoneCollection _zones = new ZoneCollection();
|
||||
public virtual IZoneCollection Zones {
|
||||
get {
|
||||
return _zones;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The ContentItem's identifier.
|
||||
/// </summary>
|
||||
|
5
src/Orchard/DisplayManagement/IPositioned.cs
Normal file
5
src/Orchard/DisplayManagement/IPositioned.cs
Normal file
@ -0,0 +1,5 @@
|
||||
namespace Orchard.DisplayManagement {
|
||||
public interface IPositioned {
|
||||
string Position { get; }
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
using System.Diagnostics;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
|
||||
namespace Orchard.DisplayManagement {
|
||||
/// <summary>
|
||||
|
26
src/Orchard/DisplayManagement/PositionWrapper.cs
Normal file
26
src/Orchard/DisplayManagement/PositionWrapper.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using System.Web;
|
||||
|
||||
namespace Orchard.DisplayManagement {
|
||||
public class PositionWrapper : IHtmlString, IPositioned {
|
||||
|
||||
private IHtmlString _value;
|
||||
public string Position { get; private set; }
|
||||
|
||||
public PositionWrapper(IHtmlString value, string position) {
|
||||
_value = value;
|
||||
Position = position;
|
||||
}
|
||||
|
||||
public PositionWrapper(string value, string position)
|
||||
: this(new HtmlString(HttpUtility.HtmlEncode(value)), position) {
|
||||
}
|
||||
|
||||
public string ToHtmlString() {
|
||||
return _value.ToHtmlString();
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return _value.ToString();
|
||||
}
|
||||
}
|
||||
}
|
@ -4,11 +4,11 @@ using System.Dynamic;
|
||||
using System.Linq;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Mvc;
|
||||
using System.Web;
|
||||
|
||||
namespace Orchard.DisplayManagement.Shapes {
|
||||
[DebuggerTypeProxy(typeof(ShapeDebugView))]
|
||||
public class Shape : Composite, IShape, IEnumerable<object> {
|
||||
public class Shape : Composite, IShape, IPositioned, IEnumerable<object> {
|
||||
private const string DefaultPosition = "5";
|
||||
|
||||
private readonly IList<object> _items = new List<object>();
|
||||
@ -22,6 +22,12 @@ namespace Orchard.DisplayManagement.Shapes {
|
||||
public virtual IDictionary<string, string> Attributes { get { return _attributes; } }
|
||||
public virtual IEnumerable<dynamic> Items { get { return _items; } }
|
||||
|
||||
public string Position {
|
||||
get {
|
||||
return Metadata.Position;
|
||||
}
|
||||
}
|
||||
|
||||
public Shape() {
|
||||
Metadata = new ShapeMetadata();
|
||||
}
|
||||
@ -33,13 +39,14 @@ namespace Orchard.DisplayManagement.Shapes {
|
||||
}
|
||||
|
||||
try {
|
||||
// todo: (sebros) this is a temporary implementation to prevent common known scenarios throwing exceptions. The final solution would need to filter based on the fact that it is a Shape instance
|
||||
if (item is MvcHtmlString ||
|
||||
item is String) {
|
||||
// need to implement positioned wrapper for non-shape objects
|
||||
if (position != null && item is IHtmlString) {
|
||||
item = new PositionWrapper((IHtmlString)item, position);
|
||||
}
|
||||
else if (position != null && item is string) {
|
||||
item = new PositionWrapper((string)item, position);
|
||||
}
|
||||
else if (item is IShape) {
|
||||
((dynamic)item).Metadata.Position = position;
|
||||
((IShape)item).Metadata.Position = position;
|
||||
}
|
||||
}
|
||||
catch {
|
||||
|
@ -150,6 +150,8 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="BackgroundHttpContextFactory.cs" />
|
||||
<Compile Include="DisplayManagement\IPositioned.cs" />
|
||||
<Compile Include="DisplayManagement\PositionWrapper.cs" />
|
||||
<Compile Include="Localization\Services\ILocalizationStreamParser.cs" />
|
||||
<Compile Include="Localization\Services\LocalizationStreamParser.cs" />
|
||||
<Compile Include="Mvc\Html\LinkExtensions.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user