privilegedemarque/themes/site/js/jquery.scrollNav.min.js

4 lines
6.8 KiB
JavaScript
Raw Normal View History

2016-04-14 16:14:31 +02:00
/*! scrollNav - v2.2.0 - 2014-03-14
* http://scrollnav.com
* Copyright (c) 2014 James Wilson; Licensed MIT */
(function(s){var t=function(t,e,i,n){if(s(t).length>0){var a=s(t).offset().top;e=n?e:0,s("html:not(:animated),body:not(:animated)").animate({scrollTop:a-i},e)}},e=function(){return window.location.hash},i={classes:{loading:"sn-loading",failed:"sn-failed",success:"sn-active"},defaults:{sections:"h2",subSections:!1,sectionElem:"section",className:"scroll-nav",showHeadline:!0,headlineText:"Scroll To",showTopLink:!0,topLinkText:"Top",fixedMargin:40,scrollOffset:40,animated:!0,speed:500,insertLocation:"insertBefore",arrowKeys:!1,onInit:null,onRender:null,onDestroy:null},_set_body_class:function(t){var e=s("body");"loading"===t?e.addClass(i.classes.loading):"success"===t?e.removeClass(i.classes.loading).addClass(i.classes.success):e.removeClass(i.classes.loading).addClass(i.classes.failed)},_find_sections:function(t){var e=i.settings.sections,n=[];if(i.settings.showTopLink){var a=t.children().first();a.is(e)||n.push(a.nextUntil(e).andSelf())}t.find(e).each(function(){n.push(s(this).nextUntil(e).andSelf())}),i.sections={raw:n}},_setup_sections:function(t){var e=[];s(t).each(function(t){var n=[],a=s(this),o="scrollNav-"+(t+1),l=function(){return 0===t},c=function(){return!a.eq(0).is(i.settings.sections)},r=i.settings.showTopLink&&l()&&c()?i.settings.topLinkText:a.filter(i.settings.sections).text();if(a.wrapAll("<"+i.settings.sectionElem+' id="'+o+'" class="'+i.settings.className+'__section" />'),i.settings.subSections){var d=a.filter(i.settings.subSections);d.length>0&&d.each(function(t){var e=o+"-"+(t+1),l=s(this).text(),c=a.filter(s(this).nextUntil(d).andSelf());c.wrapAll('<div id="'+e+'" class="'+i.settings.className+'__sub-section" />'),n.push({id:e,text:l})})}e.push({id:o,text:r,sub_sections:n})}),i.sections.data=e},_tear_down_sections:function(t){s(t).each(function(){var t=this.sub_sections;s("#"+this.id).children().unwrap(),t.length>0&&s(t).each(function(){s("#"+this.id).children().unwrap()})})},_setup_nav:function(t){var e=s("<span />",{"class":i.settings.className+"__heading",text:i.settings.headlineText}),n=s("<div />",{"class":i.settings.className+"__wrapper"}),a=s("<nav />",{"class":i.settings.className,role:"navigation"}),o=s("<ol />",{"class":i.settings.className+"__list"});s.each(t,function(t){var e,n=0===t?s("<li />",{"class":i.settings.className+"__item active"}):s("<li />",{"class":i.settings.className+"__item"}),a=s("<a />",{href:"#"+this.id,"class":i.settings.className+"__link",text:this.text});this.sub_sections.length>0&&(n.addClass("is-parent-item"),e=s("<ol />",{"class":i.settings.className+"__sub-list"}),s.each(this.sub_sections,function(){var t=s("<li />",{"class":i.settings.className+"__sub-item"}),n=s("<a />",{href:"#"+this.id,"class":i.settings.className+"__sub-link",text:this.text});e.append(t.append(n))})),o.append(n.append(a).append(e))}),i.settings.showHeadline?a.append(n.append(e).append(o)):a.append(n.append(o)),i.nav=a},_insert_nav:function(){var s=i.settings.insertLocation,t=i.settings.insertTarget;i.nav[s](t)},_setup_pos:function(){var t=i.nav,e=s(window).height(),n=t.offset().top;s.each(i.sections.data,function(){var t=s("#"+this.id),e=t.height();this.top_offset=t.offset().top,this.bottom_offset=this.top_offset+e}),i.dims={vp_height:e,nav_offset:n}},_check_pos:function(){var t=i.nav,e=s(window).scrollTop(),n=e+i.settings.scrollOffset,a=e+i.dims.vp_height-i.settings.scrollOffset,o=[];e>i.dims.nav_offset-i.settings.fixedMargin?t.addClass("fixed"):t.removeClass("fixed"),s.each(i.sections.data,function(){(this.top_offset>n&&a>this.top_offset||this.bottom_offset>n&&a>this.bottom_offset||n>this.top_offset&&this.bottom_offset>a)&&o.push(this)}),t.find("."+i.settings.className+"__item").removeClass("active").removeClass("in-view"),s.each(o,function(s){0===s?t.find('a[href="#'+this.id+'"]').parents("."+i.settings.className+"__item").addClass("active").addClass("in-view"):t.find('a[href="#'+this.id+'"]').parents("."+i.settings.className+"__item").addClass("in-view"),s++,i.sections.active=o})},_init_scroll_listener:function(){s(window).on("scroll.scrollNav",function(){i._check_pos()})},_rm_scroll_list