/* jslint browser: true, jquery: true, asi: true */
/* globals google: false, Tablesort, DocumentTouch */
(function($) {
  'use strict'


  // Feature detection ////////////////////////////////////

  var reduceMotion = window.matchMedia("(prefers-reduced-motion)").matches

  // Touch: from https://github.com/Modernizr/Modernizr/blob/master/feature-detects/touchevents.js
  if (('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch) {
    $('html').addClass('touch')
  }


  // Animation ////////////////////////////////////////////
  //
  // Appear-on-scroll Animation Support
  //
  // Requires:
  // Animate.css - https://daneden.github.io/animate.css/
  // jquery.appear - https://github.com/bas2k/jquery.appear/
  // jquery.countTo - https://github.com/mhuggins/jquery-countTo/
  //
  // Define animation blocks like so:
  //
  //     <div class="animated" data-animation="fadeInDown" data-delay="1"></div>
  //
  // Count to a number using this inside .animated like this:
  //
  //     <div class="animated counter">
  //       <span class="timer" data-from="0" data-to="4800">4800</span>
  //     </div>
  //
  // The block will animate when it is scrolled into view.
  function disableAnimations() {
    $('.animated').removeClass('animated transparent')
  }

  // Stop animations on small screens, or if disabled, or if user
  // is asking to reduce motion
  if ($(window).width() < 768 || !$('body.animations-on') || reduceMotion) {
    disableAnimations()
  }

  function animate(element, animation) {
    element.addClass(animation + " opaque").removeClass('transparent')
    if (element.hasClass('counter')) {
      element.find('.timer').countTo()
    }
  }

  $('body.animations-on .animated').addClass('transparent').appear(function() {
    var element = $(this)
    var animation = element.data('animation')
    var animationDelay = element.data('delay')

    if (animationDelay) {
      setTimeout(function() {
        animate(element, animation)
      }, animationDelay)
    } else {
      animate(element, animation)
    }
  }, {accY: -150})

  // jQuery for page scrolling feature - requires jQuery Easing plugin
  if (!reduceMotion) {
    $('a.page-scroll').bind('click', function(event) {
      var anchor = $(this)
      $('html, body').stop().animate({
        scrollTop: $(anchor.attr('href')).offset().top - $('.navbar-custom').height() * 1.2
      }, 1000, 'easeInOutExpo')
      event.preventDefault()
    })
  }


  // Add print callbacks //////////////////////////////////
  window.onbeforeprint = function() {
    disableAnimations()
    $('#qrcode:empty').qrcode({width: '64', height: '64', correctLevel: 0, text: window.location.href})
  }
  if (window.matchMedia) {
    window.matchMedia('print').addListener(function(mql) {
      if (mql.matches) {
        window.onbeforeprint()
      }
    })
  }

  // Closes the Responsive Menu on Menu Item Click
  $('.navbar-collapse ul li a').click(function() {
    if ($(this).attr('class') !== 'dropdown-toggle active' &&
        $(this).attr('class') !== 'dropdown-toggle') {
      $('.navbar-toggle:visible').click()
    }
  })


  // Google Maps //////////////////////////////////////////
  if (typeof google !== 'undefined') {
    var map = null
    var mapMarker = null

    // When the window has finished loading create our google map below
    google.maps.event.addDomListener(window, 'load', function() {
      // Get the HTML DOM elements for all maps
      $('.canvas-map').each(function() {
        var mapElement = this

        // Get the marker's lat and long from the DOM
        var mapData = $(mapElement).data()
        mapMarker = new google.maps.LatLng(
          parseFloat(mapData.markerLat || -25.608539),
          parseFloat(mapData.markerLng || 134.361731)
        )

        // Basic options for a simple Google Map
        // For more options see: https://developers.google.com/maps/documentation/javascript/reference#MapOptions
        var mapOptions = {
          zoom: mapData.initialZoom || 6,
          center: mapMarker,
          mapTypeId: mapData.mapTypeId || google.maps.MapTypeId.HYBRID,
          disableDefaultUI: mapData.disableDefaultUI !== false,
          scrollwheel: mapData.scrollwheel !== false,
          draggable: mapData.draggable !== false,
          styles: [
            {featureType: 'poi.business', stylers: [{visibility: 'off'}]}
          ]
        }

        // Create the Google Map using out element and options defined above
        map = new google.maps.Map(mapElement, mapOptions)

        // Save into the window for later
        map._ourMarker = mapMarker
        if (!window.maps) {
          window.maps = {}
        }
        window.maps[mapElement.id] = map

        // Custom Map Marker icon
        var image = mapData.markerUrl || 'https://www.jcu.edu.au/__data/assets/file/0007/285460/marker.svg'  // Mega hack for quick Squiz Matrix URL
        var locationMarker = new google.maps.Marker({
          position: mapMarker,
          map: map,
          icon: image
        })
        locationMarker.addListener('click', function() {
          map.setCenter(mapMarker)
          map.setZoom(mapData.fullZoom || 16)
        })
        google.maps.event.addDomListener(window, 'resize', function() {
          map.setCenter(mapMarker)

          // If loaded in an iframe, wait and recentre
          if (window.frameElement && window.frameElement.nodeName === 'IFRAME') {
            setTimeout(function() { map.setCenter(mapMarker) }, 1000)
          }
        })
      })
    })
  }

  // Table sorting ////////////////////////////////////////
  $('table.table-sortable').each(function () { new Tablesort(this) })


  // Galleries and lightboxes /////////////////////////////
  var magnificConfig = {
    type: 'image',
    image: {
        cursor: null,
        verticalFit: true,
        titleSrc: 'data-mfp-caption'
    },
    gallery: { enabled: true }
  }

  // find every lightboxable image
  var $boxables = $('.link-gallery')

  // boxables inside a "parent" should share a lightbox gallery
  $('.link-gallery-parent').each( function(index, parent) {
    var $children = $(parent).find('.link-gallery') // this parent's boxables
    $children.magnificPopup(magnificConfig) // make a lightbox for them
    $boxables = $boxables.not($children) // remove them from the Big List
  })

  // anything left without a parent goes into "dregs" lightbox gallery
  $boxables.magnificPopup(magnificConfig)


  // Link rewriting ///////////////////////////////////////
  // Retarget external links to specific types of browser-viewable files
  // `i` means case insensitive match
  $('a[href$=".pdf" i]').each(function() {
    // Only rewrite if we don't have a target already
    if (!this.target) {
      this.target = '_blank'
      $(this).append('<small class="icon-opennewwindow m-l-1/4 hidden-print" title="Opens in new window"></small>')
    }
  })

})(jQuery)

@@ -6489,17 +6489,16 @@
 onfig)%0A%0A
-%0A
   // Lin
@@ -6626,46 +6626,8 @@
 les%0A
-  // %60i%60 means case insensitive match%0A
   $(
@@ -6641,18 +6641,32 @@
 $=%22.pdf%22
- i
+%5D,a%5Bhref$=%22.PDF%22
 %5D').each

Fix JS syntax error on IE 11 lacking CSS4 selectors