jquery navi

/// <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);
相關文章
相關標籤/搜索