hjg
2024-07-09 30304784e82d4bba24121328da8eb8490aec4f4f
提交 | 用户 | 时间
58d006 1 jQuery(document).ready(function($) {
A 2     /*metro menu*/
3     var root=createmenu();
4     activemenu(root);
5 });
6 function createmenu()
7 {/*metro menu*/
8     
9     var urroot=jQuery('#page-sidebar-menu');
10     var menus=jQuery.cookie('metro-menu');
11     if(menus==null)
12     {
13         urroot=ajaxcreate();
14         if(urroot!=null)
15             jQuery.cookie('metro-menu',urroot.html());
16     }else
17     {
18         urroot.html(menus);
19     }
20     return urroot;
21 }
22 function activemenu(urroot)
23 {
24     var url=window.location.pathname;
25     var active_a=urroot.find('a[href="'+url+'"]');
26     if(active_a==null)
27         return;
28     active_a.parent('li').addClass('active');
29     active_a.parent('li').parents('li').addClass('open');
30     active_a.parent('li').parents('li').child('span.arrow').addClass('open');
31 }
32 function ajaxcreate()
33 {/*metro menu*/
34     var urroot=jQuery('#page-sidebar-menu');
35     jQuery.post('/mandi/smenus.loginmenu.action', {}, function(data, textStatus, xhr) {
36         if(data==null)
37             return;
38         var stack=[];
39         jQuery.each(data.menus, function(index, val) {
40             var li_o=jQuery('<li></li>');
41             if(index==0)
42                 li_o.addClass('start');
43             var temp=null;
44             while(stack.length>0)
45             {
46                 var ele=stack[0];
47                 if(ele==null||(!ele.is('ul')&&!ele.is('UL')))
48                 {
49                     stack.shift();
50                     continue;
51                 }
52                 var lft=parseInt(ele.attr('lft'));
53                 var rgt=parseInt(ele.attr('rgt'));
54                 if(parseInt(val.lft)<lft||parseInt(val.rgt)>rgt)
55                 {
56                     stack.shift();
57                     continue;
58                 }
59                 temp=ele;
60                 break;
61             }
62             if(temp==null)
63                 temp=urroot;
64             temp.append(li_o);
65             var a_o=jQuer('<a></a>');
66             a_o.appendTo(li_o);
67             a_o.attr('href',val.url);
68             a_o.attr('rev',val.id);
69             a_o.text(val.title);
70             var span_o=jQuery('<span></span>');
71             span_o.addClass(val.icon);
72             span_o.appendTo(li_o);
73             if(val.rgt-val.lft>1)
74             {
75                 var biaoji=jQuery('<span class="arrow"></span>');
76                 biaoji.appendTo(li_o);
77                 var ppul=jQuery('<ul></ul>');
78                 ppul.appendTo(li_o);
79                 ppul.addClass('sub-menu');
80                 ppul.attr('role','menu');
81                 ppul.attr('lft',val.lft);
82                 ppul.attr('rgt',val.rgt);
83                 stack.push(ppul);
84             }
85         });
86     },'json');
87     return urroot;
88 }