mirror of
https://github.com/s00500/ESPUI.git
synced 2026-02-05 17:02:41 +00:00
1 line
2.9 KiB
JavaScript
1 line
2.9 KiB
JavaScript
(function(e,t,n,s){"use strict";var o=function(o,i){var y={links:o.prev().find("a").length?o.prev().find("a"):".tabs a",errorSelector:".error-message",speed:!1,onSwitch:!1,onInit:!1,currentClass:"active",tabErrorClass:"has-errors",history:!0,historyOnInit:!0,loop:!1},p=!1,a=o.children(),l=n.history,d=t.location,c=null;i=e.extend(y,i),i.links instanceof e||(i.links=e(i.links));function j(e){return Boolean(a.filter(e).length)}function O(){return c===0}function E(e){return e%1===0}function x(){return c===a.length-1}function h(t){return e(this).attr("href").match(new RegExp(t+"$"))}function m(t){return t instanceof e?{tab:t,link:i.links.eq(t.index())}:E(t)?{tab:a.eq(t),link:i.links.eq(t)}:a.filter(t).length?{tab:a.filter(t),link:i.links.filter(function(){return h.apply(this,[t])})}:{tab:a.filter("#"+t),link:i.links.filter(function(){return h.apply(this,["#"+t])})}}function b(){return i.links.parent().filter("."+i.currentClass).index()}function w(e){return++c,e===s&&(e=i.loop),c<a.length?r(c,!0):!!(e&&c>=a.length)&&r(0,!0)}function _(e){return--c,e===s&&(e=i.loop),c>=0?r(c,!0):!!(e&&c<0)&&r(a.length-1,!0)}function f(e){i.history&&i.historyOnInit&&p&&l!==s&&"pushState"in l&&(p=!1,n.setTimeout(function(){l.replaceState(null,"",e)},100)),c=b(),i.onSwitch&&typeof i.onSwitch=="function"&&i.onSwitch(e,u()),o.trigger("tabcontent.switch",[e,u()])}function r(e,t){return e.toString().match(/^#/)||(e="#"+m(e).tab.attr("id")),!!j(e)&&(i.links.attr("aria-selected","false").parent().removeClass(i.currentClass),i.links.filter(function(){return h.apply(this,[e])}).attr("aria-selected","true").parent().addClass(i.currentClass),a.hide(),i.history&&t&&(l!==s&&"pushState"in l?l.pushState(null,"",e):n.location.hash=e),a.attr("aria-hidden","true").filter(e).show(i.speed,function(){i.speed&&f(e)}).attr("aria-hidden","false"),i.speed||f(e),!0)}function v(e){return r(e,!0)}function g(){r(d.hash)}function C(){if(j(d.hash)?r(d.hash):i.links.parent().filter("."+i.currentClass).length?r(i.links.parent().filter("."+i.currentClass).index()):i.errorSelector&&a.find(i.errorSelector).length?a.each(function(){if(e(this).find(i.errorSelector).length)return r("#"+e(this).attr("id")),!1}):r("#"+a.filter(":first-child").attr("id")),i.errorSelector&&a.find(i.errorSelector).each(function(){var t=m(e(this).parent());t.link.parent().addClass(i.tabErrorClass)}),"onhashchange"in n)e(n).bind("hashchange",g);else{var t=d.href;n.setInterval(function(){t!==d.href&&(g.call(n.event),t=d.href)},100)}e(i.links).on("click",function(t){r(e(this).attr("href").replace(/^[^#]+/,""),i.history),t.preventDefault()}),i.onInit&&typeof i.onInit=="function"&&i.onInit(u()),o.trigger("tabcontent.init",[u()])}function u(){return{switch:v,switchTab:v,getCurrent:b,getTab:m,next:w,prev:_,isFirst:O,isLast:x}}return C(),u()};e.fn.tabbedContent=function(t){return this.each(function(){var n=new o(e(this),t);e(this).data("api",n)})}})(window.jQuery||window.Zepto||window.$,document,window) |