tabs-state.js 2.5 KB
jQuery(function($){if(typeof wgxpath.install==="function"){wgxpath.install()}$.urlParam=function(a){if(!new RegExp("=$").exec(a)){a=a+'='}var b=new RegExp("[\\?&]("+a+")([^&#]*)").exec(window.location.href);return b?b[1]:null};$.getXpath=function(c){if(typeof c=="string"){return document.evaluate(c,document,null,0,null)}if(!c||c.nodeType!=1){return""}if(c.id){return"//*[@id='"+c.id+"']"}var a=[];var d=a.filter.call(c.parentNode.children,function(x){return x.tagName==c.tagName});var b=[];return $.getXpath(c.parentNode)+"/"+c.tagName.toLowerCase()+(d.length>1?"["+(b.indexOf.call(d,c)+1)+"]":"")};$.findXpath=function(a,b){var c;var d=[];var e=document.evaluate(a,b||document,null,5,null);while(c=e.iterateNext()){d.push(c)}return $(d)};var m=function(){function remove_item(a,b){for(var i=0;i<a.length;i++){if(a[i].indexOf(b)>-1){a.splice(i,1)}}return a}function getStorageKey(){return window.location.href.toString().split(window.location.host)[1].replace(/&return=[a-zA-Z0-9%]+/,"").split('#')[0]}function saveActiveTab(a){var b=getStorageKey();var c=$(a.target).attr("href");var d=$.getXpath($(a.target).closest(".nav-tabs").first().get(0));if(!d||typeof c=="undefined"){return}var e=d+"|"+c;var f=JSON.parse(sessionStorage.getItem(b));if(!f){var f=[]}else{remove_item(f,d)}f.push(e);sessionStorage.setItem(b,JSON.stringify(f))}var g=JSON.parse(sessionStorage.getItem(getStorageKey()));var h=$("a[data-toggle='tab']");h.on("click",function(e){saveActiveTab(e)});h.parent(".active").removeClass("active");if(!g){var j=getStorageKey().replace(/\&id=[0-9]*|[a-z]\&{1}_id=[0-9]*/,'');g=JSON.parse(sessionStorage.getItem(j));sessionStorage.removeItem(j)}if(g!==null&&!window.location.hash){$.each(g,function(a,b){var c=b.split("|");$.findXpath(c[0]).find("a[data-toggle='tab'][href='"+c[1]+"']").click()})}else{var k=[];if(window.location.hash){h.parents("ul").each(function(a,b){var c=$(b).find("a[href='"+window.location.hash+"']");if(c.length){if(c.selector){k.push(c)}else{k.push(c.first())}var d=c.closest('.tab-pane');if(d){var e=d.attr('id');if(e){var f=$(d).find("a[href='#"+e+"']");if(f){k.push(f)}}}}f=null;c=null;d=null;e=null});k.reverse();for(var i=0;i<k.length;i++){jQuery(k[i].selector).click()}var l,scrollH,loc=window.location;if("pushState"in history)history.pushState("",document.title,loc.pathname+loc.search);else{l=document.body.scrollTop;scrollH=document.body.scrollLeft;loc.hash="";document.body.scrollTop=l;document.body.scrollLeft=scrollH}}else{h.parents("ul").each(function(a,b){$(b).find("a").first().click()})}}};setTimeout(m,100)});