コード例 #1
0
ファイル: PiczUrlHelper.cs プロジェクト: Steve-Fenton/PICZ
        public static string PiczUrl(this UrlHelper helper, string url, string hash = "")
        {
            var options = PiczOptions.Load();
            var size    = options.Sizes.OrderByDescending(s => s).FirstOrDefault();

            return(PiczUrl(helper, url, size, hash));
        }
コード例 #2
0
 public static MvcHtmlString PiczBackground(this HtmlHelper helper, string url, string id, string hash = "")
 {
     return(PiczBackground(helper, url, id, PiczOptions.Load(), hash));
 }
コード例 #3
0
 private static decimal GetBreakpoint(PiczOptions options, int size)
 {
     return(Math.Round((size / 100M) * (100M - options.BackgroundAdjustmentPercent), 0));
 }
コード例 #4
0
        public static MvcHtmlString PiczBackgroundAppend(this HtmlHelper helper, string url, string id, PiczOptions options, string hash = "")
        {
            var builder = new StringBuilder();

            builder.AppendLine("<style scoped>");

            bool isDefaultSet = false;

            foreach (var size in options.Sizes.OrderByDescending(s => s))
            {
                var img        = $"{url}?s={size}{BaseHelper.GetImageHashForUrl(hash)}";
                var breakpoint = GetBreakpoint(options, size);

                if (!isDefaultSet)
                {
                    builder.AppendLine($"#{id} {{ background-image: url(\"{img}\") }}");
                    isDefaultSet = true;
                }

                builder.AppendLine($"@media only screen and (max-width: {breakpoint}px) {{ #{id} {{ background-image: url(\"{img}\") }} }} ");
            }

            builder.AppendLine("</style>");
            return(MvcHtmlString.Create(builder.ToString()));
        }
コード例 #5
0
 public static MvcHtmlString Picz(this HtmlHelper helper, string url, string sizes, object htmlAttributes, string hash = "")
 {
     return(Picz(helper, url, sizes, PiczOptions.Load(), htmlAttributes, hash));
 }
コード例 #6
0
        public static MvcHtmlString PiczAppend(this HtmlHelper helper, string url, string sizes, PiczOptions options, object htmlAttributes, string hash = "")
        {
            var attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);

            var sourceSets = new List <string>();

            foreach (var size in options.Sizes)
            {
                sourceSets.Add($"{url}?s={size}{BaseHelper.GetImageHashForUrl(hash)} {size}w");
            }

            var defaultSource = $"{url}?s={options.Sizes.Min()}{BaseHelper.GetImageHashForUrl(hash)}";

            return(BuildImageTag(sizes, attributes, sourceSets, defaultSource));
        }