Split expand switch into two: setttings switch and one-time switch

This commit is contained in:
Georgy Litvinov 2021-03-03 13:43:03 +01:00
parent a911179bba
commit 0dbe7232de
4 changed files with 89 additions and 73 deletions

View file

@ -1,38 +1,54 @@
document.addEventListener('DOMContentLoaded', addCollapsibleOnClick(), false); document.addEventListener('DOMContentLoaded', addCollapsibleOnClick(), false);
document.addEventListener('DOMContentLoaded', expandAllCollapsedElements(), false); document.addEventListener('DOMContentLoaded', expandAllCollapsedElements(), false);
function addCollapsibleOnClick(){ function addCollapsibleOnClick() {
var coll = document.getElementsByClassName("collapsible"); var coll = document.getElementsByClassName("collapsible");
var i; var i;
for (i = 0; i < coll.length; i++) { for (i = 0; i < coll.length; i++) {
coll[i].addEventListener("click", function() { coll[i].addEventListener("click", function() {
this.classList.toggle("active"); this.classList.toggle("active");
var content = this.nextElementSibling; var content = this.nextElementSibling;
if (content.style.display === "block") { if (content.style.display === "block") {
content.style.display = "none"; content.style.display = "none";
} else { } else {
content.style.display = "block"; content.style.display = "block";
} }
}); });
} }
} }
function expandAllCollapsedElements(){ function expandAllCollapsedElements() {
if (localStorage.getItem('switchExpand') === true || localStorage.getItem('switchExpand') === 'true') { if (localStorage.getItem('switchExpand') === true || localStorage.getItem('switchExpand') === 'true') {
document.getElementById("expandCB").checked = true; var expandSwitchCB = document.getElementById("expandCB");
$('.autoExpand').show(); if ( expandSwitchCB != null ){
} else { expandSwitchCB.checked = true;
$('.autoExpand').hide(); }
} var expandSwitchSettingsCB = document.getElementById("expandSettingsCB");
if ( expandSwitchSettingsCB != null ){
expandSwitchSettingsCB.checked = true;
}
$('.autoExpand').show();
} else {
$('.autoExpand').hide();
}
} }
function switchExpand(){
var checkBox = document.getElementById("expandCB");
if (checkBox.checked == true){
$('.autoExpand').show();
localStorage.setItem('switchExpand',true);
} else {
$('.autoExpand').hide();
localStorage.setItem('switchExpand',false);
}
}
function switchExpand() {
var checkBox = document.getElementById("expandCB");
if (checkBox.checked == true) {
$('.autoExpand').show();
localStorage.setItem('switchExpand', true);
} else {
$('.autoExpand').hide();
localStorage.setItem('switchExpand', false);
}
}
function switchExpandSettings() {
var checkBox = document.getElementById("expandSettingsCB");
if (checkBox.checked == true) {
localStorage.setItem('switchExpand', true);
} else {
localStorage.setItem('switchExpand', false);
}
}

View file

