(function() { // Her kan en skrive inn/justere fast tekst for sida - to spraak var labels = { 'SokeFeltanvisning' : ['Søk på heil eller del av emnekode eller -namn','Type the entire or a only a part of a code or title'], 'FinnLister' : ['Finn lister','Search for lists'], 'ResultatPresentasjon' : ['Treff på pensumlister for søkestreng','Found reading lists for search term'], 'StudieAar' : ['Studieår','Year of study'], 'IngentingFunnet' : ['Ingenting blei funne på','Nothing was found for'], } // Eksempel: labels['FinnLister'][lang] var lang = 0; // Norsk if (document.documentElement.lang == 'en'){ lang = 1; // Engelsk } try{ var targ = document.getElementById('bergenarkiv'); //document.getElementsByClassName('l-2-col__main-content')[0]; // finn-form var scheme = document.createElement('div'); scheme.id = 'searchemne'; scheme.style.margin = '2rem 0'; targ.insertBefore(scheme,targ.childNodes[0]); var url = window.location.href; var reqUri = window.location.href.split(/(\?|\&|\=)/); var createSearch = function(){ document.getElementById('searchemne').innerHTML = '

' + labels['SokeFeltanvisning'][lang] + ':

'; if(typeof(window.fetch) == 'function'){ try{ document.querySelector('.MSIEnotSupportedMessage').innerHTML = ''; }catch(e){ console.log('No MSIEnotSupportedMessage field found for emptyfying'); } }else{ console.log('Function fetch is not supported'); } }; var createMsg = function(msg){ return '

' + msg + '

'; }; this.outpHTML = function(d){ if (typeof d != 'undefined'){ var outElm = document.createElement('section'); outElm.innerHTML = d; try{ targ.insertBefore(outElm,targ.childNodes[1]); let t = setTimeout(function(){ var concertina = new Concertina([document.getElementById('listeVisning')]); },2000); }catch(e){ alert('Feil: Finner ikke leveringsstedet "' + targ.classList + '".'); } } }; outpHTML(createSearch()); if (reqUri.length > 0){ for (var i = 0; i < reqUri.length; i++){ if (reqUri[i] == 'q'){ if ((typeof reqUri[i + 2] != 'undefined') && (reqUri[i + 2].length > 0)){ var emnekode = reqUri[i + 2]; try{ //fetch('https://hvalross.hib.no/webmaster/emnekatalog/pensum_som_json.php?emnekode=' + escape(reqUri[i + 2])).then(response => { console.log('https://hvalross.hib.no/webmaster/emnekatalog/pensum_som_json.php?emnekode=' + decodeURIComponent(escape(reqUri[i + 2]))); fetch('https://hvalross.hib.no/webmaster/emnekatalog/pensum_som_json.php?emnekode=' + decodeURIComponent(reqUri[i + 2])).then(response => { return response.json(); }) .then(data => { var html = []; //html.push(createSearch()); if (data.length > 0){ html.push('

' + labels['ResultatPresentasjon'][lang] + ' ' + decodeURIComponent(emnekode) + ':

'); html.push('
'); for (var j = 0; j < reqUri.length; j++){ if (typeof data[j] == 'object'){ html.push('
'); var out = {}; // trengs for riktig rekkefoelge for (var prop in data[j]) { if (prop == 'infotermin'){ out[prop] = labels['StudieAar'][lang] + ': ' + data[j][prop] + '/' + (parseInt(data[j][prop]) + 1); } if (prop == 'emnekode'){ out[prop] = data[j][prop]; } if (prop == 'emnenavn'){ out[prop] = data[j][prop]; } if (prop == 'litteratur'){ out[prop] = data[j][prop]; } } html.push('

' + out['emnenavn'] + ' (' + out['emnekode'] + ') ' + out['infotermin'] + '

' + out['litteratur'] + '
'); html.push('
'); } } html.push('
'); }else{ html.push(createMsg(labels['IngentingFunnet'][lang] + ' «' + decodeURIComponent(emnekode) + '».')); } outpHTML(html.join('\n')); i = reqUri.length; }) .catch(err => { outpHTML(createMsg('Ein feil oppstod: Kunne ikkje etablere kontakt med datakjelda (' + err + ' [-2])')); }); }catch(e){ outpHTML(createMsg('Ein feil oppstod: Nettlesaren er ikkje ES6-kompatibel. [-1]')); } } }else{ outpHTML(createSearch()); }; } }else{ outpHTML(''); }; }catch(e){ console.log('Kunne ikkje teikna ut: ' + e); } })() /* Lightweight accordeon by Terje Rudi, 2019 Example: After class, use javascript: let concertina = new Concertina([ document.getElementById('concertinaPanel') ]); Where array is array of elements containing elements of css class 'concertina'. Open concertinas has extra class 'open'. Remember to insert CSS from https://v.hvl.no/css/concertina.php.css OR use param $extension = "css" in parent script before requiring this */ // Insert CSS into page try{ let cCss = document.createElement('link'); cCss.rel = 'stylesheet'; cCss.href = 'https://v.hvl.no/css/concertina.php.css'; document.head.appendChild(cCss); }catch(e){ console.error('Could not insert Concertina CSS: ' + e); } let Concertina = function(elementArray){ console.info('Concertina activated with array: ' + elementArray); // Collect all concertina elements for later use this.concertinaCollection = []; // Class for handling css by opening and closing let CssClassHandler = function(el){ let hasClass = function (el, className) { return el.classList ? el.classList.contains(className) : new RegExp('\\b'+ className +'\\b').test(el.className); }; let addClass = function (el, className) { if (el.classList) el.classList.add(className); else if (!hasClass(el, className)) el.className += ' ' + className; }; let removeClass = function (el, className) { if (el.classList) el.classList.remove(className); else el.className = el.className.replace(new RegExp('\\b'+ className+'\\b', 'g'), ''); }; let headerItem = el.querySelector('*'); headerItem.setAttribute('data-before','\u25BC'); if (hasClass(el,'open')){ headerItem.setAttribute('data-before','\u25B2'); } if (headerItem.hasEvent !== true){ headerItem.hasEvent = true; headerItem.addEventListener('click',function(){ if (hasClass(headerItem.parentNode,'open')){ //console.info('close: ' + headerItem.innerHTML); let r = removeClass(headerItem.parentNode,'open'); headerItem.setAttribute('data-before','\u25BC'); }else{ //console.info('open: ' + headerItem.innerHTML); let a = addClass(headerItem.parentNode,'open'); headerItem.setAttribute('data-before','\u25B2'); } }); }; } // Go, find the elements with class concertina and append style and events for (let cParent = 0;cParent < elementArray.length;cParent++){ let waitForConcertinas = setInterval(function(){ let concertinas = elementArray[cParent].querySelectorAll('.concertina'); if (concertinas.length > 0){ clearInterval(waitForConcertinas); for (let c = 0; c < concertinas.length;c++){ let thisConcertina = concertinas[c]; thisConcertina.eventHandler = new CssClassHandler(thisConcertina); } if (this.concertinaCollection != undefined){ this.concertinaCollection.push(concertinas); } }; },1000); } // Adjust sub concertinas bottom space let targ = document.querySelectorAll('.concertina > .concertina:last-child'); targ.forEach(function(elm){ elm.parentNode.style.paddingBottom = '0'; }); }