/// <summary> /// Check if MooTools is already registered. /// </summary> public static bool CheckMooTools(MooVersion version, MooModule module) { if (HttpContext.Current == null) { throw (new InvalidOperationException("Invalid HttpContext.")); } Page Page = HttpContext.Current.CurrentHandler as Page; if (Page == null) { throw (new InvalidOperationException("This request must be a Page request.")); } if (Page.Header == null) { throw (new InvalidOperationException("Header tag must be a server control.")); } foreach (Control c in Page.Header.Controls) { if (c is Literal) { Literal lit = (Literal)c; if (module == MooModule.Core) { //Any module defined contains the core. for (MooModule i = MooModule.Core; i <= MooModule.Full; i++) { string script = GetScript(Page, version, i); if (lit.Text.Contains(script)) { return(true); } } } else { //Only the self module or the full one. string script = GetScript(Page, version, module); string scriptFull = GetScript(Page, version, MooModule.Full); if (lit.Text.Contains(script) || lit.Text.Contains(scriptFull)) { return(true); } } } } return(false); }
/// <summary> /// Gets a script tag that references the choosed mootools module. /// </summary> public static string GetScript(Page Page, MooVersion Version, MooModule @Module) { switch (Version) { case MooVersion.Version_1_11: return(Environment.NewLine + "<script src=\"" + Page.ClientScript.GetWebResourceUrl(typeof(MooTools), Configuration.Resources.MooRoot111 + @Module.ToString() + ".js") + "\" type=\"text/javascript\"></script>"); case MooVersion.Version_1_2: string script = ""; if (@Module != MooModule.Core) { script += Environment.NewLine + GetScript(Page, Version, MooModule.Core); } script += Environment.NewLine + "<script src=\"" + Page.ClientScript.GetWebResourceUrl(typeof(MooTools), Configuration.Resources.MooRoot12 + @Module.ToString() + ".js") + "\" type=\"text/javascript\"></script>"; return(script); default: return(null); } }
/// <summary> /// Gets a script tag that references the choosed mootools module. /// </summary> public static string GetScript(Page Page, MooModule @Module) { return(GetScript(Page, MooVersion.Version_1_11, @Module)); }
/// <summary> /// Check if MooTools is already registered. /// </summary> public static bool CheckMooTools(MooModule module) { return(CheckMooTools(MooVersion.Version_1_11, module)); }