$(document).ready(function() {
  $('.print-link a').attr('target', '_blank');

  var $searchFocus = $('.js-search-focus');
  $searchFocus.each(function(i, el){
    if($(el).val() !== ''){
      $(el).addClass('focus');
    }
  });
  $searchFocus.on('focus', function(e){
    $(e.target).addClass('focus');
  });
  $searchFocus.on('blur', function(e){
    if($(e.target).val() === ''){
      $(e.target).removeClass('focus');
    }
  });

  if (window.GOVUK) {
    if (GOVUK.userSatisfaction){
      var currentURL = window.location.pathname;

      function stringContains(str, substr) {
        return str.indexOf(substr) > -1;
      }

      // We don't want the satisfaction survey appearing for users who
      // have completed a transaction as they may complete the survey with
      // the department's transaction in mind as opposed to the GOV.UK content.
      if (!stringContains(currentURL, "/done") &&
          !stringContains(currentURL, "/transaction-finished") &&
          !stringContains(currentURL, "/driving-transaction-finished")) {
        GOVUK.userSatisfaction.randomlyShowSurveyBar();
      }
    }
  }

  // for radio buttons and checkboxes
  var $buttons = $("label.selectable input[type='radio'], label.selectable input[type='checkbox']");
  new GOVUK.SelectionButtons($buttons);
});



$(document).ready(function() {
  $('.print-link a').attr('target', '_blank');

  var $searchFocus = $('.js-search-focus');
  $searchFocus.each(function(i, el){
    if($(el).val() !== ''){
      $(el).addClass('focus');
    }
  });
  $searchFocus.on('focus', function(e){
    $(e.target).addClass('focus');
  });
  $searchFocus.on('blur', function(e){
    if($(e.target).val() === ''){
      $(e.target).removeClass('focus');
    }
  });

  if (window.GOVUK) {
    if (GOVUK.userSatisfaction){
      var currentURL = window.location.pathname;

      function stringContains(str, substr) {
        return str.indexOf(substr) > -1;
      }

      // We don't want the satisfaction survey appearing for users who
      // have completed a transaction as they may complete the survey with
      // the department's transaction in mind as opposed to the GOV.UK content.
      if (!stringContains(currentURL, "/done") &&
          !stringContains(currentURL, "/transaction-finished") &&
          !stringContains(currentURL, "/driving-transaction-finished")) {
        GOVUK.userSatisfaction.randomlyShowSurveyBar();
      }
    }
  }

  // for radio buttons and checkboxes
  var buttonsSelector = "label.selectable input[type='radio'], label.selectable input[type='checkbox']";
  new GOVUK.SelectionButtons(buttonsSelector);
});



Use SelectionButtons live selector, for JS/AJAX content
Use SelectionButtons live selector, for JS/AJAX content

Some GOV.UK pages, like Smart Answers, load content via JS, including
radio buttons or checkboxes. These will be added to the DOM after the
selector is run and the resulting elements are passed to SelectionButtons

SelectionButtons can also take a string selector and use document
events (https://github.com/alphagov/govuk_frontend_toolkit/pull/139/)
so use that and any JS loaded content  will get the behaviour too.
