Keep in mind that my solution is just that! It is a Visual Studio 2008 solution for a site definition. As I said earlier though, you do not have to do it this way. With that in mind, to duplicate what I have, you need to at least have the following things done:
- An images folder in the Master Page Gallery. (It is just a doc library!)
- The stylesheets you want to use loaded into the Master Page Gallery. (I used 5)
- A doc library called Scripts in the root of the site.
- <ul>
- <li><a class="hide" href="javascript:loadpage('/default.aspx');">Home</a></li>
- <li><a class="hide" href="javascript:loadpage('/Lists/Tracking/AllItems.aspx');">Tracking</a>
- <ul>
- <li><a href="javascript:loadpage('/Lists/Tracking/Project.aspx');">By Project</a></li>
- <li><a href="javascript:loadpage('/Lists/Tracking/Code.aspx');">By Code</a></li>
- <li><a href="javascript:loadpage('/Lists/Tracking/Engineer.aspx');">By Engineer</a></li>
- <li><a href="javascript:loadpage('/Lists/Tracking/Supervisor.aspx');">By Supervisor</a></li>
- <li><a href="javascript:loadpage('/Lists/Tracking/Reference.aspx');">By Reference</a></li>
- <li><a href="javascript:loadpage('/Lists/Tracking/MyItems.aspx');">My Items</a></li>
- </ul>
- </li>
- <li><a class="hide" href="javascript:loadpage('/Lists/Twds/AllItems.aspx');">Twds</a>
- <ul>
- <li><a href="javascript:loadpage('/Lists/Twds/Project.aspx');">By Project</a></li>
- <li><a href="javascript:loadpage('/Lists/Twds/Code.aspx');">By Code</a></li>
- <li><a href="javascript:loadpage('/Lists/Twds/Engineer.aspx');">By Engineer</a></li>
- <li><a href="javascript:loadpage('/Lists/Twds/Supervisor.aspx');">By Supervisor</a></li>
- <li><a href="javascript:loadpage('/Lists/Twds/Reference.aspx');">By Reference</a></li>
- <li><a href="javascript:loadpage('/Lists/Twds/MyItems.aspx');">My Items</a></li>
- </ul>
- </li>
- <li><a class="hide" href="javascript:loadpage('/Lists/References/AllItems.aspx');">References</a></li>
- <li><a class="hide" href="mailto:evilgenius@fake.net">Contact</a></li>
Yes, it is not complete and there is a cool reason for this. If you look back at the code for the master page, I left the site actions control there but in a hidden div element. Part of the script will use some code to get the href elements of the hidden site settings and add it to the main navigation at the end. I think that is slick don't you!
Here is the code for the side menu:
- <div class="sidebarbutton">Tracking</div>
- <div class="sidebarcontent" id="sidebarcontent">
- <ul>
- <li><a href="javascript:loadpage('/Lists/Tracking/Project.aspx');">By Project</a></li>
- <li><a href="javascript:loadpage('/Lists/Tracking/Code.aspx');">By Code</a></li>
- <li><a href="javascript:loadpage('/Lists/Tracking/Engineer.aspx');">By Engineer</a></li>
- <li><a href="javascript:loadpage('/Lists/Tracking/Supervisor.aspx');">By Supervisor</a></li>
- <li><a href="javascript:loadpage('/Lists/Tracking/Reference.aspx');">By Reference</a></li>
- <li><a href="javascript:loadpage('/Lists/Tracking/MyItems.aspx');">My Items</a></li>
- </ul>
- </div>
- <div class="sidebarbutton">Twds</div>
- <div class="sidebarcontent" id="sidebarcontent">
- <ul>
- <li><a href="javascript:loadpage('/Lists/Twds/Project.aspx');">By Project</a></li>
- <li><a href="javascript:loadpage('/Lists/Twds/Code.aspx');">By Code</a></li>
- <li><a href="javascript:loadpage('/Lists/Twds/Engineer.aspx');">By Engineer</a></li>
- <li><a href="javascript:loadpage('/Lists/Twds/Supervisor.aspx');">By Supervisor</a></li>
- <li><a href="javascript:loadpage('/Lists/Twds/Reference.aspx');">By Reference</a></li>
- <li><a href="javascript:loadpage('/Lists/Twds/MyItems.aspx');">My Items</a></li>
- </ul>
- </div>
- <div class="sidebarbutton">Information</div>
- <div class="sidebarcontent" id="sidebarcontent">
- <table width="100%">
- <tr>
- <td>Title:</td>
- <td>Totally Fake Title!</td>
- </tr>
- <tr>
- <td>Designed By:</td>
- <td>A wickedly cool guy!</td>
- </tr>
- <tr>
- <td>Functional POC:</td>
- <td>
- <a href="mailto:evilgenius@fake.net">Evil Genius (At cox.net)</a>
- </td>
- </tr>
- <tr>
- <td>Technical POC:</td>
- <td>
- That same cool guy.
- </td>
- </tr>
- </table>
- </div>
This is the code for the accordion style menu on the right. It is neat and again can be changed as needed. The stylesheets handle the formatting for this.
Now let's go over the javascript code!
- var source;
- var test = null;
- var loc = null;
- var viewpage = null;
- var viewname;
- var reqXML;
- var menuhtml;
- $(document).ready(function() {
- source = window.location;
- test = new String(window.location);
- /* ---------------------------------------- Begin Menu Section ------------------------------------------------------------*/
- // Get and load the menu data
- lnk = L_Menu_BaseUrl + "/Scripts/mainmenu.xml";
- req = new ActiveXObject("Microsoft.XMLHTTP");
- if (req) {
- req.open("GET", lnk, false);
- req.send();
- menuhtml = req.responseText;
- }
- // Can we add site settings links to the menu?
- menuhtml += "<li><a class='hide' href='#'>Site Settings</a>";
- menuhtml += "<ul>";
- $("menu[id*='FeatureMenuTemplate1'] ie\\:menuitem").each(function() {
- menuhtml += "<li><a href=\"javascript:" + $(this).attr('onMenuClick') + "\"; >" + $(this).attr('text') + "</a></li>";
- });
- menuhtml += "</ul></ul>";
- $("#menu").html(menuhtml);
- lnk2 = L_Menu_BaseUrl + "/Scripts/sidemenu.xml";
- req2 = new ActiveXObject("Microsoft.XMLHTTP");
- if (req2) {
- req2.open("GET", lnk2, false);
- req2.send();
- $("#sidemenu").html(req2.responseText);
- }
- $('.sidebarbutton').click(function() {
- $('.sidebarcontent').slideUp('normal');
- if($(this).next().is(':hidden') == true) {
- $(this).next().slideDown('normal');
- }
- });
- $('.sidebarbutton').mouseover(function() {
- $('.sidebarcontent').slideUp('normal');
- if ($(this).next().is(':hidden') == true) {
- $(this).next().slideDown('normal');
- }
- });
- $(".sidebarcontent").hide();
- /*------------------------------------------ End Menu Section -------------------------------------------------------------*/
- /*----------------------------------------- Begin Style Section -----------------------------------------------------------*/
- // Can we determine our useable resolution?
- var h = screen.availHeight;
- var w = screen.availWidth;
- h = h - 350;
- // load a stylesheet based on the resolution
- if (w < 1024) {
- switchstyle("default");
- }
- if (w >= 1024 && w < 1280) {
- switchstyle("mcurves1024");
- }
- if (w >= 1200 && w < 1440) {
- switchstyle("mcurves1200");
- }
- if (w >= 1440 && w < 1600) {
- switchstyle("mcurves1440");
- }
- if (w >= 1600) {
- switchstyle("mcurves1600");
- }
- /*------------------------------------------ End Style Section ------------------------------------------------------------*/
- viewname = "";
- viewname = $("td[id*='onetViewSelector']").text();
- if (viewname == "") { viewname = "All"; }
- try {
- var $table = $("TABLE[Summary*='MCurveData']");
- $table.wrap("<div id='wptable1' style='height:" + h + "px;overflow:scroll;'></div>");
- $("TR.ms-viewheadertr:first", $table).addClass("fixedheader");
- }
- catch (e) { }
- $("#printalert").dialog({
- bgiframe: true,
- autoOpen: false,
- resizable: false,
- modal: true,
- position: ['center', 'center'],
- overlay: { backgroundColor: '#ffdddd', opacity: 0.8 },
- height: 150,
- width: 475,
- closeOnEscape: true,
- title: 'ALERT',
- buttons: { "OK": function() { $(this).dialog("close"); } }
- });
- window.onbeforeprint = function() { beforeprint(); }
- });
- function switchstyle(style) {
- var z, tag;
- for (z=0, tag = document.getElementsByTagName("link"); z < tag.length; z++)
- {
- if ((tag[z].rel.indexOf("stylesheet") != -1) && tag[z].title)
- {
- tag[z].disabled = true;
- if (tag[z].title == style)
- {
- tag[z].disabled = false;
- }
- }
- }
- }
- function sitesettings() {
- var smenua = $("menu[id*='FeatureMenuTemplate1']").attr("id");
- var smenub = $("a[id*='SiteActionsMenu']").attr("id");
- MMU_Open(byid(smenua), MMU_GetMenuFromClientId(smenub), event, false, null, 0);
- }
- function SearchIt() {
- var k = $("#search-text").val();
- var lnk = L_Menu_BaseUrl + "/_layouts/searchresults.aspx?k=" + k;
- window.location = lnk;
- }
- function loadpage(lnk) {
- lnk = L_Menu_BaseUrl + lnk;
- window.location = lnk;
- }
- function beforeprint() {
- $("#printalert").dialog("open");
- }
So there you have the code! As you can see I show how I add the site settings links to the main menu and then I load the accordion menu and setup the "buttons" to allow the accordion functionality to work. This could be modified to just a click event if desired. The next thing that I do here is check the width of the screen to determine which of the loaded stylesheets should be set as active. Remember that I load all of them in the master page. This just determines which one to set.
There are some other things here that I use to make things look better. In list view pages, I try to keep the list views from scrolling off the page to ensure that the footer is always at the bottom and that items do not scroll under it. You will find a try/catch block here that wraps the list view in a scrollable div and also sets the header row to fixed so that it functions similar to locked rows in Excel. This function was for a specific listview and should be changed or removed. I did not take the time to set a fixed height for the content div so I just used some math to sort of guess how tall it should be.
The other function of note that I left in here is the sitesettings function. If you wanted to create a button or some other method to run it, the function opens the real site actions where it is so in my case I chose not to add this.
The styles that I used are carried maybe a bit too far as the toolbar dropdowns are black with red hover like the main menu, but I wanted to show that you could do it and I kind of like it!
Well, that is it for this series of posts! I would really like your comments and feedback!