1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
;(function ($, window, document, undefined) {
'use strict';
var settings = {
callback: $.noop,
deep_linking: true,
init: false
},
methods = {
init : function (options) {
settings = $.extend({}, settings, options);
return this.each(function () {
if (!settings.init) methods.events();
if (settings.deep_linking) methods.from_hash();
});
},
events : function () {
$(document).on('click.fndtn', '.tabs a', function (e) {
methods.set_tab($(this).parent('dd, li'), e);
});
settings.init = true;
},
set_tab : function ($tab, e) {
var $activeTab = $tab.closest('dl, ul').find('.active'),
target = $tab.children('a').attr("href"),
hasHash = /^#/.test(target),
$content = $(target + 'Tab');
if (hasHash && $content.length > 0) {
// Show tab content
if (e && !settings.deep_linking) e.preventDefault();
$content.closest('.tabs-content').children('li').removeClass('active').hide();
$content.css('display', 'block').addClass('active');
}
// Make active tab
$activeTab.removeClass('active');
$tab.addClass('active');
settings.callback();
},
from_hash : function () {
var hash = window.location.hash,
$tab = $('a[href="' + hash + '"]');
$tab.trigger('click.fndtn');
}
}
$.fn.foundationTabs = 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.foundationTabs');
}
};
}(jQuery, this, this.document));
|