/*global jQuery*/ /** * ohs-reps * Global JS * * version: 0.0.1 * file: global.js * author: Squiz Australia * change log: * 13-01-2016 20:05 - First revision */ /* * Table of Contents * * - Global * - Modules * search-bar * datatables (0.1.3) * matrix-form (0.1.3) * navbar (1.0.0-beta2) * quick-search (0.1.2) * responsive-tables (0.0.3) * slick (0.0.2) * Renata Form */ 'use strict'; /* -------------------- Global -------------------- */ // Declare JS Enabled. $('body').removeClass('no-js').addClass('js-enabled'); (function ($) { //Script for Mobile Search Button $('.quick-search__input, .quick-search__submit').hide(); // Hide when we first load. $('.quick-search__toggle').on('click', function(clickEvent) { $('.quick-search__input').focus(); $('.header__search').toggleClass('expanded'); $('.quick-search__input, .quick-search__submit').toggle(300).promise().done(function() { $('.quick-search__input').focus(); }); }); //Script for Mobile Navigation Button // $('.navigation').hide(); $('.navbar__toggle').on('click', function(){ if ($('.navbar__dropdown').is(':hidden')) { $('.navbar__dropdown').attr('aria-expanded', 'true'); } else { $('.navbar__dropdown').attr('aria-expanded','false'); $('.navbar__item').removeClass('is-expanded'); } }); //Script for Mobile Navigation Button //$('.navigation').hide(); //$('.togglenav').on('click', function(){ // $('.navigation').slideToggle(); //}) }(jQuery)); /* -------------------- Modules -------------------- */ /*-- module:search-bar --*/ (function ($) { 'use strict'; var $searchInput = $('#search-bar__query'); // Mimick placeholder support where it is not available. // Credit: http://webdesignerwall.com/tutorials/cross-browser-html5-placeholder-text if(!Modernizr.input.placeholder && $searchInput.attr('placeholder') !== '') { $searchInput.focus(function () { var input = $(this); if (input.val() === input.attr('placeholder')) { input.val(''); input.removeClass('placeholder'); } }).blur(function () { var input = $(this); if (input.val() === '' || input.val() === input.attr('placeholder')) { input.addClass('placeholder'); input.val(input.attr('placeholder')); } }).blur(); $searchInput.parents('form').submit(function () { $(this).find('[placeholder]').each(function () { var input = $(this); if (input.val() === input.attr('placeholder')) { input.val(''); } }); }); }//end if }(jQuery)); /*-- module:squiz-module-datatables --*/ (function($){ // Data table with only sorting enabled $('table.table-sortable').dataTable({ 'bPaginate': false, 'bLengthChange': false, 'bFilter': false, 'bSort': true, 'bInfo': false, 'bAutoWidth': false }); }(jQuery)); /*-- module:squiz-module-matrix-form --*/ (function($){ var getContainerForInput = function (elem) { var $container = $(elem).parents('.sq-form-question'); return $container; }; var options = { errorClass: 'sq-form-error', errorPlacement: function (error, element) { var $container = $(element).parents('.sq-form-question-answer'); if ($(element).attr('id') === 'recaptcha_response_field') { error.insertAfter(element); } else { $container.append(error); } }, // fn((element, errorClass, validClass)) highlight: function (element) { getContainerForInput(element).addClass('sq-form-question-error'); }, // fn element, errorClass, validClass) unhighlight: function (element) { getContainerForInput(element).removeClass('sq-form-question-error'); } }; $('.sq-form').validate(options); }(jQuery)); /*-- module:squiz-module-navbar --*/ /*eslint no-console: 0, new-cap: 0*/ (function($){ // Match this with the breakpoint at which the screen transforms // from smaller size to medium size var minMq = '(min-width: 1152px)'; var $body = $('body'); var $nav = $('#navbar__dropdown'); function expandLink(evt) { var $li = $(this).parent(); if (!$li.hasClass('is-expanded')) { $li.addClass('is-expanded'); evt.preventDefault(); } // else just follow the link. } // Load the menu function loadMenu() { var isCurrent = $nav.find('.navbar__item--current .sub-nav').length !== 0; $nav.NavBar({ onState: function($item, active) { if (isCurrent) { return; } if ($item.find('.sub-nav').length && active) { $body.addClass('is-nav-active'); } else { $body.removeClass('is-nav-active'); } } }); if (isCurrent) { $body.addClass('is-nav-active'); } } window.matchMedia(minMq).addListener(function(mql) { // Emoty console statement needed to ensure FF always runs this console.log(''); if (mql.matches) { loadMenu(); $body.off('click', '.navbar__item > a'); } else { $nav.NavBar('destroy'); $body.on('click', '.navbar__item > a', expandLink); } }); if (window.matchMedia(minMq).matches) { loadMenu(); } else { $body.on('click', '.navbar__item > a', expandLink); } }(jQuery)); /*-- module:squiz-module-quick-search --*/ (function ($) { var $searchInput = $('#quick-search__query'); // Mimick placeholder support where it is not available. // Credit: http://webdesignerwall.com/tutorials/cross-browser-html5-placeholder-text if(!Modernizr.input.placeholder && $searchInput.attr('placeholder') !== '') { $searchInput.focus(function () { var input = $(this); if (input.val() === input.attr('placeholder')) { input.val(''); input.removeClass('placeholder'); } }).blur(function () { var input = $(this); if (input.val() === '' || input.val() === input.attr('placeholder')) { input.addClass('placeholder'); input.val(input.attr('placeholder')); } }).blur(); $searchInput.parents('form').submit(function () { $(this).find('[placeholder]').each(function () { var input = $(this); if (input.val() === input.attr('placeholder')) { input.val(''); } }); }); }//end if }(jQuery)); /*-- module:squiz-module-responsive-tables --*/ (function($){ $('.responsive-table').each(function() { var headings = $('th', this).map(function(){ return $(this).text(); }); $('tr', this).each(function(){ var $row = $(this); $.each(headings, function(i, heading) { $('td:eq(' + i + ')', $row).attr('data-th', heading); }); }); }); }(jQuery)); /*-- module:squiz-module-slick --*/ (function($){ var $slideshow = $('.slick-slideshow--hero'); $slideshow.slick({ autoplay: true, autoplaySpeed: 5000, dots: true, arrows: true, speed: 400, slide: '.slick-slideshow__slide', slidesToShow: 1 }); }(jQuery)); (function($){ var $slideshow = $('.slick-slideshow__event-topic'); $slideshow.slick({ dots: true, arrows: true, speed: 400, slide: '.slick-slideshow__slide', slidesToShow: 3, responsive: [ { breakpoint: 600, settings: { dots: true, arrows: true, speed: 400, slide: '.slick-slideshow__slide', slidesToShow: 1 } } ] }); }(jQuery)); /*-- module:renata-form --*/ (function($){ 'use strict'; var renataForm = { form: $('form#form_email_181632'), areYou: $('#q181632_q16'), otherPosition: $('#q181632_q19'), issueInquiry: $('#q181632_q15'), otherInquiry: $('#q181632_q18'), unionMemberNo: $('#q181632_q11_1'), whichUnion: $('#q181632_q14'), otherUnion: $('#q181632_q12'), init: function(){ var _this = this; this.hideQuestion(this.otherPosition); this.hideQuestion(this.otherInquiry); this.hideQuestion(this.otherUnion); this.form.on('change', this.changeHandler.bind(_this)); }, hideQuestion: function(input) { input.parents('.sq-form-question').hide(); }, showQuestion: function(input) { input.parents('.sq-form-question').show(); }, changeHandler: function() { this.position(); this.inquiry(); this.unionMember(); }, unionMember: function(){ this.unionMemberNo.is(':checked') ? this.hideQuestion(this.whichUnion) : this.showQuestion(this.whichUnion); if (this.whichUnion.val() === 'Other' && !this.unionMemberNo.is(':checked')) { this.showQuestion(this.otherUnion); } else { this.hideQuestion(this.otherUnion); } }, inquiry: function() { this.issueInquiry.val() === 'Other' ? this.showQuestion(this.otherInquiry) : this.hideQuestion(this.otherInquiry); }, position: function() { this.areYou.val() === 'Other' ? this.showQuestion(this.otherPosition) : this.hideQuestion(this.otherPosition); } }; renataForm.init(); }(jQuery));