Skip to content

Instantly share code, notes, and snippets.

@oranj
Created December 19, 2012 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oranj/4339941 to your computer and use it in GitHub Desktop.
Save oranj/4339941 to your computer and use it in GitHub Desktop.
Tabber.js
(function($) {
var default_prefs = {
"active_index" : 0,
"active_class" : 'active'
};
var prefs = {};
var methods = {
"init" : function(_prefs) {
var that = this;
prefs = $.extend(default_prefs, _prefs);
methods.active_index.apply(that, [prefs.active_index]);
$('[href]', this).click(function(e) {
methods.active_index.apply(that, [$(this).index() - 1]);
e.preventDefault();
});
methods.active_index.apply(this, [prefs.active_index]);
},
"active_index" : function(_value) {
if (_value == undefined) {
return prefs.active_index;
}
var that = this;
var active_element = $('[href]:eq('+_value+')', this);
var active_href = $(active_element).attr('href');
console.log(active_element, active_href, this);
$('[href]', this).each(function(e) {
var inactive_href = $(this).attr('href');
if (inactive_href == active_href) { return true; }
$(this).removeClass(prefs.active_class);
$(inactive_href).css('display', 'none');
});
$(active_element).addClass(prefs.active_class);
$(active_href).css('dispay', 'block');
prefs.active_index = _value;
}
};
$.fn.tabber = function(method) {
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || ! method) {
return methods.init.apply(this, arguments);
} else {
$.error('Method ' + method + ' does not exist on jQuery.tabber');
}
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment