mirror of
https://github.com/danog/sass-site.git
synced 2024-12-04 02:17:57 +01:00
183 lines
8.7 KiB
JavaScript
183 lines
8.7 KiB
JavaScript
/*!
|
|
* jQuery Scrollspy Plugin
|
|
* Author: @sxalexander
|
|
* Licensed under the MIT license
|
|
*/
|
|
;(function ( $, window, document, undefined ) {
|
|
|
|
$.fn.extend({
|
|
scrollspy: function ( options ) {
|
|
|
|
var defaults = {
|
|
min: 0,
|
|
max: 0,
|
|
mode: 'vertical',
|
|
namespace: 'scrollspy',
|
|
buffer: 0,
|
|
container: window,
|
|
onEnter: options.onEnter ? options.onEnter : [],
|
|
onLeave: options.onLeave ? options.onLeave : [],
|
|
onTick: options.onTick ? options.onTick : []
|
|
}
|
|
|
|
var options = $.extend( {}, defaults, options );
|
|
|
|
return this.each(function (i) {
|
|
|
|
var element = this;
|
|
var o = options;
|
|
var $container = $(o.container);
|
|
var mode = o.mode;
|
|
var buffer = o.buffer;
|
|
var enters = leaves = 0;
|
|
var inside = false;
|
|
|
|
/* add listener to container */
|
|
$container.bind('scroll.' + o.namespace, function(e){
|
|
var position = {top: $(this).scrollTop(), left: $(this).scrollLeft()};
|
|
var xy = (mode == 'vertical') ? position.top + buffer : position.left + buffer;
|
|
var max = o.max;
|
|
var min = o.min;
|
|
|
|
/* fix max */
|
|
if($.isFunction(o.max)){
|
|
max = o.max();
|
|
}
|
|
|
|
/* fix max */
|
|
if($.isFunction(o.min)){
|
|
min = o.min();
|
|
}
|
|
|
|
if(max == 0){
|
|
max = (mode == 'vertical') ? $container.height() : $container.outerWidth() + $(element).outerWidth();
|
|
}
|
|
|
|
/* if we have reached the minimum bound but are below the max ... */
|
|
if(xy >= min && xy <= max){
|
|
/* trigger enter event */
|
|
if(!inside){
|
|
inside = true;
|
|
enters++;
|
|
|
|
/* fire enter event */
|
|
$(element).trigger('scrollEnter', {position: position})
|
|
if($.isFunction(o.onEnter)){
|
|
o.onEnter(element, position);
|
|
}
|
|
|
|
}
|
|
|
|
/* trigger tick event */
|
|
$(element).trigger('scrollTick', {position: position, inside: inside, enters: enters, leaves: leaves})
|
|
if($.isFunction(o.onTick)){
|
|
o.onTick(element, position, inside, enters, leaves);
|
|
}
|
|
}else{
|
|
|
|
if(inside){
|
|
inside = false;
|
|
leaves++;
|
|
/* trigger leave event */
|
|
$(element).trigger('scrollLeave', {position: position, leaves:leaves})
|
|
|
|
if($.isFunction(o.onLeave)){
|
|
o.onLeave(element, position);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
});
|
|
}
|
|
|
|
})
|
|
|
|
|
|
})( jQuery, window, document, undefined );
|
|
|
|
$(document).ready(function() {
|
|
$('.sl-js-sticky').scrollspy({
|
|
min: $('ul').offset().top,
|
|
onEnter: function(element, position) {
|
|
$("ul").addClass('sl-is-fixed');
|
|
},
|
|
onLeave: function(element, position) {
|
|
$("ul").removeClass('sl-is-fixed');
|
|
}
|
|
});
|
|
});
|
|
|
|
/*!
|
|
* jQuery Smooth Scroll - v2.2.0 - 2017-05-05
|
|
* https://github.com/kswedberg/jquery-smooth-scroll
|
|
* Copyright (c) 2017 Karl Swedberg
|
|
* Licensed MIT
|
|
*/
|
|
|
|
|
|
!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a("object"==typeof module&&module.exports?require("jquery"):jQuery)}(function(a){var b={},c={exclude:[],excludeWithin:[],offset:0,direction:"top",delegateSelector:null,scrollElement:null,scrollTarget:null,autoFocus:!1,beforeScroll:function(){},afterScroll:function(){},easing:"swing",speed:400,autoCoefficient:2,preventDefault:!0},d=function(b){var c=[],d=!1,e=b.dir&&"left"===b.dir?"scrollLeft":"scrollTop";return this.each(function(){var b=a(this);if(this!==document&&this!==window)return!document.scrollingElement||this!==document.documentElement&&this!==document.body?void(b[e]()>0?c.push(this):(b[e](1),d=b[e]()>0,d&&c.push(this),b[e](0))):(c.push(document.scrollingElement),!1)}),c.length||this.each(function(){this===document.documentElement&&"smooth"===a(this).css("scrollBehavior")&&(c=[this]),c.length||"BODY"!==this.nodeName||(c=[this])}),"first"===b.el&&c.length>1&&(c=[c[0]]),c},e=/^([\-\+]=)(\d+)/;a.fn.extend({scrollable:function(a){var b=d.call(this,{dir:a});return this.pushStack(b)},firstScrollable:function(a){var b=d.call(this,{el:"first",dir:a});return this.pushStack(b)},smoothScroll:function(b,c){if("options"===(b=b||{}))return c?this.each(function(){var b=a(this),d=a.extend(b.data("ssOpts")||{},c);a(this).data("ssOpts",d)}):this.first().data("ssOpts");var d=a.extend({},a.fn.smoothScroll.defaults,b),e=function(b){var c=function(a){return a.replace(/(:|\.|\/)/g,"\\$1")},e=this,f=a(this),g=a.extend({},d,f.data("ssOpts")||{}),h=d.exclude,i=g.excludeWithin,j=0,k=0,l=!0,m={},n=a.smoothScroll.filterPath(location.pathname),o=a.smoothScroll.filterPath(e.pathname),p=location.hostname===e.hostname||!e.hostname,q=g.scrollTarget||o===n,r=c(e.hash);if(r&&!a(r).length&&(l=!1),g.scrollTarget||p&&q&&r){for(;l&&j<h.length;)f.is(c(h[j++]))&&(l=!1);for(;l&&k<i.length;)f.closest(i[k++]).length&&(l=!1)}else l=!1;l&&(g.preventDefault&&b.preventDefault(),a.extend(m,g,{scrollTarget:g.scrollTarget||r,link:e}),a.smoothScroll(m))};return null!==b.delegateSelector?this.off("click.smoothscroll",b.delegateSelector).on("click.smoothscroll",b.delegateSelector,e):this.off("click.smoothscroll").on("click.smoothscroll",e),this}});var f=function(a){var b={relative:""},c="string"==typeof a&&e.exec(a);return"number"==typeof a?b.px=a:c&&(b.relative=c[1],b.px=parseFloat(c[2])||0),b},g=function(b){var c=a(b.scrollTarget);b.autoFocus&&c.length&&(c[0].focus(),c.is(document.activeElement)||(c.prop({tabIndex:-1}),c[0].focus())),b.afterScroll.call(b.link,b)};a.smoothScroll=function(c,d){if("options"===c&&"object"==typeof d)return a.extend(b,d);var e,h,i,j,k=f(c),l={},m=0,n="offset",o="scrollTop",p={},q={};k.px?e=a.extend({link:null},a.fn.smoothScroll.defaults,b):(e=a.extend({link:null},a.fn.smoothScroll.defaults,c||{},b),e.scrollElement&&(n="position","static"===e.scrollElement.css("position")&&e.scrollElement.css("position","relative")),d&&(k=f(d))),o="left"===e.direction?"scrollLeft":o,e.scrollElement?(h=e.scrollElement,k.px||/^(?:HTML|BODY)$/.test(h[0].nodeName)||(m=h[o]())):h=a("html, body").firstScrollable(e.direction),e.beforeScroll.call(h,e),l=k.px?k:{relative:"",px:a(e.scrollTarget)[n]()&&a(e.scrollTarget)[n]()[e.direction]||0},p[o]=l.relative+(l.px+m+e.offset),i=e.speed,"auto"===i&&(j=Math.abs(p[o]-h[o]()),i=j/e.autoCoefficient),q={duration:i,easing:e.easing,complete:function(){g(e)}},e.step&&(q.step=e.step),h.length?h.stop().animate(p,q):g(e)},a.smoothScroll.version="2.2.0",a.smoothScroll.filterPath=function(a){return a=a||"",a.replace(/^\//,"").replace(/(?:index|default).[a-zA-Z]{3,4}$/,"").replace(/\/$/,"")},a.fn.smoothScroll.defaults=c});
|
|
|
|
var tab = $('.sl-c-tabs__button'),
|
|
accordion = $('.sl-c-tabs__content');
|
|
|
|
tab.click(function () {
|
|
if (accordion.hasClass('sl-is-inactive')) {
|
|
accordion.slideUp(0, function () {
|
|
accordion.removeClass('inactive').slideDown(1000);
|
|
});
|
|
}
|
|
|
|
else {
|
|
accordion.slideUp(1000, function () {
|
|
accordion.addClass('sl-is-inactive').slideDown(0);
|
|
});
|
|
}
|
|
});
|
|
|
|
$(function() {
|
|
$(".code-example").each(function() {
|
|
var figure = $(this);
|
|
var id = figure.attr("data-unique-id");
|
|
|
|
var ul = $("<ul></ul>");
|
|
|
|
if (figure.find(".sass").length) {
|
|
ul.prepend("<li><a href='#example-" + id + "-sass'>Sass</a></li>");
|
|
}
|
|
|
|
if (figure.find(".scss").length) {
|
|
ul.prepend("<li><a href='#example-" + id + "-scss'>SCSS</a></li>");
|
|
}
|
|
|
|
var hasCssTab = figure.find(".css").length;
|
|
if (hasCssTab) {
|
|
ul.prepend(
|
|
$("<li class='css-tab'></li>")
|
|
.prepend("<a href='#example-" + id + "-css'>CSS</a>"));
|
|
}
|
|
|
|
figure.prepend(ul).tabs({active: hasCssTab ? 1 : 0});
|
|
});
|
|
|
|
// Switch ALL the tabs (Sass/SCSS) together
|
|
var
|
|
noRecursion = false,
|
|
jqA = $( "a.ui-tabs-anchor" ),
|
|
jqASass = jqA.filter( ":contains('Sass')" ).click(function() {
|
|
if ( !noRecursion ) {
|
|
noRecursion = true;
|
|
jqASass.not( this ).click();
|
|
noRecursion = false;
|
|
}
|
|
}),
|
|
jqASCSS = jqA.filter( ":contains('SCSS')" ).click(function() {
|
|
if ( !noRecursion ) {
|
|
noRecursion = true;
|
|
jqASCSS.not( this ).click();
|
|
noRecursion = false;
|
|
}
|
|
})
|
|
;
|
|
});
|