2012-04-16 26 views
0

在我的function.js文件裏面我有兩個函數:第一個使用ajax加載我的頁面。另一個用於在我的主頁上縮小選項卡式內容。最初,這兩個功能都起作用。但是,當我單擊任何一個菜單欄鏈接,然後單擊主頁鏈接返回到主頁時,我的選項卡區域不再起作用。我有一種感覺,那就是在第一次加載index.html時,僅僅調用organictabs()函數。我怎樣才能改變這個,以便在每次加載新頁面時調用organictabs()?如何在點擊導航菜單欄鏈接後使此功能生效?

// remap jQuery to $ 
(function($){})(window.jQuery); 


/* trigger when page is ready */ 
$(document).ready(function(){ 
    initialize(); 

}); 

function initialize() { 
    //Click on nav to load external content through AJAX 
    $('#topnav a, #bottomnav a').not('#bottomnav #fbcallus a').click(function(e){ 

     e.preventDefault(); 

     $('#pages').load(e.target.href + ' #loadcontent'); //pages finished loading 
    }); //clicked on nav 
    //handle AJAX for left nav 
$(function() { 
     $("#tabedarea").organicTabs(); 
    }); 


} 



    //Click on nav to load external content through AJAX 
    // $('#topnav a').click(function(e){ 
    // e.preventDefault(); 
    // $('#pages').load(e.target.href + ' #loadcontent'); //pages finished loading 
    // }); //clicked on nav 



(function($) { 

    $.organicTabs = function(el, options) { 

     var base = this; 
     base.$el = $(el); 
     base.$navtabs = base.$el.find(".navtabs"); 

     base.init = function() { 

      base.options = $.extend({},$.organicTabs.defaultOptions, options); 

      // Accessible hiding fix 
      $(".hidetabs").css({ 
       "position": "relative", 
       "top": 0, 
       "left": 0, 
       "display": "none" 
      }); 

      base.$navtabs.delegate("li > a", "click", function() { 

       // Figure out current list via CSS class 
       var curList = base.$el.find("a.current").attr("href").substring(1), 

       // List moving to 
        $newList = $(this), 

       // Figure out ID of new list 
        listID = $newList.attr("href").substring(1), 

       // Set outer wrapper height to (static) height of current inner list 
        $allListWrap = base.$el.find(".list-wrap"), 
        curListHeight = $allListWrap.height(); 
       $allListWrap.height(curListHeight); 

       if ((listID != curList) && (base.$el.find(":animated").length == 0)) { 

        // Fade out current list 
        base.$el.find("#"+curList).fadeOut(base.options.speed, function() { 

         // Fade in new list on callback 
         base.$el.find("#"+listID).fadeIn(base.options.speed); 

         // Adjust outer wrapper to fit new list snuggly 
         //var newHeight = base.$el.find("#"+listID).height(); 
         //$allListWrap.animate({ 
         // height: newHeight 
         //}); 

         // Remove highlighting - Add to just-clicked tab 
         base.$el.find(".navtabs li a").removeClass("current"); 
         $newList.addClass("current"); 

        }); 

       } 

       // Don't behave like a regular link 
       // Stop propegation and bubbling 
       return false; 
      }); 

     }; 
     base.init(); 
    }; 

    $.organicTabs.defaultOptions = { 
     "speed": 300 
    }; 

    $.fn.organicTabs = function(options) { 
     return this.each(function() { 
      (new $.organicTabs(this, options)); 
     }); 
    }; 

})(jQuery); 

回答

1

利用了jQuery負荷全部功能都可以解決你的問題,我相信:

function initialize() { 
//Click on nav to load external content through AJAX 
$('#topnav a, #bottomnav a').not('#bottomnav #fbcallus a').click(function(e){ 

    e.preventDefault(); 

    $('#pages').load(e.target.href + ' #loadcontent', function() { $("#tabedarea").organicTabs(); }); //pages finished loading 
}); 
} 
相關問題