forked from elboletaire/tabbedcontent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.tabbedcontent.min.js
3 lines (3 loc) · 2.15 KB
/
jquery.tabbedcontent.min.js
1
2
3
/* Tabs plugin for jQuery created by Òscar Casajuana < elboletaire at underave dot net >
* Copyright 2013 Òscar Casajuana (Apache License v.2.0) */
(function(e,t,n,r){"use strict";var i=function(i,s){function h(e){return a.filter(e).length?true:false}function p(e){if(e.toString().match(/^[0-9]$/)){return"#"+a.eq(e).attr("id")}return"#"+e}function d(){var t;s.links.each(function(n){if(e(this).hasClass(s.currentClass)){t=n}});return t}function v(){return p(d()).replace("#","")}function m(e){var t=d(),n=t+1;if(n<a.length){return b(n,true)}else if(e&&n>=a.length){return b(0,true)}return false}function g(e){var t=d(),n=t-1;if(n>=0){return b(n,true)}else if(e&&n<0){return b(a.length-1,true)}return false}function y(e){if(u&&f!==r&&"pushState"in f){u=false;n.setTimeout(function(){f.replaceState(null,"",e)},100)}if(s.onSwitch&&typeof s.onSwitch==="function"){s.onSwitch(e)}}function b(e,t){if(!e.toString().match(/^#/)){e=p(e)}if(!h(e)){return false}s.links.removeClass(s.currentClass);s.links.filter("a[href="+e+"]").addClass(s.currentClass);a.hide();if(t){if(f!==r&&"pushState"in f){f.pushState(null,"",e)}else{n.location.hash=e}}a.filter(e).show(s.speed,function(){if(s.speed){y(e)}});if(!s.speed){y(e)}return true}function w(e){return b(e,true)}function E(e){b(l.hash)}function S(){if(h(l.hash)){b(l.hash)}else if(s.errorSelector&&a.find(s.errorSelector).length){a.each(function(){if(e(this).find(s.errorSelector).length){b("#"+e(this).attr("id"));return false}})}else{b("#"+i.children(":first-child").attr("id"))}if("onhashchange"in n){e(n).bind("hashchange",E)}else{var t=l.href;n.setInterval(function(){if(t!==l.href){E.call(n.event);t=l.href}},100)}if(s.onInit&&typeof s.onInit==="function"){s.onInit()}}var o={links:i.prev().find("a").length?i.prev().find("a"):".tabs a",errorSelector:".error-message",speed:false,onSwitch:false,onInit:false,currentClass:"current"},u=true,a=i.children(),f=n.history,l=t.location,c=null;s=e.extend(o,s);if(!s.links.version){s.links=e(s.links)}S();return{"switch":w,switchTab:w,getCurrent:d,getCurrentId:v,next:m,prev:g}};e.fn.tabbedContent=function(t){return this.each(function(){var n=new i(e(this),t);e(this).data("api",n)})}})(jQuery,document,window)