示例#1
0
        public override void TranslateField(ParseVariantFieldArgs args)
        {
            ParseVariantFieldArgs variantFieldArgs = args;

            var variantImageWithClass = new VariantImageWithClass();

            variantImageWithClass.ItemName    = args.VariantItem.Name;
            variantImageWithClass.FieldName   = args.VariantItem[Constants.RenderingVariants.Fields.ImageWithClass.FieldName];
            variantImageWithClass.CssClass    = args.VariantItem[Constants.RenderingVariants.Fields.ImageWithClass.CssClass];
            variantImageWithClass.Sizes       = args.VariantItem[Constants.RenderingVariants.Fields.ImageWithClass.Sizes];
            variantImageWithClass.Widths      = args.VariantItem[Constants.RenderingVariants.Fields.ImageWithClass.Widths];
            variantImageWithClass.DefaultSize = args.VariantItem[Constants.RenderingVariants.Fields.ImageWithClass.DefaultSize];
            variantFieldArgs.TranslatedField  = variantImageWithClass;
        }
示例#2
0
        protected virtual HtmlGenericControl CreateResponsiveImage(Item mediaItem, VariantImageWithClass variantResponsiveImage, string altText)
        {
            string str       = ServiceLocator.GetRequiredResetableService <BaseMediaManager>().Value.GetMediaUrl(mediaItem);
            string sourceSet = GetSourceSet(variantResponsiveImage.Widths, str);

            if (!string.IsNullOrWhiteSpace(variantResponsiveImage.DefaultSize))
            {
                str = AddWidthParam(str, variantResponsiveImage.DefaultSize);
            }

            HtmlGenericControl htmlGenericControl = new HtmlGenericControl("img");

            htmlGenericControl.Attributes.Add("src", str);

            if (!string.IsNullOrWhiteSpace(altText))
            {
                htmlGenericControl.Attributes.Add("alt", altText);
            }

            if (!string.IsNullOrWhiteSpace(variantResponsiveImage.CssClass))
            {
                htmlGenericControl.Attributes.Add("class", variantResponsiveImage.CssClass);
            }

            if (!string.IsNullOrWhiteSpace(variantResponsiveImage.Sizes))
            {
                htmlGenericControl.Attributes.Add("sizes", variantResponsiveImage.Sizes);
            }

            if (!string.IsNullOrWhiteSpace(sourceSet))
            {
                htmlGenericControl.Attributes.Add("srcset", sourceSet);
            }

            return(htmlGenericControl);
        }