1
|
|
|
/* |
2
|
|
|
* Bookmarks_FullTextSearch - Indexing bookmarks |
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
|
|
|
|
27
|
|
|
/** global: OCA */ |
28
|
|
|
|
29
|
|
|
const fullTextSearch = OCA.FullTextSearch.api; |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
var elements = { |
33
|
|
|
old_bookmarks: null, |
34
|
|
|
search_result: null, |
35
|
|
|
template_entry: null |
36
|
|
|
}; |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
const Bookmarks_FullTextSearch = function () { |
40
|
|
|
this.init(); |
41
|
|
|
}; |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
Bookmarks_FullTextSearch.prototype = { |
45
|
|
|
|
46
|
|
|
init: function () { |
47
|
|
|
var self = this; |
48
|
|
|
|
49
|
|
|
elements.old_bookmarks = $('.bookmarks_list'); |
50
|
|
|
|
51
|
|
|
elements.search_result = $('<div>'); |
52
|
|
|
elements.search_result.insertBefore(elements.old_bookmarks); |
53
|
|
|
|
54
|
|
|
elements.search_input = $('#next_search_input'); |
55
|
|
|
|
56
|
|
|
elements.template_entry = self.generateTemplateEntry(); |
57
|
|
|
fullTextSearch.setEntryTemplate(elements.template_entry); |
58
|
|
|
fullTextSearch.setResultContainer(elements.search_result); |
59
|
|
|
fullTextSearch.initFullTextSearch('bookmarks', 'bookmarks', self); |
60
|
|
|
}, |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
generateTemplateEntry: function () { |
64
|
|
|
|
65
|
|
|
var divLeft = $('<div>', {class: 'result_entry_left'}); |
66
|
|
|
divLeft.append($('<div>', {id: 'title'})); |
67
|
|
|
divLeft.append($('<div>', {id: 'line1'})); |
68
|
|
|
divLeft.append($('<div>', {id: 'line2'})); |
69
|
|
|
|
70
|
|
|
var divRight = $('<div>', {class: 'result_entry_right'}); |
71
|
|
|
divRight.append($('<div>', {id: 'score'})); |
72
|
|
|
|
73
|
|
|
var divDefault = $('<div>', {class: 'result_entry_default'}); |
74
|
|
|
divDefault.append(divLeft); |
75
|
|
|
divDefault.append(divRight); |
76
|
|
|
|
77
|
|
|
return $('<div>').append(divDefault); |
78
|
|
|
}, |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
onEntryGenerated: function (entry) { |
82
|
|
|
entry.off('click').on('click', function () { |
83
|
|
|
window.open(entry.attr('data-link'), '_blank'); |
84
|
|
|
}); |
85
|
|
|
}, |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
onResultDisplayed: function () { |
89
|
|
|
elements.old_bookmarks.fadeOut(150, function () { |
90
|
|
|
elements.search_result.fadeIn(150); |
91
|
|
|
}); |
92
|
|
|
}, |
93
|
|
|
|
94
|
|
|
|
95
|
|
|
onSearchReset: function () { |
96
|
|
|
elements.search_result.fadeOut(150, function () { |
97
|
|
|
elements.old_bookmarks.fadeIn(150); |
98
|
|
|
}); |
99
|
|
|
}, |
100
|
|
|
|
101
|
|
|
|
102
|
|
|
onResultClose: function () { |
103
|
|
|
elements.search_result.fadeOut(150, function () { |
104
|
|
|
elements.old_bookmarks.fadeIn(150); |
105
|
|
|
}); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
}; |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
OCA.FullTextSearch.Bookmarks = Bookmarks_FullTextSearch; |
112
|
|
|
|
113
|
|
|
$(document).ready(function () { |
114
|
|
|
OCA.FullTextSearch.navigate = new Bookmarks_FullTextSearch(); |
115
|
|
|
}); |
116
|
|
|
|
117
|
|
|
|
118
|
|
|
|
119
|
|
|
|