Merge pull request #695 from albig/cherrypick-693

Refactor check for fulltext into utility function
This commit is contained in:
Alexander Bigga 2021-10-18 09:40:49 +02:00 committed by GitHub
commit 930e22ce55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 3 deletions

View File

@ -164,7 +164,7 @@ dlfViewer.prototype.addCustomControls = function() {
// Adds fulltext behavior and download only if there is fulltext available and no double page
// behavior is active
if (this.fulltexts[0] !== undefined && this.fulltexts[0].length !== 0 && this.fulltexts[0].url !== '' && this.images.length === 1) {
if (dlfUtils.isFulltextDescriptor(this.fulltexts[0]) && this.images.length === 1) {
fulltextControl = new dlfViewerFullTextControl(this.map, this.images[0], this.fulltexts[0].url);
fulltextDownloadControl = new dlfViewerFullTextDownloadControl(this.map, this.images[0], this.fulltexts[0].url);
} else {
@ -331,7 +331,7 @@ dlfViewer.prototype.displayHighlightWord = function(highlightWords = null) {
}
}
if (this.fulltexts[0] !== undefined && this.fulltexts[0].url !== '' && this.images.length > 0) {
if (dlfUtils.isFulltextDescriptor(this.fulltexts[0]) && this.images.length > 0) {
var values = [],
fulltextData = dlfFullTextUtils.fetchFullTextDataFromServer(this.fulltexts[0].url, this.images[0]),
fulltextDataImageTwo = undefined;
@ -341,7 +341,7 @@ dlfViewer.prototype.displayHighlightWord = function(highlightWords = null) {
}
// check if there is another image / fulltext to look for
if (this.images.length === 2 & this.fulltexts[1] !== undefined && this.fulltexts[1].url !== '') {
if (this.images.length === 2 && dlfUtils.isFulltextDescriptor(this.fulltexts[1])) {
var image = $.extend({}, this.images[1]);
image.width = image.width + this.images[0].width;
fulltextDataImageTwo = dlfFullTextUtils.fetchFullTextDataFromServer(this.fulltexts[1].url, this.images[1], this.images[0].width);

View File

@ -755,6 +755,22 @@ dlfUtils.isCorsEnabled = function (imageObjs) {
return response;
};
/**
* Checks if {@link obj} is a valid object describing the location of a
* fulltext (@see PageView::getFulltext in PageView.php).
*
* @param {any} obj The object to test.
* @return {boolean}
*/
dlfUtils.isFulltextDescriptor = function (obj) {
return (
typeof obj === 'object'
&& obj !== null
&& 'url' in obj
&& obj.url !== ''
);
};
/**
* Functions checks if WebGL is enabled in the browser
* @return {boolean}