Jquery cookies 记忆菜单

1.利用第三方控件:DevExpress.Web.v8.3 Navbar
2.利用jquery cookies 记忆功能克服母板页页面跳转,无法显示刷新前点击的菜单。
要下载 jquery lib  and cookies plugin to use;
a.准备dev web.dll,data.dll,放入GAC。  c:\windows\assembely
b.write to web.config
  <SafeControl Assembly="DevExpress.Web.v8.3, Version=8.3.2.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073" Namespace="DevExpress.Web.ASPxNavBar" TypeName="*" Safe="True" />
  <SafeControl Assembly="DevExpress.Data.v8.3, Version=8.3.2.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073" Namespace="DevExpress.Data" TypeName="*" Safe="True" />
 
c.在v4.master page 写入:
 
<%@ Register Assembly="DevExpress.Web.v8.3, Version=8.3.2.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073" Namespace="DevExpress.Web.ASPxNavBar" TagPrefix="dxnb" %>
 
d.在 <Sharepoint:SPNavigationManager 下的<SharePoint:UIVersionedContent UIVersion="4" runat="server"> <ContentTemplate>
加入:
 
<dxnb:ASPxNavBar id="QuickLaunchNavBar33" runat="server" DataSourceID="QuickLaunchSiteMap" AllowSelectItem="True" EnableAnimation="True">
          <ClientSideEvents Init="function(s, e) {
    ASPxNavBar_Init(s, e)
}" ExpandedChanged="function(s, e) {
    ASPxNavBar_ExpandedChanged(s, e);
}" ItemClick="function(s, e) {
    ASPxNavBar_ItemClick(s,e);
}" HeaderClick="function(s, e) {
   ASPxNavBar_HeaderClick(s,e);
}" />
         </dxnb:ASPxNavBar>
其中引用的js可以放在body最下面:
 
 
 <script type="text/javascript"><!--

    var cookie_nameGroup = 'myicoNavbarGroupIndex'; 
      var cookie_nameItem = 'myicoNavbarItemIndex'; 
      var options = {path: '/', expires: 10};   //定义路径和过期时间
    function ASPxNavBar_Init(s, e) {
   
      var tempNavBarGroupIndex=$.cookie(cookie_nameGroup);   //Request('yourClickGroupIndex',window.location.href)
      var tempNavItemIndex= $.cookie(cookie_nameItem);       //Request('yourClickNavItemIndex',window.location.href)
    
 
 
       //s.CollapseAll();
      if(tempNavBarGroupIndex==''||tempNavBarGroupIndex==null)
      {
      s.CollapseAll();
        return ;
       }
   
            for (var i = 0; i < s.GetGroupCount(); i++)
            {
               if (i == tempNavBarGroupIndex) 
              {
                s.SetActiveGroup(i); 
               // s.GetGroup(i).SetExpanded(true);
               if(tempNavItemIndex!=null||tempNavItemIndex=='')
               {
                s.SetSelectedItem(s.GetGroup(i).GetItem(tempNavItemIndex));
               
                }
               // s.GetGroup(i).GetItem(tempNavItemIndex).SetEnabled(true);
              }
              else
              {
                 s.GetGroup(i).SetExpanded(false);
               }
            }

           
           
  // $.cookie(cookie_nameGroup, null, options);  //清空cookie_name
 //$.cookie(cookie_nameItem, null, options);  //清空cookie_name
       
    }
 

    function  ASPxNavBar_HeaderClick(s,e)
    {
  
   var myNavbarGroupIndex;
  
  $.cookie(cookie_nameGroup, null, options);  //清空cookie_name
  $.cookie(cookie_nameItem, null, options);  //清空cookie_name
  
           if(e.group!=null)
           {  
               myNavbarGroupIndex=e.group.index;
            
                for (var m = 0; m < s.GetGroupCount(); m++)
                {
                   if (m == myNavbarGroupIndex) 
                    { 
                      // var CurrentNavBarItem=s.GetGroup(myNavbarGroupIndex).GetItem(0);
                      
                        //alert(CurrentNavBarItem);
                     
                         $.cookie(cookie_nameGroup,myNavbarGroupIndex, options); //保存
                        
                          //  window.alert(window.document.cookie);
                         //  $.cookie(cookie_nameItem,CurrentNavBarItem, options); //保存

                         
                    }
                 }  
           }  
    
    }
   
 
   
    function  ASPxNavBar_ItemClick(s,e)
    {    
   
 
 
    $.cookie(cookie_nameGroup, null, options);  //清空cookie_name
   $.cookie(cookie_nameItem, null, options);  //清空cookie_name

           var myNavbarGroupIndex;
           var myNavbarItemIndex;
           if(e.item!=null)
           {  
               myNavbarGroupIndex=e.item.group.index;
               myNavbarItemIndex=e.item.index;
              
            
                for (var m = 0; m < s.GetGroupCount(); m++)
                {
                   if (m == myNavbarGroupIndex) 
                    { 
                   
                       $.cookie(cookie_nameGroup,myNavbarGroupIndex, options); //保存
                       $.cookie(cookie_nameItem,myNavbarItemIndex, options); //保存
                   
                 
                    }
                 }  
           }  
    
         
         
       
    }
    function ASPxNavBar_ExpandedChanged(s, e)
     {
        if (e.group.GetExpanded() == true)
        {
           
         
                 for(var i = 0; i < s.GetGroupCount(); i++)
                 {
                  if(i == e.group.index) continue;
                s.GetGroup(i).SetExpanded(false);
               }
          
        }
       
       
   

    }
   
 
// --></script>
 
作者:johnny 出处:http://www.cnblogs.com/sunjunlin 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
原文地址:https://www.cnblogs.com/sunjunlin/p/1821980.html