|
using System; |
|
using System.Linq; |
|
using System.Web; |
|
using System.Web.UI; |
|
using umbraco.BusinessLogic; |
|
using umbraco.presentation.LiveEditing; |
|
using umbraco.presentation.masterpages; |
|
using umbraco.uicontrols; |
|
|
|
namespace YourApp |
|
{ |
|
public class PageEvents : ApplicationBase |
|
{ |
|
|
|
public PageEvents() |
|
{ |
|
umbracoPage.Load += umbracoPage_Init; |
|
} |
|
|
|
void umbracoPage_Init(object sender, EventArgs e) |
|
{ |
|
var umbPage = sender as umbracoPage; |
|
|
|
if (umbPage == null) |
|
return; |
|
|
|
var path = umbPage.Page.Request.Path.ToLower(); |
|
|
|
if (!path.Contains("someumbracopage.aspx")) |
|
return; |
|
|
|
AddToolbarButton(umbPage); |
|
} |
|
|
|
private void AddToolbarButton(umbracoPage page) |
|
{ |
|
int pageId; |
|
int.TryParse(HttpContext.Current.Request.QueryString["id"], out pageId); |
|
|
|
var menu = (ScrollingMenu)Utility.FindControl<Control>((Control c) => c.ClientID.EndsWith("_menu"), page.Page); |
|
if (menu == null) |
|
{ |
|
var tabView = (TabView)Utility.FindControl<Control>((Control c) => c.ID == "TabView1", page.Page); |
|
|
|
foreach (TabPage page3 in tabView.GetPanels()) |
|
{ |
|
AddSomeMenuIcon(page3.Menu, page, pageId); |
|
} |
|
} |
|
else |
|
{ |
|
AddSomeMenuIcon(menu, page, pageId); |
|
} |
|
|
|
// Optional: Register some dirty JS/CSS to fix styling issues |
|
string s = "<script type='text/javascript'>"; |
|
s += "$(document).ready(function() {"; |
|
s += @"$('.editorIcon[alt]').each( |
|
function() { |
|
if ($(this).attr('alt').indexOf('Icon Title') != -1) { |
|
$(this).css('padding-bottom', '4px').css('cursor', 'pointer'); } });"; |
|
s += "});"; |
|
s += "</script>"; |
|
page.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "jsfixpadding", s); |
|
|
|
string strCss = "<style type='text/css'>.mceToolbarExternal{padding-left: 15px;}</style>"; |
|
page.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "cssfixtoolbar", strCss); |
|
} |
|
|
|
private void AddSomeMenuIcon(ScrollingMenu menu, umbracoPage page, int pageId) |
|
{ |
|
MenuIconI ni = menu.NewIcon(); |
|
ni.AltText = "Icon Title"; |
|
ni.OnClickCommand = "UmbClientMgr.openModalWindow('some-page.aspx', 'Modal Title', true, 600, 500, 0, 0); return false;"; |
|
ni.ImageURL = "/umbraco/images/umbraco/some-icon.png"); |
|
} |
|
} |
|
} |