/// <summary> /// Includes a Javascript file inline. /// </summary> /// /// <typeparam name="T"> /// Generic type parameter. /// </typeparam> /// <param name="helper"> /// The current helper context. /// </param> /// <param name="script"> /// Full pathname of the server file. /// </param> /// <param name="location"> /// (optional) The location of the script. This parameter can be used to move the script into the /// <head> tag of the document. /// </param> /// /// <returns> /// An HtmlString. /// </returns> public static IHtmlString Script <T>(this HtmlHelper <T> helper, string script, ScriptLocations location) { return(Script(helper, script, null, location)); }
/// <summary> /// Includes a Javascript file inline. /// </summary> /// /// <param name="helper"> /// The current helper context. /// </param> /// <param name="script"> /// Full pathname of the server file. /// </param> /// <param name="attributes"> /// (optional) the attributes. /// </param> /// <param name="location"> /// (optional) The location of the script. This parameter can be used to move the script into the /// <head> tag of the document. /// </param> /// /// <returns> /// An HtmlString. /// </returns> public static IHtmlString Script <T>(this HtmlHelper <T> helper, string script, object attributes, ScriptLocations location) { string path = PathList.NormalizePath(PathList.NormalizeName(script)); var el = CQ.CreateFragment("<script />"); if (attributes != null) { el.AttrSet(attributes); } if (!el.HasAttr("type")) { el.Attr("type", "text/javascript"); } el.Attr("src", script + (script.EndsWith(".js", StringComparison.CurrentCultureIgnoreCase) ? "" : ".js") ); if (location == ScriptLocations.Head) { el.Attr("data-moveto", "head"); } return(new HtmlString(el.Render())); }
/// <summary> /// Includes a Javascript file inline. /// </summary> /// /// <typeparam name="T"> /// Generic type parameter. /// </typeparam> /// <param name="helper"> /// The current helper context. /// </param> /// <param name="script"> /// Full pathname of the server file. /// </param> /// <param name="location"> /// (optional) The location of the script. This parameter can be used to move the script into the /// <head> tag of the document. /// </param> /// /// <returns> /// An HtmlString. /// </returns> public static IHtmlString Script <T>(this HtmlHelper <T> helper, string script, ScriptLocations location = ScriptLocations.Inline) { string path = PathList.NormalizePath(PathList.NormalizeName(script)); string template = "<script class=\"csquery-script\" type=\"text/javascript\" src=\"{0}\"{1}></script>"; string parms = ""; if (location == ScriptLocations.Head) { parms = "data-location=\"head\""; } return(new HtmlString(String.Format(template, path, parms))); }