Skip to content
Snippets Groups Projects
Commit a36afda5 authored by Beatrycze Volk's avatar Beatrycze Volk
Browse files

Load JS initial setup only if there are some results to be displayed

parent c633c280
No related branches found
No related tags found
No related merge requests found
......@@ -9,17 +9,13 @@ $(document).ready(function () {
tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl)
)
var visible = $("#results").is(":visible");
var keywordsList;
var keywords;
var keywordsElement = document.getElementById("list-keywords");
if (keywordsElement) {
keywordsList = keywordsElement.querySelectorAll("li");
keywords = $("#list-keywords :input");
}
var basePublicationTimeMax = $("#input-publication-time-max").attr('max');
var baseApcMax = $("#label-apc-max").attr('max');
var keywordsElement;
var basePublicationTimeMax;
var baseApcMax;
var retainsAuthorCopyright = false;
var publicationTimeMax = false;
var apcMax = false;
......@@ -27,151 +23,162 @@ $(document).ready(function () {
var subject = false;
var checkedKeywords = [];
if ($("#suggest-language").length) {
language = $("#suggest-language").val();
$("#filter-languages").val(language);
filter();
}
$("#button-list").trigger('click');
$("#button-list").click(function () {
changeResultView('#result-table', '#result-list');
});
$("#button-table").click(function () {
changeResultView('#result-list', '#result-table');
});
$("#button-clear").click(function (e) {
e.preventDefault();
$('#results').hide();
$('#input-title').val('');
$('#input-abstract').val('');
$('#input-references').val('');
});
$("#btn-fetch").click(function () {
$.get(
"https://service.tib.eu/bison/api/fetchdoi",
{
doi: $("#input-doi").val(),
format: "json"
}
)
.done(function (json) {
$("#input-title").val(json.title);
$("#input-abstract").val(json.abstract);
$("#input-references").val(json.references);
$("#modal-doi .btn-close").click();
})
.fail(function () {
$("#validation-doi-feedback").show();
})
});
$("#checkbox-author-rights").bind('change', function () {
if ($(this).is(':checked')) {
retainsAuthorCopyright = true;
if (visible) {
keywordsElement = document.getElementById("list-keywords");
if (keywordsElement) {
keywordsList = keywordsElement.querySelectorAll("li");
keywords = $("#list-keywords :input");
}
else {
retainsAuthorCopyright = false;
basePublicationTimeMax = $("#input-publication-time-max").attr('max');
baseApcMax = $("#label-apc-max").attr('max');
if ($("#suggest-language").length) {
language = $("#suggest-language").val();
$("#filter-languages").val(language);
filter();
}
filter();
});
$(".form-check-input").bind('change', function () {
if ($(this).attr('id') != 'checkbox-author-rights') {
$("#button-list").trigger('click');
$("#button-list").click(function () {
changeResultView('#result-table', '#result-list');
});
$("#button-table").click(function () {
changeResultView('#result-list', '#result-table');
});
$("#button-clear").click(function (e) {
e.preventDefault();
$('#results').hide();
$('#input-title').val('');
$('#input-abstract').val('');
$('#input-references').val('');
});
$("#btn-fetch").click(function () {
$.get(
"https://service.tib.eu/bison/api/fetchdoi",
{
doi: $("#input-doi").val(),
format: "json"
}
)
.done(function (json) {
$("#input-title").val(json.title);
$("#input-abstract").val(json.abstract);
$("#input-references").val(json.references);
$("#modal-doi .btn-close").click();
})
.fail(function () {
$("#validation-doi-feedback").show();
})
});
$("#checkbox-author-rights").bind('change', function () {
if ($(this).is(':checked')) {
checkedKeywords.push($(this).val());
retainsAuthorCopyright = true;
}
else {
let index = checkedKeywords.indexOf($(this).val());
if (index !== -1) {
checkedKeywords.splice(index, 1);
retainsAuthorCopyright = false;
}
filter();
});
$(".form-check-input").bind('change', function () {
if ($(this).attr('id') != 'checkbox-author-rights') {
if ($(this).is(':checked')) {
checkedKeywords.push($(this).val());
}
else {
let index = checkedKeywords.indexOf($(this).val());
if (index !== -1) {
checkedKeywords.splice(index, 1);
}
}
}
}
filter();
});
filter();
});
$(document).on('input change', '#input-publication-time-max', function () {
publicationTimeMax = $(this).val();
const label = $("#label-publication-time-max");
const labelParts = label.text().split(' ');
label.empty();
const newLabel = `<b>${labelParts[0]} ${labelParts[1]} </b> ${publicationTimeMax} ${labelParts.slice(-1)[0]}`;
label.append(newLabel);
filter();
});
$(document).on('input change', '#input-publication-time-max', function () {
publicationTimeMax = $(this).val();
const label = $("#label-publication-time-max");
const labelParts = label.text().split(' ');
label.empty();
const newLabel = `<b>${labelParts[0]} ${labelParts[1]} </b> ${publicationTimeMax} ${labelParts.slice(-1)[0]}`;
label.append(newLabel);
filter();
});
$(document).on('input change', '#input-apc-max', function () {
apcMax = $(this).val();
const label = $("#label-apc-max");
const labelParts = label.text().split(' ');
label.empty();
const newLabel = `<b>${labelParts[0]} ${labelParts[1]} ${labelParts[2]} </b> ${apcMax} ${labelParts.slice(-1)[0]}`;
label.append(newLabel);
filter();
});
$(document).on('input change', '#filter-keywords', function () {
if ($(this).val() !== '') {
for (let i = 0; i < keywords.length; i++) {
if (keywords[i].value.indexOf($(this).val()) >= 0) {
keywordsList[i].style.display = "list-item";
} else {
keywordsList[i].style.display = "none";
$(document).on('input change', '#input-apc-max', function () {
apcMax = $(this).val();
const label = $("#label-apc-max");
const labelParts = label.text().split(' ');
label.empty();
const newLabel = `<b>${labelParts[0]} ${labelParts[1]} ${labelParts[2]} </b> ${apcMax} ${labelParts.slice(-1)[0]}`;
label.append(newLabel);
filter();
});
$(document).on('input change', '#filter-keywords', function () {
if ($(this).val() !== '') {
for (let i = 0; i < keywords.length; i++) {
if (keywords[i].value.indexOf($(this).val()) >= 0) {
keywordsList[i].style.display = "list-item";
} else {
keywordsList[i].style.display = "none";
}
}
}
}
});
});
$("#filter-languages").change(function () {
if ($(this).val() === '') {
language = false;
} else {
language = $(this).val();
}
filter();
});
$("#filter-subjects").change(function () {
if ($(this).val() === '') {
subject = false;
} else {
subject = $(this).val();
}
filter();
});
$("#filter-languages").change(function () {
if ($(this).val() === '') {
language = false;
} else {
language = $(this).val();
}
filter();
});
$("#sort-select").change(function () {
if ($(this).val() === 'score') {
sortList('data-score');
sortTable('data-score');
}
if ($(this).val() === 'title') {
sortList('data-title');
sortTable('data-title');
}
if ($(this).val() === 'publisher') {
sortList('data-publisher');
sortTable('data-publisher');
}
if ($(this).val() === 'apcs') {
sortList('data-apc');
sortTable('data-apc');
}
if ($(this).val() === 'publication_time') {
sortList('data-publication-time');
sortTable('data-publication-time');
}
});
$("#filter-subjects").change(function () {
if ($(this).val() === '') {
subject = false;
} else {
subject = $(this).val();
}
filter();
});
$("#sort-select").change(function () {
if ($(this).val() === 'score') {
sortList('data-score');
sortTable('data-score');
}
if ($(this).val() === 'title') {
sortList('data-title');
sortTable('data-title');
}
if ($(this).val() === 'publisher') {
sortList('data-publisher');
sortTable('data-publisher');
}
if ($(this).val() === 'apcs') {
sortList('data-apc');
sortTable('data-apc');
}
if ($(this).val() === 'publication_time') {
sortList('data-publication-time');
sortTable('data-publication-time');
}
});
$("#reset-filters").click(function () {
resetFilters();
});
$("#reset-filters").click(function () {
resetFilters();
});
}
function changeResultView(hide, show) {
$(hide).hide();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment