/// <summary> /// Indicates whether or not the user's browser mets the given specification. /// </summary> /// <param name="browser">The browser.</param> /// <param name="baseversion">The baseversion.</param> /// <param name="direction">The direction.</param> /// <returns></returns> public bool BrowserIs(string browser, int baseversion, versionDirection direction) { BrowserSpec spec = new BrowserSpec(browser, baseversion, direction); return spec.MatchesBrowser(browCaps); }
/// <summary> /// Includes the script text for the given browser in the given version range. /// </summary> /// <remarks>Script blocks are only include in the output is the browser specified matches the /// browser making the request. <paramref name="browser"/> can be the name of a browser defined in the BrowserCaps /// (<c>"ie", "firefox", "netscape"</c>, et al, including all defined in the *.browser files installed), /// <c>"all", "other", "inline" </c>or <c> "noscript"</c>. /// "all" block are always included. "other" blocks are include only if a more specific block has /// not already included. <para/> /// "inline" and "noscript" blocks are rendered in place with the rest of the viewcomponent. /// Other blocks are gathered together, and rendered at the location of the <see cref="InsertJavascriptComponent"/>. /// </remarks> /// <param name="browser">The name of the browser which this script is specific to.</param> /// <param name="baseversion">The baseversion.</param> /// <param name="direction">The direction versionDirection.andUp or .andDown.</param> /// <param name="script">The script.</param> public void IncludeScriptText(string browser, int baseversion, versionDirection direction, string script) { BrowserSpec spec = new BrowserSpec(browser, baseversion, direction); if (browser == "all") { AddScriptBlock(script); } if ((browser == "inline")) { RenderScriptImmedaitely(script); } if (!segmentChoosen) { if (browser=="other" || spec.MatchesBrowser(browCaps)) { AddScriptBlock(script); segmentChoosen = true; } } }
public static BrowserSpec ParseBrowser(string tag) { BrowserSpec retn = null; BrowserSpec spec = new BrowserSpec(); spec.full = tag; string name = tag.ToLowerInvariant(); System.Web.Caching.Cache cache = HttpRuntime.Cache; foreach (string browser in browsers) { if (name.StartsWith(browser)) { spec.browser = browser; if (name == browser) { retn = spec; } else { int len = name.Length - browser.Length; spec.direction = versionDirection.Exact; if (name.EndsWith("u") || name.EndsWith("h")) { len--; spec.direction = versionDirection.andHigher; } if (name.EndsWith("d") || name.EndsWith("l")) { len--; spec.direction = versionDirection.andLower; } string version = name.Substring(browser.Length, len); if (int.TryParse(version, out spec.version)) retn = spec; } break; } } return retn; }