$(document).ready(function () {
showSelectionsButtonDisplay();
$(function () {
$('[data-bs-toggle="tooltip"]').tooltip();
});
$("#goSearch").click(function(){
window.location.href='/' + ressources.langInt + '/search';
});
$('#quickSearchText').keypress(function (e) {
if (e.which == 13) {
$("#goResult").click();
}
});
$("#goResult").click(function(){
var quickSearch = $("#quickSearchText").val().trim();
if(quickSearch.length > 0 ){
window.location.href='/' + ressources.langInt + '/result?command=search&search_type=all&title_search_type=any&corpus=all&corpusType=c&langCont=' + ressources.langInt + '&fragment=' + encodeURIComponent(quickSearch)+ '&shorttitle=&stemmed=stemmed';
}else{
window.location.href='/' + ressources.langInt + '/search';
}
});
selectMenuItem(ressources.cmdId);
$('#menu').on('shown.bs.collapse', function () {
$('#toggleMenu').html(" " + ressources.hideMenu);
});
$('#menu').on('hidden.bs.collapse', function () {
$('#toggleMenu').html(" " + ressources.diplayMenu);
});
var cleanLocationHash = DOMPurify.sanitize(location.hash);
var idSelector = cleanLocationHash;
if(idSelector){
var span = $(document.getElementById(idSelector.replace("#",""))).find("span.hit")[0];
if(span){
$(span).addClass("hit-selected");
}
}
$("#showSelectionsInCurrentDocument").click(function(){
printDocument('tagged');
});
$("#showAllSelectionsInCollection").click(function(){
printDocument('all');
});
$("#printPreviewResetSelections").click(function(){
resetSelections();
});
$("#printPreviewShowSelections").click(function(){
showSelections();
});
});
function selectMenuItem(id){
var menuItemId;
if(id == "browsechapter"){
corpus = UrlHelper.getParameterByName("corpus");
if(corpus == "regs") {
menuItemId = "chapterRegulations";
}
else{
menuItemId = "chapterStatutes";
}
}
else if(id == "content"){
menuItemId = id + "-" + UrlHelper.getLastUrlSegment();
}
else if(id == "browseannual"){
corpus = UrlHelper.getParameterByName("filter");
//todo:trouver un autre moyen comme passer par un champ html caché
if (corpus == null){
corpus = UrlHelper.getParameterByName("filtre");
}
if(corpus == "regs") {
menuItemId = "browseannual-regs";
}
else{
menuItemId = "browseannual-statutes";
}
}
selector = "#" + menuItemId;
if(menuItemId && $(selector).length > 0){
$(selector).toggleClass("selected");
}
}
function resetSelections(){
cyberlex.selectionsProxy().clear();
$('#myModal').modal('hide');
showSelectionsButtonDisplay();
}
// Afficher le code JSON qui représente les sélections
function showSelections(){
//alert TEMPORAIRE, on devrait afficher un petit tableau comme les lois habilitantes d'un règlement
alert(cyberlex.selectionsProxy().showData());
}
function showSelectionsButtonDisplay(){
var mySelectionsCount = cyberlex.selectionsProxy().count();
$('#printPreviewButton').find('span.badge').text(mySelectionsCount);
if(mySelectionsCount > 0){
var tooltipStr = mySelectionsCount == 1 ? ressources.showSelectionsButtonTooltipSingleFrag : mySelectionsCount + " " + ressources.showSelectionsButtonTooltipMultipleFrags;
$('#goPrintPreview').attr('title', tooltipStr).tooltip('_fixTitle');
$('#printPreviewButton').removeClass("d-none").addClass("d-block");
$('#myModalSubtitle small').text(tooltipStr);
}
else{
$('#printPreviewButton').removeClass("d-block").addClass("d-none");;
}
}
function resizeWin(p_win, p_width, p_height){
p_win.resizeTo(p_width, p_height);
var left = (screen.availWidth - p_width ) / 2;
var top = (screen.availHeight - p_height) / 2;
p_win.moveTo(left, top);
}
function generateWindowWidth(){
return screen.width * .81;
}
function generateWindowHeight(){
return screen.height * .8;
}
function generateWindowCoordinates(){
var leftPos = 1;
var topPos = 1;
var width = generateWindowWidth();
var height = generateWindowHeight();
return ',left=' + leftPos + ',top=' + topPos + ',width=' + width + ',height=' + height;
}
// Pour lancer l'impression des sélections
function printDocument(p_type) {
// On ferme la fenetre modal d'impression
$('#myModal').modal('hide');
// On ouvre une fenetre pour envoyer les informations de la form pour le print.
var printWindow = window.open('', 'printWindow', 'directories=0,location=0,menubar=1,scrollbars=1,status=0,toolbar=1,resizable=1' + generateWindowCoordinates());
resizeWin(printWindow, generateWindowWidth(), generateWindowHeight());
printWindow.focus();
var printForm = $("#printForm")[0];
printForm.target = "printWindow";
printForm.action = "/" + ressources.langInt + "/ShowDoc?isPrint=true";
printForm.printType.value = p_type;
switch (p_type) {
case "hits" :
printWindow.location.href = "/" + ressources.langInt + "/PrintResult";
return null;
break;
case "tagged" :
printForm.selfrag.value = getSelectedFragments();
break;
case "all" :
printForm.selfrag.value = cyberlex.selectionsProxy().serializeData();
break;
}
printForm.recordsWithHits.value = (p_type == "record");
printForm.submit();
printForm.selfrag.value = "";
}