private static void LoadResources() { jQueryAjaxOptions options = new jQueryAjaxOptions(); options.Async = false; int lcid = Page.Context.GetUserLcid(); if (_siteMap == null) { options.Url = Page.Context.GetClientUrl() + "/" + PageEx.GetCacheKey() + "/WebResources/dev1_/js/SiteMap" + lcid.ToString() + ".js"; _siteMap = jQuery.ParseJsonData <SiteMap>(jQuery.Ajax(options).ResponseText); } if (_resources == null) { Dictionary <string, string> loadedResources = null; options.Url = GetResourceStringWebResourceUrl(lcid); try { loadedResources = jQuery.ParseJsonData <Dictionary <string, string> >(jQuery.Ajax(options).ResponseText); } catch { } if (loadedResources == null) { // We fall back to the 1033 because this is included in the solution options.Url = GetResourceStringWebResourceUrl(1033); loadedResources = jQuery.ParseJsonData <Dictionary <string, string> >(jQuery.Ajax(options).ResponseText); } _resources = loadedResources; } }
/// <summary> /// Load the content by inserting the lcid after the filename, before the extension /// E.g. someResource.html is replaced with someResource_1033.js /// Ideally this url should be relative so to benefit from caching without having /// to explicitly specify the cache key /// </summary> /// <param name="webresourceFileName"></param> /// <param name="lcid"></param> /// <param name="callback"></param> public static void LoadContent(string webresourceFileName, int lcid, Action callback) { bool lcidSupported = SupportedLCIDs.Contains(0) || SupportedLCIDs.Contains(lcid); // Check the locale is in the supported locales if (!lcidSupported || (lcid == FallBackLCID)) { callback(); return; } int pos = webresourceFileName.LastIndexOf('.'); string resourceFileName = Page.Context.GetClientUrl() + "/" + PageEx.GetCacheKey() + "WebResources/" + webresourceFileName.Substr(0, pos) + "_" + lcid.ToString() + webresourceFileName.Substr(pos); jQueryAjaxOptions options = new jQueryAjaxOptions(); options.Type = "GET"; options.Url = resourceFileName; options.DataType = "script"; options.Cache = true; options.Success = delegate(object data, string textStatus, jQueryXmlHttpRequest request) { callback(); }; options.Error = delegate(jQueryXmlHttpRequest request, string textStatus, Exception error) { Script.Alert(String.Format("Could not load resource file '{0}'. Please contact your system adminsitrator.\n\n{1}:{2}", resourceFileName, textStatus, error.Message)); callback(); }; jQuery.Ajax(options); }
private static string DecodeImageUrl(string url) { if (url.ToLowerCase().StartsWith("$webresource:")) { url = Page.Context.GetClientUrl() + "/" + PageEx.GetCacheKey() + "WebResources/" + url.Substr(13); } return(url); }
private static string GetResourceStringWebResourceUrl(int lcid) { return(Page.Context.GetClientUrl() + "/" + PageEx.GetCacheKey() + "/WebResources/dev1_/js/QuickNavigationResources_" + lcid.ToString() + ".js"); }