/// <summary> /// Called by the ASP.NET page framework to notify server controls /// that use composition-based implementation to create any child controls /// they contain in preparation for posting back or rendering. /// </summary> protected override void CreateChildControls() { base.CreateChildControls(); //we need a DependencyLoader control bool isNew; UmbracoClientDependencyLoader.TryCreate(this, out isNew); //force it to use the canvas provider ClientDependencyLoader.Instance.ProviderName = CanvasClientDependencyProvider.DefaultName; m_Communicator = new Communicator(); m_Communicator.ID = "Communicator"; Controls.Add(m_Communicator); m_Toolbar = new LiveEditingToolbar(this); m_Toolbar.ID = "Toolbar"; Controls.Add(m_Toolbar); UpdatePanel m_OutputWrapper = new UpdatePanel(); m_OutputWrapper.ID = "OutputWrapper"; Controls.Add(m_OutputWrapper); m_Output = new PlaceHolder(); m_Output.ID = "Output"; m_OutputWrapper.ContentTemplateContainer.Controls.Add(m_Output); }
/// <summary> /// Handles the PreRequestHandlerExecute event of the context control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void RegisterTargetClientResources(object sender, EventArgs e) { var context = sender as HttpApplication; if (string.Equals(context.Response.ContentType, MediaTypeNames.Text.Html, StringComparison.OrdinalIgnoreCase) && context.Context.Handler is Page) { var page = context.Context.Handler as Page; var currentExecutionFilePath = context.Request.RawUrl; var registeredClientResources = this.GetRegisteredClientResources(currentExecutionFilePath); if (page != null && registeredClientResources != null && registeredClientResources.Count > 0) { page.Load += (s2, e2) => { try { bool created; var loader = UmbracoClientDependencyLoader.TryCreate(page, out created); if (loader != null) { foreach (var clientResource in registeredClientResources) { loader.RegisterDependency(clientResource.Priority, IOHelper.ResolveUrl(clientResource.Path), clientResource.Type); } } } catch (Exception ex) { Log.Add(LogTypes.Error, -1, string.Concat("Error loading Our.Umbraco.BackOfficePowerScripts.Modules.RegisterClientResources: ", ex)); } }; } } }
protected void RegisterSisyphus(object sender, EventArgs e) { // make sure the page is an umbracoPage; otherwise exit var page = sender as umbracoPage; if (page == null) { return; } // specify the pages that Sisyphus is allowed to be used on var allowedPages = new[] { "editcontent.aspx", "editmedia.aspx", "editmember.aspx" }; var path = page.Page.Request.Path.ToLower(); // check thath the path is allowed if (!allowedPages.Any(path.Contains)) { return; } // make sure there is a body container; otherwise exit var container = page.FindControl("body") as ContentPlaceHolder; if (container == null) { return; } // attempt to find/create the ClientDependency loader for the page bool created; var loader = UmbracoClientDependencyLoader.TryCreate(page, out created); if (loader != null) { // set the path for Sisyphus ... and load the scripts loader.AddPath("Sisyphus", IOHelper.ResolveUrl(string.Concat(SystemDirectories.Umbraco, "/plugins/sisyphus"))); loader.RegisterDependency(998, "sisyphus.min.js", "Sisyphus", ClientDependencyType.Javascript); loader.RegisterDependency(999, "loader.js", "Sisyphus", ClientDependencyType.Javascript); } }
/// <summary> /// Adds an embedded resource to the ClientDependency output by name /// </summary> /// <param name="page">The Page to add the resource to</param> /// <param name="resourceContainer">The type containing the embedded resourcre</param> /// <param name="resourceName">Name of the resource.</param> /// <param name="type">The type.</param> /// <param name="priority">The priority.</param> public static void AddResourceToClientDependency(this Page page, Type resourceContainer, string resourceName, ClientDependencyType type, int priority) { // get the urls for the embedded resources var resourceUrl = page.ClientScript.GetWebResourceUrl(resourceContainer, resourceName); // check if they want to use ClientDependency if (Library.UseClientDependency) { bool created; var loader = UmbracoClientDependencyLoader.TryCreate(page, out created); if (loader != null) { loader.RegisterDependency(priority, page.Server.HtmlEncode(resourceUrl), type); } } else { // get the urls for the embedded resources var target = page.Header; // if there's no <head runat="server" /> don't throw an exception. if (target != null) { // Seems that ClientDependency still has issues with querystrings in virtual paths. switch (type) { case ClientDependencyType.Css: target.Controls.Add(new LiteralControl(string.Format("<link type=\"text/css\" rel=\"stylesheet\" href=\"{0}\" />", page.Server.HtmlEncode(resourceUrl)))); break; case ClientDependencyType.Javascript: target.Controls.Add(new LiteralControl(string.Format("<script type=\"text/javascript\" src=\"{0}\"></script>", page.Server.HtmlEncode(resourceUrl)))); break; default: break; } } } }