-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.mk_tab 2.js
126 lines (104 loc) · 3.35 KB
/
jquery.mk_tab 2.js
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
;/* $.mk_tab
****************************************************************************
/////////////////////////////////////////////////////////////////////////
@varsion : 1.0
@requiers : jquery.js, jquery.mk_cookie.js
@author : http://www.makinokobo.com - oosugi
@last update : 2010.10.30 - oosugi
@Copyright : Copyright (c) 2010 Skill Partners Inc. All Rights Reserved.
/////////////////////////////////////////////////////////////////////////
$('SELECTOR').mk_tab();
=========================================================================
タブメニュー表示プラグイン。
表示動作を起こしたい要素に対して実行する。
-------------------------------------------------------------------------
#Config
-------------------------------------------------------------------------
$('SELECTOR').mk_tab({
navi: '.mk_tabNavi',//タブナビゲーションに対して指定する
body: '.mk_tabBody',//タブコンテンツに対して指定する
currentClass: 'current',//currentのclass名
speed: 200,
cookie: true,
fixedHeight: true
});
****************************************************************************/
(function(){
/* tab setting
=========================================== */
$(function(){
$('#homeMainMenu').mk_tab({
navi: 'ul.tabNavi',
body: '.mainMenuSection'
});
});
$.fn.mk_tab = function(config){
config = $.extend({},$.mk_tab.defaults,config);
var $containers = $(this);
$containers.find(config.body).hide();
return this.each(function(){
var $container = $(this);
var $navi = $(this).find(config.navi);
var $naviItems = $navi.find('a');
var $bodys = $(this).find(config.body);
// fixed height
if(config.fixedHeight){
$bodys.wrapAll($('<div/>',{ 'class': 'mk_tabViewport'}));
var $viewport = $container.find('.mk_tabViewport');
var maxH = 0;
$bodys.each(function(){
maxH = Math.max(maxH, $(this).outerHeight());
});
if(navigator.userAgent.indexOf("MSIE 6") != -1){
$viewport.height(maxH);
}else{
$viewport.css({ minHeight: maxH+'px' });
}
}
var num = 0;
var currentNum = 0;
// cookie read
if(config.cookie){
var containerID = $containers.index($container);
var cookieName = $(this).attr('class')+containerID;
var cookieValue = $.mk_cookie.read(cookieName);
if(cookieValue){
num = cookieValue;
currentNum = cookieValue;
}
}
// begging
$bodys.eq(num).show();
$naviItems.removeClass(config.currentClass).css({cursor: 'pointer'})
.eq(num).addClass(config.currentClass).css({cursor: 'default'});
// action
$naviItems
.unbind('click.mk_smoothScroll')
.bind('mk_tab',function(){
currentNum = num;
$naviItems.removeClass(config.currentClass).css({cursor: 'pointer'})
.eq(num).addClass(config.currentClass).css({cursor: 'default'});
$bodys.hide().eq(num).fadeIn(config.speed);
// cookie create
if(config.cookie) $.mk_cookie.create({ name: cookieName, value: num});
return false;
})
.click(function(){
num = $naviItems.index(this);
if(num!=currentNum) $(this).trigger('mk_tab');
return false;
});
});
};
$.mk_tab = {
version: 1.0,
defaults: {
navi: '.mk_tabNavi',
body: '.mk_tabBody',
currentClass: 'current',
speed: 200,
cookie: true,
fixedHeight: true
}
};
})(jQuery);