Ewl » Canonical The canonical version of EWL Read More
Clone URL:  
GenericPhrasingContainer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System; using System.Collections.Generic; using Humanizer; namespace EnterpriseWebLibrary.EnterpriseWebFramework { /// <summary> /// An HTML span element. /// </summary> public class GenericPhrasingContainer: PhrasingComponent { private readonly IReadOnlyCollection<DisplayableElement> children; /// <summary> /// Creates a generic phrasing container (i.e. span element). /// </summary> /// <param name="content"></param> /// <param name="displaySetup"></param> /// <param name="classes">The classes on the element.</param> /// <param name="etherealChildren"></param> public GenericPhrasingContainer( IReadOnlyCollection<PhrasingComponent> content, DisplaySetup displaySetup = null, ElementClassSet classes = null, IReadOnlyCollection<EtherealComponent> etherealChildren = null ) { children = new DisplayableElement( context => new DisplayableElementData( displaySetup, () => new DisplayableElementLocalData( "span" ), classes: classes, children: content, etherealChildren: etherealChildren ) ).ToCollection(); } IReadOnlyCollection<FlowComponentOrNode> FlowComponent.GetChildren() { return children; } } public static class GenericPhrasingContainerExtensionCreators { /// <summary> /// Creates a generic phrasing container (i.e. span element) that depends on this page-modification value. /// </summary> public static IReadOnlyCollection<PhrasingComponent> ToGenericPhrasingContainer<ModificationValueType>( this PageModificationValue<ModificationValueType> pageModificationValue, Func<ModificationValueType, string> textSelector, Func<string, string> jsTextExpressionGetter ) { return new CustomPhrasingComponent( new DisplayableElement( context => { pageModificationValue.AddJsModificationStatement( valueExpression => "$( '#{0}' ).text( {1} );".FormatWith( context.Id, jsTextExpressionGetter( valueExpression ) ) ); return new DisplayableElementData( null, () => new DisplayableElementLocalData( "span", focusDependentData: new DisplayableElementFocusDependentData( includeIdAttribute: true ) ), children: new TextNode( () => textSelector( pageModificationValue.Value ) ).ToCollection() ); } ).ToCollection() ).ToCollection(); } } }