Ejemplo n.º 1
0
        /// <summary>
        /// Creates a reference to the sprite / inlined version of the desired image including special attributes.
        /// </summary>
        /// <param name="virtualPath">The relative path of the image to be displayed</param>
        /// <param name="htmlAttributes">Html Attributes of IDictionary form</param>
        /// <returns>Image tag.</returns>
        public static IHtmlString Image(string virtualPath, IDictionary <string, object> htmlAttributes)
        {
            ImageOptimizations.EnsureInitialized();

            TagBuilder htmlTag = new TagBuilder("img");

            htmlTag.MergeAttributes(htmlAttributes);

            HttpContextBase httpContext = new HttpContextWrapper(HttpContext.Current);

            if (ImageOptimizations.LinkCompatibleCssFile(httpContext.Request.Browser) == null)
            {
                htmlTag.MergeAttribute("src", ResolveUrl(virtualPath));
                return(new HtmlString(htmlTag.ToString(TagRenderMode.SelfClosing)));
            }
            else
            {
                htmlTag.AddCssClass(ImageOptimizations.MakeCssClassName(virtualPath));
                htmlTag.MergeAttribute("src", ResolveUrl(ImageOptimizations.GetBlankImageSource(httpContext.Request.Browser)));
                return(new HtmlString(htmlTag.ToString(TagRenderMode.SelfClosing)));
            }
        }
Ejemplo n.º 2
0
        protected override void OnPreRender(EventArgs e)
        {
            if (PrepareSpriteRendering())
            {
                string spriteDirectoryPath = Path.GetDirectoryName(ImageUrl);

                string spriteCssClassName = ImageOptimizations.MakeCssClassName(ImageUrl);
                if (CssClass.Length != 0)
                {
                    CssClass = spriteCssClassName + " " + CssClass;
                }
                else
                {
                    CssClass = spriteCssClassName;
                }

                ImageSpriteCssLink.AddCssToPage(Page, Path.Combine(spriteDirectoryPath, _cssFileName));

                _usingSprites = true;
            }

            base.OnPreRender(e);
        }