@ -120,12 +120,8 @@ ${scripts.add('<script type="text/javascript" src="${urls.base}/themes/iph/js/co
</#if> </#if>
<@expandSwitch />
<div class="expandSwitch">
<label class="switch">Раскрыть статью
<input id="expandCB" type="checkbox" onclick="switchExpand();">
</label>
</div>
<div id="TOC"></div> <div id="TOC"></div>
<#assign firstPub = propertyGroups.pullProperty("https://litvinovg.pro/text_structures#firstPublication")!> <#assign firstPub = propertyGroups.pullProperty("https://litvinovg.pro/text_structures#firstPublication")!>
<#if firstPub.statements?has_content && firstPub.type == "data"> <#if firstPub.statements?has_content && firstPub.type == "data">
@ -152,7 +148,7 @@ ${scripts.add('<script type="text/javascript" src="${urls.base}/themes/iph/js/co
</#list> </#list>
</#if> </#if>
<@showRubrics /> <@documentRubrics />
<div class="articleParts" style="display:block;"> <div class="articleParts" style="display:block;">
<#list paths as order> <#list paths as order>

View file

@ -11,6 +11,8 @@ ${scripts.add('<script async type="text/javascript" src="${urls.base}/themes/iph
${scripts.add('<script type="text/javascript" src="${urls.base}/themes/iph/js/collapsible_elements.js"></script>')} ${scripts.add('<script type="text/javascript" src="${urls.base}/themes/iph/js/collapsible_elements.js"></script>')}
<#import "individual-qrCodeGenerator.ftl" as qr> <#import "individual-qrCodeGenerator.ftl" as qr>
<#import "lib-vivo-properties.ftl" as vp> <#import "lib-vivo-properties.ftl" as vp>
<#include "text-lib.ftl">
<#--Number of labels present--> <#--Number of labels present-->
<#if !labelCount??> <#if !labelCount??>
<#assign labelCount = 0 > <#assign labelCount = 0 >
@ -94,11 +96,9 @@ ${scripts.add('<script type="text/javascript" src="${urls.base}/themes/iph/js/co
<#assign skipThis = propertyGroups.pullProperty("http://xmlns.com/foaf/0.1/firstName")!> <#assign skipThis = propertyGroups.pullProperty("http://xmlns.com/foaf/0.1/firstName")!>
<#assign skipThis = propertyGroups.pullProperty("http://xmlns.com/foaf/0.1/lastName")!> <#assign skipThis = propertyGroups.pullProperty("http://xmlns.com/foaf/0.1/lastName")!>
</#if> </#if>
<div class="expandSwitch">
<label class="switch">Раскрыть статью <@expandSwitch />
<input id="expandCB" type="checkbox" onclick="switchExpand();">
</label>
</div>
<#assign firstPub = propertyGroups.pullProperty("https://litvinovg.pro/text_structures#firstPublication")!> <#assign firstPub = propertyGroups.pullProperty("https://litvinovg.pro/text_structures#firstPublication")!>
<#if firstPub.statements?has_content && firstPub.type == "data"> <#if firstPub.statements?has_content && firstPub.type == "data">
<div class="firstPub" style="list-style:none;"> <div class="firstPub" style="list-style:none;">
@ -108,23 +108,6 @@ ${scripts.add('<script type="text/javascript" src="${urls.base}/themes/iph/js/co
</div> </div>
</#if> </#if>
<#--
<#assign issue = propertyGroups.pullProperty("https://litvinovg.pro/text_structures#issue")!>
<#if issue.statements?has_content && issue.type == "data">
<div class="issue" style="list-style:none;">
<div class="label">Выпуск</div>
<@p.dataPropertyList issue editable />
</div>
</#if>
<#assign year = propertyGroups.pullProperty("https://litvinovg.pro/text_structures#year")!>
<#if year.statements?has_content && year.type == "data">
<div class="year" style="list-style:none;">
<div class="label">Год</div>
<@p.dataPropertyList year editable />
</div>
</#if>
-->
<#if authors??> <#if authors??>
<#list authors as author> <#list authors as author>
@ -142,18 +125,7 @@ ${scripts.add('<script type="text/javascript" src="${urls.base}/themes/iph/js/co
</#list> </#list>
</#if> </#if>
<#assign articleRubrics = propertyGroups.pullProperty("https://iph.ras.ru/relationships#belongsTo")!> <@documentRubrics />
<#if articleRubrics?? && articleRubrics?has_content>
<div class="label">Относится к рубрикам: <@p.addLink articleRubrics editable /> <@p.verboseDisplay articleRubrics /></div>
<#if rubrics?? && rubrics?has_content>
<#list rubrics as rubric>
<li role="listitem" style="list-style:none;">
<a href="${urls.base}/individual?uri=${rubric.rubricID?url}"">${rubric.rubricName}</a>
</li>
</#list>
</#if>
<br/>
</#if>
<div class="articleParts" style="display:block;"> <div class="articleParts" style="display:block;">
<#list paths as order> <#list paths as order>

View file

@ -33,6 +33,38 @@
</div> </div>
</#if> </#if>
</#macro> </#macro>
<#macro showWorks works >
<#macro documentRubrics >
<#assign docRubrics = propertyGroups.pullProperty("https://iph.ras.ru/relationships#belongsTo")!>
<#if ( docRubrics?? && docRubrics?has_content ) || (rubrics?? && rubrics?has_content)>
<div class="label">Относится к рубрикам:
<#if docRubrics?? && docRubrics?has_content >
<@p.addLink docRubrics editable /> <@p.verboseDisplay docRubrics /><br/>
</#if>
</div>
</#if>
<#if rubrics?? && rubrics?has_content>
<#list rubrics as rubric>
<li role="listitem" style="list-style:none;">
<a href="${urls.base}/individual?uri=${rubric.rubricID?url}"">${rubric.rubricName}</a>
</li>
</#list>
</#if>
</#macro>
<#macro expandSettingsSwitch >
<div class="expandSettingsSwitch">
<label class="switch">Раскрывать документы по умолчанию
<input id="expandSettingsCB" type="checkbox" onclick="switchExpandSettings();">
</label>
</div>
</#macro>
<#macro expandSwitch>
<div class="expandSwitch">
<label class="switch">Раскрыть все главы документа
<input id="expandCB" type="checkbox" onclick="switchExpand();">
</label>
</div>
</#macro> </#macro>