/* ========================================================== * autocomplete.js * Deal with the Typeahead.js/Bloodhound library to build the search field autocomplete * * Author: Yann, yann@antistatique.net * Date: 2014-05-01 14:23:18 * * Copyright 2014 Federal Chancellery of Switzerland * Licensed under MIT ========================================================== */ (function($, data) { 'use strict'; var $searchFields = $('.form-search .search-field'); if (data) { // Init the Bloodhound suggestion engine var bloodhound = new Bloodhound({ datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'), queryTokenizer: Bloodhound.tokenizers.whitespace, local: $.map(data, function(state) { return { value: state }; }) }); bloodhound.initialize(); // Init Typeahead on search-fields $searchFields.typeahead({ hint: false, highlight: true, minLength: 1 }, { name: 'search', displayKey: 'value', source: bloodhound.ttAdapter() }); } }) (jQuery, (typeof searchData === 'undefined' ? false : searchData)); /* ========================================================== * carousel.js * Carousel helper * * Author: Yann, yann@antistatique.net * Date: 2014-05-15 13:55:53 * * Copyright 2014 Federal Chancellery of Switzerland * Licensed under MIT ========================================================== */ (function($) { 'use strict'; $(window).load(function () { carouselInit(jQuery); }); $(window).resize(function () { carouselInit(jQuery); }); // slideshow counter var slideshow_total = $('.carousel-slideshow .item').length; $('#carousel-total').text(slideshow_total); $('.carousel-slideshow').on('slid.bs.carousel', function () { var carouselData = $(this).data('bs.carousel'); var currentIndex = carouselData.getItemIndex(carouselData.$element.find('.item.active')); var total = carouselData.$items.length; var text = (currentIndex + 1); $('#carousel-index').text(text); $('#carousel-total').text(total); }); }) (jQuery); function carouselInit($) { 'use strict'; var $carousel = $('.carousel:not(.carousel-slideshow)'); $('.carousel .item:first-child').addClass('first'); $('.carousel .item:last-child').addClass('last'); $('.carousel').each(function() { disableControl($(this)); }); $('.carousel').on('slid.bs.carousel', function () { disableControl($(this)); }); if($carousel) { $carousel.each(function () { var biggestHeight = 0, titleHeight = $(this).find('.item.active h3:first-child').height(), imgHeight = $(this).find('.item.active .carousel-img').height(); $(this).find('.carousel-indicators, .carousel-control').css('top', titleHeight + imgHeight + 50); $(this).find('.item').each(function () { if ($(this).height() >= biggestHeight) { biggestHeight = $(this).height(); } }); $(this).find('.item').height(biggestHeight); }); } } function disableControl(element) { 'use strict'; if (element.find('.first').hasClass('active')) { element.find('.left').addClass('disabled').attr('aria-disabled', 'true'); } else { element.find('.left').removeClass('disabled').attr('aria-disabled', 'false'); } if (element.find('.last').hasClass('active')) { element.find('.right').addClass('disabled').attr('aria-disabled', 'true'); } else { element.find('.right').removeClass('disabled').attr('aria-disabled', 'false'); } } /* ========================================================== * collapse.js * Add class when nav collapse is open * * Author: Yann, yann@antistatique.net * Date: 2014-05-06 * * Copyright 2014 Federal Chancellery of Switzerland * Licensed under MIT ========================================================== */ (function($) { 'use strict'; // Normal Collapse $('.collapse:not(tbody)').on('show.bs.collapse', function () { $(this) .prev() .addClass('active icon--root') .removeClass('icon--greater') .attr({ 'aria-selected': 'true', 'aria-expanded': 'true' }); }); $('.collapse:not(tbody)').on('hide.bs.collapse', function () { $(this) .prev() .removeClass('active icon--root') .addClass('icon--greater') .attr( { 'aria-selected': 'false', 'aria-expanded': 'false' }); }); // Table Collapse $('tbody.collapse').on('show.bs.collapse', function () { $(this) .prev().find('[data-toggle=collapse]') .addClass('active') .attr({ 'aria-selected': 'true', 'aria-expanded': 'true' }); }); $('tbody.collapse').on('hide.bs.collapse', function () { $(this) .prev().find('[data-toggle=collapse]') .removeClass('active') .attr({ 'aria-selected': 'false', 'aria-expanded': 'false' }); }); // Ensure every first collapse toggle for accordions is accessible // (cf. https://github.com/paypal/bootstrap-accessibility-plugin/issues/98): $('[aria-multiselectable="true"]').each(function() { $(this).find('[data-toggle="collapse"][data-parent]').first().attr({tabindex: 0}); }); }) (jQuery); /* ========================================================== * drilldown.js * Drilldown plugin scripts. For page-list-nav element * * Author: Toni Fisler, toni@antistatique.net * Date: 2014-05-30 09:02:09 * * Copyright 2014 Federal Chancellery of Switzerland * Licensed under MIT ========================================================== */ (function($) { 'use strict'; var options = { event: 'click', // * View note below selector: 'a', // * View note below speed: 100, cssClass: { container: 'drilldown-container', root: 'nav-page-list', sub: 'drilldown-sub', back: 'drilldown-back' } }; $('.drilldown').drilldown(options); }) (jQuery); /* ========================================================== * global-nav.js * Global Navigation syripts * * Author: Toni Fisler, toni@antistatique.net * Date: 2014-05-27 16:36:15 * * Copyright 2014 Federal Chancellery of Switzerland * Licensed under MIT ========================================================== */ (function($) { 'use strict'; // Handle scroll to position nav as fixed var top = 36; $(window).scroll(function () { var y = $(this).scrollTop(); if (y >= top) { if (!$('.nav-mobile').hasClass('fixed')) { $('.nav-mobile').addClass('fixed') .after(''); } } else { if ($('.nav-mobile').hasClass('fixed')) { $('.nav-mobile').removeClass('fixed'); $('#spacer').remove(); } } }); }) (jQuery); // OUTLINE.JS // https://github.com/lindsayevans/outline.js // // Based on http://www.paciellogroup.com/blog/2012/04/how-to-remove-css-outlines-in-an-accessible-manner/ // // Hide outline on mouse interactions // Show it on keyboard interactions (function(doc){ 'use strict'; var styleElement = doc.createElement('STYLE'), domEvents = 'addEventListener' in doc, addListener = function(type, callback){ // Basic cross-browser event handling if (domEvents) { doc.addEventListener(type, callback); } else { doc.attachEvent('on' + type, callback); } }, setCSS = function(cssText){ !!styleElement.styleSheet ? styleElement.styleSheet.cssText = cssText : styleElement.innerHTML = cssText; }; doc.getElementsByTagName('HEAD')[0].appendChild(styleElement); // Using mousedown instead of mouseover, so that previously focused elements don't lose focus ring on mouse move addListener('mousedown', function(){ setCSS(':focus{outline:0!important}::-moz-focus-inner{border:0!important}'); }); addListener('keydown', function(){ setCSS(''); }); })(document); /* ========================================================== * print.js * Add print preview windows * * Author: Yann, yann@antistatique.net * Date: 2015-02-02 * * Copyright 2014 Federal Chancellery of Switzerland * Licensed under MIT ========================================================== */ (function($) { 'use strict'; // Initialization $.fn.printPreview = function() { return this; }; $.printPreview = { printPreview: function(element) { var $body = $('body'), $container = $('.container-main'), footnoteLinks = "", linksIndex = 0; $body.find('.nav-mobile, .drilldown, .nav-main, .header-separator, .nav-service, .nav-lang, .form-search, .yamm--select, footer, .alert, .icon--print, .social-sharing, form, .nav-process, .carousel-indicators, .carousel-control, .breadcrumb, .pagination-container').remove(); // if an element is passed, we want it to be the only thing to print out if (element) { element = $('[data-print=' + element + ']').clone(); // clone to fix issue with IE render var header = $('header').clone(), // clone to fix issue with IE render title = element.attr('data-title') ? '

' + element.attr('data-title') + '

' : ''; $container.addClass('print-element').html('').append(header, title, element); } $body.addClass('print-preview'); $container.prepend(''); $('#print-button').click(function () { $.printPreview.printProcess(); }); $('#close-button').click(function () { $.printPreview.printClose(); }); $('a').not('.access-keys a').each(function () { var target = $(this).attr('href'); target = String(target); if (target !== "undefined" && target.indexOf("http") === 0) { linksIndex ++; footnoteLinks += '
  • '+target+'
  • '; $('('+linksIndex+')').insertAfter(this); } }); $('#footnote-links').change(function(){ if (this.checked) { $container.append(''); $body.addClass('print-footnotes'); } else { $('#footnote-links-wrapper').remove(); $body.removeClass('print-footnotes'); } }); }, printProcess: function() { window.print(); }, printClose: function() { window.location.reload(); } }; }) (jQuery); /* ========================================================== * rich-menu.js * Add overlay when openning a rich yamm menu and define open/close events * * Author: Yann Gouffon, yann@antistatique.net * Date: 2014-04-30 11:48:48 * * Copyright 2014 Federal Chancellery of Switzerland * Licensed under MIT =========================================================== */ (function($) { 'use strict'; // Keep jQuery object in variables var $yamm = $('.yamm'), $yammClose = $('.yamm-close, .yamm-close-bottom'), $dropdown = $('.yamm .dropdown'), $dropdownToggle = $('.yamm .dropdown-toggle'); // Toggle dropdown and fix z-index errors $yamm.each(function () { var $that = $(this); $that.on('click', '.dropdown-toggle', function () { if (!$(this).parent().hasClass('open')){ var dropdownHeight = $(window).height() - 49; $that.find('.drilldown-container').height( dropdownHeight ); } }); }); // "tabindex = -1" is added by bootstrap-accessibility-plugin to dropdown's elements. // The yamm menu uses the dropdown class, but is not a conventional dropdown, hence, the tabindex must not // be present. $dropdown.find('li a').removeAttr('tabindex'); $dropdownToggle.on('click', function() { $(this).parents($dropdown).trigger('get.hidden'); }); $dropdown.on({ "shown.bs.dropdown": function() { this.closable = false; }, "get.hidden": function() { this.closable = true; } }); $('.dropdown').on('show.bs.dropdown', function () { $dropdown.removeClass('open'); $yamm.removeClass('nav-open'); $(this).parents($yamm).addClass('nav-open'); }); $dropdown.on('hide.bs.dropdown', function () { // only remove the nav-open class if effectively closing dropdown if (this.closable) { $yamm.removeClass('nav-open'); } return this.closable; }); $(document).on('click', function(e) { // hide dropdown if dropdown is open and target is not in dropdown if ($('.dropdown.open').length > 0 && $(e.target).parents('.dropdown').length === 0) { $('.dropdown.open .dropdown-toggle').trigger('click'); } }); // Trigger close yamm menu $dropdown.each(function () { var $that = $(this); $that.find($yammClose).click( function (e) { e.preventDefault(); $that.find($dropdownToggle).trigger("click"); }); }); }) (jQuery); (function($) { 'use strict'; var datasets = []; $('.dropdown.yamm-fw').each(function() { var title = $('.dropdown-toggle', $(this)).html(); var links = $('.dropdown-menu li a', $(this)); var suggestions = []; links.each(function() { suggestions.push({ title: $(this).html(), link: $(this).attr('href') }); }); if (!suggestions.length) { return; } var engine = new Bloodhound({ initialize: true, local: suggestions, identify: function(obj) { return obj.link; }, datumTokenizer: Bloodhound.tokenizers.obj.whitespace('title'), queryTokenizer: Bloodhound.tokenizers.whitespace }); datasets.push({ display: 'title', source: engine, templates: { empty: function() { return [ '
  • ', title, '
  • ', '
  • ', window.translations['global-search']['nothing-found'], '
  • ' ].join(''); }, header: function() { return [ '
  • ', title, '
  • ' ].join(''); }, dataset: '