@@ -65,19 +65,20 @@ function addHighlightEffect(highlightIds) {
65
65
/**
66
66
* Get base URL for snippet links.
67
67
*
68
+ * @param {string } id
69
+ *
68
70
* @returns {string }
69
71
*/
70
- function getBaseUrl ( ) {
72
+ function getBaseUrl ( id ) {
71
73
// Take the workview baseUrl from the form action.
72
74
// The URL may be in the following form
73
75
// - http://example.com/index.php?id=14
74
76
// - http://example.com/workview (using slug on page with uid=14)
75
77
var baseUrl = $ ( "form#tx-dlf-search-in-document-form" ) . attr ( 'action' ) ;
76
78
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' ) ;
81
82
}
82
83
83
84
return baseUrl ;
@@ -87,11 +88,11 @@ function getBaseUrl() {
87
88
* Get current URL query parameters.
88
89
* 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
89
90
*
91
+ * @param {string } baseUrl
92
+ *
90
93
* @returns {array } array with params or empty
91
94
*/
92
- function getCurrentQueryParams ( ) {
93
- var baseUrl = getBaseUrl ( ) ;
94
-
95
+ function getCurrentQueryParams ( baseUrl ) {
95
96
if ( baseUrl . indexOf ( '?' ) > 0 ) {
96
97
return baseUrl . slice ( baseUrl . indexOf ( '?' ) + 1 ) . split ( '&' ) ;
97
98
}
@@ -103,12 +104,13 @@ function getCurrentQueryParams() {
103
104
* Get all URL query parameters for snippet links.
104
105
* All means that it includes together params which were already supplied in the page url and params which are returned as search results.
105
106
*
107
+ * @param {string } baseUrl
106
108
* @param {array } queryParams
107
109
*
108
110
* @returns {array } array with params in form 'param' => 'value'
109
111
*/
110
- function getAllQueryParams ( queryParams ) {
111
- var params = getCurrentQueryParams ( ) ;
112
+ function getAllQueryParams ( baseUrl , queryParams ) {
113
+ var params = getCurrentQueryParams ( baseUrl ) ;
112
114
113
115
var queryParam ;
114
116
for ( var i = 0 ; i < params . length ; i ++ ) {
@@ -138,12 +140,15 @@ function getNeededQueryParams(element) {
138
140
var page = $ ( "input[id='tx-dlf-search-in-document-page']" ) . attr ( 'name' ) ;
139
141
140
142
var queryParams = [ ] ;
143
+
144
+ if ( getBaseUrl ( element [ 'uid' ] ) . split ( '?' ) [ 0 ] . indexOf ( element [ 'uid' ] ) === - 1 ) {
141
145
queryParams . push ( id ) ;
142
146
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' ] ;
147
152
148
153
return queryParams ;
149
154
}
@@ -156,12 +161,12 @@ function getNeededQueryParams(element) {
156
161
* @returns {string }
157
162
*/
158
163
function getLink ( element ) {
159
- var baseUrl = getBaseUrl ( ) ;
164
+ var baseUrl = getBaseUrl ( element [ 'uid' ] ) ;
160
165
161
166
var queryParams = getNeededQueryParams ( element ) ;
162
167
163
168
if ( baseUrl . indexOf ( '?' ) > 0 ) {
164
- queryParams = getAllQueryParams ( queryParams ) ;
169
+ queryParams = getAllQueryParams ( baseUrl , queryParams ) ;
165
170
baseUrl = baseUrl . split ( '?' ) [ 0 ] ;
166
171
}
167
172
@@ -225,8 +230,6 @@ function search() {
225
230
}
226
231
227
232
addHighlightEffect ( element [ 'highlight' ] ) ;
228
-
229
- // TODO: highlight found phrase in image
230
233
} ) ;
231
234
// Sort result by page.
232
235
resultItems . sort ( function ( a , b ) {
0 commit comments