Ewl » Canonical The canonical version of EWL Read More
Clone URL:  
Pushed to 2 repositories · View In Graph Contained in tip and canonical

Created a method that makes a dynamic span from a page-modification value.

Changeset e58f2e76d564

Parent 2349af4fdd37

by Profile picture of William GrossWilliam Gross

Changes to one file · Browse files at e58f2e76d564 Showing diff from parent 2349af4fdd37 Diff from another changeset...

 
1
 
 
 
2
3
4
 
30
31
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
 
 
1
2
3
4
5
6
 
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
 
@@ -1,4 +1,6 @@
-using System.Collections.Generic; +using System; +using System.Collections.Generic; +using Humanizer;    namespace EnterpriseWebLibrary.EnterpriseWebFramework {   /// <summary> @@ -30,4 +32,24 @@
  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(); + } + }  } \ No newline at end of file