處理EasyUI中tab的切換問題以及accordion左側導航欄的代碼實現


 //左側導航菜單
   function leftMenus()
   {
         //$(".easyui-accordion").empty();
         $.each(_menus.menus, function(i, n) {
              $(".easyui-accordion").accordion('add',
                {
                   title: n.text,
                   content:moduleIndex(n.menus),
                   iconCls:'icon-search'
             });
        });
        $(".easyui-accordion").accordion();
        liClick();
   }
   
   function liClick()
   {
       $('.easyui-accordion li a').click(function()
        {
            var tabTitle = $(this).text();
                /**
          *處理tab切換問題:將"href"修改成"way"。
          */
            var url = $(this).attr("way");
            addTab(tabTitle,url);//打開tab選項卡
            $('.easyui-accordion li div').removeClass("selected");
            $(this).parent().addClass("selected");
       }).hover(function()
       {
            $(this).parent().addClass("hover");
       },function()
       {
            $(this).parent().removeClass("hover");
       });
   }
   
   function moduleIndex(menusData)
   {
      var text="";
      text += '<ul>';
      $.each(menusData,function(j,o)
      {
      /**
      *處理tab切換問題:將‘a’標簽中的"href"修改成"way"。
      */
          text += '<li><div ><a target="mainFrame" way="'+o.attributes+'" >' + o.text + '</a></div></li> ';
      });
      text += '</ul>';
      return text;
   }
   
   function addTab(subtitle,url)
   {
        if(!$('#tabs').tabs('exists',subtitle))
        {
            $('#tabs').tabs('add',{
                title:subtitle,
                content:createFrame(url),
                closable:false,
                width:$('#mainPanle').width()-10,
                height:$('#mainPanle').height()-26,
                iconCls:'icon-search'
            });
        }
        else
        {
            $('#tabs').tabs('select',subtitle);
        }
        tabClose();
    }

    function createFrame(url)
    {
        var s = '<iframe name="mainFrame" scrolling="auto" frameborder="0"  src="'+url+'" style="width:100%;height:100%;"></iframe>';
        return s;
    }
    
        function tabClose()
    {
        /*雙擊關閉TAB選項卡*/
        $(".tabs-inner").dblclick(function(){
            var subtitle = $(this).children("span").text();
            $('#tabs').tabs('close',subtitle);
        })
        
         //綁定右鍵菜單
        $(".tabs-inner").bind('contextmenu',function(e){
            $('#mm').menu('show', {
                left: e.pageX,
                top: e.pageY,
            });

            var subtitle =$(this).children("span").text();
            $('#mm').data("currtab",subtitle);
            
            return false;
        });
     }
    
    //綁定右鍵菜單事件
    function tabCloseEven()
    {
        //關閉當前
        $('#mm-tabclose').click(function(){
            var currtab_title = $('#mm').data("currtab");
            $('#tabs').tabs('close',currtab_title);
        })
        //全部關閉
        $('#mm-tabcloseall').click(function(){
            $('.tabs-inner span').each(function(i,n){
                var t = $(n).text();
                $('#tabs').tabs('close',t);
            });    
        });
        //關閉除當前之外的TAB
        $('#mm-tabcloseother').click(function(){
            var currtab_title = $('#mm').data("currtab");
            $('.tabs-inner span').each(function(i,n){
                var t = $(n).text();
                if(t!=currtab_title)
                    $('#tabs').tabs('close',t);
            });    
        });
        //關閉當前右側的TAB
        $('#mm-tabcloseright').click(function(){
            var nextall = $('.tabs-selected').nextAll();
            if(nextall.length==0){
                //msgShow('系統提示','后邊沒有啦~~','error');
                alert('后邊沒有啦~~');
                return false;
            }
            nextall.each(function(i,n){
                var t=$('a:eq(0) span',$(n)).text();
                $('#tabs').tabs('close',t);
            });
            return false;
        });
        //關閉當前左側的TAB
        $('#mm-tabcloseleft').click(function(){
            var prevall = $('.tabs-selected').prevAll();
            if(prevall.length==0){
                alert('到頭了,前邊沒有啦~~');
                return false;
            }
            prevall.each(function(i,n){
                var t=$('a:eq(0) span',$(n)).text();
                $('#tabs').tabs('close',t);
            });
            return false;
        });

        //退出
        $("#mm-exit").click(function(){
            $('#mm').menu('hide');
        })
    }
    
    /*進度條*/
    function progress(){
            var win = $.messager.progress({
                title:'請稍等',
                msg:'正在加載數據...'
            });
            setTimeout(function(){
                $.messager.progress('close');
            },2000)
        }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM