jquery navi

时间:2021-01-15 05:39:56
/// <reference path="../global.js" />
/******************************************************
我的活动左则菜单
edit by yezhi
******************************************************/ YDW.SideNavi = (function () { var instance; function constructor() {
return {
accordion: function () {
var $sb = $('#sidebar');
var $sideNavBlock = $('#sidebar > .sideNav_block');
var $content = $('#content');
//隐藏子菜单
function hideSubmenu() {
$('#sidebar > #sideNav_block > div#ye_accordion > div > ul').hide();
}
function removeTitleClass() {
$('#sidebar > #sideNav_block > div#ye_accordion > div > h3 > a').removeClass('current');
}
function removeSubTitleClass() {
$('#sidebar > #sideNav_block > div#ye_accordion > div > ul > li').removeClass('current');
}
//添加标题右则小三角
function addDownArrow() {
$('#sidebar > #sideNav_block > div#ye_accordion > div > h3').each(function () {
var $ul = $(this).next('ul');
if ($ul.length > 0) {
$(this).append('<span class="dropdownArrow"></span>');
}
});
}
//设置菜单的最小高度
function setSitebarHeight() {
$sideNavBlock.css({ 'min-height': $(document).height() });
}
//为不够权限的菜单添加提示
function addTitleForUnauthorized() {
$('#sidebar > #sideNav_block > div#ye_accordion > div.unauthorized_block > ul > li').attr({ 'title': '此功能要升级为API版本方可使用' });
}
//给主体页添加背景,因左则无素切换不同的同容,只有左则内容为活动的菜单才须要添加该类,其它将移除该类
function addContainerBg() {
//$('.admin_master #content').css({ 'background': 'url(../content/images/admin/menu_bg.jpg) left top ' });
$('.admin_master #content').addClass('contentBg');
}
//初始化
function init() {
addContainerBg();
hideSubmenu();
addDownArrow();
addTitleForUnauthorized();
setSitebarHeight();
} init(); //父标题点击
$('#sidebar > #sideNav_block > div#ye_accordion > div > h3 > a').click(function () {
hideSubmenu();
removeTitleClass();
$(this).addClass('current').parent().next('ul').slideToggle();
return false;
});
//子标题点击
$('#sidebar > #sideNav_block > div#ye_accordion > div:not(".unauthorized_block") > ul > li').click(function () {
removeSubTitleClass();
$(this).addClass('current');
setSitebarHeight();
});
}
};
} return {
getInstance: function () {
if (!instance) {
instance = constructor();
}
return instance;
}
}
})(); (function ($) {
$(function () {
YDW.SideNavi.getInstance().accordion();
});
})(jQuery);