Creating the internal GetBaseCropUrl method and moving the logic from the Model GetCropUrl method to ImageCropperBaseExtensions so that it can be used by both the Model method and the template extensions
Also added some new tests
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Globalization;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -70,5 +71,38 @@ namespace Umbraco.Web
|
||||
|
||||
return dataset.FirstOrDefault(x => x.Alias.ToLowerInvariant() == cropAlias.ToLowerInvariant());
|
||||
}
|
||||
|
||||
internal static string GetCropBaseUrl(this ImageCropDataSet cropDataSet, string cropAlias, bool preferFocalPoint)
|
||||
{
|
||||
var cropUrl = new StringBuilder();
|
||||
|
||||
var crop = cropDataSet.GetCrop(cropAlias);
|
||||
|
||||
// if crop alias has been specified but not found in the Json we should return null
|
||||
if (string.IsNullOrEmpty(cropAlias) == false && crop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if ((preferFocalPoint && cropDataSet.HasFocalPoint()) || (crop != null && crop.Coordinates == null && cropDataSet.HasFocalPoint()) || (string.IsNullOrEmpty(cropAlias) && cropDataSet.HasFocalPoint()))
|
||||
{
|
||||
cropUrl.Append("?center=" + cropDataSet.FocalPoint.Top.ToString(CultureInfo.InvariantCulture) + "," + cropDataSet.FocalPoint.Left.ToString(CultureInfo.InvariantCulture));
|
||||
cropUrl.Append("&mode=crop");
|
||||
}
|
||||
else if (crop != null && crop.Coordinates != null)
|
||||
{
|
||||
cropUrl.Append("?crop=");
|
||||
cropUrl.Append(crop.Coordinates.X1.ToString(CultureInfo.InvariantCulture)).Append(",");
|
||||
cropUrl.Append(crop.Coordinates.Y1.ToString(CultureInfo.InvariantCulture)).Append(",");
|
||||
cropUrl.Append(crop.Coordinates.X2.ToString(CultureInfo.InvariantCulture)).Append(",");
|
||||
cropUrl.Append(crop.Coordinates.Y2.ToString(CultureInfo.InvariantCulture));
|
||||
cropUrl.Append("&cropmode=percentage");
|
||||
}
|
||||
else
|
||||
{
|
||||
cropUrl.Append("?anchor=center");
|
||||
cropUrl.Append("&mode=crop");
|
||||
}
|
||||
return cropUrl.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user