{"size": 1007, "ext": "js", "max_stars_repo_path": "assets/javascripts/moreless/moreless.js", "max_stars_repo_name": "ministryofjustice/iis", "max_stars_repo_stars_event_min_datetime": "2022-03-07T02:03:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T02:03:28.000Z", "max_issues_repo_path": "assets/javascripts/moreless/moreless.js", "max_issues_repo_name": "ministryofjustice/iis", "max_issues_repo_issues_event_min_datetime": "2022-01-24T16:58:24.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-03T11:29:29.000Z", "max_forks_repo_path": "assets/javascripts/moreless/moreless.js", "max_forks_repo_name": "ministryofjustice/iis", "max_forks_repo_forks_event_min_datetime": "2021-04-11T06:42:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-11T06:42:18.000Z"}
{"max_stars_count": 1, "max_issues_count": 2, "max_forks_count": 1, "avg_line_length": 24.5609756098, "max_line_length": 89, "alphanum_fraction": 0.5680238332}
const $ = require('jquery');

const moreLessMarkup = '<li id="moreless" class="font-xsmall"><a>more</a></li>';
const hideableItems = $('#prisonerInfoSummary').children().filter($('.initiallyHidden'));
let moreless;

(() => {
    $('.initiallyHidden').removeClass('initiallyHidden');
    if(hideableItems.length > 0) {
        $('#prisonerInfoSummary').append(moreLessMarkup);
    }
    moreless = ('#moreless a');
    hide();
    $(moreless).on('click', morelessClickHandler);
})();

function morelessClickHandler() {
    if($(moreless).text() === 'more') {
        $(moreless).first().text('less');
        reveal();
        return;
    }
    $(moreless).text('more');
    hide();
}

function hide() {
    $(hideableItems).each((index, item) => {
        $(item).addClass('js-hidden');
        $(item).attr('aria-hidden', 'true');
    });
}

function reveal() {
    $(hideableItems).each((index, item) => {
        $(item).removeClass('js-hidden');
        $(item).attr('aria-hidden', 'false');
    });
}

