--- regenerate: true --- {% capture cache %} {% comment %} # ----------------------------------------------------------------------------- # ~/assets/themes/j1/adapter/js/lunr_search.js # Liquid template to adapt J1LunrSearch # # Product/Info: # https://jekyll.one # Copyright (C) 2021 Juergen Adams # # J1 Template is licensed under the MIT License. # For details, see https://jekyll.one # ----------------------------------------------------------------------------- # Test data: # {{ liquid_var | debug }} # ----------------------------------------------------------------------------- {% endcomment %} {% comment %} Liquid procedures -------------------------------------------------------------------------------- {% endcomment %} {% comment %} Process YML config data ================================================================================ {% endcomment %} {% comment %} Set config files -------------------------------------------------------------------------------- {% endcomment %} {% assign template_config = site.data.j1_config %} {% assign blocks = site.data.blocks %} {% assign modules = site.data.modules %} {% comment %} Set config data -------------------------------------------------------------------------------- {% endcomment %} {% assign environment = site.environment %} {% assign template_version = site.version %} {% assign lunr_search_defaults = modules.defaults.lunr_search.defaults %} {% assign lunr_search_settings = modules.lunr_search.settings %} {% comment %} Set config options -------------------------------------------------------------------------------- {% endcomment %} {% assign lunr_search_options = lunr_search_defaults | merge: lunr_search_settings %} {% assign production = false %} {% if environment == 'prod' or environment == 'production' %} {% assign production = true %} {% endif %} /* # ----------------------------------------------------------------------------- # ~/assets/themes/j1/adapter/js/lunr_search.js # J1 Adapter for lunr_search # # Product/Info: # https://jekyll.one # # Copyright (C) 2021 Juergen Adams # # J1 Template is licensed under the MIT License. # For details, see https://jekyll.one # ----------------------------------------------------------------------------- # Adapter generated: {{site.time}} # ----------------------------------------------------------------------------- */ // ----------------------------------------------------------------------------- // ESLint shimming // ----------------------------------------------------------------------------- /* eslint indent: "off" */ // ----------------------------------------------------------------------------- 'use strict'; {% comment %} Main -------------------------------------------------------------------------------- {% endcomment %} j1.adapter['lunr_search'] = (function (j1, window) { {% comment %} Set global variables ------------------------------------------------------------------------------ {% endcomment %} var environment = '{{environment}}'; var searchOptions = {}; var _this; var logger; var logText; // --------------------------------------------------------------------------- // Helper functions // --------------------------------------------------------------------------- // --------------------------------------------------------------------------- // Main object // --------------------------------------------------------------------------- return { // ------------------------------------------------------------------------- // Initializer // ------------------------------------------------------------------------- init: function (options) { // ----------------------------------------------------------------------- // globals // ----------------------------------------------------------------------- _this = j1.adapter.lunr_search; logger = log4javascript.getLogger('j1.adapter.lunr_search'); // initialize state flag _this.setState('started'); logger.info('state: ' + _this.getState()); logger.info('module is being initialized'); // ----------------------------------------------------------------------- // defaults // ----------------------------------------------------------------------- var settings = $.extend({ module_name: 'j1.adapter.lunr_search', generated: '{{site.time}}' }, options); // ----------------------------------------------------------------------- // options loader // ----------------------------------------------------------------------- /* eslint-disable */ searchOptions = $.extend({}, {{lunr_search_options | replace: '=>', ':' | replace: 'nil', '""'}}); // ----------------------------------------------------------------------- // lunr_search initializer // ----------------------------------------------------------------------- var log_text = 'module is being initialized'; logger.info(log_text); var dependencies_met_j1_finished = setInterval(function() { if (j1.getState() == 'finished') { $(searchOptions.search_input).lunrSearch({ index_file: searchOptions.index_file, results: searchOptions.results, template: searchOptions.template, titleMsg: searchOptions.titleMsg, emptyMsg: searchOptions.emptyMsg }); _this.setState('finished'); logger.info('state: ' + _this.getState()); clearInterval(dependencies_met_j1_finished); } // END dependencies_met_j1_finished }, 25); _this.eventHandler(); }, // END init // ------------------------------------------------------------------------- // event handler // ------------------------------------------------------------------------- eventHandler: function () { // hide|clear results from top search $('#clear-topsearch').on('click', function() { $(this).addClass('d-none').prevAll(':input').val(''); $('#search-results').hide(); $('#search-results').html(''); }); }, // END eventHandler // ------------------------------------------------------------------------- // messageHandler: MessageHandler for J1 CookieConsent module // Manage messages send from other J1 modules // ------------------------------------------------------------------------- messageHandler: function (sender, message) { var json_message = JSON.stringify(message, undefined, 2); logText = 'received message from ' + sender + ': ' + json_message; logger.debug(logText); // ----------------------------------------------------------------------- // Process commands|actions // ----------------------------------------------------------------------- if (message.type === 'command' && message.action === 'module_initialized') { // // Place handling of command|action here // logger.info(message.text); } // // Place handling of other command|action here // return true; }, // END messageHandler // ------------------------------------------------------------------------- // setState() // Sets the current (processing) state of the module // ------------------------------------------------------------------------- setState: function (stat) { _this.state = stat; }, // END setState // ------------------------------------------------------------------------- // getState() // Returns the current (processing) state of the module // ------------------------------------------------------------------------- getState: function () { return _this.state; } // END getState }; // END return })(j1, window); {% endcapture %} {% if production %} {{ cache | minifyJS }} {% else %} {{ cache | strip_empty_lines }} {% endif %} {% assign cache = nil %}