Skip to content

Commit ae32fd8

Browse files
committed
NEW: <our-img> tag helper
1 parent bc6df56 commit ae32fd8

File tree

8 files changed

+786
-0
lines changed

8 files changed

+786
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Our.Umbraco.TagHelpers.Enums;
2+
3+
namespace Our.Umbraco.TagHelpers.Classes
4+
{
5+
internal class OurImageSize
6+
{
7+
public OurImageSize() { }
8+
public OurImageSize(OurScreenSize screenSize, int imageWidth, string? cropAlias = null)
9+
{
10+
ScreenSize = screenSize;
11+
ImageWidth = imageWidth;
12+
CropAlias = cropAlias;
13+
}
14+
public OurImageSize(OurScreenSize screenSize, int imageWidth, int imageHeight)
15+
{
16+
ScreenSize = screenSize;
17+
ImageWidth = imageWidth;
18+
ImageHeight = imageHeight;
19+
}
20+
public OurScreenSize ScreenSize { get; set; }
21+
public int ImageWidth { get; set; }
22+
public int ImageHeight { get; set; }
23+
public string? CropAlias { get; set; }
24+
}
25+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Our.Umbraco.TagHelpers.Enums;
2+
3+
namespace Our.Umbraco.TagHelpers.Configuration
4+
{
5+
public class OurUmbracoTagHelpersConfiguration
6+
{
7+
public ImgTagHelperConfiguration OurImg { get; set; } = new ImgTagHelperConfiguration();
8+
}
9+
public class ImgTagHelperConfiguration
10+
{
11+
/// <summary>
12+
/// Define the typical responsive breakpoints (S,M,L,XL,XXL) in which your website uses during screen resize
13+
/// </summary>
14+
public MediaQuerySizes MediaQueries { get; set; } = new MediaQuerySizes();
15+
/// <summary>
16+
/// If true, let the browser handle image lazy loading, otherwise disable to use a 3rd party JavaScript based library
17+
/// </summary>
18+
public bool UseNativeLazyLoading { get; set; } = true;
19+
/// <summary>
20+
/// Applicable if UseNativeLazyLoading is false
21+
/// </summary>
22+
public string LazyLoadCssClass { get; set; } = "lazyload";
23+
/// <summary>
24+
/// Applicable if UseNativeLazyLoading is false
25+
/// </summary>
26+
public ImagePlaceholderType LazyLoadPlaceholder { get; set; } = ImagePlaceholderType.SVG;
27+
/// <summary>
28+
/// Applicable if UseNativeLazyLoading is false & LazyLoadPlaceholder is LowQualityImage
29+
/// </summary>
30+
public int LazyLoadPlaceholderLowQualityImageQuality { get; set; } = 5;
31+
public bool ApplyAspectRatio { get; set; } = false;
32+
public bool MobileFirst { get; set; } = true;
33+
34+
/// <summary>
35+
/// The property alias of the media type containing the alternative text value.
36+
/// </summary>
37+
public string AlternativeTextMediaTypePropertyAlias { get; set; } = "alternativeText";
38+
}
39+
public class MediaQuerySizes
40+
{
41+
public int Small { get; set; } = 576;
42+
public int Medium { get; set; } = 768;
43+
public int Large { get; set; } = 992;
44+
public int ExtraLarge { get; set; } = 1200;
45+
public int ExtraExtraLarge { get; set; } = 1400;
46+
}
47+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
using Our.Umbraco.TagHelpers.Services;
3+
using Umbraco.Cms.Core.Composing;
4+
using Umbraco.Cms.Core.DependencyInjection;
5+
6+
namespace Our.Umbraco.TagHelpers.Configuration
7+
{
8+
public class OurUmbracoTagHelpersConfigurationComposer : IComposer
9+
{
10+
public void Compose(IUmbracoBuilder builder)
11+
{
12+
builder.Services.AddOptions<OurUmbracoTagHelpersConfiguration>()
13+
.Bind(builder.Config.GetSection("Our.Umbraco.TagHelpers"));
14+
}
15+
}
16+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Our.Umbraco.TagHelpers.Enums
8+
{
9+
public enum ImagePlaceholderType
10+
{
11+
SVG,
12+
LowQualityImage
13+
}
14+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Our.Umbraco.TagHelpers.Enums
8+
{
9+
public enum OurScreenSize
10+
{
11+
Small = 100,
12+
Medium = 200,
13+
Large = 300,
14+
ExtraLarge = 400,
15+
ExtraExtraLarge = 500
16+
}
17+
}

0 commit comments

Comments
 (0)