Ejemplo n.º 1
0
        public static string GetBackgroundImageStyle(IPublishedContent image = null, USNBackgroundOption backgroundImageOptions = null)
        {
            string output             = String.Empty;
            string backgroundImage    = String.Empty;
            string backgroundStyle    = String.Empty;
            string backgroundPosition = String.Empty;

            if (image != null)
            {
                backgroundImage = String.Format("background-image:url('{0}');", image.Url);

                if (backgroundImageOptions != null)
                {
                    switch (backgroundImageOptions.Style)
                    {
                    case USNOptions.BG_Cover:
                        backgroundStyle = "background-repeat:no-repeat;background-size:cover;";
                        break;

                    case USNOptions.BG_FullWidth:
                        backgroundStyle = "background-repeat:no-repeat;background-size:100% auto;";
                        break;

                    case USNOptions.BG_Auto:
                        backgroundStyle = "background-repeat:no-repeat;background-size:auto;";
                        break;

                    case USNOptions.BG_Repeat:
                        backgroundStyle = "background-repeat:repeat;background-size:auto;";
                        break;

                    case USNOptions.BG_RepeatX:
                        backgroundStyle = "background-repeat:repeat-x;background-size:auto;";
                        break;

                    case USNOptions.BG_RepeatY:
                        backgroundStyle = "background-repeat:repeat-y;background-size:auto;";
                        break;

                    default:
                        backgroundStyle = "background-repeat:no-repeat;background-size:auto;";
                        break;
                    }

                    switch (backgroundImageOptions.Position)
                    {
                    case USNOptions.BG_TopCenter:
                        backgroundPosition = "background-position:center top;";
                        break;

                    case USNOptions.BG_CenterCenter:
                        backgroundPosition = "background-position:center center;";
                        break;

                    case USNOptions.BG_BottomCenter:
                        backgroundPosition = "background-position:center bottom;";
                        break;

                    case USNOptions.BG_TopRight:
                        backgroundPosition = "background-position:right top;";
                        break;

                    case USNOptions.BG_CenterRight:
                        backgroundPosition = "background-position:right center;";
                        break;

                    case USNOptions.BG_BottomRight:
                        backgroundPosition = "background-position:right bottom;";
                        break;

                    case USNOptions.BG_TopLeft:
                        backgroundPosition = "background-position:left top;";
                        break;

                    case USNOptions.BG_CenterLeft:
                        backgroundPosition = "background-position:left center;";
                        break;

                    case USNOptions.BG_BottomLeft:
                        backgroundPosition = "background-position:left bottom;";
                        break;

                    default:
                        backgroundPosition = "background-position:center center;";
                        break;
                    }
                }

                output = backgroundImage + backgroundStyle + backgroundPosition;

                if (output != String.Empty)
                {
                    output = String.Format(" style=\"{0}\"", output);
                }
            }

            return(output);
        }
        public static string GetBackgroundImageStyle(IPublishedContent image = null, USNBackgroundOption backgroundImageOptions = null)
        {
            string output             = String.Empty;
            string backgroundImage    = String.Empty;
            string backgroundStyle    = String.Empty;
            string backgroundPosition = String.Empty;

            if (image != null)
            {
                backgroundImage = String.Format("background-image:url('{0}');", image.Url);

                if (backgroundImageOptions != null)
                {
                    switch (backgroundImageOptions.Style)
                    {
                    case "Cover":
                        backgroundStyle = "background-repeat:no-repeat;background-size:cover;";
                        break;

                    case "Full width":
                        backgroundStyle = "background-repeat:no-repeat;background-size:100% auto;";
                        break;

                    case "Original":
                        backgroundStyle = "background-repeat:no-repeat;background-size:auto;";
                        break;

                    case "Repeat":
                        backgroundStyle = "background-repeat:repeat;background-size:auto;";
                        break;

                    case "Repeat X":
                        backgroundStyle = "background-repeat:repeat-x;background-size:auto;";
                        break;

                    case "Repeat Y":
                        backgroundStyle = "background-repeat:repeat-y;background-size:auto;";
                        break;

                    default:
                        backgroundStyle = "background-repeat:no-repeat;background-size:auto;";
                        break;
                    }

                    switch (backgroundImageOptions.Position)
                    {
                    case "Center / Top":
                        backgroundPosition = "background-position:center top;";
                        break;

                    case "Center / Center":
                        backgroundPosition = "background-position:center center;";
                        break;

                    case "Center / Bottom":
                        backgroundPosition = "background-position:center bottom;";
                        break;

                    case "Right / Top":
                        backgroundPosition = "background-position:right top;";
                        break;

                    case "Right / Center":
                        backgroundPosition = "background-position:right center;";
                        break;

                    case "Right / Bottom":
                        backgroundPosition = "background-position:right bottom;";
                        break;

                    case "Left / Top":
                        backgroundPosition = "background-position:left top;";
                        break;

                    case "Left / Center":
                        backgroundPosition = "background-position:left center;";
                        break;

                    case "Left / Bottom":
                        backgroundPosition = "background-position:left bottom;";
                        break;

                    default:
                        backgroundPosition = "background-position:center center;";
                        break;
                    }
                }

                output = backgroundImage + backgroundStyle + backgroundPosition;

                if (output != String.Empty)
                {
                    output = String.Format(" style=\"{0}\"", output);
                }
            }

            return(output);
        }