Exemple #1
0
        /// <summary>
        /// load the Page.Items's script
        /// </summary>
        /// <param name="page"></param>
        public static void LoadStyle(Page page)
        {
            List <string> styleList = page.Items["StyleList"] as List <string>;

            if (styleList != null)
            {
                bool optimizeStyle = ConfigurationManager.AppSettings["OptimizeStyle"] == "1";
                if (optimizeStyle)
                {
                    // cache the style if not cached already
                    PageHelpers.Cache(CacheFactory.CreateStyleCache(), styleList);
                    string url = string.Format("{0}?hash={1}",
                                               page.ResolveClientUrl("~/StyleOptimizer.ashx"),
                                               HttpUtility.UrlEncode(PageHelpers.GetHash(styleList)));
                    AddStyleToPage(page, url);
                }
                else
                {
                    foreach (string styleUrl in styleList)
                    {
                        AddStyleToPage(page, styleUrl);
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// load the Page.Items's script
        /// </summary>
        /// <param name="page"></param>
        public static void LoadScript(Page page)
        {
            List <string> scriptList = page.Items["ScriptList"] as List <string>;

            if (scriptList != null)
            {
                bool optimizeJS = ConfigurationManager.AppSettings["OptimizeJS"] == "1";
                if (optimizeJS)
                {
                    // cache the scripts if not cached already
                    PageHelpers.Cache(CacheFactory.CreateScriptCache(), scriptList);
                    string url = string.Format("{0}?hash={1}",
                                               page.ResolveClientUrl("~/ScriptOptimizer.ashx"),
                                               HttpUtility.UrlEncode(PageHelpers.GetHash(scriptList)));
                    AddScriptToPage(page, url);
                    //or use: page.ClientScript.RegisterClientScriptInclude("baseall", url);
                }
                else
                {
                    foreach (string scriptUrl in scriptList)
                    {
                        AddScriptToPage(page, scriptUrl);
                    }
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Add scriptFileName's script url to Page.Items
        /// </summary>
        /// <param name="page">page</param>
        /// <param name="scriptItem">file name under App_Data/Script</param>
        public static void AddStyle(Page page, string styleFileName)
        {
            IEnumerable <XElement> styleList = StyleItem.GetStyleList(styleFileName);

            if (styleList != null)
            {
                foreach (XElement x in styleList)
                {
                    PageHelpers.Add(page, "StyleList", x.Value);
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Add scriptFileName's script url to Page.Items
        /// </summary>
        /// <param name="page">page</param>
        /// <param name="scriptItem">file name under App_Data/Script</param>
        public static void AddScript(Page page, string scriptFileName)
        {
            IEnumerable <XElement> scriptList = ScriptItem.GetJSList(scriptFileName);

            if (scriptList != null)
            {
                foreach (XElement x in scriptList)
                {
                    PageHelpers.Add(page, "ScriptList", x.Value);
                }
            }
        }