Difference between revisions of "Widget:GuidelinesList"

From LINKS Community Center
Jump to: navigation, search
 
(5 intermediate revisions by 2 users not shown)
Line 3: Line 3:
 
     <link href="/resources/assets/tabulator/dist/css/tabulator.min.css" rel="stylesheet">
 
     <link href="/resources/assets/tabulator/dist/css/tabulator.min.css" rel="stylesheet">
 
     <script type="text/javascript" src="/resources/assets/tabulator/dist/js/tabulator.min.js"></script>
 
     <script type="text/javascript" src="/resources/assets/tabulator/dist/js/tabulator.min.js"></script>
     <style>
+
      
        #guideline-list-wrapper {
+
  <!-- STYLES BEGIN -->
            font-family: 'Open Sans';
+
<link rel="stylesheet" href="https://www.safetyinnovation.center/lcc/gl_list/styles.css">
            margin-top: 4em;
+
<!-- STYLES END -->
        }
 
 
 
        #guideline-list-wrapper h1,
 
        #guideline-list-wrapper h2,
 
        #guideline-list-wrapper h3,
 
        #guideline-list-wrapper h4 {
 
            font-family: 'Raleway';
 
            font-weight: 300;
 
            letter-spacing: .06em;
 
        }
 
 
 
        #guideline-list-wrapper h1,
 
        #guideline-filters h2 {
 
            color: var(--links-orange);
 
            display: flex;
 
            align-items: center;
 
        }
 
 
 
        #guideline-list-wrapper h1 svg {
 
            height: 2.5em;
 
            width: 2.5em;
 
            fill: var(--links-orange);
 
            margin-right: .5em;
 
        }
 
 
 
        #filter-bar {
 
            position: relative;
 
            margin: 1em 0 2em 0;
 
        }
 
 
 
        #gl-filters {
 
            position: absolute;
 
            top: 0;
 
            right: 0;
 
            z-index: 100;
 
            padding: 2em;
 
            width: 45vw;
 
            background: #fff;
 
            border: 1px solid var(--links-orange);
 
            clip-path: inset(0 0 100% 100%);
 
            box-shadow: -10px 10px 10px 5px rgb(0 0 0 / 10%);
 
            transition: all 400ms ease-in-out;
 
        }
 
 
 
        #gl-filters.open {
 
            clip-path: inset(0 0 -50px -50px);
 
        }
 
 
 
        #close-filter-button {
 
            display: block;
 
            cursor: pointer;
 
            font-size: 2.5em;
 
            line-height: .7em;
 
            margin-top: -.2em;
 
            font-weight: 100;
 
            color: var(--links-orange);
 
        }
 
 
 
        #gl-filters h2 svg {
 
            height: 1.5em;
 
            width: 1.5em;
 
            margin-right: .5em;
 
            margin-left: -.2em;
 
        }
 
 
 
        .large-button {
 
            border: 1px solid var(--links-orange);
 
            font-size: 1.5em;
 
            font-family: 'Open Sans';
 
            font-weight: 100;
 
            margin-bottom: 2em;
 
            padding: 0.3em 0.8em;
 
            color: var(--links-orange);
 
            background: transparent;
 
            font-variant: small-caps;
 
            display: inline-block;
 
            transition: all 200ms ease-in-out;
 
        }
 
 
 
        .large-button:hover {
 
            background-color: var(--links-orange);
 
            color: #fff;
 
        }
 
 
 
        #guidelines-list-wrapper h2 {
 
            margin-bottom: 1em;
 
        }
 
 
 
        .filter-button-wrapper {
 
            margin-bottom: 1em;
 
        }
 
 
 
        .filter-wrapper button {
 
            border: 0 none;
 
            color: var(--links-orange);
 
            background-color: transparent;
 
            font-variant: small-caps;
 
            font-size: 1.2em;
 
            text-decoration: underline;
 
            padding: 0;
 
        }
 
 
 
        .filter-wrapper .filter-container {
 
            display: none;
 
        }
 
 
 
        .filter-wrapper.open .filter-container {
 
            display: block;
 
        }
 
 
 
        .filter-wrapper .filter-toggle {
 
            cursor: pointer;
 
        }
 
 
 
        .filter-wrapper.open .plus.icon::after {
 
            transform: rotate(0);
 
        }
 
 
 
        .filter-content {
 
            font-size: 1.2em;
 
            margin-bottom: 2em;
 
            display: grid;
 
            grid-template-columns: repeat(auto-fit, minmax(14em, 1fr));
 
            align-items: start;
 
        }
 
 
 
        .filter-content.loose {
 
            gap: .5em .5em;
 
        }
 
 
 
        .filter-group-header {
 
            grid-column: 1/-1;
 
            margin-bottom: -.5em;
 
            margin-top: 1em;
 
            font-family: 'Raleway';
 
            font-weight: 200;
 
            letter-spacing: .06em;
 
        }
 
 
 
        .filter-group-start {
 
            grid-column-start: 1;
 
        }
 
 
 
        .filter-content input[type="checkbox"] {
 
            margin-right: .5em;
 
        }
 
 
 
        .filter-content img {
 
            width: 2em;
 
            height: 2em;
 
            margin: 0 .5em 0 0;
 
        }
 
 
 
        .filter-content label {
 
            display: inline;
 
        }
 
 
 
        #guideline-intro {
 
            font-size: larger;
 
            margin-bottom: 4em;
 
        }
 
 
 
        #guideline-intro ul {
 
            font-size: initial;
 
        }
 
 
 
        #guideline-tabulator.tabulator {
 
            border: 0 none;
 
            background-color: transparent;
 
            font-size: 1.2em;
 
        }
 
 
 
        #guideline-tabulator.tabulator .tabulator-header {
 
            background-color: transparent;
 
            border: 0 none;
 
        }
 
 
 
        #guideline-tabulator.tabulator .tabulator-header .tabulator-col {
 
            border-bottom: 4px double var(--links-orange);
 
            border-right: 0 none;
 
            background: transparent;
 
        }
 
 
 
        #guideline-tabulator.tabulator .tabulator-header .tabulator-col-content {
 
            padding: .5em 0;
 
        }
 
 
 
        #guideline-tabulator.tabulator .tabulator-header .tabulator-col-sorter {
 
            right: .5em;
 
        }
 
 
 
        #guideline-tabulator.tabulator .tabulator-row {
 
            background-color: transparent;
 
        }
 
 
 
        #guideline-tabulator.tabulator .tabulator-cell {
 
            border-right: 0 none;
 
            border-top: 1px solid var(--links-orange);
 
            padding: .5em .5em .5em 0;
 
        }
 
 
 
        #guideline-tabulator.tabulator .tabulator-row .tabulator-responsive-collapse {
 
            border: 0 none;
 
            padding: 0 .5em 2em 0;
 
        }
 
 
 
        #filter-summary {
 
            margin-right: 1em;
 
        }
 
 
 
        #filter-summary table tr td {
 
            vertical-align: top;
 
        }
 
 
 
        #filter-summary table tr td:first-of-type {
 
            padding-right: 10px;
 
        }
 
 
 
        #guideline-tabulator.tabulator .tabulator-row .tabulator-responsive-collapse table {
 
            font-size: smaller;
 
        }
 
 
 
        #filter-summary table tr td strong,
 
        #guideline-tabulator.tabulator .tabulator-row .tabulator-responsive-collapse td>strong {
 
            font-weight: 300;
 
        }
 
 
 
        #guideline-tabulator.tabulator .guideline-title a,
 
        #guideline-tabulator.tabulator .tabulator-responsive-collapse table a {
 
            color: var(--links-orange);
 
        }
 
 
 
        /* .data-source-img,
 
        .func-img {
 
            width: 1.2rem;
 
            height: 1.2rem;
 
            margin-right: .4rem;
 
            margin-bottom: .4rem;
 
            filter: grayscale(1);
 
        } */
 
    </style>
 
    <script>
 
        'use strict';
 
 
 
        /**
 
        * @typedef {Object} FilterState
 
        * @property {string[]} phases
 
        * @property {string[]} thematics
 
        * @property {string[]} audienceExperiences
 
        * @property {string[]} audienceTargets
 
        * @property {string[]} languages
 
        * @property {string[]} techs
 
        */
 
 
 
        let table;  // Tabulator instance
 
 
 
        // This defines how sources are grouped in the filter.
 
        // Any source not listed here will be added to the last group entitled "More platforms".
 
        // const sourcesLayout = [
 
        //    {
 
        //        title: 'General',
 
        //        sources: ['Crowd', 'Web']
 
        //    },
 
        //    {
 
        //        title: 'Platforms',
 
        //        sources: ['Facebook', 'Twitter', 'Instagram', 'YouTube']
 
        //    }
 
        // ];
 
 
 
        const PHASES = ["Before", "During", "After"];
 
        const EX_LEVEL = ["Starter", "Intermediate", "Advanced"];
 
  
        // Helpers
+
    <!-- SCRIPT BEGIN -->
        const escapeAttr = text => text ? text.replace(/\W/g, '-') : text;
+
    <script type="text/javascript" src="https://www.safetyinnovation.center/lcc/gl_list/script.js"></script>
        const getFilePath = title => title ? '/index.php/Special:FilePath/' + title : title;
+
    <!-- SCRIPT END -->
        const getQueryUrl = query => '/api.php?action=ask&format=json&query=' + encodeURIComponent(query);
 
        const removePrefix = str => str.substring(str.indexOf(':') + 1);
 
  
        // const DATASRC_PROP = 'Data Sources';
 
        const PHASE_PROP = 'Disaster Management Phase';
 
        const THEME_PROP = 'Covers Thematic';
 
        const LANG_PROP = 'Language';
 
        const YEAR_PROP = 'Year Published';
 
        const EX_PROP = 'Audience Experience Level';
 
        const TA_PROP = 'Target Audience';
 
        const TECH_PROP = 'Technologies'
 
        const PUB_PROP = 'Publishing Organisation';
 
 
        const guidelineQuery = '[[Category:Guideline]]'
 
            // + '|?' + DATASRC_PROP
 
            + '|?' + PHASE_PROP
 
            + '|?' + THEME_PROP
 
            + '|?' + LANG_PROP
 
            + '|?' + YEAR_PROP
 
            + '|?' + EX_PROP
 
            + '|?' + TA_PROP
 
            + '|?' + TECH_PROP
 
            + '|?' + PUB_PROP
 
            + '|limit=500';
 
 
        async function getGuidelines() {
 
            const guidelinesResponse = await fetch(getQueryUrl(guidelineQuery)).then(response => response.json());
 
 
            return Object.keys(guidelinesResponse.query.results).map(title => {
 
                const guidelineResult = guidelinesResponse.query.results[title];
 
 
                /** @type {Guideline} **/
 
                const guideline = {};
 
                guideline.title = title;
 
                guideline.url = guidelineResult.fullurl;
 
                // guideline[DATASRC_PROP] = guidelineResult.printouts[DATASRC_PROP].map(source => source.fulltext).sort();
 
                guideline[PHASE_PROP] = guidelineResult.printouts[PHASE_PROP].map(value => value.fulltext);
 
                guideline[THEME_PROP] = guidelineResult.printouts[THEME_PROP].map(value => value.fulltext);
 
                guideline[LANG_PROP] = guidelineResult.printouts[LANG_PROP].map(value => value.fulltext);
 
                guideline[TA_PROP] = guidelineResult.printouts[TA_PROP].map(value => value.fulltext);
 
                guideline[EX_PROP] = guidelineResult.printouts[EX_PROP].map(value => value.fulltext);
 
                guideline[YEAR_PROP] = guidelineResult.printouts[YEAR_PROP][0] && guidelineResult.printouts[YEAR_PROP][0].raw.slice(-4);
 
                guideline[TECH_PROP] = guidelineResult.printouts[TECH_PROP].map(value => value.fulltext);
 
                guideline[PUB_PROP] = guidelineResult.printouts[PUB_PROP].map(value => value.fulltext);
 
                return guideline;
 
            });
 
        }
 
 
        // Fetches platform / data source information.
 
        // async function getSources() {
 
        //    const IMG_KEY = 'IMAGE';
 
        //    const sourceResponse = await fetch(
 
        //        getQueryUrl('[[Category:Social media platform]]|?' + IMG_KEY)
 
        //    ).then(response => response.json());
 
 
        //    return Object.keys(sourceResponse.query.results).map(platform => {
 
        //        const img = sourceResponse.query.results[platform].printouts[IMG_KEY][0];
 
        //        return {
 
        //            name: platform,
 
        //            image: img ? getFilePath(img.fulltext) : undefined
 
        //        };
 
        //    });
 
        // }
 
 
        function applyFilters(clear) {
 
            if (!table) return;
 
 
            // If clear=true, pass empty object to the filter to disable it.
 
            if (clear) {
 
                table.setFilter(guidelineFilter, {});
 
                return;
 
            }
 
 
            /** @type {FilterState} **/
 
            const filterState = {};
 
 
            const selectedPhases = Array.from(document.querySelectorAll('#phase-filter input[type="checkbox"]:checked'))
 
                .map(checkbox => checkbox.value);
 
            if (selectedPhases.length > 0) filterState.phases = selectedPhases;
 
 
            const selectedThematics = Array.from(document.querySelectorAll('#thematic-filter input[type="checkbox"]:checked'))
 
                .map(checkbox => checkbox.value);
 
            if (selectedThematics.length > 0) filterState.thematics = selectedThematics;
 
 
            const selectedExp = Array.from(document.querySelectorAll('#audience-experience-filter input[type="checkbox"]:checked'))
 
                .map(checkbox => checkbox.value);
 
            if (selectedExp.length > 0) filterState.audienceExperiences = selectedExp;
 
 
            const selectedTA = Array.from(document.querySelectorAll('#target-audience-filter input[type="checkbox"]:checked'))
 
                .map(checkbox => checkbox.value);
 
            if (selectedTA.length > 0) filterState.audienceTargets = selectedTA;
 
 
            const selectedLang = Array.from(document.querySelectorAll('#language-filter input[type="checkbox"]:checked'))
 
                .map(checkbox => checkbox.value);
 
            if (selectedLang.length > 0) filterState.languages = selectedLang;
 
 
            // const selectedSources = Array.from(document.querySelectorAll('#data-source-filter input[type="checkbox"]:checked'))
 
            //    .map(checkbox => checkbox.value);
 
            // if (selectedSources.length > 0) filterState.dataSources = selectedSources;
 
 
            const selectedTech = Array.from(document.querySelectorAll('#tech-filter input[type="checkbox"]:checked'))
 
                .map(checkbox => checkbox.value);
 
            if (selectedTech.length > 0) filterState.techs = selectedTech;
 
 
            table.setFilter(guidelineFilter, filterState);
 
        }
 
 
 
        /**
 
        * @param {Guideline} guideline
 
        * @param {FilterState} filterState
 
        */
 
        function guidelineFilter(guideline, filterState) {
 
            // If filtering property is empty, don't apply the filter (set the check to true).
 
            // Passing an empty object (as with applyFilters(true)) should result in an unfiltered table.
 
            const phaseCheck = filterState.phases
 
                ? filterState.phases.every(phase => guideline[PHASE_PROP].includes(phase))
 
                : true;
 
            const thematicCheck = filterState.thematics
 
                ? filterState.thematics.every(thematic => guideline[THEME_PROP].includes(thematic))
 
                : true;
 
            const audienceExperiencesCheck = filterState.audienceExperiences
 
                ? filterState.audienceExperiences.every(exp => guideline[EX_PROP].includes(exp))
 
                : true;
 
            const audienceTargetCheck = filterState.audienceTargets
 
                ? filterState.audienceTargets.every(target => guideline[TA_PROP].includes(target))
 
                : true;
 
            const langCheck = filterState.languages
 
                ? filterState.languages.every(lang => guideline[LANG_PROP].includes(lang))
 
                : true;
 
            // const sourcesCheck = filterState.dataSources
 
            //    ? filterState.dataSources.every(src => guideline[DATASRC_PROP].includes(src))
 
            //    : true;
 
            const techCheck = filterState.techs
 
                ? filterState.techs.every(tech => guideline[TECH_PROP].includes(tech))
 
                : true;
 
 
            return phaseCheck && thematicCheck && audienceExperiencesCheck && audienceTargetCheck && langCheck && sourcesCheck & techCheck;
 
        }
 
 
        Promise.all([
 
            // getSources(),
 
            getGuidelines()
 
        ]).then(data => {
 
 
            const [
 
                // dataSources,
 
                guidelines
 
            ] = data;
 
 
            let COVERS_THEMATIC_VALUES = []
 
            let LANGUAGES_VALUES = [];
 
            let TARGET_AUDIENCE_VALUES = [];
 
            let EXPERIENCE_LEVEL_VALUES = [];
 
            let YEAR_LEVEL_VALUES = [];
 
            let PHASE_VALUES = [];
 
            let MENTIONS_TECHNOLOGIES_VALUES = [];
 
 
            for (const guideline of guidelines) {
 
 
                LANGUAGES_VALUES = LANGUAGES_VALUES.concat(guideline[LANG_PROP]);
 
                COVERS_THEMATIC_VALUES = COVERS_THEMATIC_VALUES.concat(guideline[THEME_PROP]);
 
                TARGET_AUDIENCE_VALUES = TARGET_AUDIENCE_VALUES.concat(guideline[TA_PROP]);
 
                YEAR_LEVEL_VALUES = YEAR_LEVEL_VALUES.concat(guideline[YEAR_PROP]);
 
                MENTIONS_TECHNOLOGIES_VALUES = MENTIONS_TECHNOLOGIES_VALUES.concat(guideline[TECH_PROP]);
 
            }
 
 
            LANGUAGES_VALUES = LANGUAGES_VALUES.sort();
 
            COVERS_THEMATIC_VALUES = COVERS_THEMATIC_VALUES.sort();
 
            TARGET_AUDIENCE_VALUES = TARGET_AUDIENCE_VALUES.sort();
 
            MENTIONS_TECHNOLOGIES_VALUES = MENTIONS_TECHNOLOGIES_VALUES.sort();
 
 
            LANGUAGES_VALUES = new Set(LANGUAGES_VALUES);
 
            COVERS_THEMATIC_VALUES = new Set(COVERS_THEMATIC_VALUES);
 
            TARGET_AUDIENCE_VALUES = new Set(TARGET_AUDIENCE_VALUES);
 
            YEAR_LEVEL_VALUES = new Set(YEAR_LEVEL_VALUES);
 
            MENTIONS_TECHNOLOGIES_VALUES = new Set(MENTIONS_TECHNOLOGIES_VALUES);
 
            PHASE_VALUES = PHASES;
 
            EXPERIENCE_LEVEL_VALUES = EX_LEVEL;
 
 
            // Set up sources filter
 
            // const groupedSources = [];
 
            // const sourcesCopy = Array.from(dataSources);
 
            // for (const layoutGroup of sourcesLayout) {
 
            //    const group = [];
 
            //    for (const source of layoutGroup.sources) {
 
            //        let idx = sourcesCopy.findIndex(src => src.name === source);
 
            //        if (idx !== -1) { group.push(sourcesCopy.splice(idx, 1)[0]); }
 
            //    }
 
            //    if (group.length > 0) { groupedSources.push({ title: layoutGroup.title, sources: group }); }
 
            // }
 
            // groupedSources.push({ title: 'More platforms', sources: sourcesCopy });
 
 
            // let dataSourceFilterHtml = '';
 
            // groupedSources.forEach(group => {
 
            //    dataSourceFilterHtml += '<div class="filter-group-header">' + group.title + '</div>';
 
            //    dataSourceFilterHtml += group.sources.reduce((acc, curr, idx) => {
 
            //        const identifier = escapeAttr(curr.name);
 
            //        return acc +
 
            //            '<div ' + (idx === 0 ? ' class="filter-group-start">' : '>') +
 
            //            '<input type="checkbox" id="filter-' + identifier + '" value="' + curr.name + '">' +
 
            //            '<label for="filter-' + identifier + '"><img src="' + curr.image + '"> ' + curr.name + '</label></div>'
 
            //    }, '');
 
            // });
 
            // document.getElementById('data-source-filter').innerHTML = dataSourceFilterHtml;
 
 
 
            let languageFilterHtml = Array.from(LANGUAGES_VALUES.values()).reduce((acc, curr) => {
 
                const identifier = escapeAttr(curr);
 
                return acc
 
                    + '<div><input type="checkbox" id="language-filter-' + identifier
 
                    + '" value="' + curr + '">'
 
                    + '<label for="language-filter-' + identifier + '">' + curr + '</label></div>'
 
            }, '');
 
            document.getElementById('language-filter').innerHTML = languageFilterHtml;
 
 
            let coversThematicHtml = Array.from(COVERS_THEMATIC_VALUES.values()).reduce((acc, curr) => {
 
                const identifier = escapeAttr(curr);
 
                return acc
 
                    + '<div><input type="checkbox" id="thematic-filter-' + identifier
 
                    + '" value="' + curr + '">'
 
                    + '<label for="thematic-filter-' + identifier + '">' + curr + '</label></div>'
 
            }, '');
 
            document.getElementById('thematic-filter').innerHTML = coversThematicHtml;
 
 
            let phaseHtml = Array.from(PHASE_VALUES.values()).reduce((acc, curr) => {
 
                const identifier = escapeAttr(curr);
 
                return acc
 
                    + '<div><input type="checkbox" id="phase-filter-' + identifier
 
                    + '" value="' + curr + '">'
 
                    + '<label for="phase-filter-' + identifier + '">' + curr + '</label></div>'
 
            }, '');
 
            document.getElementById('phase-filter').innerHTML = phaseHtml;
 
 
            let targetAudienceHtml = Array.from(TARGET_AUDIENCE_VALUES.values()).reduce((acc, curr) => {
 
                const identifier = escapeAttr(curr);
 
                return acc
 
                    + '<div><input type="checkbox" id="target-audience-filter-' + identifier
 
                    + '" value="' + curr + '">'
 
                    + '<label for="target-audience-filter-' + identifier + '">' + curr + '</label></div>'
 
            }, '');
 
            document.getElementById('target-audience-filter').innerHTML = targetAudienceHtml;
 
 
            let targetAudienceExperienceHtml = Array.from(EXPERIENCE_LEVEL_VALUES.values()).reduce((acc, curr) => {
 
                const identifier = escapeAttr(curr);
 
                return acc
 
                    + '<div><input type="checkbox" id="audience-experience-filter-' + identifier
 
                    + '" value="' + curr + '">'
 
                    + '<label for="audience-experience-filter-' + identifier + '">' + curr + '</label></div>'
 
            }, '');
 
            document.getElementById('audience-experience-filter').innerHTML = targetAudienceExperienceHtml;
 
         
 
            let techHtml = Array.from(MENTIONS_TECHNOLOGIES_VALUES.values()).reduce((acc, curr) => {
 
                const identifier = escapeAttr(curr);
 
                return acc
 
                    + '<div><input type="checkbox" id="tech-filter-' + identifier
 
                    + '" value="' + curr + '">'
 
                    + '<label for="tech-filter-' + identifier + '">' + curr + '</label></div>'
 
            }, '');
 
            document.getElementById('tech-filter').innerHTML = techHtml;
 
 
            const tabulator = new Tabulator('#guideline-tabulator', {
 
                data: guidelines,
 
                layout: 'fitDataFill',
 
                responsiveLayout: 'collapse',
 
                columns: [
 
                    {
 
                        title: 'Title',
 
                        field: 'title',
 
                        cssClass: 'guideline-title',
 
                        formatter: cell => '<a href="' + cell.getData().url + '">' + cell.getValue() + '</a>'
 
                    },
 
                    {
 
                        title: 'Year',
 
                        field: YEAR_PROP
 
                    },
 
                    {
 
                        title: 'Publishing Organisation',
 
                        field: PUB_PROP,
 
                        formatter: cell => cell.getValue().join(', ')
 
                    },
 
                    {
 
                        title: 'Language',
 
                        field: LANG_PROP,
 
                        formatter: cell => cell.getValue().join(', ')
 
                    },
 
                    {
 
                        title: 'Audience Experience Level',
 
                        field: EX_PROP,
 
                        formatter: cell => cell.getValue().join(', ')
 
                    },
 
                    {
 
                        title: 'Covers Thematic',
 
                        field: THEME_PROP,
 
                        formatter: cell => cell.getValue().join(', ')
 
                    },
 
                    {
 
                        title: 'Target Audience',
 
                        field: TA_PROP,
 
                        formatter: cell => cell.getValue().join(', ')
 
                    },
 
                    {
 
                        title: 'Disaster Management Phase',
 
                        field: PHASE_PROP,
 
                        formatter: cell => cell.getValue().join(', ')
 
                    },
 
                    {
 
                        title: 'Mentions Technologies',
 
                        field: TECH_PROP,
 
                        formatter: cell => cell.getValue().join(', ') || '&mdash;'
 
                    },
 
                    // {
 
                    //    title: 'Mentions Platforms',
 
                    //    field: DATASRC_PROP,
 
                    //    minWidth: 300, // required for responsiveness when using fitColumns
 
                    //    cssClass: 'data-sources-cell',
 
                    //    formatter: function (cell) {
 
                    //        const val = cell.getValue();
 
                    //        let out = '';
 
 
                    //        groupedSources.forEach((group, gIndex) => {
 
                    //            // if (gIndex === groupedSources.length - 1) { out += '<div class="sources-collapse">'; }
 
                    //            out += group.sources.reduce((prev, curr) => {
 
                    //                const idx = val.findIndex(src => src === curr.name);
 
                    //                if (idx === -1) {
 
                    //                    return prev;
 
                    //                } else {
 
                    //                    return curr.image
 
                    //                        ? prev + '<img class="data-source-img" data-value="' + curr.name
 
                    //                        + '" src="' + curr.image
 
                    //                        + '" alt="' + curr.name
 
                    //                        + '" title="' + curr.name + '">'
 
                    //                        : prev + ' ' + curr.name;
 
                    //                }
 
                    //            }, '');
 
                    //            if (gIndex === groupedSources.length - 1) {
 
                    //                // out += '<span class="sources-collapse-toggle"></span>';
 
                    //                // out += '</div>';
 
                    //            }
 
                    //        });
 
 
                    //        if (!out) { out = '&mdash;' }
 
 
                    //        return '<div>' + out + '</div>';
 
                    //    }
 
                    // }
 
                ],
 
                initialSort: [
 
                    { column: 'title', dir: 'asc' }
 
                ]
 
            });
 
 
            tabulator.on('tableBuilt', () => {
 
                tabulator.redraw(true);
 
                table = tabulator;
 
 
                // Set up the table if parameter was passed.
 
                const params = new URLSearchParams(window.location.search);
 
                const encoded = params.get('do');
 
 
                if (encoded) {
 
                    const actions = JSON.parse(decodeURIComponent(atob(encoded)));
 
                    const filter = actions.filter;
 
 
                    if (filter) {
 
                        const thematic = filter[THEME_PROP];
 
                        if (thematic) {
 
                            Object.keys(thematic).forEach(theme => {
 
                                const box = document.getElementById('thematic-filter-' + escapeAttr(theme));
 
                                box.checked = !!thematic[theme];
 
                                box.dispatchEvent(new Event('change', { bubbles: true }));
 
                            });
 
 
                            document.getElementById('thematic-filter').closest('.filter-wrapper').classList.toggle('open');
 
                        }
 
 
                        const audience = filter[TA_PROP];
 
                        if (audience) {
 
                            Object.keys(audience).forEach(ta => {
 
                                const box = document.getElementById('target-audience-filter-' + escapeAttr(ta));
 
                                box.checked = !!audience[ta];
 
                                box.dispatchEvent(new Event('change', { bubbles: true }));
 
                            });
 
 
                            document.getElementById('target-audience-filter').closest('.filter-wrapper').classList.toggle('open');
 
                        }
 
 
                        applyFilters();
 
                        toggleFilter();
 
                    }
 
 
                    // Further actions (e.g. open filter panel, etc.)
 
                    // ...
 
                }
 
            });
 
 
            tabulator.on('dataFiltered', (filters, rows) => {
 
                const summary = document.getElementById('filter-summary');
 
 
                /** @type {FilterState}  **/
 
 
                const filter = filters[0];
 
 
                // Set result counter
 
                document.getElementById('result-count').textContent = rows.length;
 
 
                // Exit if filter object/type doesn't exist (happens after Tabulator's own filter reset).
 
                if (!(filter && filter.type)) { summary.textContent = 'No filter. Showing all results.'; return; }
 
 
                // Update filter text.
 
                if (
 
                    !filter.type.thematics &&
 
                    !filter.type.languages &&
 
                    !filter.type.phases &&
 
                    !filter.type.audienceTargets &&
 
                    !filter.type.audienceExperiences &&
 
                    // !filter.type.dataSources &&
 
                    !filter.type.techs
 
                ) { summary.textContent = 'No filter. Showing all results.'; }
 
                else {
 
                    let summaryHtml = '<table>';
 
                    if (filter.type.thematics) {
 
                        summaryHtml += '<tr><td><strong>Covers Thematic</strong></td><td>'
 
                            + (filter.type.thematics.length > 0 ? filter.type.thematics.join(', ') : 'none')
 
                            + '</td></tr>';
 
                    }
 
                    if (filter.type.languages) {
 
                        summaryHtml += '<tr><td><strong>Language</strong></td><td>'
 
                            + (filter.type.languages.length > 0 ? filter.type.languages.join(', ') : 'none')
 
                            + '</td></tr>';
 
                    }
 
                    if (filter.type.phases) {
 
                        summaryHtml += '<tr><td><strong>Disaster Management Phase</strong></td><td>'
 
                            + (filter.type.phases.length > 0 ? filter.type.phases.join(', ') : 'none')
 
                            + '</td></tr>';
 
                    }
 
                    if (filter.type.audienceTargets) {
 
                        summaryHtml += '<tr><td><strong>Target audience</strong></td><td>'
 
                            + (filter.type.audienceTargets.length > 0 ? filter.type.audienceTargets.join(', ') : 'none')
 
                            + '</td></tr>';
 
                    }
 
                    if (filter.type.audienceExperiences) {
 
                        summaryHtml += '<tr><td><strong>Audience experience level</strong></td><td>'
 
                            + (filter.type.audienceExperiences.length > 0 ? filter.type.audienceExperiences.join(', ') : 'none')
 
                            + '</td></tr>';
 
                    }
 
                    // if (filter.type.dataSources) {
 
                    //    summaryHtml += '<tr><td><strong>Mentions Platforms</strong></td><td>'
 
                    //        + (filter.type.dataSources.length > 0 ? filter.type.dataSources.join(', ') : 'none')
 
                    //        + '</td></tr>';
 
                    // }
 
                    if (filter.type.techs) {
 
                        summaryHtml += '<tr><td><strong>Mentions Technologies</strong></td><td>'
 
                            + (filter.type.techs.length > 0 ? filter.type.techs.join(', ') : 'none')
 
                            + '</td></tr>';
 
                    }
 
                    summaryHtml += '</table>';
 
                    summary.innerHTML = summaryHtml;
 
                }
 
 
                // const markImages = () => {
 
                //    const selectedSources = filter.type.dataSources;
 
                //    const selectedFunctions = filter.type.functions;
 
 
                //    // Mark data source images
 
                //    document.querySelectorAll('.data-sources-cell .data-source-img, .tabulator-responsive-collapse .data-source-img')
 
                //        .forEach(img => {
 
                //            if (!selectedSources || selectedSources.includes(img.dataset.value)) { img.classList.remove('unselected'); }
 
                //            else { img.classList.add('unselected'); }
 
                //        });
 
 
                //    // Mark functions images
 
                //    document.querySelectorAll('.functions-cell .func-img').forEach(img => {
 
                //        if (!selectedFunctions || selectedFunctions.includes(img.dataset.value)) { img.classList.remove('unselected'); }
 
                //        else { img.classList.add('unselected'); }
 
                //    });
 
 
                //    tabulator.off('renderComplete', markImages);
 
                // }
 
                // // TODO: Prevent this from running if corresponding filters are not active.
 
                // tabulator.on('renderComplete', markImages);
 
            });
 
 
            // Listen for changes in filter checkbox state.
 
            document.getElementById('thematic-filter').addEventListener('change', event => {
 
                applyFilters();
 
            }, { passive: true });
 
            document.getElementById('audience-experience-filter').addEventListener('change', event => {
 
                applyFilters();
 
            }, { passive: true });
 
            document.getElementById('language-filter').addEventListener('change', event => {
 
                applyFilters();
 
            }, { passive: true });
 
            document.getElementById('phase-filter').addEventListener('change', event => {
 
                applyFilters();
 
            }, { passive: true });
 
            document.getElementById('target-audience-filter').addEventListener('change', event => {
 
                applyFilters();
 
            }, { passive: true });
 
            // document.getElementById('data-source-filter').addEventListener('change', event => {
 
            //    applyFilters();
 
            // }, { passive: true });
 
            document.getElementById('tech-filter').addEventListener('change', event => {
 
                applyFilters();
 
            }, { passive: true });
 
 
            // Listen for clicks on filter toggles
 
            document.querySelectorAll('.filter-wrapper .filter-toggle').forEach(el => {
 
                const wrapper = el.closest('.filter-wrapper');
 
                el.addEventListener('click', event => void wrapper.classList.toggle('open'));
 
            });
 
 
            // Close filter pane when clicked outside of it.
 
            document.body.addEventListener('click', event => {
 
                const filterPane = document.getElementById('gl-filters');
 
                if (
 
                    filterPane.classList.contains('open') &&
 
                    !filterPane.contains(event.target) &&
 
                    event.target !== document.querySelector('#filter-bar .large-button')
 
                ) { filterPane.classList.remove('open'); }
 
            }, { passive: true });
 
 
            // Fix bug where the table is truncated to zero height despite having visible rows.
 
            tabulator.on('renderComplete', function () {
 
                // TODO: Check the bugfix for a possible infinite event loop.
 
                // This will help detect it, in case it happens.
 
                // console.log('Table height bugfix: render complete.');
 
 
                try {
 
                    const holderHeight = tabulator.rowManager.element.offsetHeight;
 
                    const tableHeight = tabulator.rowManager.tableElement.offsetHeight;
 
                    if (
 
                        holderHeight < tableHeight ||                          // table is truncated vertically (including zero-height)
 
                        holderHeight - tableHeight > window.screen.availHeight  // table is more than a screen longer than content
 
                    ) {
 
                        tabulator.redraw();
 
                    }
 
                } catch (ignore) { }
 
            });
 
            // End bugfix
 
        });
 
 
        function selectAll(context) {
 
            document.querySelectorAll(context + ' input[type="checkbox"]').forEach(checkbox => checkbox.checked = true);
 
            applyFilters();
 
        }
 
 
        function deselectAll(context) {
 
            document.querySelectorAll(context + ' input[type="checkbox"]').forEach(checkbox => checkbox.checked = false);
 
            applyFilters();
 
        }
 
 
        function clearFilters() {
 
            document.querySelectorAll('#gl-filters input[type="checkbox"]').forEach(checkbox => checkbox.checked = checkbox.defaultChecked);
 
            applyFilters(true);
 
        }
 
 
        function toggleFilter() {
 
            document.getElementById('gl-filters').classList.toggle('open');
 
        }
 
    </script>
 
 
     <!-- Icon definitons -->
 
     <!-- Icon definitons -->
     <svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" overflow="hidden" style="display:none;">
+
     <img src="https://www.safetyinnovation.center/lcc/gl_list/img/unknown.svg">
        <defs>
 
            <symbol id="chevron-down" viewBox="0 0 96 96">
 
                <clipPath id="chev">
 
                    <path d="M592 312h96v96h-96z" />
 
                </clipPath>
 
                <g clip-path="url(#chev)" transform="translate(-592 -312)">
 
                    <path
 
                        d="m640 370.586-25.293-25.293-1.414 1.414L640 373.414l26.707-26.707-1.414-1.414L640 370.586Z" />
 
                </g>
 
            </symbol>
 
        </defs>
 
    </svg>
 
  
 
     <div id="guideline-list-wrapper">
 
     <div id="guideline-list-wrapper">
 
         <h1>
 
         <h1>
             <svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" overflow="hidden" viewBox="0 0 96 96">
+
             <img src="https://www.safetyinnovation.center/lcc/gl_list/img/filters.svg">
                <defs>
 
                    <clipPath id="tit">
 
                        <path d="M65 455h96v96H65z" />
 
                    </clipPath>
 
                </defs>
 
                <g clip-path="url(#tit)" transform="translate(-65 -455)">
 
                    <path
 
                        d="M138 463H84v79.961h54a5.014 5.014 0 0 0 5.019-5V468a5.014 5.014 0 0 0-5.019-5Zm-52 2h6.261v75.961H86Zm55.019 72.963a3.012 3.012 0 0 1-3.019 3H94.261V465H138a3.013 3.013 0 0 1 3.019 3Z" />
 
                    <path d="M104 489h28v2h-28ZM110 500h16v2h-16Z" />
 
                </g>
 
            </svg>
 
 
             <div>
 
             <div>
 
                 <div>Guidelines</div>
 
                 <div>Guidelines</div>
Line 884: Line 30:
 
             </p>
 
             </p>
 
             <ul>
 
             <ul>
                 <li>Building a communication strategy for social media and consideration of the main elements (e.g.
+
                 <li>Building a communication strategy for social media and consideration of the main elements (e.g. needed roles for the team)</li>
                    needed roles for the team)</li>
 
 
                 <li>Set up and evaluate social media activities</li>
 
                 <li>Set up and evaluate social media activities</li>
 
                 <li>Recommended actions on social media before, during and after a crisis</li>
 
                 <li>Recommended actions on social media before, during and after a crisis</li>
Line 895: Line 40:
 
             </ul>
 
             </ul>
 
         </div>
 
         </div>
   
 
 
      
 
      
 
         <!-- FILTERS -->
 
         <!-- FILTERS -->
Line 915: Line 59:
 
      
 
      
 
             <div id="gl-filters">
 
             <div id="gl-filters">
 +
 
                 <h2 style="display: flex; justify-content: space-between;">
 
                 <h2 style="display: flex; justify-content: space-between;">
 
                     <div>
 
                     <div>
                         <svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" overflow="hidden" viewBox="0 0 96 96">
+
                         <img src="https://www.safetyinnovation.center/lcc/gl_list/img/2-gl.svg">
                            <defs>
 
                                <clipPath id="b">
 
                                    <path d="M592 312h96v96h-96z" />
 
                                </clipPath>
 
                            </defs>
 
                            <g clip-path="url(#b)" transform="translate(-592 -312)">
 
                                <path
 
                                    d="M636 356.012v38.011l8-8v-30.011L674 326h-68Zm6.588-1.412-.588.584v30.008l-4 4v-34.008l-.585-.586L610.828 328h58.348Z" />
 
                            </g>
 
                        </svg>
 
 
                         <span>Filters</span>
 
                         <span>Filters</span>
 
                     </div>
 
                     </div>
Line 935: Line 70:
 
                     <button class="large-button" type="button" onclick="clearFilters()">Clear Filters</button>
 
                     <button class="large-button" type="button" onclick="clearFilters()">Clear Filters</button>
 
                 </div>
 
                 </div>
 +
 
                 <div class="filter-wrapper">
 
                 <div class="filter-wrapper">
 
                     <h4 class="filter-toggle">Covers Thematic <div class="plus icon"></div></h4>
 
                     <h4 class="filter-toggle">Covers Thematic <div class="plus icon"></div></h4>
Line 945: Line 81:
 
                     </div>
 
                     </div>
 
                 </div>
 
                 </div>
 +
 
                 <div class="filter-wrapper">
 
                 <div class="filter-wrapper">
 
                     <h4 class="filter-toggle">Language <div class="plus icon"></div></h4>
 
                     <h4 class="filter-toggle">Language <div class="plus icon"></div></h4>
Line 955: Line 92:
 
                     </div>
 
                     </div>
 
                 </div>
 
                 </div>
 +
 
                 <div class="filter-wrapper">
 
                 <div class="filter-wrapper">
 
                     <h4 class="filter-toggle">Disaster Management Phase <div class="plus icon"></div></h4>
 
                     <h4 class="filter-toggle">Disaster Management Phase <div class="plus icon"></div></h4>
Line 965: Line 103:
 
                     </div>
 
                     </div>
 
                 </div>
 
                 </div>
 +
 
                 <div class="filter-wrapper">
 
                 <div class="filter-wrapper">
 
                     <h4 class="filter-toggle">Target Audience <div class="plus icon"></div></h4>
 
                     <h4 class="filter-toggle">Target Audience <div class="plus icon"></div></h4>
Line 975: Line 114:
 
                     </div>
 
                     </div>
 
                 </div>
 
                 </div>
 +
 
                 <div class="filter-wrapper">
 
                 <div class="filter-wrapper">
 
                     <h4 class="filter-toggle">Audience Experience Level <div class="plus icon"></div></h4>
 
                     <h4 class="filter-toggle">Audience Experience Level <div class="plus icon"></div></h4>
Line 985: Line 125:
 
                     </div>
 
                     </div>
 
                 </div>
 
                 </div>
 +
 
                 <!-- <div class="filter-wrapper">
 
                 <!-- <div class="filter-wrapper">
 
                     <h4 class="filter-toggle">Mentions Platforms <div class="plus icon"></div></h4>
 
                     <h4 class="filter-toggle">Mentions Platforms <div class="plus icon"></div></h4>
Line 995: Line 136:
 
                     </div>
 
                     </div>
 
                 </div> -->
 
                 </div> -->
 +
 
                 <div class="filter-wrapper">
 
                 <div class="filter-wrapper">
 
                     <h4 class="filter-toggle">Mentions Technologies <div class="plus icon"></div></h4>
 
                     <h4 class="filter-toggle">Mentions Technologies <div class="plus icon"></div></h4>
Line 1,005: Line 147:
 
                     </div>
 
                     </div>
 
                 </div>
 
                 </div>
 +
 
             </div>
 
             </div>
 
         </div>
 
         </div>

Latest revision as of 23:30, 10 May 2024

Current version of the List of Guidelines.
Currently in use – do not modify!