Sha256: ebb82561e5348a9e6e861780765c52394b6a8d32c0c236a6290a96bac2b99d59

Contents?: true

Size: 1.61 KB

Versions: 26

Compression:

Stored size: 1.61 KB

Contents

jQuery.fn.tabs = function(){

  var getAnchor = function(str) {
    return /#([a-z][\w.:-]*)$/i.exec(str)[1];
  }

  var windowHash = window.location.hash.substr(1);

  return this.each(function(){
    var selectedLink = null;
    var selectedContainer = null;

    $(this).find('li a').each(function(){
      // Find & hide the container
      var container = $('#' + getAnchor(this.href));
      if (container == []) return;
      container.hide();
      // Setup the click handlers for the tab links
      $(this).click(function(){
        var self = $(this)

        var switchTab = function(){
          if (selectedContainer) selectedContainer.hide();
          if (selectedLink) selectedLink.removeClass('selected');

          selectedContainer = container.show();
          selectedLink = self.addClass('selected');
        }

        if (self.attr('ajax')){
          self.addClass('loading')
          $.ajax({
            url: self.attr('ajax'),
            success: function(data){
              container.html(data)
              self.removeClass('loading')
              self[0].removeAttribute('ajax')
              switchTab()
            },
            failure: function(data){
              alert("An error occured, please reload the page")
            }
          })
        }else{
          switchTab()
        }

        return false;
      });

      if ($(this).hasClass('selected')) $(this).click();
    });

    // Try to match window.location.hash
    $(this).find("li a[href='#" + windowHash + "']").click()
    // Show one tab by default
    if (selectedContainer == null) $($(this).find('li a')[0]).click();
  });
};

Version data entries

26 entries across 26 versions & 4 rubygems

Version Path
gollum-site-0.1.12 lib/gollum-site/layout/javascript/jquery.tabs.js
gollum-site-0.1.11 lib/gollum-site/layout/javascript/jquery.tabs.js
gollum-site-0.1.10 lib/gollum-site/layout/javascript/jquery.tabs.js
gollum-site-0.1.9 lib/gollum-site/layout/javascript/jquery.tabs.js
gollum-site-0.1.8 lib/gollum-site/layout/javascript/jquery.tabs.js
gollum-1.1.1 lib/gollum/frontend/public/javascript/jquery.tabs.js
gollum-site-0.1.7 lib/gollum-site/layout/javascript/jquery.tabs.js
gollum-site-0.1.6 lib/gollum-site/layout/javascript/jquery.tabs.js
gollum-site-0.1.5 lib/gollum-site/layout/javascript/jquery.tabs.js
gollum-site-0.1.4 lib/gollum-site/layout/javascript/jquery.tabs.js
gollum-site-0.1.3 lib/gollum-site/layout/javascript/jquery.tabs.js
gollum-site-0.1.2 lib/gollum-site/layout/javascript/jquery.tabs.js
gollum-site-0.1.1 lib/gollum-site/layout/javascript/jquery.tabs.js
gollum-site-0.1.0 lib/gollum-site/layout/javascript/jquery.tabs.js
gollum-site-0.0.6 lib/gollum-site/layout/javascript/jquery.tabs.js
gollum-site-0.0.5 lib/gollum-site/layout/javascript/jquery.tabs.js
gollum-site-0.0.4 lib/gollum-site/layout/javascript/jquery.tabs.js
gollum-1.1.0 lib/gollum/frontend/public/javascript/jquery.tabs.js
gollum-site-0.0.3 lib/gollum-site/layout/javascript/jquery.tabs.js
gollum-site-0.0.2 lib/gollum-site/layout/javascript/jquery.tabs.js