Source: components/search/_course-results.js

'use strict';

/**
 * Course search setup and control scripts.
 * @namespace search
 * @memberof UCASDesignFramework
 * @param {object} global - UCASDesignFramework object.
 * @param {object} _u - UCASUtilities object.
 */
(function (global, _u) {
  // Create namespace for public methods.
  global.search = {}
  var searchFiltersTitle
  var mapView

  /**
   * Initialise plugin.
   * @function init
   * @memberof! UCASDesignFramework.search
   * @public
   */
  function init () {
    // The only way we can find out which view we're on
    // is to search for a hidden input called CurrentView.
    var currentView = document.getElementsByName('CurrentView')
    mapView = (currentView[0] && currentView[0].value === 'Map')
    if (mapView) {
      // We use this to control how the map page responds at different sizes.
      document.body.setAttribute('data-search-current-view', 'Map')
    }

    searchFiltersTitle = document.getElementById('search-filters__title')
    if (searchFiltersTitle) {
      searchFiltersTitle.classList.add('hidden--to-medium')
    }

    // We want to set something when the user focuses on the search input
    // so we can hide the fixed-position advert on small screens
    // as it can obscure the search input on Android devices.
    var searchInput = document.getElementById('SearchText')
    if (searchInput) {
      searchInput.addEventListener('focus', function () { document.body.setAttribute('data-searchinputfocus', '') })
      searchInput.addEventListener('blur', function () { document.body.removeAttribute('data-searchinputfocus') })
    }
  }

  /**
   * Assign public methods.
   */
  global.search = {
    init: init
  }
})(UCASDesignFramework, UCASUtilities)