public string GetJsCode(string getP, string pageId, HttpContext context) { string content = (string)context.Cache[pageId + "js"]; if (content == null) { // Load all js scripts for web.config #region Search/Save path //Get the list of files specified in the FileSet List <string> fileNames = new List <string>(); // Get CssPaths in web.config DataPageSection config = (DataPageSection)System.Configuration.ConfigurationManager.GetSection( "DataPageHolderGroup/DataPageHolder"); // Load CssPaths in web.config if (config.enable) { JsElementCollection jsElements = new JsElementCollection(); JsElementCollection masterJsElements = new JsElementCollection(); // Find page css paths foreach (PageElement page in config.Pages) { if (page.pagePath.ToLower() == getP.ToString().ToLower()) { jsElements = page.Jss; } if (page.pagePath.ToLower() == "~/MasterPage.master".ToLower()) { masterJsElements = page.Jss; } } // Load master css paths if (masterJsElements != null) { foreach (JsElement js in masterJsElements) { fileNames.Add(js.Path); } } // Load css paths if (jsElements != null) { foreach (JsElement js in jsElements) { fileNames.Add(js.Path); } } } #endregion if (fileNames.Count > 0) { //Write each files foreach (string file in fileNames) { // Create a request using a URL StreamReader getStream = File.OpenText(context.Request.MapPath(file)); content += getStream.ReadToEnd(); getStream.Dispose(); getStream.Close(); } fileNames.Clear(); } content = StripWhitespace(content); var getCssCode = new SearchWar.Optimize.Css.ResourceHandler(); string csscode = getCssCode.StripWhitespace2(getCssCode.GetCss(context, getP, ref pageId)).Replace("'", string.Empty); csscode = ChangeBackgroundImageUrls(csscode, "http://localhost"); content += "\n function addCss(cssCode) {" + "var styleElement = document.createElement('style');" + " styleElement.type = 'text/css';" + " if (styleElement.styleSheet) {" + " styleElement.styleSheet.cssText = cssCode;" + " } else {" + " styleElement.appendChild(document.createTextNode(cssCode));" + " }" + " document.getElementsByTagName('head')[0].appendChild(styleElement);}" + "addCss('" + csscode + "');"; // bug fix context.Response.ContentType = "text/javascript"; // add Cache context.Cache.Add(pageId + "js", content, null, TimeZoneManager.DateTimeNow.AddDays(DAYS_IN_CACHE), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.High, null); } return(content); }
public string GetCss(HttpContext context, string getp, ref string pageId) { string output = null; #region Search/Save path //Get the list of files specified in the FileSet List<string> fileNames = new List<string>(); // Get CssPaths in web.config DataPageSection config = (DataPageSection)System.Configuration.ConfigurationManager.GetSection( "DataPageHolderGroup/DataPageHolder"); // Load CssPaths in web.config if (config.enable) { CssElementCollection cssElements = null; CssElementCollection masterCssElements = null; // Find page css paths foreach (PageElement cssPage in config.Pages) { if (cssPage.pagePath.ToLower() == getp.ToLower()) { cssElements = cssPage.Csss; } if (cssPage.pagePath.ToLower() == "~/MasterPage.master".ToLower()) { masterCssElements = cssPage.Csss; } } // Load master css paths if (masterCssElements != null) { foreach (CssElement css in masterCssElements) { if (css.Name != "CssIe6") { fileNames.Add(css.Path); } else { // IE6 Fix if (context.Request.Browser.Type.Equals("IE6")) { fileNames.Add(css.Path); // Change pageid (create new cache for IE6) pageId += "-IE6"; } } } } // Load css paths if (cssElements != null) { foreach (CssElement css in cssElements) { fileNames.Add(css.Path); } } } #endregion // loop all files if (fileNames.Count > 0) { //Write each files foreach (string file in fileNames) { // Create a request using a URL StreamReader getStream = File.OpenText(context.Request.MapPath(file)); output += getStream.ReadToEnd(); getStream.Dispose(); getStream.Close(); } fileNames.Clear(); return output; } return null; }