Last active
December 16, 2015 13:29
-
-
Save dereke/5442187 to your computer and use it in GitHub Desktop.
Inject JavaScript into Umbraco Admin pages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Global : HttpApplication | |
{ | |
protected void Application_Start(object sender, EventArgs e) | |
{ | |
umbracoPage.Load += InjectJavascript; | |
} | |
private void InjectJavascript(object sender, EventArgs eventArgs) | |
{ | |
var page = sender as umbracoPage; | |
if (page != null && page.IsEditorPage()) { | |
page.Script('/path/to/your.js'); | |
page.Css('/path/to/your.css'); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class UmbracoPageExtensions | |
{ | |
public static bool IsEditorPage(this umbracoPage page) | |
{ | |
return page.Request.Path == "/umbraco/editContent.aspx"; | |
} | |
public static void Script(this umbracoPage page, string path) | |
{ | |
page.Controls.Add(new LiteralControl(string.Format(@"<script src=""{0}""></script>", path))); | |
} | |
public static void Css(this umbracoPage page, string path) | |
{ | |
page.Controls.Add(new LiteralControl(string.Format(@"<link rel=""stylesheet"" href=""{0}"">", path))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment