Birgitta of Sweden

Technologies

Omeka S

Data model

Fuseki

CI/CD

Networks

and digital editions

'use strict'
"use strict"

$(function(){

    createAccordion();
    removePrintTypeHref();
    
    let includedWorks = $(".property:contains('Included works')")

    // Check if item has included works 
    if (includedWorks.length) {
        let includedWorksIDs = getIncludedItemIDs();
        getIncludedItemValues(includedWorksIDs);
    } else {
        return;
    }
    
    // If yes, get item id of included objects
    function getIncludedItemIDs() {
        
        let links = []
        let IDs = []

        // Only get ids of direct descendants of includedWorks
        links.push(includedWorks.find('.items a'))
        
        for (let i = 0; i < links[0].length; i++) {
            IDs.push(links[0][i].href.match(/([\d]+)/g))
        }
        return IDs
    }

    function getIncludedItemValues(includedWorksIDs) {

        // Each included work has a lot of properties, many of which we are not interested in. These are the relevant ones.
        let relevantProperties = [
            'schema:isPartOf',
            'schema:position',
            'bdm2:hand',
            'schema:author',
            'schema:position', 
            'schema:productionDate',
            'schema:language',
            'schema:dateCreated',
            'bdm2:writingSupport',
            'bdm2:numberColumns',
            'bdm2:numberLines',
            'bdm2:numberLeaves',
        ];
        
        // Fetch all properties related to each included work ID
        for (let i = 0; i < includedWorksIDs.length; i++) {
                let propertiesToWrite = [];
                
                $.get( `/api/items/${includedWorksIDs[i]}`, function(data) {
                // Filter out irrelevant properties
                for (const property in data) {
                    if (relevantProperties.includes(property)) {
                        propertiesToWrite.push({ key: property, value: data[property] })
                    }
                }
                // Pass the data to our function that actually writes to the HTML
                findCorrectHTMLElement(propertiesToWrite, includedWorksIDs[i])
            });  
        } 
    }

    function findCorrectHTMLElement(propertiesToWrite, includedWorksID) {
        
        // Ensure that we write to the correct HTML child. This is done by matching our ID with the id in the href of the html child.
        
        // THIS CHECK HAS TO BE MADE BULLETPROOF! AS OF NOW IT ISNT - I THINK?
        let correctHTML = $('.items a[href*="'+ getPathName() +''+includedWorksID+'"]').parent(); 
        writeProperties(propertiesToWrite, correctHTML, includedWorksID);

    }

    function writeProperties(propertiesToWrite, correctHTML, includedWorksID) {

        // Append our custom accordionContainer class as well as the id of the included work to the HTML element
        correctHTML.append('<span class=\"accordionContainer_'+includedWorksID+'\">');

        let accordionContainer = $(".accordionContainer_"+includedWorksID+"");

        // Write the properties to the accordionContainer class
        for (let i = 0; i < propertiesToWrite.length; i++) {
            if (propertiesToWrite[i].value[0]['@value']) {
                accordionContainer.append(
                    "<div class=\"property\"><h4>" +
                    propertiesToWrite[i].value[0].property_label +
                    "</h4> <div class=\"values\"> <div class=\"value\" lang>" +
                    propertiesToWrite[i].value[0]['@value'] +
                    "</div></div>" +
                    "</div>");
            } else if (propertiesToWrite[i].key == 'schema:author') {
                accordionContainer.append(
                    "<div class=\"property\"><h4>" +
                    propertiesToWrite[i].value[0].property_label +
                    "</h4> <div class=\"values\"> <div class=\"value\" lang>" +
                    propertiesToWrite[i].value[0].display_title +
                    "</div></div>" +
                    "</div>");
            }
        }
        // Append a link to the item page of the work item
        accordionContainer.append("<div class=\"property\"><h4>Link to resource</h4>" + "<div class=\"values\"> <div class=\"value\" lang>" + "<a href="+getPathName()+includedWorksID+" target=_blank>" +'Click to open in new window'+"</a>" + "</div></div></div>");
        correctHTML.append('</span>')
        correctHTML.accordion("refresh")
    }
});


function createAccordion() {
    $(".property:contains('Included works') .values .resource").accordion({
        collapsible: true,
        active: false
    });
}

function getPathName() {
    let pathName = window.location.pathname;
    return pathName.replace(/\d/g, '')
}

function refreshAccordion()
{
    includedWorks.accordion("refresh");
}

function removePrintTypeHref() {
    let hrefToRemove = $(".property:contains('Manuscript or print') .values .resource a");
   // console.log(hrefToRemove.html())
    hrefToRemove.css({"text-decoration": "none", "color": "inherit"});
    hrefToRemove.removeAttr("href");
}

Customizing Omeka s

Watch out!

No NREC-backup

Custom JS in Omeka

Custom network app

Links

Birgitta - DU

By ahl.nilsen@uib.no