Skip to content

Commit 19cdc62

Browse files
committed
Code refactoring
1 parent 6314c74 commit 19cdc62

File tree

3 files changed

+27
-29
lines changed

3 files changed

+27
-29
lines changed

demo/javascripts/vendor/jquery.tabslet.min.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@
3737
3838
*/
3939

40-
!function($,window,undefined){"use strict";$.fn.tabslet=function(options){var defaults={mouseevent:"click",attribute:"href",animation:!1,autorotate:!1,deeplinking:!1,pauseonhover:!0,delay:2e3,active:1,container:!1,controls:{prev:".prev",next:".next"}},options=$.extend(defaults,options);return this.each(function(){function deep_link(){var t=[];elements.find("a").each(function(){t.push($(this).attr(options.attribute))});var e=$.inArray(location.hash,t);return e>-1?e+1:$this.data("active")||options.active}var $this=$(this),_cache_li=[],_cache_div=[],_container=options.container?$(options.container):$this,_tabs=_container.find("> div");_tabs.each(function(){_cache_div.push($(this).css("display"))});var elements=$this.find("> ul li"),i=options.active-1;if(!$this.data("tabslet-init")){$this.data("tabslet-init",!0),options.mouseevent=$this.data("mouseevent")||options.mouseevent,options.attribute=$this.data("attribute")||options.attribute,options.animation=$this.data("animation")||options.animation,options.autorotate=$this.data("autorotate")||options.autorotate,options.deeplinking=$this.data("deeplinking")||options.deeplinking,options.pauseonhover=$this.data("pauseonhover")||options.pauseonhover,options.delay=$this.data("delay")||options.delay,options.active=options.deeplinking?deep_link():$this.data("active")||options.active,options.container=$this.data("container")||options.container,_tabs.hide(),options.active&&(_tabs.eq(options.active-1).show(),elements.eq(options.active-1).addClass("active"));var fn=eval(function(){$(this).trigger("_before"),elements.removeClass("active"),$(this).addClass("active"),_tabs.hide(),i=elements.index($(this));var t=$(this).find("a").attr(options.attribute);return options.deeplinking&&(location.hash=t),options.animation?_container.find(t).animate({opacity:"show"},"slow",function(){$(this).trigger("_after")}):(_container.find(t).show(),$(this).trigger("_after")),!1}),init=eval("elements."+options.mouseevent+"(fn)"),t,forward=function(){i=++i%elements.length,"hover"==options.mouseevent?elements.eq(i).trigger("mouseover"):elements.eq(i).click(),options.autorotate&&(clearTimeout(t),t=setTimeout(forward,options.delay),$this.mouseover(function(){options.pauseonhover&&clearTimeout(t)}))};options.autorotate&&(t=setTimeout(forward,options.delay),$this.hover(function(){options.pauseonhover&&clearTimeout(t)},function(){t=setTimeout(forward,options.delay)}),options.pauseonhover&&$this.on("mouseleave",function(){clearTimeout(t),t=setTimeout(forward,options.delay)}));var move=function(t){"forward"==t&&(i=++i%elements.length),"backward"==t&&(i=--i%elements.length),elements.eq(i).click()};$this.find(options.controls.next).click(function(){move("forward")}),$this.find(options.controls.prev).click(function(){move("backward")}),$this.on("destroy",function(){$(this).removeData().find("> ul li").each(function(t){$(this).removeClass("active")}),_tabs.each(function(t){$(this).removeAttr("style").css("display",_cache_div[t])})})}})},$(document).ready(function(){$('[data-toggle="tabslet"]').tabslet()})}(jQuery);
40+
!function($,window,undefined){"use strict";$.fn.tabslet=function(options){var defaults={mouseevent:"click",attribute:"href",animation:!1,autorotate:!1,deeplinking:!1,pauseonhover:!0,delay:2e3,active:1,container:!1,controls:{prev:".prev",next:".next"}},options=$.extend(defaults,options);return this.each(function(){function deep_link(){var t=[];elements.find("a").each(function(){t.push($(this).attr($this.opts.attribute))});var e=$.inArray(location.hash,t);return e>-1?e+1:$this.data("active")||options.active}var $this=$(this),_cache_li=[],_cache_div=[],_container=options.container?$(options.container):$this,_tabs=_container.find("> div");_tabs.each(function(){_cache_div.push($(this).css("display"))});var elements=$this.find("> ul li"),i=options.active-1;if(!$this.data("tabslet-init")){$this.data("tabslet-init",!0),$this.opts=[],$.map(["mouseevent","attribute","animation","autorotate","deeplinking","deeplinking","pauseonhover","delay","container"],function(t,e){$this.opts[t]=$this.data(t)||options[t]}),$this.opts.active=$this.opts.deeplinking?deep_link():$this.data("active")||options.active,_tabs.hide(),$this.opts.active&&(_tabs.eq($this.opts.active-1).show(),elements.eq($this.opts.active-1).addClass("active"));var fn=eval(function(){$(this).trigger("_before"),elements.removeClass("active"),$(this).addClass("active"),_tabs.hide(),i=elements.index($(this));var t=$(this).find("a").attr($this.opts.attribute);return $this.opts.deeplinking&&(location.hash=t),$this.opts.animation?_container.find(t).animate({opacity:"show"},"slow",function(){$(this).trigger("_after")}):(_container.find(t).show(),$(this).trigger("_after")),!1}),init=eval("elements."+$this.opts.mouseevent+"(fn)"),t,forward=function(){i=++i%elements.length,"hover"==$this.opts.mouseevent?elements.eq(i).trigger("mouseover"):elements.eq(i).click(),$this.opts.autorotate&&(clearTimeout(t),t=setTimeout(forward,$this.opts.delay),$this.mouseover(function(){$this.opts.pauseonhover&&clearTimeout(t)}))};$this.opts.autorotate&&(t=setTimeout(forward,$this.opts.delay),$this.hover(function(){$this.opts.pauseonhover&&clearTimeout(t)},function(){t=setTimeout(forward,$this.opts.delay)}),$this.opts.pauseonhover&&$this.on("mouseleave",function(){clearTimeout(t),t=setTimeout(forward,$this.opts.delay)}));var move=function(t){"forward"==t&&(i=++i%elements.length),"backward"==t&&(i=--i%elements.length),elements.eq(i).click()};$this.find(options.controls.next).click(function(){move("forward")}),$this.find(options.controls.prev).click(function(){move("backward")}),$this.on("destroy",function(){$(this).removeData().find("> ul li").each(function(t){$(this).removeClass("active")}),_tabs.each(function(t){$(this).removeAttr("style").css("display",_cache_div[t])})})}})},$(document).ready(function(){$('[data-toggle="tabslet"]').tabslet()})}(jQuery);

jquery.tabslet.js

+25-27
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,19 @@
7676

7777
$this.data( 'tabslet-init', true );
7878

79-
// Ungly overwrite
80-
options.mouseevent = $this.data('mouseevent') || options.mouseevent;
81-
options.attribute = $this.data('attribute') || options.attribute;
82-
options.animation = $this.data('animation') || options.animation;
83-
options.autorotate = $this.data('autorotate') || options.autorotate;
84-
options.deeplinking = $this.data('deeplinking') || options.deeplinking;
85-
options.pauseonhover = $this.data('pauseonhover') || options.pauseonhover;
86-
options.delay = $this.data('delay') || options.delay;
87-
options.active = options.deeplinking ? deep_link() : ( $this.data('active') || options.active )
88-
options.container = $this.data('container') || options.container;
79+
$this.opts = [];
80+
81+
$.map( ['mouseevent', 'attribute', 'animation', 'autorotate', 'deeplinking', 'deeplinking', 'pauseonhover', 'delay', 'container'], function( val, i ) {
82+
$this.opts[val] = $this.data(val) || options[val];
83+
});
84+
85+
$this.opts['active'] = $this.opts.deeplinking ? deep_link() : ( $this.data('active') || options.active )
8986

9087
_tabs.hide();
91-
if ( options.active ) {
92-
_tabs.eq(options.active - 1).show();
93-
elements.eq(options.active - 1).addClass('active');
88+
89+
if ( $this.opts.active ) {
90+
_tabs.eq($this.opts.active - 1).show();
91+
elements.eq($this.opts.active - 1).addClass('active');
9492
}
9593

9694
var fn = eval(
@@ -105,11 +103,11 @@
105103

106104
i = elements.index($(this));
107105

108-
var currentTab = $(this).find('a').attr(options.attribute);
106+
var currentTab = $(this).find('a').attr($this.opts.attribute);
109107

110-
if (options.deeplinking) location.hash = currentTab;
108+
if ($this.opts.deeplinking) location.hash = currentTab;
111109

112-
if (options.animation) {
110+
if ($this.opts.animation) {
113111

114112
_container.find(currentTab).animate( { opacity: 'show' }, 'slow', function() {
115113
$(this).trigger('_after');
@@ -128,7 +126,7 @@
128126

129127
);
130128

131-
var init = eval("elements." + options.mouseevent + "(fn)");
129+
var init = eval("elements." + $this.opts.mouseevent + "(fn)");
132130

133131
init;
134132

@@ -138,47 +136,47 @@
138136

139137
i = ++i % elements.length; // wrap around
140138

141-
options.mouseevent == 'hover' ? elements.eq(i).trigger('mouseover') : elements.eq(i).click();
139+
$this.opts.mouseevent == 'hover' ? elements.eq(i).trigger('mouseover') : elements.eq(i).click();
142140

143-
if (options.autorotate) {
141+
if ($this.opts.autorotate) {
144142

145143
clearTimeout(t);
146144

147-
t = setTimeout(forward, options.delay);
145+
t = setTimeout(forward, $this.opts.delay);
148146

149147
$this.mouseover(function () {
150148

151-
if (options.pauseonhover) clearTimeout(t);
149+
if ($this.opts.pauseonhover) clearTimeout(t);
152150

153151
});
154152

155153
}
156154

157155
}
158156

159-
if (options.autorotate) {
157+
if ($this.opts.autorotate) {
160158

161-
t = setTimeout(forward, options.delay);
159+
t = setTimeout(forward, $this.opts.delay);
162160

163161
$this.hover(function() {
164162

165-
if (options.pauseonhover) clearTimeout(t);
163+
if ($this.opts.pauseonhover) clearTimeout(t);
166164

167165
}, function() {
168166

169-
t = setTimeout(forward, options.delay);
167+
t = setTimeout(forward, $this.opts.delay);
170168

171169
});
172170

173-
if (options.pauseonhover) $this.on( "mouseleave", function() { clearTimeout(t); t = setTimeout(forward, options.delay); });
171+
if ($this.opts.pauseonhover) $this.on( "mouseleave", function() { clearTimeout(t); t = setTimeout(forward, $this.opts.delay); });
174172

175173
}
176174

177175
function deep_link() {
178176

179177
var ids = [];
180178

181-
elements.find('a').each(function() { ids.push($(this).attr(options.attribute)); });
179+
elements.find('a').each(function() { ids.push($(this).attr($this.opts.attribute)); });
182180

183181
var index = $.inArray(location.hash, ids)
184182

jquery.tabslet.min.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@
3737
3838
*/
3939

40-
!function($,window,undefined){"use strict";$.fn.tabslet=function(options){var defaults={mouseevent:"click",attribute:"href",animation:!1,autorotate:!1,deeplinking:!1,pauseonhover:!0,delay:2e3,active:1,container:!1,controls:{prev:".prev",next:".next"}},options=$.extend(defaults,options);return this.each(function(){function deep_link(){var t=[];elements.find("a").each(function(){t.push($(this).attr(options.attribute))});var e=$.inArray(location.hash,t);return e>-1?e+1:$this.data("active")||options.active}var $this=$(this),_cache_li=[],_cache_div=[],_container=options.container?$(options.container):$this,_tabs=_container.find("> div");_tabs.each(function(){_cache_div.push($(this).css("display"))});var elements=$this.find("> ul li"),i=options.active-1;if(!$this.data("tabslet-init")){$this.data("tabslet-init",!0),options.mouseevent=$this.data("mouseevent")||options.mouseevent,options.attribute=$this.data("attribute")||options.attribute,options.animation=$this.data("animation")||options.animation,options.autorotate=$this.data("autorotate")||options.autorotate,options.deeplinking=$this.data("deeplinking")||options.deeplinking,options.pauseonhover=$this.data("pauseonhover")||options.pauseonhover,options.delay=$this.data("delay")||options.delay,options.active=options.deeplinking?deep_link():$this.data("active")||options.active,options.container=$this.data("container")||options.container,_tabs.hide(),options.active&&(_tabs.eq(options.active-1).show(),elements.eq(options.active-1).addClass("active"));var fn=eval(function(){$(this).trigger("_before"),elements.removeClass("active"),$(this).addClass("active"),_tabs.hide(),i=elements.index($(this));var t=$(this).find("a").attr(options.attribute);return options.deeplinking&&(location.hash=t),options.animation?_container.find(t).animate({opacity:"show"},"slow",function(){$(this).trigger("_after")}):(_container.find(t).show(),$(this).trigger("_after")),!1}),init=eval("elements."+options.mouseevent+"(fn)"),t,forward=function(){i=++i%elements.length,"hover"==options.mouseevent?elements.eq(i).trigger("mouseover"):elements.eq(i).click(),options.autorotate&&(clearTimeout(t),t=setTimeout(forward,options.delay),$this.mouseover(function(){options.pauseonhover&&clearTimeout(t)}))};options.autorotate&&(t=setTimeout(forward,options.delay),$this.hover(function(){options.pauseonhover&&clearTimeout(t)},function(){t=setTimeout(forward,options.delay)}),options.pauseonhover&&$this.on("mouseleave",function(){clearTimeout(t),t=setTimeout(forward,options.delay)}));var move=function(t){"forward"==t&&(i=++i%elements.length),"backward"==t&&(i=--i%elements.length),elements.eq(i).click()};$this.find(options.controls.next).click(function(){move("forward")}),$this.find(options.controls.prev).click(function(){move("backward")}),$this.on("destroy",function(){$(this).removeData().find("> ul li").each(function(t){$(this).removeClass("active")}),_tabs.each(function(t){$(this).removeAttr("style").css("display",_cache_div[t])})})}})},$(document).ready(function(){$('[data-toggle="tabslet"]').tabslet()})}(jQuery);
40+
!function($,window,undefined){"use strict";$.fn.tabslet=function(options){var defaults={mouseevent:"click",attribute:"href",animation:!1,autorotate:!1,deeplinking:!1,pauseonhover:!0,delay:2e3,active:1,container:!1,controls:{prev:".prev",next:".next"}},options=$.extend(defaults,options);return this.each(function(){function deep_link(){var t=[];elements.find("a").each(function(){t.push($(this).attr($this.opts.attribute))});var e=$.inArray(location.hash,t);return e>-1?e+1:$this.data("active")||options.active}var $this=$(this),_cache_li=[],_cache_div=[],_container=options.container?$(options.container):$this,_tabs=_container.find("> div");_tabs.each(function(){_cache_div.push($(this).css("display"))});var elements=$this.find("> ul li"),i=options.active-1;if(!$this.data("tabslet-init")){$this.data("tabslet-init",!0),$this.opts=[],$.map(["mouseevent","attribute","animation","autorotate","deeplinking","deeplinking","pauseonhover","delay","container"],function(t,e){$this.opts[t]=$this.data(t)||options[t]}),$this.opts.active=$this.opts.deeplinking?deep_link():$this.data("active")||options.active,_tabs.hide(),$this.opts.active&&(_tabs.eq($this.opts.active-1).show(),elements.eq($this.opts.active-1).addClass("active"));var fn=eval(function(){$(this).trigger("_before"),elements.removeClass("active"),$(this).addClass("active"),_tabs.hide(),i=elements.index($(this));var t=$(this).find("a").attr($this.opts.attribute);return $this.opts.deeplinking&&(location.hash=t),$this.opts.animation?_container.find(t).animate({opacity:"show"},"slow",function(){$(this).trigger("_after")}):(_container.find(t).show(),$(this).trigger("_after")),!1}),init=eval("elements."+$this.opts.mouseevent+"(fn)"),t,forward=function(){i=++i%elements.length,"hover"==$this.opts.mouseevent?elements.eq(i).trigger("mouseover"):elements.eq(i).click(),$this.opts.autorotate&&(clearTimeout(t),t=setTimeout(forward,$this.opts.delay),$this.mouseover(function(){$this.opts.pauseonhover&&clearTimeout(t)}))};$this.opts.autorotate&&(t=setTimeout(forward,$this.opts.delay),$this.hover(function(){$this.opts.pauseonhover&&clearTimeout(t)},function(){t=setTimeout(forward,$this.opts.delay)}),$this.opts.pauseonhover&&$this.on("mouseleave",function(){clearTimeout(t),t=setTimeout(forward,$this.opts.delay)}));var move=function(t){"forward"==t&&(i=++i%elements.length),"backward"==t&&(i=--i%elements.length),elements.eq(i).click()};$this.find(options.controls.next).click(function(){move("forward")}),$this.find(options.controls.prev).click(function(){move("backward")}),$this.on("destroy",function(){$(this).removeData().find("> ul li").each(function(t){$(this).removeClass("active")}),_tabs.each(function(t){$(this).removeAttr("style").css("display",_cache_div[t])})})}})},$(document).ready(function(){$('[data-toggle="tabslet"]').tabslet()})}(jQuery);

0 commit comments

Comments
 (0)