|
| 1 | +var RESTLET = window.RESTLET || {}; |
| 2 | +var RESTLET = (function ($) { |
| 3 | + return { |
| 4 | + base : { |
| 5 | + //initialize base object @function init |
| 6 | + init : function () { |
| 7 | + |
| 8 | + }, |
| 9 | + } |
| 10 | + } |
| 11 | +})(jQuery); |
| 12 | + |
| 13 | +$(document).ready(function () { |
| 14 | + RESTLET.base.init(); |
| 15 | +}); |
| 16 | + |
| 17 | +/*************************** |
| 18 | + event handlers |
| 19 | + ****************************/ |
| 20 | + |
| 21 | +$(function () { |
| 22 | + |
| 23 | + // Mobi nav trigger |
| 24 | + $('#j-navigation-trigger').on('click', function () { |
| 25 | + $(this).toggleClass('collapse'); |
| 26 | + }); |
| 27 | + |
| 28 | + function mobiNav() { |
| 29 | + if ($(window).width() <= 992) { |
| 30 | + $('.navigation__link').on('click', function (e) { |
| 31 | + if ($(this).siblings().length) { |
| 32 | + $(this).siblings().toggle(); |
| 33 | + e.preventDefault(); |
| 34 | + } |
| 35 | + }); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + mobiNav(); |
| 40 | + |
| 41 | + // Window resize events |
| 42 | + $(window).on('resize', function () { |
| 43 | + $('#j-navigation-trigger').removeClass('collapse'); |
| 44 | + |
| 45 | + if ($(window).width() <= 992) { |
| 46 | + mobiNav(); |
| 47 | + } |
| 48 | + }); |
| 49 | + |
| 50 | + // SVG Generator |
| 51 | + if($('img.svg').length){ |
| 52 | + $('img.svg').each(function(){ |
| 53 | + var $img = jQuery(this); |
| 54 | + var imgID = $img.attr('id'); |
| 55 | + var imgClass = $img.attr('class'); |
| 56 | + var imgURL = $img.attr('src'); |
| 57 | + |
| 58 | + $.get(imgURL, function(data) { |
| 59 | + // Get the SVG tag, ignore the rest |
| 60 | + var $svg = $(data).find('svg'); |
| 61 | + |
| 62 | + // Add replaced image's classes to the new SVG |
| 63 | + if(typeof imgClass !== 'undefined') { |
| 64 | + $svg = $svg.attr('class', imgClass+' replaced-svg'); |
| 65 | + } |
| 66 | + |
| 67 | + // Remove any invalid XML tags as per http://validator.w3.org |
| 68 | + $svg = $svg.removeAttr('xmlns:a'); |
| 69 | + |
| 70 | + // Replace image with new SVG |
| 71 | + $img.replaceWith($svg); |
| 72 | + |
| 73 | + }, 'xml'); |
| 74 | + |
| 75 | + }); |
| 76 | + } |
| 77 | + |
| 78 | + // Documentation sidebar submenu click handler |
| 79 | + //when a group is shown, save it as the active accordion group |
| 80 | + if ($('.documentation-sidebar #accordion').length) { |
| 81 | + $('a[class="active"]').closest('ul').parents('ul').addClass('in'); |
| 82 | + $('a[class="active"]').closest('ul').addClass('in'); |
| 83 | + } |
| 84 | + |
| 85 | + // Documentation sidebar affix |
| 86 | + if ($('.documentation-sidebar').length) { |
| 87 | + $('.documentation-sidebar').affix({ |
| 88 | + offset: { |
| 89 | + top: 70, |
| 90 | + bottom: function () { |
| 91 | + return (this.bottom = $('footer').outerHeight(true) + 50) |
| 92 | + } |
| 93 | + } |
| 94 | + }); |
| 95 | + } |
| 96 | + |
| 97 | + if ($('.documentation-wrapper .inner-nav').length) { |
| 98 | + $('.documentation-wrapper .inner-nav').affix({ |
| 99 | + offset: { |
| 100 | + top: 155, |
| 101 | + bottom: function () { |
| 102 | + return (this.bottom = $('footer').outerHeight(true) + 100) |
| 103 | + } |
| 104 | + } |
| 105 | + }); |
| 106 | + } |
| 107 | + |
| 108 | + // Fix affix scrolling when .documentation-content is shorter than .inner-nav |
| 109 | + if ( $('.documentation-content').outerHeight() < $('.inner-nav').outerHeight() ) { |
| 110 | + $('.documentation-content').css('height', '2610'); |
| 111 | + } |
| 112 | + |
| 113 | + // Anchor link scroll to section |
| 114 | + if (window.location.hash) { |
| 115 | + var target = $(window.location.hash); |
| 116 | + |
| 117 | + if (target.length) { |
| 118 | + $('html, body').animate({ |
| 119 | + scrollTop: target.offset().top - 190 |
| 120 | + }, 1000); |
| 121 | + return false; |
| 122 | + } |
| 123 | + } |
| 124 | + |
| 125 | +}); |
0 commit comments