Commit 9053e1bb authored by Ubbo Veentjer's avatar Ubbo Veentjer
Browse files

remove all inline javascript

parent 2939a238
Pipeline #134953 passed with stages
in 4 minutes and 29 seconds
......@@ -116,3 +116,105 @@ $( function() {
})
})
/* for the basket */
/* retrieve number of basket items on page load to set number display */
document.addEventListener("DOMContentLoaded", event => {
fetch("/service/shelf/count")
.then(response => response.text())
.then(cnt => setBasketCount(cnt));
});
/* show number of items in basket */
function setBasketCount(num) {
document.querySelectorAll('.topbox_shelf-count').forEach( elem => {
elem.textContent = num;
})
}
/* the javascript for the shelf buttons, needed on browse and search-result and shelf pages */
document.addEventListener("DOMContentLoaded", function(event) {
const removeLabel = document.querySelector('#i18n-remove-from-shelf-label').dataset.value;
const addLabel = document.querySelector('#i18n-add-to-shelf-label').dataset.value;
/* the buttons */
$(document).on('click', '.-add-to-shelf', function(e) {
var $this = $(this);
$.ajax({
url: "/service/shelf/add" ,
type: 'POST',
dataType:'json',
data: {
uri: $this.attr('data-textgrid-targeturi')
},
success: function(data) {
$this.removeClass('-add-to-shelf');
$this.addClass('-remove-from-shelf');
$this.html(removeLabel);
setBasketCount(data);
}
});
});
$(document).on('click', '.-remove-from-shelf', function(e) {
var $this = $(this);
$.ajax({
url: "/service/shelf/remove" ,
type: 'POST',
dataType:'json',
data: {
uri: $this.attr('data-textgrid-targeturi')
},
success: function(data) {
$this.removeClass('-remove-from-shelf');
$this.addClass('-add-to-shelf');
$this.html(addLabel);
setBasketCount(data);
}
});
});
});
/* the browse.jsp has an iframe when showing html directly loaded from tgcrud */
document.addEventListener("DOMContentLoaded", function(event) {
$("#htmlIframe").contents().find("body").attr("style","margin-left: 0");
});
/* add/remove filters in search jsp */
document.addEventListener("DOMContentLoaded", function(event) {
var filters = [];
// get the filters from the left sidebar to append them to the search form
document.querySelectorAll('.tgrep.sidebar_item.-filter').forEach( elem => {
filters.push(elem.dataset.filter);
});
function addFiltersToSearchForm(filters) {
filters.forEach(function(filter) {
$('form.search').append($('<input type="hidden" class="hiddenFilterInput" name="filter" value="'+filter+'" />'));
});
}
function removeFiltersFromSearchForm() {
$('.hiddenFilterInput').remove();
}
addFiltersToSearchForm(filters);
//$('form.search').append($('<input type="hidden" name="order" value="${order}" />'));
//$('form.search').append($('<input type="hidden" name="limit" value="${limit}" />'));
$('#search-filters-active').change(function() {
if($('#search-filters-active').is(':checked')){
addFiltersToSearchForm(filters);
} else {
removeFiltersFromSearchForm();
}
});
});
......@@ -40,20 +40,6 @@
<script src="/js/jquery.min.js"></script>
<script src="/js/theme.js"></script>
<script type="text/javascript">
/* show number of items in basket */
document.addEventListener("DOMContentLoaded", event => {
fetch("/service/shelf/count")
.then(response => response.text())
.then(cnt => setBasketCount(cnt));
});
function setBasketCount(num) {
document.querySelectorAll('.topbox_shelf-count').forEach( elem => {
elem.textContent = num;
})
}
</script>
</div>
</body>
</html>
......@@ -17,6 +17,9 @@
<body class="html_body aui">
<div class="tg site">
<span hidden="true" id="i18n-remove-from-shelf-label" data-value="${i18n['remove-from-shelf']}"></span>
<span hidden="true" id="i18n-add-to-shelf-label" data-value="${i18n['add-to-shelf']}"></span>
<header class="tg header">
<div class="tg header_logo" role="banner">
<a href="/" title="TextGrid Repository">
......
......@@ -15,12 +15,9 @@
<div class="tg search_search">
<label class="sr-only" for="search-query-2">${i18n['search-term']}:</label>
<!-- #set ($queryParam = $escapeTool.html($request.getParameter('query')))
#if ( $queryParam ) -->
<input value="${query}" class="tg search_input -header" id="search-query-2" name="query" placeholder="${i18n['search-term']}" type="search">
<!-- #else
<input class="tg search_input -header" id="search-query-2" name="query" placeholder="#language('search-term')" type="search">
#end-->
<input type="hidden" name="order" value="${order}" />
<input type="hidden" name="limit" value="${limit}" />
<button class="tg search_submit" type="submit"><span class="sr-only">${i18n['do-search']}</span></button>
</div>
</fieldset>
......
......@@ -5,79 +5,10 @@
<%@ taglib uri="http://textgrid.info/rep/utils" prefix="utils" %>
<%@ include file="base/head.jsp" %>
<%@ include file="components/js-incl.jsp" %>
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function(event) {
<script type="text/javascript" src="/js/basket.js"></script>
$(document).on('click', '.-remove-from-shelf', function(e) {
var $this = $(this);
var tgObjectUri = $this.attr('data-textgrid-targeturi');
$.ajax({
url: '/service/shelf/remove' ,
type: 'POST',
dataType:'json',
data: {
uri: tgObjectUri
},
success: function(data) {
$this.closest('li.tgrep.result').remove();
$this.closest('li.tgrep.gallery-item').remove();
$('.tgrep.header_count').html(data);
setBasketCount(data);
removeFromAggregatorItemString(tgObjectUri)
}
});
});
$(document).on('click', '.tgrep.header_button.-clear', function(e) {
$.ajax({
url: '/service/shelf/clear' ,
type: 'POST',
dataType:'json',
data: {
empty: 'empty'
},
success: function(data) {
$('.tgrep.results_list').empty();
$('.tgrep.results_gallery').empty();
$('.tgrep.header_count').html(0);
setBasketCount(data);
removeUselessActionsFromEmptyShelf();
}
});
});
});
// set by jsp
var basketItemString = '${basketItemString}';
// removes the tguri from aggregatorUrl
function removeFromAggregatorItemString(tgObjectUri) {
var basketItemStringOld = basketItemString;
var itemArr = basketItemString.split(',');
itemArr.splice(itemArr.indexOf(tgObjectUri),1);
// are there any objects left on the shelf?
if(itemArr.length > 0) {
basketItemString = itemArr.join(',');
document.querySelectorAll('.aggregator-items').forEach( elem => {
elem.href = elem.href.replace(basketItemStringOld, basketItemString);
});
} else {
removeUselessActionsFromEmptyShelf();
}
}
// dislable download and voyant links if shelf is empty
function removeUselessActionsFromEmptyShelf() {
document.querySelectorAll('.remove_on_shelf_empty').forEach( elem => {
elem.remove();
});
}
</script>
<span hidden="true" id="basketItemString" data-value="${basketItemString}"></span>
<div class="tgrep wrap">
<div class="tgrep sidebar-toggle">
......
......@@ -6,20 +6,12 @@
<%@ include file="base/head.jsp" %>
<%@ include file="components/js-incl.jsp" %>
<style>
iframe {
width: 100%;
}
</style>
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function(event) {
$("#htmlIframe").contents().find("body").attr("style","margin-left: 0");
});
</script>
<div class="tgrep wrap">
<c:if test="${browseRootAggregations}">
......@@ -228,6 +220,7 @@
</c:when>
<c:when test="${image}">
<!-- TODO: openseadragon without inline javscript
<div id="openseadragon1" style="width: 800px; height: 1200px;"></div>
<script src="/js/openseadragon.min.js"></script>
<script type="text/javascript">
......@@ -242,9 +235,8 @@
tileSources: "${textgridHost}/1.0/digilib/rest/IIIF/${metadata.object.generic.generated.textgridUri.value}/info.json"
});
</script>
<!--
<img src="${textgridHost}/1.0/digilib/rest/IIIF/${metadata.object.generic.generated.textgridUri.value}/full/,1500/0/native.jpg"/>
-->
-->
<img src="${textgridHost}/1.0/digilib/rest/IIIF/${metadata.object.generic.generated.textgridUri.value}/full/,1000/0/native.jpg"/>
</c:when>
<c:when test="${metadata.object.generic.provided.identifier[0].type eq 'METSXMLID'}">
......
......@@ -3,36 +3,7 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://textgrid.info/rep/utils" prefix="utils" %>
<!--
<portlet:defineObjects />
<portlet:resourceURL id="addToBasket" var="addToBasketUrl" ></portlet:resourceURL>
<portlet:resourceURL id="removeFromBasket" var="removeFromBasketUrl" ></portlet:resourceURL>
-->
<%@ include file="base/head.jsp" %>
<%@ include file="components/js-incl.jsp" %>
<script type="text/javascript">
$(function() {
// set order-select
$(".tgrep.header_order-by option[value='${order}']").attr('selected',true);
// set limit select
$(".tgrep.header_limit option[value='${limit}']").attr('selected',true);
});
$(document).on('change', '.tgrep.header_order-by', function(e) {
window.location.href='?query=${query}${filterQueryString}&start=${start}&limit=${limit}&order='+$(this).val();
});
$(document).on('change', '.tgrep.header_limit', function(e) {
window.location.href='?query=${query}${filterQueryString}&order=${order}&start=${start}&limit='+$(this).val();
});
</script>
<div class="tgrep wrap">
......
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function(event) {
/* the buttons */
$(document).on('click', '.-add-to-shelf', function(e) {
var $this = $(this);
$.ajax({
url: "/service/shelf/add" ,
type: 'POST',
dataType:'json',
data: {
uri: $this.attr('data-textgrid-targeturi')
},
success: function(data) {
$this.removeClass('-add-to-shelf');
$this.addClass('-remove-from-shelf');
$this.html('${i18n['remove-from-shelf']}');
setBasketCount(data);
}
});
});
$(document).on('click', '.-remove-from-shelf', function(e) {
var $this = $(this);
$.ajax({
url: "/service/shelf/remove" ,
type: 'POST',
dataType:'json',
data: {
uri: $this.attr('data-textgrid-targeturi')
},
success: function(data) {
$this.removeClass('-remove-from-shelf');
$this.addClass('-add-to-shelf');
$this.html('${i18n['add-to-shelf']}');
setBasketCount(data);
}
});
});
});
</script>
......@@ -6,50 +6,6 @@
<%@ include file="base/head.jsp" %>
<!--
<portlet:resourceURL id="addToBasket" var="addToBasketUrl" ></portlet:resourceURL>
<portlet:resourceURL id="removeFromBasket" var="removeFromBasketUrl" ></portlet:resourceURL>
-->
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function(event) {
function addFiltersToSearchForm(filters) {
filters.forEach(function(filter) {
$('form.search').append($('<input type="hidden" class="hiddenFilterInput" name="filter" value="'+filter+'" />'));
});
}
function removeFiltersFromSearchForm() {
$('.hiddenFilterInput').remove();
}
var filters = [];
<c:forEach items="${filter}" var="activeFilter">
filters.push('${activeFilter}');
</c:forEach>
addFiltersToSearchForm(filters);
$('form.search').append($('<input type="hidden" name="order" value="${order}" />'));
$('form.search').append($('<input type="hidden" name="limit" value="${limit}" />'));
$('#search-filters-active').change(function() {
if($('#search-filters-active').is(':checked')){
addFiltersToSearchForm(filters);
} else {
removeFiltersFromSearchForm();
}
});
});
</script>
<%@ include file="components/js-incl.jsp" %>
<div class="tgrep wrap">
<c:if test="${results.size() eq 0 and not empty query and empty filter}">
......@@ -91,7 +47,7 @@ document.addEventListener("DOMContentLoaded", function(event) {
<ul class="tgrep sidebar_list">
<c:forEach items="${filter}" var="activeFilter">
<c:set var="afArray" value="${fn:split(activeFilter, ':')}" />
<li class="tgrep sidebar_item -filter">
<li class="tgrep sidebar_item -filter" data-filter="${activeFilter}">
<a class="tgrep sidebar_remove-filter"
title="${i18n['remove-filter']}"
href="?query=${query}&order=${order}&limit=${limit}${fn:replace(filterQueryString, '&filter='.concat(afArray[0]).concat('%3A').concat(utils:urlencode(afArray[1])) , '')}">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment