using System; using System.Web.UI; using umbraco; using umbraco.cms.businesslogic.datatype; using System.Web.UI.HtmlControls; namespace umbraco.editorControls { /// /// Extension methods for embedded resources /// public static class ResourceExtensions { /// /// Registers the embedded client resource. /// /// The control. /// Name of the resource. /// The type. public static void RegisterEmbeddedClientResource(this Control ctl, string resourceName, ClientDependencyType type) { ctl.RegisterEmbeddedClientResource(ctl.GetType(), resourceName, type); } /// /// Registers the embedded client resource. /// /// The control. /// The resource container. /// Name of the resource. /// The type. public static void RegisterEmbeddedClientResource(this Control ctl, Type resourceContainer, string resourceName, ClientDependencyType type) { ctl.Page.RegisterEmbeddedClientResource(resourceContainer, resourceName, type); } /// /// Registers the embedded client resource. /// /// The page. /// The type containing the embedded resource /// Name of the resource. /// The type. public static void RegisterEmbeddedClientResource(this Page page, Type resourceContainer, string resourceName, ClientDependencyType type) { var target = page.Header; // if there's no don't throw an exception. if (target != null) { switch (type) { case ClientDependencyType.Css: // get the urls for the embedded resources var resourceUrl = page.ClientScript.GetWebResourceUrl(resourceContainer, resourceName); var link = new HtmlLink(); link.Attributes.Add("href", resourceUrl); link.Attributes.Add("type", "text/css"); link.Attributes.Add("rel", "stylesheet"); target.Controls.Add(link); break; case ClientDependencyType.Javascript: page.ClientScript.RegisterClientScriptResource(resourceContainer, resourceName); break; default: break; } } } } }