Skip to content

Commit a32763a

Browse files
Adjust URL generation for results' links
After this adjustments displaying and highlighting of the results in image works.
1 parent 186e2fd commit a32763a

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

Resources/Public/Javascript/Search/SearchInDocument.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,20 @@ function addHighlightEffect(highlightIds) {
6565
/**
6666
* Get base URL for snippet links.
6767
*
68+
* @param {string} id
69+
*
6870
* @returns {string}
6971
*/
70-
function getBaseUrl() {
72+
function getBaseUrl(id) {
7173
// Take the workview baseUrl from the form action.
7274
// The URL may be in the following form
7375
// - http://example.com/index.php?id=14
7476
// - http://example.com/workview (using slug on page with uid=14)
7577
var baseUrl = $("form#tx-dlf-search-in-document-form").attr('action');
7678

77-
// it is specific to DDB Zeitungsportal
78-
// TODO: make this solution more generic
79-
if(baseUrl.indexOf('ddb-current/newspaper/item')) {
80-
baseUrl = window.location.href;
79+
// check if action URL contains id, if not, get URL from window
80+
if(baseUrl.split('?')[0].indexOf(id) === -1) {
81+
baseUrl = $(location).attr('href');
8182
}
8283

8384
return baseUrl;
@@ -87,11 +88,11 @@ function getBaseUrl() {
8788
* Get current URL query parameters.
8889
* It returns array of params in form 'param=value' if there are any params supplied in the given url. If there are none it returns empty array
8990
*
91+
* @param {string} baseUrl
92+
*
9093
* @returns {array} array with params or empty
9194
*/
92-
function getCurrentQueryParams() {
93-
var baseUrl = getBaseUrl();
94-
95+
function getCurrentQueryParams(baseUrl) {
9596
if(baseUrl.indexOf('?') > 0) {
9697
return baseUrl.slice(baseUrl.indexOf('?') + 1).split('&');
9798
}
@@ -103,12 +104,13 @@ function getCurrentQueryParams() {
103104
* Get all URL query parameters for snippet links.
104105
* All means that it includes together params which were already supplied in the page url and params which are returned as search results.
105106
*
107+
* @param {string} baseUrl
106108
* @param {array} queryParams
107109
*
108110
* @returns {array} array with params in form 'param' => 'value'
109111
*/
110-
function getAllQueryParams(queryParams) {
111-
var params = getCurrentQueryParams();
112+
function getAllQueryParams(baseUrl, queryParams) {
113+
var params = getCurrentQueryParams(baseUrl);
112114

113115
var queryParam;
114116
for(var i = 0; i < params.length; i++) {
@@ -138,12 +140,15 @@ function getNeededQueryParams(element) {
138140
var page = $("input[id='tx-dlf-search-in-document-page']").attr('name');
139141

140142
var queryParams = [];
143+
144+
if(getBaseUrl(element['uid']).split('?')[0].indexOf(element['uid']) === -1) {
141145
queryParams.push(id);
142146
queryParams[id] = element['uid'];
143-
queryParams.push(highlightWord);
144-
queryParams[highlightWord] = encodeURIComponent(searchWord);
145-
queryParams.push(page);
146-
queryParams[page] = element['page'];
147+
}
148+
queryParams.push(highlightWord);
149+
queryParams[highlightWord] = encodeURIComponent(searchWord);
150+
queryParams.push(page);
151+
queryParams[page] = element['page'];
147152

148153
return queryParams;
149154
}
@@ -156,12 +161,12 @@ function getNeededQueryParams(element) {
156161
* @returns {string}
157162
*/
158163
function getLink(element) {
159-
var baseUrl = getBaseUrl();
164+
var baseUrl = getBaseUrl(element['uid']);
160165

161166
var queryParams = getNeededQueryParams(element);
162167

163168
if (baseUrl.indexOf('?') > 0) {
164-
queryParams = getAllQueryParams(queryParams);
169+
queryParams = getAllQueryParams(baseUrl, queryParams);
165170
baseUrl = baseUrl.split('?')[0];
166171
}
167172

@@ -225,8 +230,6 @@ function search() {
225230
}
226231

227232
addHighlightEffect(element['highlight']);
228-
229-
// TODO: highlight found phrase in image
230233
});
231234
// Sort result by page.
232235
resultItems.sort(function (a, b) {

0 commit comments

Comments
 (0)