forked from grandnode/grandnode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
KrzysztofPajak
committed
Jul 10, 2019
1 parent
0f121e5
commit 0df4975
Showing
6 changed files
with
74 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Grand.Core.Caching; | ||
using Grand.Services.Media; | ||
using Microsoft.AspNetCore.Razor.TagHelpers; | ||
using System.Threading.Tasks; | ||
|
||
namespace Grand.Framework.TagHelpers | ||
{ | ||
[HtmlTargetElement("source", ParentTag = "picture")] | ||
public class PictureSourceTagHelper : TagHelper | ||
{ | ||
private const string PICTURE_PATH = "Grand.Picture.{0}.{1}"; | ||
|
||
[HtmlAttributeName("picture-id")] | ||
public string PictureId { set; get; } | ||
|
||
[HtmlAttributeName("picture-size")] | ||
public int PictureSize { set; get; } | ||
|
||
private readonly IPictureService _pictureService; | ||
private readonly ICacheManager _cacheManager; | ||
|
||
public PictureSourceTagHelper(IPictureService pictureService, ICacheManager cacheManager) | ||
{ | ||
_pictureService = pictureService; | ||
_cacheManager = cacheManager; | ||
} | ||
|
||
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) | ||
{ | ||
if (!string.IsNullOrEmpty(PictureId)) | ||
{ | ||
var cacheKey = string.Format(PICTURE_PATH, PictureId, PictureSize); | ||
var pictureurl = await _cacheManager.GetAsync(cacheKey, async () => | ||
{ | ||
return await _pictureService.GetPictureUrl(PictureId, PictureSize, showDefaultPicture: false); | ||
}); | ||
var srcset = new TagHelperAttribute("srcset", pictureurl); | ||
output.Attributes.Add(srcset); | ||
} | ||
base.Process(context, output); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,10 @@ | |
<div class="[email protected]_Xl [email protected]_Lg [email protected]_Md [email protected]_Sm [email protected]_Col mb-2"> | ||
<div class="card pb-0"> | ||
<a href="@Url.RouteUrl("Manufacturer", new { SeName = item.SeName })" title="@item.PictureModel.Title"> | ||
<img class="img-fluid" alt="@item.PictureModel.AlternateText" src="@item.PictureModel.ImageUrl" title="@item.PictureModel.Title" /> | ||
<picture> | ||
<source media="(max-width: 480px)" picture-id="@item.PictureModel.Id" picture-size="350" /> | ||
<img class="img-fluid" alt="@item.PictureModel.AlternateText" src="@item.PictureModel.ImageUrl" title="@item.PictureModel.Title" /> | ||
</picture> | ||
</a> | ||
<h4 class="h6 p-sm-3 p-2 mb-0 card-title"> | ||
<a href="@Url.RouteUrl("Manufacturer", new { SeName = item.SeName })" title="@item.PictureModel.Title"> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters