From 41ec895e82a6b08b92a7aeb6efa1d4dc968c8fbf Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Wed, 20 Aug 2014 19:28:33 +0000 Subject: [PATCH] Superfish is ugly as ugliest fuck BUT OPERATIONAL. Yay or something. Much work ahead to make it look decent... --- Site5/App_Code/MainMenuItem.cs | 172 +++++++++++++++++-- Site5/App_GlobalResources/Menu5.resx | 3 + Site5/Controls/v5/Base/MainMenu.ascx.cs | 89 ++++++++-- Site5/Images/PageIcons/transparency-16px.png | Bin 0 -> 170 bytes Site5/MainMenu-v5.xml | 59 +++++++ Site5/Master-v5.master | 6 + Site5/Scripts/ScriptLicenses.txt | 2 +- Site5/Scripts/hoverIntent.min.js | 9 + Site5/Style/superfish.css | 113 ++++++++++++ 9 files changed, 421 insertions(+), 32 deletions(-) create mode 100644 Site5/Images/PageIcons/transparency-16px.png create mode 100644 Site5/MainMenu-v5.xml create mode 100644 Site5/Scripts/hoverIntent.min.js create mode 100644 Site5/Style/superfish.css diff --git a/Site5/App_Code/MainMenuItem.cs b/Site5/App_Code/MainMenuItem.cs index 4f5e7f1e..def8948e 100644 --- a/Site5/App_Code/MainMenuItem.cs +++ b/Site5/App_Code/MainMenuItem.cs @@ -1,30 +1,166 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Web; +using System.Web.UI.WebControls; +using System.Xml.Serialization; +using Swarmops.Logic.Security; -/// -/// Summary description for MainMenuItem -/// -[Serializable] -public class MainMenuItem + +namespace Swarmops { - public MainMenuItem() - { - Children = new MainMenuItem[0]; - } + /// + /// Summary description for MainMenuItem + /// + [Serializable] + public class MainMenuItem + { + public MainMenuItem() + { + Children = new MainMenuItem[0]; + } - // FromXml - // ToXml + public static MainMenuItem Separator + { + get + { + MainMenuItem result = new MainMenuItem(); + result.Type = MenuItemType.Separator; - public string ResourceKey { get; set; } - public int UserLevel { get; set; } - public string Permissions { get; set; } - public string ImageUrl { get; set; } - public string NavigateUrl { get; set; } + return result; + } + } - // TODO: INSERTION POINT (for plugins) + public static MainMenuItem Link(string image, string navUrl, string resourceKey, int userLevel, + string permissions) + { + MainMenuItem result = new MainMenuItem() + { + ImageUrl = image, + NavigateUrl = navUrl, + Permissions = permissions, + ResourceKey = resourceKey, + UserLevel = userLevel, + Type = MenuItemType.Link + }; - public MainMenuItem[] Children { get; set; } + return result; + } + public static MainMenuItem Submenu(string resourceKey, int userLevel, string permissions) + { + MainMenuItem result = new MainMenuItem() + { + Permissions = permissions, + ResourceKey = resourceKey, + UserLevel = userLevel, + Type = MenuItemType.Submenu + }; + + return result; + } + + public static MainMenuItem Disabled(string image, string resourceKey, int userLevel, string permissions) + { + MainMenuItem result = new MainMenuItem() + { + ImageUrl = image, + Permissions = permissions, + ResourceKey = resourceKey, + UserLevel = userLevel, + Type = MenuItemType.Disabled + }; + + return result; + } + + public static void PrimeXml(MainMenuItem[] items) + { + // This is only supposed to be used once, to prime the initial menu + XmlSerializer serializer = new XmlSerializer(typeof (MainMenuItem[])); + + using (TextWriter writer = new StreamWriter("C:\\Windows\\Temp\\temp.xml")) + { + serializer.Serialize(writer, items); + } + } + + public static void PrimeNewMenuFile() + { + MainMenuItem todoItem = MainMenuItem.Disabled(string.Empty, "Placeholder_Todo", 1, string.Empty); + MainMenuItem[] todoItemArray = new MainMenuItem[] {todoItem}; + + MainMenuItem peopleItem = MainMenuItem.Submenu("People", 1, string.Empty); + peopleItem.Children = todoItemArray; + + MainMenuItem commsItem = MainMenuItem.Submenu("Communications", 1, string.Empty); + peopleItem.Children = todoItemArray; + + MainMenuItem claimRefundItem = MainMenuItem.Link("iconshock-moneyback", + "/Pages/v5/Financial/FileExpenseClaim.aspx", "Financial_ClaimExpense", 2, String.Empty); + MainMenuItem separatorItem = MainMenuItem.Separator; + + MainMenuItem[] financialChildren = new[] {claimRefundItem, separatorItem}; + MainMenuItem financialItem = MainMenuItem.Submenu("Financial", 2, string.Empty); + financialItem.Children = financialChildren; + + MainMenuItem[] protoMenu = new[] {peopleItem, commsItem, financialItem}; + PrimeXml(protoMenu); + + } + + public string ResourceKey { get; set; } + public int UserLevel { get; set; } + public string Permissions { get; set; } + public string ImageUrl { get; set; } + public string NavigateUrl { get; set; } + public MenuItemType Type { get; set; } + + // TODO: INSERTION POINT (for plugins) + + public MainMenuItem[] Children { get; set; } + + + } + + public enum MenuItemType + { + Unknown = 0, + + /// + /// A normal link + /// + Link, + + /// + /// Something that looks like a menu item but is disabled + /// + Disabled, + + /// + /// A header (with or without image) that leads to more options as sub + /// + Submenu, + + /// + /// A thin line separating menu items + /// + Separator, + + /// + /// A major header (non-link) introducing new menu section + /// + Header, + + /// + /// Build number indicator + /// + BuildNumber, + + /// + /// SPECIAL CASE: Close Books menu item + /// + SpecialCloseBooks + } } \ No newline at end of file diff --git a/Site5/App_GlobalResources/Menu5.resx b/Site5/App_GlobalResources/Menu5.resx index 37f0ca5e..b5bbf6a5 100644 --- a/Site5/App_GlobalResources/Menu5.resx +++ b/Site5/App_GlobalResources/Menu5.resx @@ -351,4 +351,7 @@ Self-Signup Page + + Placeholder (Todo) + \ No newline at end of file diff --git a/Site5/Controls/v5/Base/MainMenu.ascx.cs b/Site5/Controls/v5/Base/MainMenu.ascx.cs index f08af76c..88431c4a 100644 --- a/Site5/Controls/v5/Base/MainMenu.ascx.cs +++ b/Site5/Controls/v5/Base/MainMenu.ascx.cs @@ -1,31 +1,94 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; +using System.Security.Cryptography; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; +using System.Xml.Serialization; +// ReSharper disable once CheckNamespace namespace Swarmops.Controls.Base { - public partial class MainMenu : System.Web.UI.UserControl + public partial class MainMenu : ControlV5Base { protected void Page_Load(object sender, EventArgs e) { + // TODO: Put a small cache on this + // TODO: Put plugins on it + + XmlSerializer serializer = new XmlSerializer(typeof(MainMenuItem[])); + + using (TextReader reader = new StreamReader(Server.MapPath("~/MainMenu-v5.xml"))) + { + this.MainMenuData = (MainMenuItem[]) serializer.Deserialize(reader); + } + } + + protected override void Render(HtmlTextWriter output) + { + output.Write(""); + } + + private void WriteMenuItem(MainMenuItem menuItem, HtmlTextWriter output) + { + output.Write("
  • "); + string localizedText = "RESOURCE NOT FOUND"; + + if (!String.IsNullOrEmpty(menuItem.ResourceKey)) + { + object resourceObject = GetGlobalResourceObject("Menu5", "Menu5_" + menuItem.ResourceKey); + if (resourceObject != null) + { + localizedText = resourceObject.ToString(); + } + } + localizedText = Server.HtmlEncode(localizedText); // muy importante + + switch (menuItem.Type) + { + case MenuItemType.Link: + output.Write("{2}", + menuItem.ImageUrl, menuItem.NavigateUrl, localizedText); + break; + case MenuItemType.Disabled: + string imageUrl = "/Images/PageIcons/" + menuItem.ImageUrl + "-16px.png"; + if (String.IsNullOrEmpty(menuItem.ImageUrl)) + { + imageUrl = "/Images/PageIcons/transparency-16px.png"; + } + output.Write("{1}", imageUrl, localizedText); + break; + case MenuItemType.Submenu: + output.Write(localizedText); + break; + case MenuItemType.Separator: + output.Write("---"); + break; + default: + throw new NotImplementedException(); + } + + if (menuItem.Children.Length > 0) + { + output.Write(""); + } + + output.Write("
  • "); } public MainMenuItem[] MainMenuData { get; set; } } - - [Serializable] - public class MainMenuItem - { - public string ResourceString; - public string IconUrl; - public string NavigateUrl; - public int UserLevel; - public string Permission; - public bool IsSeparator; - public MainMenuItem[] Children; - } } \ No newline at end of file diff --git a/Site5/Images/PageIcons/transparency-16px.png b/Site5/Images/PageIcons/transparency-16px.png new file mode 100644 index 0000000000000000000000000000000000000000..533854edb18057212a631a118b8b5a00f6e4139d GIT binary patch literal 170 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmPqhX}ti=kY^V_<%x^C9V-A&iT2ysd*&~&PAz-C8;S2 z<(VZJ3hti10pX2&;y^`0o-U3d7N?UFBv= + + + + + People + 1 + + Submenu + + + Placeholder_Todo + 1 + + + Disabled + + + + + + Communications + 1 + + Submenu + + + Placeholder_Todo + 1 + + + Disabled + + + + + + Financial + 2 + + Submenu + + + Financial_ClaimExpense + 2 + + iconshock-moneyback + /Pages/v5/Financial/FileExpenseClaim.aspx + Link + + + + 0 + Separator + + + + + \ No newline at end of file diff --git a/Site5/Master-v5.master b/Site5/Master-v5.master index 0a5eedac..c01c6c79 100644 --- a/Site5/Master-v5.master +++ b/Site5/Master-v5.master @@ -1,6 +1,7 @@ <%@ Master Language="C#" AutoEventWireup="true" CodeFile="Master-v5.master.cs" Inherits="Swarmops.MasterV5" %> <%@ Register Src="~/Controls/v5/Base/LanguageSelector.ascx" TagName="LanguageSelector" TagPrefix="act5" %> <%@ Register TagPrefix="Swarmops5" TagName="ExternalScripts" Src="~/Controls/v5/UI/ExternalScripts.ascx" %> +<%@ Register TagPrefix="Swarmops5" TagName="MainMenu" Src="~/Controls/v5/Base/MainMenu.ascx" %> @@ -12,6 +13,7 @@ + @@ -25,6 +27,7 @@ + @@ -67,6 +70,8 @@ $("a[rel*=leanModal]").leanModal(); + $("#MainMenuContainer").superfish(); + }); @@ -113,6 +118,7 @@
    +
    diff --git a/Site5/Scripts/ScriptLicenses.txt b/Site5/Scripts/ScriptLicenses.txt index ae04cf5d..8d7df7f6 100644 --- a/Site5/Scripts/ScriptLicenses.txt +++ b/Site5/Scripts/ScriptLicenses.txt @@ -1,6 +1,6 @@ Some of these scripts are not in the public domain. -jQuery is licensed as MIT (free to use for any purpose). So is FancyBox, Alertify, Superfish, and jQuery SwitchButton. +jQuery is licensed as MIT (free to use for any purpose). So is FancyBox, Alertify, Superfish, HoverIntent, and jQuery SwitchButton. SmartWizard is licensed under Creative Commons Attribution-ShareAlike. diff --git a/Site5/Scripts/hoverIntent.min.js b/Site5/Scripts/hoverIntent.min.js new file mode 100644 index 00000000..ed673696 --- /dev/null +++ b/Site5/Scripts/hoverIntent.min.js @@ -0,0 +1,9 @@ +/*! + * hoverIntent v1.8.0 // 2014.06.29 // jQuery v1.9.1+ + * http://cherne.net/brian/resources/jquery.hoverIntent.html + * + * You may use hoverIntent under the terms of the MIT license. Basically that + * means you are free to use hoverIntent as long as this header is left intact. + * Copyright 2007, 2014 Brian Cherne + */ +(function ($) { $.fn.hoverIntent = function (handlerIn, handlerOut, selector) { var cfg = { interval: 100, sensitivity: 6, timeout: 0 }; if (typeof handlerIn === "object") { cfg = $.extend(cfg, handlerIn) } else { if ($.isFunction(handlerOut)) { cfg = $.extend(cfg, { over: handlerIn, out: handlerOut, selector: selector }) } else { cfg = $.extend(cfg, { over: handlerIn, out: handlerIn, selector: handlerOut }) } } var cX, cY, pX, pY; var track = function (ev) { cX = ev.pageX; cY = ev.pageY }; var compare = function (ev, ob) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); if (Math.sqrt((pX - cX) * (pX - cX) + (pY - cY) * (pY - cY)) < cfg.sensitivity) { $(ob).off("mousemove.hoverIntent", track); ob.hoverIntent_s = true; return cfg.over.apply(ob, [ev]) } else { pX = cX; pY = cY; ob.hoverIntent_t = setTimeout(function () { compare(ev, ob) }, cfg.interval) } }; var delay = function (ev, ob) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); ob.hoverIntent_s = false; return cfg.out.apply(ob, [ev]) }; var handleHover = function (e) { var ev = $.extend({}, e); var ob = this; if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t) } if (e.type === "mouseenter") { pX = ev.pageX; pY = ev.pageY; $(ob).on("mousemove.hoverIntent", track); if (!ob.hoverIntent_s) { ob.hoverIntent_t = setTimeout(function () { compare(ev, ob) }, cfg.interval) } } else { $(ob).off("mousemove.hoverIntent", track); if (ob.hoverIntent_s) { ob.hoverIntent_t = setTimeout(function () { delay(ev, ob) }, cfg.timeout) } } }; return this.on({ "mouseenter.hoverIntent": handleHover, "mouseleave.hoverIntent": handleHover }, cfg.selector) } })(jQuery); \ No newline at end of file diff --git a/Site5/Style/superfish.css b/Site5/Style/superfish.css new file mode 100644 index 00000000..77302518 --- /dev/null +++ b/Site5/Style/superfish.css @@ -0,0 +1,113 @@ +/*** ESSENTIAL STYLES ***/ +.sf-menu, .sf-menu * { + margin: 0; + padding: 0; + list-style: none; +} +.sf-menu li { + position: relative; +} +.sf-menu ul { + position: absolute; + display: none; + top: 100%; + left: 0; + z-index: 9990; +} +.sf-menu > li { + float: left; +} +.sf-menu li:hover > ul, +.sf-menu li.sfHover > ul { + display: block; +} + +.sf-menu a { + display: block; + position: relative; +} +.sf-menu ul ul { + top: 0; + left: 100%; +} + + +/*** DEMO SKIN ***/ +.sf-menu { + float: left; + margin-bottom: 1em; +} +.sf-menu ul { + box-shadow: 2px 2px 6px rgba(0,0,0,.2); + min-width: 12em; /* allow long menu items to determine submenu width */ + *width: 12em; /* no auto sub width for IE7, see white-space comment below */ +} +.sf-menu a { + border-left: 1px solid #fff; + border-top: 1px solid #dFeEFF; /* fallback colour must use full shorthand */ + border-top: 1px solid rgba(255,255,255,.5); + padding: .75em 1em; + text-decoration: none; + zoom: 1; /* IE7 */ +} +.sf-menu a { + color: #13a; +} +.sf-menu li { + background: #BDD2FF; + white-space: nowrap; /* no need for Supersubs plugin */ + *white-space: normal; /* ...unless you support IE7 (let it wrap) */ + -webkit-transition: background .2s; + transition: background .2s; +} +.sf-menu ul li { + background: #AABDE6; +} +.sf-menu ul ul li { + background: #9AAEDB; +} +.sf-menu li:hover, +.sf-menu li.sfHover { + background: #CFDEFF; + /* only transition out, not in */ + -webkit-transition: none; + transition: none; +} + +/*** arrows (for all except IE7) **/ +.sf-arrows .sf-with-ul { + padding-right: 2.5em; + *padding-right: 1em; /* no CSS arrows for IE7 (lack pseudo-elements) */ +} +/* styling for both css and generated arrows */ +.sf-arrows .sf-with-ul:after { + content: ''; + position: absolute; + top: 50%; + right: 1em; + margin-top: -3px; + height: 0; + width: 0; + /* order of following 3 rules important for fallbacks to work */ + border: 5px solid transparent; + border-top-color: #dFeEFF; /* edit this to suit design (no rgba in IE8) */ + border-top-color: rgba(255,255,255,.5); +} +.sf-arrows > li > .sf-with-ul:focus:after, +.sf-arrows > li:hover > .sf-with-ul:after, +.sf-arrows > .sfHover > .sf-with-ul:after { + border-top-color: white; /* IE8 fallback colour */ +} +/* styling for right-facing arrows */ +.sf-arrows ul .sf-with-ul:after { + margin-top: -5px; + margin-right: -3px; + border-color: transparent; + border-left-color: #dFeEFF; /* edit this to suit design (no rgba in IE8) */ + border-left-color: rgba(255,255,255,.5); +} +.sf-arrows ul li > .sf-with-ul:focus:after, +.sf-arrows ul li:hover > .sf-with-ul:after, +.sf-arrows ul .sfHover > .sf-with-ul:after { + border-left-color: white; +}