Skip to content

Instantly share code, notes, and snippets.

@amasses
Created March 23, 2010 14:30
Show Gist options
  • Save amasses/341229 to your computer and use it in GitHub Desktop.
Save amasses/341229 to your computer and use it in GitHub Desktop.
(function($) {
$.fn.fabtabs = function() {
var target = $(this);
this.fabtab.init(target);
return this;
};
// Some local storage..
$.fn.fabtab = {
init: function(target) {
$.fn.fabtab.menu = jQuery("a", target);
$.fn.fabtab.show($.fn.fabtab.getInitialTab());
$.fn.fabtab.menu.bind("click", $.fn.fabtab.activate);
},
show: function(target) {
target.addClass("active-tab");
$(target.attr("href")).addClass("active-tab-body").show();
},
hide: function(target) {
$(target).removeClass("active-tab");
$($(target).attr("href")).removeClass("active-tab-body").hide();
},
activate: function(e) {
var element = $(this);
if (element.hasClass("nostop")) return this;
if (!element.hasClass("anchor")) e.preventDefault();
if (element.hasClass("cam-trigger")) play_surfcam();
$.fn.fabtab.show(element);
$.fn.fabtab.menu.not(element).each(function() {
$.fn.fabtab.hide(this);
});
},
getInitialTab: function() {
if ($(".active-tab", $.fn.fabtab.menu).length > 0) {
return $(".active-tab", $.fn.fabtab.menu);
} else {
if (document.location.href.match(/(#\w.+)/)) {
var loc = document.location.href.match(/(#\w.+)/)[1];
var element = $.fn.fabtab.menu.filter("a[href=\#" + loc + "]");
return (element.length > 0) ? element : $.fn.fabtab.menu.first();
} else {
return $.fn.fabtab.menu.first();
}
}
}
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment