1
|
|
|
/* |
2
|
|
|
* FullTextSearch - Full text search framework for Nextcloud |
3
|
|
|
* |
4
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
5
|
|
|
* later. See the COPYING file. |
6
|
|
|
* |
7
|
|
|
* @author Maxence Lange <[email protected]> |
8
|
|
|
* @copyright 2018 |
9
|
|
|
* @license GNU AGPL version 3 or any later version |
10
|
|
|
* |
11
|
|
|
* This program is free software: you can redistribute it and/or modify |
12
|
|
|
* it under the terms of the GNU Affero General Public License as |
13
|
|
|
* published by the Free Software Foundation, either version 3 of the |
14
|
|
|
* License, or (at your option) any later version. |
15
|
|
|
* |
16
|
|
|
* This program is distributed in the hope that it will be useful, |
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19
|
|
|
* GNU Affero General Public License for more details. |
20
|
|
|
* |
21
|
|
|
* You should have received a copy of the GNU Affero General Public License |
22
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
23
|
|
|
* |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
/** global: searchbar */ |
27
|
|
|
/** global: api */ |
28
|
|
|
|
29
|
|
|
var settings = { |
30
|
|
|
|
31
|
|
|
delay_provider: 300, |
32
|
|
|
delay_result: 150, |
33
|
|
|
|
34
|
|
|
// 0.6.0 |
35
|
|
|
searchTimer: 1000, |
36
|
|
|
parent: null, |
37
|
|
|
searchProviderId: '', |
38
|
|
|
searchProviderName: '', |
39
|
|
|
resultContainer: null, |
40
|
|
|
resultHeader: null, |
41
|
|
|
resultFooter: null, |
42
|
|
|
entryTemplate: null, |
43
|
|
|
entryTemplateDefault: null, |
44
|
|
|
// divNoResult: null, |
45
|
|
|
options: [], |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* generate the default template to dsplay search result entries |
49
|
|
|
*/ |
50
|
|
|
generateDefaultTemplate: function () { |
51
|
|
|
|
52
|
|
|
var divLeft = $('<div>', {class: 'result_entry_left'}); |
53
|
|
|
divLeft.append($('<div>', {id: 'title'})); |
54
|
|
|
divLeft.append($('<div>', {id: 'line1'})); |
55
|
|
|
divLeft.append($('<div>', {id: 'line2'})); |
56
|
|
|
|
57
|
|
|
var divRight = $('<div>', {class: 'result_entry_right'}); |
58
|
|
|
//divRight.append($('<div>', {id: 'score'})); |
59
|
|
|
|
60
|
|
|
var div = $('<div>', {class: 'result_entry_default'}); |
61
|
|
|
div.append(divLeft); |
62
|
|
|
div.append(divRight); |
63
|
|
|
|
64
|
|
|
return $('<div>').append(div); |
65
|
|
|
}, |
66
|
|
|
|
67
|
|
|
// |
68
|
|
|
// /** |
69
|
|
|
// * generate a no result display |
70
|
|
|
// */ |
71
|
|
|
// generateNoResultDiv: function () { |
72
|
|
|
// var div = $('<div>', {id: 'noresult'}); |
73
|
|
|
// div.html('no result'); |
74
|
|
|
// div.hide(); |
75
|
|
|
// settings.divNoResult = div; |
76
|
|
|
// }, |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param template |
81
|
|
|
*/ |
82
|
|
|
setResultHeader: function (template) { |
83
|
|
|
settings.resultHeader = template; |
84
|
|
|
}, |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param template |
88
|
|
|
*/ |
89
|
|
|
setResultFooter: function (template) { |
90
|
|
|
settings.resultFooter = template; |
91
|
|
|
}, |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* used to set the template to display search result entries |
96
|
|
|
* |
97
|
|
|
* @param template |
98
|
|
|
*/ |
99
|
|
|
setEntryTemplate: function (template) { |
100
|
|
|
settings.entryTemplate = template; |
101
|
|
|
}, |
102
|
|
|
|
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* used to set the container for the search result entries |
106
|
|
|
* |
107
|
|
|
* @param container |
108
|
|
|
*/ |
109
|
|
|
setResultContainer: function (container) { |
110
|
|
|
settings.resultContainer = container; |
111
|
|
|
// settings.resultContainer.prepend(settings.divNoResult); |
112
|
|
|
}, |
113
|
|
|
|
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* initialize the full text search and assign a providerId |
117
|
|
|
* |
118
|
|
|
* @param providerId |
119
|
|
|
* @param providerName |
120
|
|
|
* @param parent |
121
|
|
|
*/ |
122
|
|
|
initFullTextSearch: function (providerId, providerName, parent) { |
123
|
|
|
settings.searchProviderId = providerId; |
124
|
|
|
settings.searchProviderName = providerName; |
125
|
|
|
settings.parent = parent; |
126
|
|
|
searchbox.init(); |
|
|
|
|
127
|
|
|
}, |
128
|
|
|
|
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* check that the app that call the lib contains a specific method |
132
|
|
|
* |
133
|
|
|
* @param method |
134
|
|
|
* @returns {boolean} |
135
|
|
|
*/ |
136
|
|
|
parentHasMethod: function (method) { |
137
|
|
|
if (settings.parent === null) { |
138
|
|
|
return false; |
139
|
|
|
} |
140
|
|
|
return (typeof eval('settings.parent. ' + method) === "function"); |
|
|
|
|
141
|
|
|
} |
142
|
|
|
}; |
143
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.