Skip to content

Commit

Permalink
Merge remote-tracking branch 'UBMA/6.x-ocr' into 6.x-ocr-0109
Browse files Browse the repository at this point in the history
Signed-off-by: Christos Sidiropoulos <[email protected]>
  • Loading branch information
csidirop committed Jan 10, 2024
2 parents 6120f56 + fc6142b commit 208dbb4
Show file tree
Hide file tree
Showing 27 changed files with 2,007 additions and 73 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/npm-grunt.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,52 @@
name: GruntComparison

on:
push:
branches: [ "master", "6.x-ocr" ]
pull_request:
branches: [ "master", "6.x-ocr" ]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x]

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: npm
cache-dependency-path: './Build/package-lock.json'

- name: Install and run Grunt
working-directory: ./Build
run: |
npm install -g grunt-cli
npm audit fix
echo "Running `grunt less`"
grunt less
echo "Running `grunt terser`"
grunt terser
- name: Test for changes
working-directory: ./
run: |
git diff -- ./Resources/Public/
if [ -n "$(git status --porcelain -- ./Resources/Public/)" ]; then
echo "Changes detected in compiled files"
exit 1
else
echo "No changes detected in compiled files"
fi
name: GruntComparison

on:
push:
branches: [ "master" ]
Expand Down
2 changes: 1 addition & 1 deletion Build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"repository": {
"type": "git",
"url": "[email protected]:slub/dfg-viewer.git"
"url": "[email protected]:csidirop/dfg-viewer.git"
},
"author": "Alexander Bigga",
"license": "GPL-3.0-or-later",
Expand Down
110 changes: 106 additions & 4 deletions Resources/Private/JavaScript/dfgviewerScripts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*!
/*!
Custom scripts
------------------------
Expand All @@ -20,11 +20,20 @@ $(document).ready(function() {

// menu toggles for offcanvas toc and metadata
$('.offcanvas-toggle').on(mobileEvent, function(event) {
// close nav on link or download if opened
close_all_submenus();

$(this).parent().toggleClass('open');
});

// active toggle for submenus
$('.document-functions li.submenu > a').on(mobileEvent, function(event) {
// close nav on link or download if opened
close_all_submenus('in-secondary-nav');

// close secondary nav if click on link or download
$('nav .secondary-nav').removeClass('open');

$('li.submenu.open a').not(this).parent().removeClass('open');
$(this).parent().toggleClass('open');
return false;
Expand All @@ -34,8 +43,18 @@ $(document).ready(function() {
$('nav .nav-toggle').on(mobileEvent, function(event) {
$(this).toggleClass('active');
$('nav .viewer-nav').toggleClass('open');

// close subnav if primary nav if opened
close_all_submenus('in-primary-nav');

});
// active toggle for subsubmenus
$('.document-functions li.subsubmenu > a').on(mobileEvent, function(event) {
$(this).parent().toggleClass('open');
return false;
});


// calendar dropdowns
$('.calendar-view .contains-issues').on(mobileEvent, function(event) {
$('.calendar-view table td.open').not($(this).parent()).removeClass('open');
Expand Down Expand Up @@ -104,6 +123,7 @@ $(document).ready(function() {

// enable click on fullscreen button
$('a.fullscreen').on(mobileEvent, function() {
close_all_submenus('all');
if($('body.fullscreen')[0]) {
exitFullscreen();
} else {
Expand Down Expand Up @@ -164,10 +184,80 @@ $(document).ready(function() {
$('body').removeClass('static');
}, 1000);

// Closing open menus in different situations
$('.tx-dlf-tools-imagetools').on('click', function (event) {
close_all_submenus('all');
});
$('.page-control').on('click', function (event) {
close_all_submenus('all');
});
$('.tx-dlf-map').on('click', function (event) {
close_all_submenus('all');
});

// Parse OCR options submenu
function parseOcrMenu() {
let lang = $('html').attr('lang').substr(0,2);
let ulid = $('#ocr-engine');
let enginesData = JSON.parse(Cookies.get('tx-dlf-ocrEngines')).ocrEngines;
/* Expected scheme:
{
"menu":[
{"name": "Tesseract", "de": "Tesseract", "en": "Tesseract", "class": "tesseract", "data": "tesseract-basic"
},
{"name": "Tess", "de": "Tess (de)", "en": "Tess (en)", "class": "tess", "data": "tess-basic"
}
]}
*/

// get cookie for ocrEngine
let ocrEngine = Cookies.get('tx-dlf-ocrEngine');
let active = '';

// Set listelement for remote fulltext (independent of the OCR engines):
if (Cookies.get('tx-dlf-ocr-remotepresent') === "Y") { // only if remote fulltext is present
active = ((ocrEngine === "originalremote") ? ' active' : ''); // set class active if this remote is active

// Build element:
$(ulid).append('<li class="subli"> <a id="ocr-on-demand-id-originalremote" class="originalremote ' + active + ' present"> <i>Original fulltext</i> <i class="checks" aria-hidden="true"></i></a></li>');
$(ulid).append('<hr>'); // Add a dividing line

if (active.length != 0) {
$('.ocr-create').addClass('disabled-item'); // deactivte OCR buttons
}

// add class active to subelement, store info in cookie and deactivate OCR buttons:
$('#ocr-on-demand-id-originalremote').on(mobileEvent, function(event) {
$('.subli a').removeClass('active');
$(this).addClass('active');
Cookies.set('tx-dlf-ocrEngine', "originalremote", { sameSite: 'lax' }); // store in cookie
$('.ocr-create').addClass('disabled-item');
});
}

// Set all other listelements (depending on the OCR engines):
for (let i=0; i<enginesData.length; i++) {
active = ((enginesData[i].data === ocrEngine) ? ' active' : ''); // set class active if this element === ocrEngine
present = ((enginesData[i].avail === "Y") ? ' present' : ''); // set class present if server sents cookie

// Build element:
$(ulid).append('<li class="subli">'
+ '<a id="ocr-on-demand-id-' + enginesData[i].data + '" class="' + enginesData[i].class + active + present + '" href="#" data-engine="' + enginesData[i].data + '">'
+ enginesData[i][lang] + '<i class="checks" aria-hidden="true"></i></a></li>');

// add class active to subelement, store selected engine in cookie and reactivate OCR buttons:
$('#ocr-on-demand-id-' + enginesData[i].data).on(mobileEvent, function(event) {
$('.subli a').removeClass('active');
$(this).addClass('active');
Cookies.set('tx-dlf-ocrEngine', this.dataset.engine, { sameSite: 'lax' }); // store in cookie
$('.ocr-create').removeClass('disabled-item');
});
}
}
parseOcrMenu();
});

$(document).keyup(function(e) {

// Check if ESC key is pressed. Then end fullscreen mode or close SRU form.
if (e.keyCode == 27) {
if($('body.fullscreen')[0]) {
Expand All @@ -181,7 +271,6 @@ $(document).keyup(function(e) {
if (e.keyCode == 70 && !$('#tx-dfgviewer-sru-query').is(':focus')) {
return enterFullscreen();
}

});

// Activate fullscreen mode and set corresponding cookie
Expand All @@ -202,8 +291,21 @@ function exitFullscreen() {

// hide warning about outdated browser and save decision to cookie
function hideBrowserAlert(){

$('#browser-hint').addClass('hidden');
Cookies.set('tx-dlf-pageview-hidebrowseralert', 'true', { sameSite: 'lax' });
}

// Auto close submenus when other menus are opened
function close_all_submenus(environment = '') {
// close nav on link or download if opened
if (environment !== 'in-secondary-nav') {
// Not with in-secondary-nav otherwise menus can no longer be closed
$('li.submenu.open a').parent().removeClass('open');
};
if ((environment === 'in-secondary-nav') || (environment === 'all') ) {
// close subnav if opend
$('nav .nav-toggle').removeClass('active');
$('nav .secondary-nav').removeClass('open');
$('nav ul.viewer-nav').removeClass('open');
};
}
8 changes: 8 additions & 0 deletions Resources/Private/Language/de.locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@
<source><![CDATA[Fullscreen Mode]]></source>
<target><![CDATA[Vollansicht]]></target>
</trans-unit>
<trans-unit id="fulltext.create_ocr_book" approved="yes">
<source><![CDATA[Create fulltext for all pages]]></source>
<target><![CDATA[Erzeuge Volltexte für alle Seiten]]></target>
</trans-unit>
<trans-unit id="fulltext.create_ocr_page" approved="yes">
<source><![CDATA[Create fulltext for current page]]></source>
<target><![CDATA[Erzeuge Volltext für die aktuelle Seite]]></target>
</trans-unit>
<trans-unit id="fulltext.no_fulltext_double" approved="yes">
<source><![CDATA[No fulltext in double page mode.]]></source>
<target><![CDATA[Keine Volltexte in der Doppelseitenansicht.]]></target>
Expand Down
12 changes: 12 additions & 0 deletions Resources/Private/Language/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
<trans-unit id="download.work">
<source>Download whole work</source>
</trans-unit>
<trans-unit id="fulltext.create_ocr_book">
<source>Create text for all pages</source>
</trans-unit>
<trans-unit id="fulltext.create_ocr_page">
<source>Create text for current page</source>
</trans-unit>
<trans-unit id="fulltext.no_fulltext_gridpage">
<source>No fulltext in gridpage mode.</source>
</trans-unit>
Expand All @@ -35,6 +41,12 @@
<trans-unit id="fulltext.no_fulltext_double">
<source>No fulltext in double page mode.</source>
</trans-unit>
<trans-unit id="fulltext.create_ocr_page">
<source>Perform OCR for current page</source>
</trans-unit>
<trans-unit id="fulltext.create_ocr_book">
<source>Perform OCR for current document</source>
</trans-unit>
<trans-unit id="gridpage.preview">
<source>Thumbnail Preview</source>
</trans-unit>
Expand Down
Loading

0 comments on commit 208dbb4

Please sign in to comment.