diff --git a/demo/javascripts/vendor/jquery.tabslet.min.js b/demo/javascripts/vendor/jquery.tabslet.min.js index 9308436..cea95b5 100644 --- a/demo/javascripts/vendor/jquery.tabslet.min.js +++ b/demo/javascripts/vendor/jquery.tabslet.min.js @@ -37,4 +37,5 @@ */ -!function($,window,undefined){"use strict";$.fn.tabslet=function(options){var defaults={mouseevent:"click",activeclass:"active",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","activeclass","attribute","animation","autorotate","deeplinking","pauseonhover","delay","container"],function(t){$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(options.activeclass));var fn=eval(function(t,e){var s=e?elements.find("a["+$this.opts.attribute+'="'+e+'"]').parent():$(this);s.trigger("_before"),elements.removeClass(options.activeclass),s.addClass(options.activeclass),_tabs.hide(),i=elements.index(s);var o=e||s.find("a").attr($this.opts.attribute);return $this.opts.deeplinking&&(location.hash=o),$this.opts.animation?_container.find(o).animate({opacity:"show"},"slow",function(){s.trigger("_after")}):(_container.find(o).show(),s.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("show",function(t,e){fn(t,e)}),$this.on("next",function(){move("forward")}),$this.on("prev",function(){move("backward")}),$this.on("destroy",function(){$(this).removeData().find("> ul li").each(function(){$(this).removeClass(options.activeclass)}),_tabs.each(function(t){$(this).removeAttr("style").css("display",_cache_div[t])})})}})},$(document).ready(function(){$('[data-toggle="tabslet"]').tabslet()})}(jQuery); + +(function($,window,undefined){"use strict";$.fn.tabslet=function(options){var defaults={mouseevent:"click",activeclass:"active",attribute:"href",animation:false,autorotate:false,deeplinking:false,pauseonhover:true,delay:2e3,active:1,container:false,controls:{prev:".prev",next:".next"}};var options=$.extend(defaults,options);return this.each(function(){var $this=$(this);if($this.data("tabslet-init"))return;var _cache_li=[];var _cache_div=[];var _container=options.container?$(options.container):$this;var _tabs=_container.find("> div");_tabs.each(function(){_cache_div.push($(this).css("display"))});var elements=$this.find("> ul > li"),i=options.active-1;$this.data("tabslet-init",true);$this.opts=[];$.map(["mouseevent","activeclass","attribute","animation","autorotate","deeplinking","pauseonhover","delay","container"],function(val,i){$this.opts[val]=$this.data(val)||options[val]});$this.opts["active"]=$this.opts.deeplinking?deep_link():$this.data("active")||options.active;_tabs.hide();if($this.opts.active){_tabs.eq($this.opts.active-1).show();elements.eq($this.opts.active-1).addClass(options.activeclass)}var fn=eval(function(e,tab){var _this=tab?elements.find("a["+$this.opts.attribute+'="'+tab+'"]').parent():$(this);_this.trigger("_before");elements.removeClass(options.activeclass);_this.addClass(options.activeclass);_tabs.hide();i=elements.index(_this);var currentTab=tab||_this.find("a").attr($this.opts.attribute);if($this.opts.deeplinking)location.hash=currentTab;if($this.opts.animation){_container.find(currentTab).animate({opacity:"show"},"slow",function(){_this.trigger("_after")})}else{_container.find(currentTab).show();_this.trigger("_after")}return false});var init=eval("elements."+$this.opts.mouseevent+"(fn)");init;var t;var forward=function(){i=++i%elements.length;$this.opts.mouseevent=="hover"?elements.eq(i).trigger("mouseover"):elements.eq(i).click();if($this.opts.autorotate){clearTimeout(t);t=setTimeout(forward,$this.opts.delay);if($this.opts.pauseonhover){$this.mouseover(function(){clearTimeout(t)})}}};if($this.opts.autorotate){t=setTimeout(forward,$this.opts.delay);$this.hover(function(){if($this.opts.pauseonhover)clearTimeout(t)},function(){t=setTimeout(forward,$this.opts.delay)});if($this.opts.pauseonhover)$this.on("mouseleave",function(){clearTimeout(t);t=setTimeout(forward,$this.opts.delay)})}function deep_link(){var ids=[];elements.find("a").each(function(){ids.push($(this).attr($this.opts.attribute))});var index=$.inArray(location.hash,ids);if(index>-1){return index+1}else{return $this.data("active")||options.active}}var move=function(direction){if(direction=="forward")i=++i%elements.length;if(direction=="backward")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("show",function(e,tab){fn(e,tab)});$this.on("next",function(){move("forward")});$this.on("prev",function(){move("backward")});$this.on("destroy",function(){$(this).removeData().find("> ul li").each(function(i){$(this).removeClass(options.activeclass)});_tabs.each(function(i){$(this).removeAttr("style").css("display",_cache_div[i])})})})};$(document).ready(function(){$('[data-toggle="tabslet"]').tabslet()})})(jQuery); diff --git a/jquery.tabslet.js b/jquery.tabslet.js index 26df420..b9d5099 100644 --- a/jquery.tabslet.js +++ b/jquery.tabslet.js @@ -62,8 +62,11 @@ var options = $.extend(defaults, options); return this.each(function() { + var $this = $(this); + if ( $this.data( 'tabslet-init' ) ) return; - var $this = $(this), _cache_li = [], _cache_div = []; + var _cache_li = []; + var _cache_div = []; var _container = options.container ? $(options.container) : $this; var _tabs = _container.find('> div'); @@ -73,170 +76,165 @@ // Autorotate var elements = $this.find('> ul > li'), i = options.active - 1; // ungly - if ( !$this.data( 'tabslet-init' ) ) { + $this.data( 'tabslet-init', true ); - $this.data( 'tabslet-init', true ); + $this.opts = []; - $this.opts = []; + $.map( ['mouseevent', 'activeclass', 'attribute', 'animation', 'autorotate', 'deeplinking', 'pauseonhover', 'delay', 'container'], function( val, i ) { + $this.opts[val] = $this.data(val) || options[val]; + }); - $.map( ['mouseevent', 'activeclass', 'attribute', 'animation', 'autorotate', 'deeplinking', 'pauseonhover', 'delay', 'container'], function( val, i ) { - $this.opts[val] = $this.data(val) || options[val]; - }); - - $this.opts['active'] = $this.opts.deeplinking ? deep_link() : ( $this.data('active') || options.active ) - - _tabs.hide(); - - if ( $this.opts.active ) { - _tabs.eq($this.opts.active - 1).show(); - elements.eq($this.opts.active - 1).addClass(options.activeclass); - } + $this.opts['active'] = $this.opts.deeplinking ? deep_link() : ( $this.data('active') || options.active ) - var fn = eval( + _tabs.hide(); - function(e, tab) { - var _this = tab ? elements.find('a[' + $this.opts.attribute + '="' + tab +'"]').parent() : $(this); + if ( $this.opts.active ) { + _tabs.eq($this.opts.active - 1).show(); + elements.eq($this.opts.active - 1).addClass(options.activeclass); + } - _this.trigger('_before'); + var fn = eval( - elements.removeClass(options.activeclass); - _this.addClass(options.activeclass); - _tabs.hide(); + function(e, tab) { + var _this = tab ? elements.find('a[' + $this.opts.attribute + '="' + tab +'"]').parent() : $(this); - i = elements.index(_this); + _this.trigger('_before'); - var currentTab = tab || _this.find('a').attr($this.opts.attribute); + elements.removeClass(options.activeclass); + _this.addClass(options.activeclass); + _tabs.hide(); - if ($this.opts.deeplinking) location.hash = currentTab; + i = elements.index(_this); - if ($this.opts.animation) { + var currentTab = tab || _this.find('a').attr($this.opts.attribute); - _container.find(currentTab).animate( { opacity: 'show' }, 'slow', function() { - _this.trigger('_after'); - }); + if ($this.opts.deeplinking) location.hash = currentTab; - } else { + if ($this.opts.animation) { - _container.find(currentTab).show(); + _container.find(currentTab).animate( { opacity: 'show' }, 'slow', function() { _this.trigger('_after'); + }); - } + } else { - return false; + _container.find(currentTab).show(); + _this.trigger('_after'); } - ); + return false; - var init = eval("elements." + $this.opts.mouseevent + "(fn)"); + } - init; + ); - var t; + var init = eval("elements." + $this.opts.mouseevent + "(fn)"); - var forward = function() { + init; - i = ++i % elements.length; // wrap around + var t; - $this.opts.mouseevent == 'hover' ? elements.eq(i).trigger('mouseover') : elements.eq(i).click(); + var forward = function() { - if ($this.opts.autorotate) { + i = ++i % elements.length; // wrap around - clearTimeout(t); + $this.opts.mouseevent == 'hover' ? elements.eq(i).trigger('mouseover') : elements.eq(i).click(); - t = setTimeout(forward, $this.opts.delay); + if ($this.opts.autorotate) { - $this.mouseover(function () { + clearTimeout(t); - if ($this.opts.pauseonhover) clearTimeout(t); + t = setTimeout(forward, $this.opts.delay); + if ($this.opts.pauseonhover) { + $this.mouseover(function () { + clearTimeout(t); }); - } } - if ($this.opts.autorotate) { + } - t = setTimeout(forward, $this.opts.delay); + if ($this.opts.autorotate) { - $this.hover(function() { + t = setTimeout(forward, $this.opts.delay); - if ($this.opts.pauseonhover) clearTimeout(t); + $this.hover(function() { - }, function() { + if ($this.opts.pauseonhover) clearTimeout(t); - t = setTimeout(forward, $this.opts.delay); + }, function() { - }); + t = setTimeout(forward, $this.opts.delay); - if ($this.opts.pauseonhover) $this.on( "mouseleave", function() { clearTimeout(t); t = setTimeout(forward, $this.opts.delay); }); + }); - } + if ($this.opts.pauseonhover) $this.on( "mouseleave", function() { clearTimeout(t); t = setTimeout(forward, $this.opts.delay); }); - function deep_link() { + } - var ids = []; + function deep_link() { - elements.find('a').each(function() { ids.push($(this).attr($this.opts.attribute)); }); + var ids = []; - var index = $.inArray(location.hash, ids) + elements.find('a').each(function() { ids.push($(this).attr($this.opts.attribute)); }); - if (index > -1) { + var index = $.inArray(location.hash, ids) - return index + 1 + if (index > -1) { - } else { + return index + 1 - return ($this.data('active') || options.active) + } else { - } + return ($this.data('active') || options.active) } - var move = function(direction) { + } - if (direction == 'forward') i = ++i % elements.length; // wrap around + var move = function(direction) { - if (direction == 'backward') i = --i % elements.length; // wrap around + if (direction == 'forward') i = ++i % elements.length; // wrap around - elements.eq(i).click(); + if (direction == 'backward') i = --i % elements.length; // wrap around - } + elements.eq(i).click(); - $this.find(options.controls.next).click(function() { - move('forward'); - }); + } - $this.find(options.controls.prev).click(function() { - move('backward'); - }); + $this.find(options.controls.next).click(function() { + move('forward'); + }); - $this.on ('show', function(e, tab) { - fn(e, tab); - }); + $this.find(options.controls.prev).click(function() { + move('backward'); + }); - $this.on ('next', function() { - move('forward'); - }); + $this.on ('show', function(e, tab) { + fn(e, tab); + }); - $this.on ('prev', function() { - move('backward'); - }); + $this.on ('next', function() { + move('forward'); + }); - $this.on ('destroy', function() { - $(this) - .removeData() - .find('> ul li').each( function(i) { - $(this).removeClass(options.activeclass); - }); - _tabs.each( function(i) { - $(this).removeAttr('style').css( 'display', _cache_div[i] ); + $this.on ('prev', function() { + move('backward'); + }); + + $this.on ('destroy', function() { + $(this) + .removeData() + .find('> ul li').each( function(i) { + $(this).removeClass(options.activeclass); }); + _tabs.each( function(i) { + $(this).removeAttr('style').css( 'display', _cache_div[i] ); }); - - } - + }); }); }; diff --git a/jquery.tabslet.min.js b/jquery.tabslet.min.js index 9308436..cea95b5 100644 --- a/jquery.tabslet.min.js +++ b/jquery.tabslet.min.js @@ -37,4 +37,5 @@ */ -!function($,window,undefined){"use strict";$.fn.tabslet=function(options){var defaults={mouseevent:"click",activeclass:"active",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","activeclass","attribute","animation","autorotate","deeplinking","pauseonhover","delay","container"],function(t){$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(options.activeclass));var fn=eval(function(t,e){var s=e?elements.find("a["+$this.opts.attribute+'="'+e+'"]').parent():$(this);s.trigger("_before"),elements.removeClass(options.activeclass),s.addClass(options.activeclass),_tabs.hide(),i=elements.index(s);var o=e||s.find("a").attr($this.opts.attribute);return $this.opts.deeplinking&&(location.hash=o),$this.opts.animation?_container.find(o).animate({opacity:"show"},"slow",function(){s.trigger("_after")}):(_container.find(o).show(),s.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("show",function(t,e){fn(t,e)}),$this.on("next",function(){move("forward")}),$this.on("prev",function(){move("backward")}),$this.on("destroy",function(){$(this).removeData().find("> ul li").each(function(){$(this).removeClass(options.activeclass)}),_tabs.each(function(t){$(this).removeAttr("style").css("display",_cache_div[t])})})}})},$(document).ready(function(){$('[data-toggle="tabslet"]').tabslet()})}(jQuery); + +(function($,window,undefined){"use strict";$.fn.tabslet=function(options){var defaults={mouseevent:"click",activeclass:"active",attribute:"href",animation:false,autorotate:false,deeplinking:false,pauseonhover:true,delay:2e3,active:1,container:false,controls:{prev:".prev",next:".next"}};var options=$.extend(defaults,options);return this.each(function(){var $this=$(this);if($this.data("tabslet-init"))return;var _cache_li=[];var _cache_div=[];var _container=options.container?$(options.container):$this;var _tabs=_container.find("> div");_tabs.each(function(){_cache_div.push($(this).css("display"))});var elements=$this.find("> ul > li"),i=options.active-1;$this.data("tabslet-init",true);$this.opts=[];$.map(["mouseevent","activeclass","attribute","animation","autorotate","deeplinking","pauseonhover","delay","container"],function(val,i){$this.opts[val]=$this.data(val)||options[val]});$this.opts["active"]=$this.opts.deeplinking?deep_link():$this.data("active")||options.active;_tabs.hide();if($this.opts.active){_tabs.eq($this.opts.active-1).show();elements.eq($this.opts.active-1).addClass(options.activeclass)}var fn=eval(function(e,tab){var _this=tab?elements.find("a["+$this.opts.attribute+'="'+tab+'"]').parent():$(this);_this.trigger("_before");elements.removeClass(options.activeclass);_this.addClass(options.activeclass);_tabs.hide();i=elements.index(_this);var currentTab=tab||_this.find("a").attr($this.opts.attribute);if($this.opts.deeplinking)location.hash=currentTab;if($this.opts.animation){_container.find(currentTab).animate({opacity:"show"},"slow",function(){_this.trigger("_after")})}else{_container.find(currentTab).show();_this.trigger("_after")}return false});var init=eval("elements."+$this.opts.mouseevent+"(fn)");init;var t;var forward=function(){i=++i%elements.length;$this.opts.mouseevent=="hover"?elements.eq(i).trigger("mouseover"):elements.eq(i).click();if($this.opts.autorotate){clearTimeout(t);t=setTimeout(forward,$this.opts.delay);if($this.opts.pauseonhover){$this.mouseover(function(){clearTimeout(t)})}}};if($this.opts.autorotate){t=setTimeout(forward,$this.opts.delay);$this.hover(function(){if($this.opts.pauseonhover)clearTimeout(t)},function(){t=setTimeout(forward,$this.opts.delay)});if($this.opts.pauseonhover)$this.on("mouseleave",function(){clearTimeout(t);t=setTimeout(forward,$this.opts.delay)})}function deep_link(){var ids=[];elements.find("a").each(function(){ids.push($(this).attr($this.opts.attribute))});var index=$.inArray(location.hash,ids);if(index>-1){return index+1}else{return $this.data("active")||options.active}}var move=function(direction){if(direction=="forward")i=++i%elements.length;if(direction=="backward")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("show",function(e,tab){fn(e,tab)});$this.on("next",function(){move("forward")});$this.on("prev",function(){move("backward")});$this.on("destroy",function(){$(this).removeData().find("> ul li").each(function(i){$(this).removeClass(options.activeclass)});_tabs.each(function(i){$(this).removeAttr("style").css("display",_cache_div[i])})})})};$(document).ready(function(){$('[data-toggle="tabslet"]').tabslet()})})(jQuery);