Commit 9330338a authored by Eva Huet's avatar Eva Huet
Browse files

JATS & JS : fix index

parent 3e869226
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -254,6 +254,9 @@ window.addEventListener('DOMContentLoaded', (event) => {
    
    initCitationCopy();

        // index collapsible
    initializeCollapsibleLists();

    // Appel fonction pour les indicateurs de scrollbar biblio
    initBibScrollIndicators();

@@ -510,6 +513,22 @@ function toggleIndexItem(li) {
    event.stopPropagation();
}

function initializeCollapsibleLists() {
  var toggleButtons = document.querySelectorAll('.toggle-button');
  toggleButtons.forEach(function (button) {
    button.addEventListener('click', function () {
      var parentLi = this.closest('li'); // Get the parent <li> element
      var indexLevel2Elements = parentLi.querySelectorAll('.index-level2'); // Get descendant elements with class .index-level2
      indexLevel2Elements.forEach(function (element) {
        element.style.display = (element.style.display === 'none' || element.style.display === '') ? 'block' : 'none'; // Toggle display
      });

      // Toggle button text on the clicked toggle button
      this.textContent = (indexLevel2Elements[0].style.display === 'none') ? '[+]' : '[-]'; // Use the first element's display property
    });
  });
}


///////////////////////////////////////////////////////
//////    Fonctions pour fenêtres externes   [EC]   ///
+122 −3
Original line number Diff line number Diff line
@@ -160,6 +160,9 @@
                <xsl:if test="//fn">
                    <button id="tabtn-footnotes" class="tab-btn trans" data-key='notes' onclick="openTab('footnotes')"></button>
                </xsl:if>
                <xsl:if test="//index-term">
                    <button id="tabtn-index" class="tab-btn trans" data-key='index' onclick="openTab('index')"></button>
                </xsl:if>
                <button id="tabtn-metas" class="tab-btn" onclick="openTab('metas')">i</button>
            </div>

@@ -267,6 +270,10 @@
                </ul>
            </div>
            
            <div id="index" class="content-tab" style="display:none">
                <xsl:call-template name="index"/>
            </div>

            <div id="metas" class="content-tab" style="display:none">
                <xsl:if test="./article-meta/volume or ./article-meta/issue-title-group/issue-title">
                    <div class="button-tabs meta-tabs">
@@ -1848,9 +1855,6 @@
        </p>
     </xsl:template>

     <!-- neutraliser les entrées d'index -->
      <xsl:template match="index-term"/>

    <!-- code -->

    <xsl:template match="code">
@@ -1868,6 +1872,121 @@
        <span class="{@xml:lang}"><xsl:apply-templates/></span>
    </xsl:template>

<!-- index -->

<xsl:template match="index-term">
    <xsl:choose>
        <xsl:when test="child::index-term[@vocab='pactols']">
            <xsl:apply-templates select="child::term/node()"/>
        </xsl:when>
        <xsl:otherwise/>
    </xsl:choose>
    <xsl:variable name="countTerm" select="count(preceding::index-term) + 1"/>
    <xsl:choose>
        <xsl:when test="ancestor::fn"/>
        <xsl:otherwise>
            <span id="{concat('term',$countTerm)}" class="index-anchor">#</span>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:key name="pactols-by-type" match="index-term[@vocab='pactols' and not(ancestor::fn)]" use="@index-type"/>
<xsl:key name="index-by-type" match="index-term[@index-type and not(@vocab) and not(child::index-term[@vocab]) and not(ancestor::fn)]" use="@index-type"/>
<xsl:key name="index-by-term-and-level" match="term[not(@xml:lang or descendant::term[@xml:lang]) and not(ancestor::fn)]" use="concat(text(), '|' , count(ancestor::index-term))"/>

<xsl:template name="index">
    <xsl:if test="//index-term[@vocab='pactols'][not(ancestor::fn)]">
        <ul class="index-level1" style="list-style-type:">
            <li>
                <xsl:text>Index Pactols</xsl:text>
                <span class="toggle-button">[+]</span>
                <xsl:for-each select="//index-term[@vocab='pactols' and not(ancestor::fn)][count(. | key('pactols-by-type',@index-type)[1]) = 1]">
                    <xsl:sort select="@index-type"/>
                    <xsl:variable name="current-type" select="@index-type"/>
                        <ul class="index-level2" style='display: none;'>
                            <li>
                                <xsl:value-of select="$current-type"/>
                                <xsl:variable name="group-terms" select="key('pactols-by-type',$current-type)/descendant::term[not(following-sibling::index-term)]"/>
                                <xsl:for-each select="$group-terms">
                                    <xsl:variable name="pos" select="position()"/>
                                    <xsl:variable name="term-value" select="."/>
                                    <xsl:if test="not(. = $group-terms[position() &lt; $pos])">
                                        <xsl:variable name="occurrences" select="$group-terms[. = $term-value]"/>
                                        <ul class="index-level3" style='list-style-type;'>
                                            <li>
                                                <xsl:apply-templates select="."/>
                                                <xsl:text> </xsl:text>
                                                <xsl:call-template name="render-occurrences">
                                                    <xsl:with-param name="occurrences" select="$occurrences"/>
                                                </xsl:call-template>
                                            </li>
                                        </ul>
                                    </xsl:if>
                                </xsl:for-each>
                            </li>
                        </ul>
                </xsl:for-each>
            </li>
        </ul>
    </xsl:if>
    <xsl:if test="//index-term[@index-type and not(@vocab) and not(child::index-term[@vocab]) and not(ancestor::fn)]">
        <xsl:for-each select="//index-term[@index-type and not(@vocab) and not(ancestor::fn)][count(. | key('index-by-type',@index-type)[1]) = 1]">
            <xsl:sort select="@index-type"/>
            <xsl:variable name="current-type" select="@index-type"/>
            <ul class="index-level1" style="list-style-type:">
                <li>
                    <xsl:value-of select="@index-type"/>
                    <span class="toggle-button">[+]</span>
                    <xsl:variable name="type-terms" select="key('index-by-type', $current-type)/child::term"/>
                    <xsl:call-template name="render-terms">
                        <xsl:with-param name="terms" select="$type-terms"/>
                    </xsl:call-template>
                </li>
            </ul>
        </xsl:for-each>
    </xsl:if>
</xsl:template>

<xsl:template name="render-terms">
    <xsl:param name="terms"/>
    <xsl:if test="$terms">
        <xsl:for-each select="$terms[count(. | key('index-by-term-and-level', concat(text(), '|', count(ancestor::index-term)))[1]) = 1]">
            <xsl:sort select="text()"/>
            <xsl:variable name="current-term" select="."/>
            <xsl:variable name="current-text" select="text()"/>
            <xsl:variable name="current-level" select="count(ancestor::index-term)"/>
            <xsl:variable name="occurrences" select="$terms[text() = $current-text][count(ancestor::index-term) = $current-level]"/>
            <ul style="list-style-type:">
                <xsl:attribute name="class"><xsl:value-of select="concat('index-level',count(ancestor::index-term) +1)"/></xsl:attribute>
                <li>
                    <xsl:value-of select="$current-text"/>
                    <xsl:call-template name="render-occurrences">
                        <xsl:with-param name="occurrences" select="$occurrences"/>
                    </xsl:call-template>
                    <xsl:variable name="sub-terms" select="$current-term/parent::index-term/child::index-term/child::term"/>
                    <xsl:call-template name="render-terms">
                        <xsl:with-param name="terms" select="$sub-terms"/>
                    </xsl:call-template>
                </li>
            </ul>
        </xsl:for-each>
    </xsl:if>
</xsl:template>

<!-- template pour les renvois dans l'index -->
<xsl:template name="render-occurrences">
    <xsl:param name="occurrences"/>
    <xsl:for-each select="$occurrences">
        <xsl:variable name="countTerm" select="count(preceding::index-term) + 1"/>
        <span class="index-link">
            <a href="{concat('#term',$countTerm)}">
                <xsl:value-of select="position()"/>
            </a>
        </span>
        <xsl:if test="position() != last()">
            <xsl:text>, </xsl:text>
        </xsl:if>
    </xsl:for-each>
</xsl:template>

</xsl:stylesheet>