This is a jQuery plug-in I've created that relies on jQuery UI's tabs plug-in. It adds some framework specific logic when setting up tabs:
- Fixes a bug in jQuery that appears when an id/class contains a "."
- Manages the tab state using a framework specific cookie API (does not use the jQuery cookie plugin)
- Exposes a couple of options for transition behavior
I'd love to get some suggestions on how to improve this, as it'll be used widely in the framework.
(function ($) {
$.fn.dnnTabs = function (options) {
var opts = $.extend({}, $.fn.dnnTabs.defaultOptions, options),
$wrap = this;
$(document).ready(function () {
// Patch for Period in IDs (jQuery bug)
$.ui.tabs.prototype._sanitizeSelector = function (hash) {
// we need this because an id may contain a ":" or a '.'
return hash.replace(/:/g, "\\:").replace(/\./g, "\\\.");
};
var id = 'dnnTabs-' + $wrap.selector.replace('#', '').replace('.', '');
if (opts.selected === -1) {
var tabCookie = dnn.dom.getCookie(id);
if (tabCookie) {
opts.selected = tabCookie;
}
if (opts.selected === -1) {
opts.selected = 0;
}
}
$wrap.tabs({
show: function (event, ui) {
dnn.dom.setCookie(id, ui.index, 1, '/', '', false);
},
selected: opts.selected,
fx: {
opacity: opts.opacity,
duration: opts.duration
}
});
});
return $wrap;
};
$.fn.dnnTabs.defaultOptions = {
opacity: 'toggle',
duration: 'fast',
selected: -1
};
})(jQuery);