Commit a4658ec1 authored by Orderic-Vital Pain's avatar Orderic-Vital Pain
Browse files

Ajout retour à l’index depuis le texte

parent ecc9446d
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -91,5 +91,11 @@ div.index .collapsible.active {
p.entries {
  margin: 5px 0px 0px 20px;
  color:black;
  max-width: 40vw;
}

.indexEntry {
  color: var(--ead-link-color);
  cursor: pointer;
}

plugins/index/index.js

0 → 100644
+55 −0
Original line number Diff line number Diff line
document.addEventListener("DOMContentLoaded", async function() {

	let currentPage = window.location.href;
	if(currentPage.includes("/index/") && currentPage.includes("#")) {
		if(document.querySelector(".subindex") !== null) {
			cleanIndexSubindex(currentPage) ;
		} else {
			cleanIndex(currentPage) ;
		}
	}
});

async function cleanIndexSubindex(currentPage) {		
	let searchedEntry = decodeURIComponent(currentPage.split("#")[1].replaceAll("+"," "));
	const foundEntry = (key) => key.textContent === searchedEntry ;
	document.querySelectorAll(".subindex").forEach(subindex => {
		let subindexContent = Array.from(subindex.querySelectorAll("span"));
		if(subindexContent.some(foundEntry)) {
			getEntry(subindex, searchedEntry).then(entry => {
				subindex.removeChild(subindex.querySelector("div"));
				entry.forEach(para => {
					subindex.appendChild(para)
				})
			})
		} else {
			subindex.style.display = "none";
		}
	});
};

async function cleanIndex(currentPage) {
	let searchedEntry = decodeURIComponent(currentPage.split("#")[1].replaceAll("+"," "));
	const foundEntry = (key) => key.textContent === searchedEntry ;
	let index = document.querySelector(".index");
	
	getEntry(index, searchedEntry).then(entry => {
		index.querySelectorAll("fieldset").forEach(field => {
			index.removeChild(field)
		})		
		entry.forEach(para => {
			index.appendChild(para)
		})
	})	
};

async function getEntry(index, searchedEntry) {
	let result = []
	index.querySelectorAll("p").forEach(entry => {
		let keyValue = entry.querySelector("span").textContent;
		if(keyValue === searchedEntry) {
			result.push(entry);
		}
	});
	return result
};
 No newline at end of file
+37 −33
Original line number Diff line number Diff line
@@ -28,39 +28,43 @@ function max.plugin.index:index($project,$type){
		then 
			let $content := fetch:xml($indexFilePath, map {'chop' : false()})
			let $content := <div id='content'>{$content}</div> 
          (:~ let $content := <div id='content'>{doc($indexFilePath)}</div>~:)
			return max.html:render($project, 'index/'||$type, $content) 
		else max.plugin.index:generateIndex($project,$type,$projectLang)
};

declare function max.plugin.index:generateIndex($project,$type,$lang){  
	let $indexFilePath := file:parent(file:parent(file:parent(static-base-uri()))) || '/editions/'||$project||'/fragments/'||$lang||'/index/index_'||$type||'.frag.html'

	let $custXQ := file:parent(file:parent(file:parent(static-base-uri())))||"editions/"||$project||"/xq/index/index_"||$type||".xq"
	let $custXSL := file:parent(file:parent(file:parent(static-base-uri())))||"editions/"||$project||"/ui/xsl/index/index_"||$type||".xsl"

let $HTMLIndex := if (file:exists($custXQ) and file:exists($custXSL))
	let $HTMLIndex :=
		if (file:exists($custXQ) and file:exists($custXSL))
		then max.plugin.index:loadIndex($project,$type,$custXQ,$custXSL,$lang)
		else "error" 
              

let $res := switch ($HTMLIndex)
	let $res :=
		switch ($HTMLIndex)
			case "error"
				return "XQ and/or XSL file not found"
			default
           return file:write($indexFilePath, <div class='index'>{$HTMLIndex}</div>)(: , max.plugin.index:index($project,$type) :)
				return file:write($indexFilePath, $HTMLIndex)
           
return if (file:exists($indexFilePath)) then max.plugin.index:index($project,$type)
	return
		if (file:exists($indexFilePath))
		then max.plugin.index:index($project,$type)
		else $res
};

declare function max.plugin.index:loadIndex($edition,$type,$xq,$xsl,$lang) {
	let $dbPath := max.config:getProjectDBPath($edition)
  let $projectIndex := xquery:eval(xs:anyURI($xq),map
                  { 'project':$edition,
	let $projectIndex :=
		xquery:eval(xs:anyURI($xq),map{
			'project':$edition,
            'baseURI': max.config:getBaseURI(),
            'dbPath':$dbPath
        })
    (:let $filePath := file:parent(file:parent(file:parent(static-base-uri()))) || '/editions/projets_ead_pdn/fragments/'||$lang||'/index/pre_index_'||$type||'.frag.html'
    return file:write($filePath, $projectIndex):)
	let $HTMLProjectIndex := xslt:transform($projectIndex, $xsl, ( map {'project' : $edition, 'locale' : $lang})) 
	return $HTMLProjectIndex
};