/* * FullTextSearch - Full text search framework for Nextcloud * * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * * @author Maxence Lange * @copyright 2018 * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . * */ /** global: searchbar */ /** global: api */ var settings = { delay_provider: 300, delay_result: 150, searchRequestTimer: 4000, searchEntryTimer: 1500, parent: null, searchProviderId: '', searchProviderName: '', resultContainer: null, resultHeader: null, resultFooter: null, entryTemplate: null, entryTemplateDefault: null, // divNoResult: null, options: [], /** * generate the default template to display search result entries */ generateDefaultTemplate: function () { var resultContent = $('
', {class: 'result_content'}); resultContent.append($('
', { id: 'title', class: 'result_title' })); resultContent.append($('
', { id: 'extract', class: 'result_extract' })); var resultEntry = $('
', {class: 'result_entry'}); resultEntry.append($('
', {class: 'result_div_checkbox'})); resultEntry.append($('
', {class: 'result_div result_div_content'}).append(resultContent)); var resultRight = $('
', {class: 'result_div result_div_right'}); resultRight.append($('
', {id: 'source'})); resultRight.append($('
', {id: 'info'})); resultEntry.append(resultRight); return $('
').append(resultEntry); }, // var divLeft = $('
', {class: 'result_entry_left'}); // divLeft.append($('
', {id: 'title'})); // divLeft.append($('
', {id: 'line1'})); // divLeft.append($('
', {id: 'line2'})); // // var divRight = $('
', {class: 'result_entry_right'}); // //divRight.append($('
', {id: 'score'})); // // var div = $('
', {class: 'result_entry_default'}); // div.append(divLeft); // div.append(divRight); // // return $('
').append(div); // }, // // /** // * generate a no result display // */ // generateNoResultDiv: function () { // var div = $('
', {id: 'noresult'}); // div.html('no result'); // div.hide(); // settings.divNoResult = div; // }, /** * @param template */ setResultHeader: function (template) { settings.resultHeader = template; }, /** * @param template */ setResultFooter: function (template) { settings.resultFooter = template; }, /** * used to set the template to display search result entries * * @param template */ setEntryTemplate: function (template) { settings.entryTemplate = template; }, /** * used to set the container for the search result entries * * @param container */ setResultContainer: function (container) { settings.resultContainer = container; // settings.resultContainer.prepend(settings.divNoResult); }, /** * initialize the full text search and assign a providerId * * @param providerId * @param providerName * @param parent */ initFullTextSearch: function (providerId, providerName, parent) { settings.searchProviderId = providerId; settings.searchProviderName = providerName; settings.parent = parent; searchbox.init(); }, /** * check that the app that call the lib contains a specific method * * @param method * @param context * @returns {boolean} */ parentHasMethod: function (method, context) { if (settings.parent === null) { return false; } var functionName = 'settings.parent.' + method; var args = Array.prototype.slice.call(arguments, 2); var namespaces = functionName.split("."); for (var i = 0; i < namespaces.length; i++) { if (context[namespaces[i]] === undefined) { return false; } context = context[namespaces[i]]; } return true; }, executeFunction: function (functionName, context) { var args = Array.prototype.slice.call(arguments, 2); var namespaces = functionName.split("."); var func = namespaces.pop(); for (var i = 0; i < namespaces.length; i++) { if (context[namespaces[i]] === undefined) { // console.log('Unknown function \'' + functionName + '\''); return false; } context = context[namespaces[i]]; } return context[func].apply(context, args); } };