//TODO: refactorize it private static string RenderGlobalizationEntries(ScriptManagerEntry entry) { var casted = entry as GlobalizationEntries; if (casted == null) { return(null); } var meta = String.Format("<meta name=\"accept-language\" content=\"{0}\">", casted.AcceptLanguage); var files = new List <string>() { "globalize.js", string.Format("cultures/globalize.culture.{0}.js", casted.AcceptLanguage) }; if (casted.AcceptLanguage != casted.AcceptLanguageSimplied) { files.Add(string.Format("cultures/globalize.culture.{0}.js", casted.AcceptLanguageSimplied)); } var references = files.Select(x => HtmlScriptManagerExtensions.RenderReference(new JsReferenceEntry() { Path = string.Format("{0}/{1}", casted.GlobalizeScriptFolder, x) })); var scriptTemplates = new[] { @"if (Globalize.cultures['{0}']) {{ Globalize.culture('{0}'); }} else if (Globalize.cultures['{1}']) {{ Globalize.culture('{1}'); }}", @"if ($) {{$(function () {{ if ($.datepicker) {{ $.datepicker.setDefaults($.datepicker.regional['{0}'] || $.datepicker.regional['{1}'] || $.datepicker.regional['']); }} }});}}" }; var scripts = scriptTemplates.Select(x => string.Format(x, casted.AcceptLanguage, casted.AcceptLanguageSimplied)); TagBuilder builder = new TagBuilder("script"); builder.MergeAttribute("type", "text/javascript"); return(string.Join("\n", new[] { meta } .Union(references) .Union(new[] { builder.ToString(TagRenderMode.StartTag) }) .Union(scripts) .Union(new[] { builder.ToString(TagRenderMode.EndTag) }))); }
private static string RenderReference(ScriptManagerEntry entry) { var casted = entry as ReferenceEntry; if (casted == null) { return(null); } TagBuilder builder = new TagBuilder(casted.TagName()); builder.MergeAttribute(casted.ReferenceAttributeName(), TransformReferencePath(casted.Path, casted.OmitAppVersion)); builder.MergeAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(casted.DefaultAttributes())); builder.MergeAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(casted.HtmlAttributes)); var tag = builder.ToString(casted.SelfClosed() ? TagRenderMode.SelfClosing : TagRenderMode.Normal); return(ProcessPatchCondition(casted, tag)); }
private static string RenderGlobalJavascript(ScriptManagerEntry entry) { var casted = entry as GlobalJavascriptEntry; if (casted == null) { return(null); } TagBuilder builder = new TagBuilder("script"); builder.MergeAttribute("type", "text/javascript"); builder.MergeAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(casted.HtmlAttributes)); return(string.Format("{0}window.{1} = {2};{3}", builder.ToString(TagRenderMode.StartTag), casted.Name, JsonConvert.SerializeObject( casted.Value, Formatting.Indented, CommonJobsController.GetSerializerSettings()), builder.ToString(TagRenderMode.EndTag))); }
private void Register(ScriptManagerEntry entry) { entry.SetOrder = entries.Count; entries.Add(entry); }