diff --git a/core/code/search.js b/core/code/search.js index 275351531..a75769e7c 100644 --- a/core/code/search.js +++ b/core/code/search.js @@ -1,4 +1,4 @@ -/* global L -- eslint */ +/* global IITC -- eslint */ /** * Provides functionality for the search system within the application. @@ -6,516 +6,138 @@ * You can implement your own result provider by listening to the search hook: * ```window.addHook('search', function(query) {});```. * - * The `query` object has the following members: - * - `term`: The term for which the user has searched. - * - `confirmed`: A boolean indicating if the user has pressed enter after searching. - * You should not search online or do heavy processing unless the user has confirmed the search term. - * - `addResult(result)`: A method to add a result to the query. - * - * The `result` object can have the following members (`title` is required, as well as one of `position` and `bounds`): - * - `title`: The label for this result. Will be interpreted as HTML, so make sure to escape properly. - * - `description`: Secondary information for this result. Will be interpreted as HTML, so make sure to escape properly. - * - `position`: A L.LatLng object describing the position of this result. - * - `bounds`: A L.LatLngBounds object describing the bounds of this result. - * - `layer`: An ILayer to be added to the map when the user selects this search result. - * Will be generated if not set. Set to `null` to prevent the result from being added to the map. - * - `icon`: A URL to an icon to display in the result list. Should be 12x12 pixels. - * - `onSelected(result, event)`: A handler to be called when the result is selected. - * May return `true` to prevent the map from being repositioned. You may reposition the map yourself or do other work. - * - `onRemove(result)`: A handler to be called when the result is removed from the map - * (because another result has been selected or the search was cancelled by the user). - * @namespace window.search - */ -window.search = { - lastSearch: null, -}; - -/** - * Represents a search query. - * - * @memberof window.search - * @class - * @name window.search.Query - * @param {string} term - The search term. - * @param {boolean} confirmed - Indicates if the search is confirmed (e.g., by pressing Enter). + * @example + * // Adding a search result + * window.addHook('search', function(query) { + * query.addResult({ + * title: 'My Result', + * position: L.latLng(0, 0) + * }); + * }); + * + * @namespace IITC.search + * @memberof IITC */ -window.search.Query = function (term, confirmed) { - this.term = term; - this.confirmed = confirmed; - this.init(); -}; /** - * Initializes the search query, setting up the DOM elements and triggering the 'search' hook. - * - * @function + * @memberOf IITC.search + * @typedef {Object} SearchQuery + * @property {string} term - The term for which the user has searched. + * @property {boolean} confirmed - Indicates if the user has pressed enter after searching. + * You should not search online or do heavy processing unless the user has confirmed the search term. + * @property {IITC.search.Query.addResult} addResult - Method to add a result to the query. + * @property {IITC.search.Query.addPortalResult} addPortalResult - Method to add a portal to the query. */ -window.search.Query.prototype.init = function () { - this.results = []; - - this.container = $('
').addClass('searchquery'); - - this.header = $('

') - .text( - this.confirmed - ? this.term - : (this.term.length > 16 ? this.term.substr(0, 8) + '…' + this.term.substr(this.term.length - 8, 8) : this.term) + ' (Return to load more)' - ) - .appendTo(this.container); - - this.list = $('