File modules/cms/ui/themes/default/script/plugin/jquery-plugin-orSearch.min.js
Last commit: Sun Feb 6 21:34:42 2022 +0100 dankert New: Use Accept-Header instead of "output" request parameter, this is the cleaner way.
1 import $ from "../jquery-global.min.js"; 2 import WorkbenchNavigator from "../openrat/navigator.min.js"; 3 import Workbench from "../openrat/workbench.min.js"; 4 export default function( options ) 5 { 6 let settings = $.extend( { 7 'dropdown': $(), 8 'select' : function( obj ) {}, 9 'afterSelect' : function() {}, 10 'onSearchActive' : function() {}, 11 'onSearchInactive' : function() {}, 12 'openDropdown' : true, 13 'action': 'search', 14 'method': 'quicksearch', 15 'resultEntryClass': 'dropdown-entry', 16 }, options); 17 let searchInput = $(this) 18 let dropdownEl = $( settings.dropdown ); 19 let closeSearch = function() { 20 settings.onSearchInactive(); 21 $(dropdownEl).empty(); 22 dropdownEl.removeClass('search-result--is-active'); 23 }; 24 $(this).on('keydown',async function(e) { 25 if ( e.keyCode == 13 ) { 26 let dialog = Workbench.getInstance().createDialog(); 27 closeSearch(); 28 dialog.start('','search','edit',0,{'text':searchInput.val()}); 29 searchInput.val(''); 30 } 31 } ); 32 return $(this).input(async function() 33 { 34 let searchArgument = searchInput.val(); 35 if ( searchArgument.length ) 36 { 37 settings.onSearchActive(); 38 $('.or-search').addClass('search--is-active'); 39 dropdownEl.addClass('search-result--is-active'); 40 let url = './?action='+settings.action+'&subaction='+settings.method+'&search='+searchArgument; 41 let response = await fetch( url, { 42 method: 'GET', 43 headers: { 44 'Accept': 'application/json' 45 } } ); 46 if ( ! response.ok ) 47 throw "Search request getting an error"; 48 let data = await response.json(); 49 $(dropdownEl).empty(); 50 for (let id in data.output.result) { 51 let result = data.output.result[id]; 52 let div = $.create('div') 53 .addClass( settings.resultEntryClass ) 54 .addClass( settings.resultEntryClass + '--active' ) 55 .attr('title',result.desc); 56 div.data( 'name' , result.name ); 57 div.data( 'action', result.type ); 58 div.data( 'id' , result.id ); 59 let link = $.create('a') 60 .addClass('link') 61 .attr('href', WorkbenchNavigator.createShortUrl(result.type, result.id)); 62 link.click(function (e) { 63 e.preventDefault(); 64 }); 65 $(link).append( 66 $.create('i').addClass('image-icon').addClass('image-icon--action-' + result.type) 67 ); 68 $(link).append( 69 $.create('span').addClass('dropdown-text').text(result.name) 70 ); 71 $(div ).append(link); 72 $(dropdownEl).append(div); 73 } 74 if (data.output.result && settings.openDropdown) { 75 $(dropdownEl).addClass('dropdown--is-open'); 76 } else { 77 $(dropdownEl).removeClass('dropdown--is-open'); 78 } 79 $(dropdownEl).find('.or-search-result-entry').click(function (e) { 80 settings.select( $(this).data() ); 81 settings.afterSelect(); 82 searchInput.val(''); 83 closeSearch(); 84 }); 85 } 86 else 87 { 88 closeSearch(); 89 } 90 }); 91 };
Downloadmodules/cms/ui/themes/default/script/plugin/jquery-plugin-orSearch.min.js
History Sun, 6 Feb 2022 21:34:42 +0100 dankert New: Use Accept-Header instead of "output" request parameter, this is the cleaner way. Sat, 18 Dec 2021 03:47:23 +0100 dankert New: Every ES6-Module should have a minified version for performance reasons. Bad: The Minifier "Jsqueeze" is unable to minify ES6-modules, so we had to implement a simple JS-Minifier which strips out all comments. Fri, 21 Aug 2020 00:22:13 +0200 Jan Dankert Refactoring: Collect all frontend compiler scripts in update.php. Compiling of CSS and JS was extracted to a new TemplateCompiler. JS and CSS is now collected in a new openrat.[min.][js|css]. Sun, 23 Feb 2020 04:01:30 +0100 Jan Dankert Refactoring with Namespaces for the cms modules, part 1: moving.