Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
dariah
search-commons-webresources
Commits
3e56a318
Commit
3e56a318
authored
Jun 04, 2019
by
Gradl, Tobias
Browse files
891: Highlighting von Treffen in der Suchausgabe
Task-Url:
https://pm.winseda.de/issues/891
parent
3784268d
Changes
2
Hide whitespace changes
Inline
Side-by-side
js/_common/util.js
View file @
3e56a318
...
...
@@ -96,13 +96,6 @@ Util.prototype.escapeHtml = function (a, obj) {
return
false
;
};
Util
.
prototype
.
contains
=
function
(
string
)
{
var
_this
=
this
;
return
String
(
string
).
replace
(
/
[
&<>"'
\/]
/g
,
function
(
s
)
{
return
_this
.
entityMap
[
s
];
});
};
Util
.
prototype
.
showLoginNote
=
function
()
{
var
_this
=
this
;
...
...
js/search/search.js
View file @
3e56a318
...
...
@@ -23,7 +23,7 @@ $(document).ready(function() {
});
var
clouds
=
[];
queryHandler
.
loadPlaceholderTagcloud
();
queryHandler
.
doSearch
();
...
...
@@ -58,6 +58,7 @@ var QueryHandler = function(options) {
this
.
schemaId
=
null
;
this
.
query
=
{};
this
.
lastDelayedQueryTs
=
null
;
// Helper variable for delayed queries (results slider)
this
.
imageQueue
=
[];
__translator
.
addTranslations
([
"
~eu.dariah.de.minfba.search.view.result.resources.score
"
,
...
...
@@ -88,9 +89,9 @@ var QueryHandler = function(options) {
sourceSelection
.
renderDatasourceList
();
if
(
$
(
"
#expression
"
).
length
>
0
)
{
/*
if ($("#expression").length>0) {
this.doSearch();
}
}
*/
if
(
$
(
"
#schemaId
"
).
length
>
0
)
{
this
.
selectFacetingSchema
();
}
...
...
@@ -259,7 +260,7 @@ QueryHandler.prototype.doSearch = function(isShowMore) {
//}
var
_this
=
this
;
this
.
query
=
this
.
buildQuery
(
isShowMore
);
this
.
imageQueue
=
[];
$
(
"
.wordcloud
"
).
text
(
""
);
this
.
clouds
=
[];
...
...
@@ -556,23 +557,10 @@ QueryHandler.prototype.processResponseResources = function(isShowMore, resultEle
content
.
push
([
"
score
"
,
""
]);
}
if
(
resultElements
[
i
].
integrationHtml
===
undefined
||
resultElements
[
i
].
integrationHtml
===
null
)
{
content
.
push
([
"
snippet
"
,
resultElements
[
i
].
contentHtml
]);
hideElements
.
push
(
"
.original-data-panel
"
);
}
else
{
content
.
push
([
"
snippet
"
,
resultElements
[
i
].
integrationHtml
]);
if
(
includeOriginal
&&
resultElements
[
i
].
contentHtml
!==
undefined
&&
resultElements
[
i
].
contentHtml
!==
null
)
{
content
.
push
([
"
original
"
,
resultElements
[
i
].
contentHtml
]);
}
else
{
hideElements
.
push
(
"
.original-data-panel
"
);
}
}
if
(
resultElements
[
i
].
explanation
!=
null
)
{
content
.
push
([
"
explanation
"
,
resultElements
[
i
].
explanation
]);
}
else
{
$
(
itemTemplate
).
find
(
"
.search-result-
subpanel
"
).
addClass
(
"
hide
"
);
$
(
itemTemplate
).
find
(
"
.search-result-
explanation
"
).
addClass
(
"
hide
"
);
}
if
(
resultElements
[
i
].
presentation
!==
undefined
&&
resultElements
[
i
].
presentation
!=
null
&&
...
...
@@ -583,42 +571,27 @@ QueryHandler.prototype.processResponseResources = function(isShowMore, resultEle
}
else
{
content
.
push
([
"
title
"
,
"
<em>
"
+
__translator
.
translate
(
"
~eu.dariah.de.minfba.search.view.result.no_title
"
)
+
"
</em>
"
]);
}
if
(
resultElements
[
i
].
presentation
.
Presentation
.
Link
!==
undefined
)
{
if
(
resultElements
[
i
].
presentation
.
Presentation
.
Link
instanceof
Array
)
{
var
link
=
""
;
for
(
var
j
=
0
;
j
<
resultElements
[
i
].
presentation
.
Presentation
.
Link
.
length
;
j
++
)
{
if
(
resultElements
[
i
].
presentation
.
Presentation
.
Link
[
j
][
"
~
"
]
===
undefined
)
{
link
+=
this
.
createLink
(
resultElements
[
i
].
presentation
.
Presentation
.
Link
[
j
].
URL
,
resultElements
[
i
].
presentation
.
Presentation
.
Link
[
j
].
Type
);
}
else
if
(
resultElements
[
i
].
presentation
.
Presentation
.
Link
[
j
][
"
~
"
].
startsWith
(
"
http
"
))
{
link
+=
this
.
createLink
(
resultElements
[
i
].
presentation
.
Presentation
.
Link
[
j
]);
}
}
content
.
push
([
"
link
"
,
{
"
~
"
:
link
}]);
}
else
{
if
(
resultElements
[
i
].
presentation
.
Presentation
.
Link
[
"
~
"
]
===
undefined
)
{
content
.
push
([
"
link
"
,
{
"
~
"
:
this
.
createLink
(
resultElements
[
i
].
presentation
.
Presentation
.
Link
.
URL
,
resultElements
[
i
].
presentation
.
Presentation
.
Link
.
Type
)}])
}
else
if
(
resultElements
[
i
].
presentation
.
Presentation
.
Link
[
"
~
"
].
startsWith
(
"
http
"
))
{
content
.
push
([
"
link
"
,
{
"
~
"
:
this
.
createLink
(
resultElements
[
i
].
presentation
.
Presentation
.
Link
)}])
}
}
}
else
{
content
.
push
([
"
link
"
,
""
]);
}
if
(
resultElements
[
i
].
fieldHighlights
!==
undefined
)
{
var
highlights
=
[];
for
(
var
j
=
0
;
j
<
resultElements
[
i
].
fieldHighlights
.
length
;
j
++
)
{
for
(
var
k
=
0
;
k
<
resultElements
[
i
].
fieldHighlights
[
j
].
highlightTexts
.
length
;
k
++
)
{
//if (!__util.contains(highlights, resultElements[i].fieldHighlights[j].highlightTexts[k])) {
for
(
var
j
=
0
;
j
<
resultElements
[
i
].
fieldHighlights
.
length
&&
j
<
10
;
j
++
)
{
for
(
var
k
=
0
;
k
<
resultElements
[
i
].
fieldHighlights
[
j
].
highlightTexts
.
length
&&
k
<
10
;
k
++
)
{
var
contained
=
false
;
for
(
l
=
0
;
l
<
highlights
.
length
;
l
++
)
{
if
(
highlights
[
l
]
==
resultElements
[
i
].
fieldHighlights
[
j
].
highlightTexts
[
k
])
{
contained
=
true
;
break
;
}
}
if
(
!
contained
)
{
highlights
.
push
(
resultElements
[
i
].
fieldHighlights
[
j
].
highlightTexts
[
k
]);
//}
}
}
}
var
strHighlight
=
""
;
for
(
var
j
=
0
;
j
<
highlights
.
length
;
j
++
)
{
strHighlight
+=
"
<
li
>
"
+
highlights
[
j
]
+
"
</
li
>
"
;
strHighlight
+=
"
<
div
>
"
+
highlights
[
j
]
+
"
</
div
>
"
;
}
...
...
@@ -627,12 +600,7 @@ QueryHandler.prototype.processResponseResources = function(isShowMore, resultEle
}
/*if (resultElements[i].presentation.Presentation.Images!==undefined && resultElements[i].presentation.Presentation.Images.Resource!==undefined) {
this.handleImages(resultElements[i].presentation.Presentation.Images.Resource, i);
} else {
$("#search-results-image-carousel-" + i).remove();
}*/
$
(
"
#search-results-resources
"
).
append
(
this
.
renderResultItem
(
itemTemplate
,
content
,
hideElements
));
...
...
@@ -659,6 +627,8 @@ QueryHandler.prototype.processResponseResources = function(isShowMore, resultEle
}
}
this
.
processImagesQueue
();
/*if (hasMore) {
$("#search-results-resources").append("<div class='search-results-resources-show-more' style='text-align: center;'><button onclick='queryHandler.doSearch(true);' class='btn btn-default btn-lg'>~Show more</button></div>");
...
...
@@ -807,8 +777,86 @@ QueryHandler.prototype.createLink = function(link, type) {
return
"
<li><a href='
"
+
link
[
"
~
"
]
+
"
' target='_blank'>
"
+
linkLabel
+
"
</a></li>
"
;
};
QueryHandler
.
prototype
.
handleImages
=
function
(
collectionId
,
endpointId
,
datasetId
,
images
,
index
,
placeholder
)
{
var
tmpsrc
=
undefined
;
var
src
=
undefined
;
if
(
placeholder
)
{
tmbsrc
=
__util
.
composeUrl
(
"
cachedimages/
"
+
collectionId
+
"
?i=
"
+
encodeURIComponent
(
images
[
0
]));
}
else
{
src
=
__util
.
composeUrl
(
"
cachedimages/
"
+
collectionId
+
"
/
"
+
endpointId
+
"
/
"
+
datasetId
+
"
?i=
"
+
encodeURIComponent
(
images
[
0
])
+
"
&type=DISPLAY
"
);
tmbsrc
=
__util
.
composeUrl
(
"
cachedimages/
"
+
collectionId
+
"
/
"
+
endpointId
+
"
/
"
+
datasetId
+
"
?i=
"
+
encodeURIComponent
(
images
[
0
]));
}
this
.
imageQueue
.
push
({
tmbsrc
:
tmbsrc
,
src
:
src
,
index
:
index
,
imageIndex
:
0
,
placeholder
:
placeholder
,
onlyImage
:
(
placeholder
||
images
.
length
==
1
)
});
};
QueryHandler
.
prototype
.
processImagesQueue
=
function
()
{
if
(
this
.
imageQueue
.
length
==
0
)
{
return
;
}
var
image
=
this
.
imageQueue
.
shift
();
var
_this
=
this
;
console
.
log
(
image
);
$
.
ajax
({
url
:
image
.
tmbsrc
,
cache
:
true
,
context
:
{
tmbsrc
:
image
.
tmbsrc
,
src
:
image
.
src
,
index
:
image
.
index
,
imageIndex
:
0
,
placeholder
:
image
.
placeholder
},
success
:
function
()
{
_this
.
showImage
(
this
.
tmbsrc
,
this
.
src
,
this
.
index
,
this
.
imageIndex
);
/*$("#search-results-resources .venobox").venobox(); */
},
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
_this
.
showImage
(
__util
.
composeUrl
(
"
theme/img/placeholder-logo.png
"
),
undefined
,
this
.
index
,
this
.
imageIndex
);
},
complete
:
function
()
{
if
(
this
.
placeholder
)
{
$
(
"
#search-results-image-
"
+
this
.
index
+
"
.no-preview-overlay
"
).
removeClass
(
"
hide
"
);
}
$
(
"
#search-results-image-
"
+
this
.
index
+
"
.image-loading-overlay
"
).
addClass
(
"
hide
"
);
_this
.
processImagesQueue
();
}
});
};
QueryHandler
.
prototype
.
showImage
=
function
(
tmbsrc
,
src
,
resultIndex
,
imageIndex
)
{
var
carouselContainer
=
$
(
"
#search-results-image-
"
+
resultIndex
);
if
(
src
===
undefined
)
{
var
image
=
"
<div id=
\"
search-results-image-
"
+
resultIndex
+
"
-
"
+
imageIndex
+
"
\"
class=
\"
search-result-image-tmb
\"
style=
\"
background-image: url(
"
+
tmbsrc
+
"
);
\"
></div>
"
;
}
else
{
var
image
=
"
<a href=
\"
"
+
src
+
"
\"
data-gall=
\"
search-results-image-
"
+
resultIndex
+
"
\"
class=
\"
venobox
\"
>
"
+
"
<div id=
\"
search-results-image-
"
+
resultIndex
+
"
-
"
+
imageIndex
+
"
\"
class=
\"
search-result-image-tmb
\"
style=
\"
background-image: url(
"
+
tmbsrc
+
"
);
\"
></div>
"
"
<a>
"
;
}
carouselContainer
.
html
(
image
);
};
QueryHandler
.
prototype
.
handleImagesOld
=
function
(
collectionId
,
endpointId
,
datasetId
,
images
,
index
,
placeholder
)
{
var
_this
=
this
;
var
imageContainer
=
$
(
"
#search-results-image-
"
+
index
);
var
imageBackgroundContainer
=
$
(
"
#search-results-image-
"
+
index
+
"
.background
"
);
...
...
@@ -821,54 +869,53 @@ QueryHandler.prototype.handleImages = function(collectionId, endpointId, dataset
if
(
images
.
length
>
0
)
{
imageBackgroundContainer
.
addClass
(
"
hide
"
);
// Limit this preview to five images
for
(
var
j
=
0
;
j
<
images
.
length
&&
j
<
5
;
j
++
)
{
if
(
images
[
j
]
===
undefined
||
images
[
j
]
===
null
)
{
continue
;
}
var
tmpsrc
=
undefined
;
var
src
=
undefined
;
if
(
placeholder
)
{
tmbsrc
=
__util
.
composeUrl
(
"
cachedimages/
"
+
collectionId
+
"
?i=
"
+
encodeURIComponent
(
images
[
j
]));
}
else
{
src
=
__util
.
composeUrl
(
"
cachedimages/
"
+
collectionId
+
"
/
"
+
endpointId
+
"
/
"
+
datasetId
+
"
?i=
"
+
encodeURIComponent
(
images
[
j
])
+
"
&type=DISPLAY
"
);
tmbsrc
=
__util
.
composeUrl
(
"
cachedimages/
"
+
collectionId
+
"
/
"
+
endpointId
+
"
/
"
+
datasetId
+
"
?i=
"
+
encodeURIComponent
(
images
[
j
]));
}
$
.
ajax
({
url
:
tmbsrc
,
cache
:
true
,
context
:
{
tmbsrc
:
tmbsrc
,
src
:
src
,
index
:
index
,
imageIndex
:
j
,
placeholder
:
placeholder
,
onlyImage
:
(
placeholder
||
images
.
length
==
1
)
},
success
:
function
()
{
_this
.
loadImage
(
this
.
tmbsrc
,
this
.
src
,
this
.
index
,
this
.
imageIndex
,
this
.
onlyImage
);
if
(
!
placeholder
)
{
$
(
"
#search-results-image-
"
+
this
.
index
+
"
.no-preview-overlay
"
).
hide
();
}
$
(
"
#search-results-resources .venobox
"
).
venobox
();
},
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
if
(
$
(
"
#search-results-image-carousel-
"
+
this
.
index
+
"
.carousel-inner .carousel-item
"
).
length
==
0
)
{
$
(
"
#search-results-image-carousel-
"
+
this
.
index
).
remove
();
}
},
complete
:
function
()
{
$
(
"
#search-results-image-carousel-
"
+
this
.
index
).
removeClass
(
"
hide
"
);
}
});
/*if (images[0]===undefined || images[0]===null) {
continue;
}*/
var
tmpsrc
=
undefined
;
var
src
=
undefined
;
if
(
placeholder
)
{
tmbsrc
=
__util
.
composeUrl
(
"
cachedimages/
"
+
collectionId
+
"
?i=
"
+
encodeURIComponent
(
images
[
0
]));
}
else
{
src
=
__util
.
composeUrl
(
"
cachedimages/
"
+
collectionId
+
"
/
"
+
endpointId
+
"
/
"
+
datasetId
+
"
?i=
"
+
encodeURIComponent
(
images
[
0
])
+
"
&type=DISPLAY
"
);
tmbsrc
=
__util
.
composeUrl
(
"
cachedimages/
"
+
collectionId
+
"
/
"
+
endpointId
+
"
/
"
+
datasetId
+
"
?i=
"
+
encodeURIComponent
(
images
[
0
]));
}
$
.
ajax
({
url
:
tmbsrc
,
cache
:
true
,
context
:
{
tmbsrc
:
tmbsrc
,
src
:
src
,
index
:
index
,
imageIndex
:
0
,
placeholder
:
placeholder
,
onlyImage
:
(
placeholder
||
images
.
length
==
1
)
},
success
:
function
()
{
_this
.
loadImage
(
this
.
tmbsrc
,
this
.
src
,
this
.
index
,
this
.
imageIndex
,
this
.
onlyImage
);
if
(
!
placeholder
)
{
$
(
"
#search-results-image-
"
+
this
.
index
+
"
.no-preview-overlay
"
).
hide
();
}
$
(
"
#search-results-resources .venobox
"
).
venobox
();
},
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
if
(
$
(
"
#search-results-image-
"
+
this
.
index
+
"
.carousel-inner .carousel-item
"
).
length
==
0
)
{
$
(
"
#search-results-image-
"
+
this
.
index
).
remove
();
}
},
complete
:
function
()
{
$
(
"
#search-results-image-
"
+
this
.
index
).
removeClass
(
"
hide
"
);
}
});
}
};
QueryHandler
.
prototype
.
loadImage
=
function
(
tmbsrc
,
src
,
resultIndex
,
imageIndex
,
onlyImage
)
{
var
carouselContainer
=
$
(
"
#search-results-image-
carousel-
"
+
resultIndex
);
var
carouselContainer
=
$
(
"
#search-results-image-
"
+
resultIndex
);
if
(
src
===
undefined
)
{
var
image
=
"
<div id=
\"
search-results-image-
"
+
resultIndex
+
"
-
"
+
imageIndex
+
"
\"
class=
\"
search-result-image-tmb
\"
style=
\"
background-image: url(
"
+
tmbsrc
+
"
);
\"
></div>
"
;
}
else
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment