Changes for page Icon Picker
Last modified by Jan Bürger on 2025/05/06 12:29
From version 1.1
edited by admin
on 2024/02/20 17:47
on 2024/02/20 17:47
Change comment:
Install extension [org.xwiki.platform:xwiki-platform-icon-ui/16.0.0]
To version 2.1
edited by Benjamin Fischer
on 2024/10/07 10:56
on 2024/10/07 10:56
Change comment:
Install extension [org.xwiki.platform:xwiki-platform-icon-ui/16.8.0]
Summary
-
Page properties (2 modified, 0 added, 0 removed)
-
Objects (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Author
-
... ... @@ -1,1 +1,1 @@ 1 -XWiki. admin1 +XWiki.fischer - Content
-
... ... @@ -1,9 +1,5 @@ 1 1 {{velocity}} 2 2 ########################### 3 -## GLOBALS 4 -########################### 5 -#set($xwikiIcons = ['home', 'wiki', 'space', 'page', 'check', 'add', 'anchor', 'terminal', 'list', 'branch', 'down', 'up', 'left', 'right', 'arrows', 'repeat', 'undo', 'refresh', 'rotate-left', 'rotate-right', 'switch', 'random', 'attach', 'shopping-cart', 'bell', 'trash', 'bomb', 'book', 'cube', 'cubes', 'briefcase', 'bug', 'building', 'caret-down', 'caret-up', 'caret-right', 'calculator', 'calendar', 'camera', 'remove', 'cross', 'car', 'truck', 'chart-bar', 'chart-organisation', 'cloud', 'clock', 'cog', 'comment', 'comments', 'desktop', 'contrast', 'eject', 'step-forward', 'step-backward', 'fast-forward', 'backward', 'play', 'pause', 'stop', 'gamepad', 'credit-card', 'coffee', 'cut', 'database', 'delete', 'floppy-disk', 'glass', 'drive', 'envelope', 'warning', 'error', 'info', 'eye', 'rss', 'female', 'male', 'film', 'flag', 'search', 'search-plus', 'search-minus', 'folder', 'user', 'group', 'heart', 'question', 'image', 'key', 'keyboard', 'lightbulb', 'link', 'unlink', 'lock', 'unlock', 'money', 'dollar', 'euro', 'gbp', 'yen', 'music', 'file', 'file-white', 'file-pdf', 'file-code', 'file-archive', 'file-word', 'file-excel', 'file-powerpoint', 'file-text', 'paste', 'pencil', 'print', 'shield', 'certificate', 'volume-up', 'volume-down', 'volume-off', 'soccer', 'star', 'table', 'phone', 'font', 'bold', 'italic', 'strikethrough', 'subscript', 'superscript', 'underline', 'align-center', 'align-justify', 'align-left', 'align-right', 'columns', 'indent-left', 'indent-right', 'list-bullets', 'list-numbers', 'sun', 'world', 'wrench']) 6 -########################### 7 7 ## DATA: ICON THEMES 8 8 ########################### 9 9 #if($request.action == 'data_iconthemes') ... ... @@ -17,6 +17,7 @@ 17 17 #elseif($request.action == 'data_icons') 18 18 #set($icons = []) 19 19 #set($iconTheme = $request.iconTheme) 16 + #set($xwikiIcons = $collectiontool.sort($services.icon.getIconNames($iconTheme))) 20 20 #foreach($xwikiIcon in $xwikiIcons) 21 21 #set($icon = {}) 22 22 #set($discard = $icon.put('name', $xwikiIcon))
- XWiki.JavaScriptExtension[0]
-
- Code
-
... ... @@ -55,23 +55,30 @@ 55 55 * Display the list of icons 56 56 */ 57 57 var displayList = function(iconTheme) { 58 + // Filter the icons we display based on the value of the input field. 59 + let selectedIconName = ''; 60 + if (currentInput.data('xwikiIconPickerSettings') !== '') { 61 + selectedIconName = currentInput[0].value.replace(currentInput.data('xwikiIconPickerSettings').prefix, ''); 62 + } 58 58 // For each icon 59 59 for (var i=0; i < iconTheme.length; ++i) { 60 60 // Display the icon 61 - var displayer = $(document.createElement('div')); 62 - iconListSection.append(displayer); 63 - displayer.addClass('xwikiIconPickerIcon'); 64 - var imageDiv = $(document.createElement('div')); 65 - imageDiv.addClass('xwikiIconPickerIconImage').html(iconTheme[i].render); 66 - displayer.append(imageDiv); 67 - var iconNameDiv = $(document.createElement('div')); 68 - iconNameDiv.addClass('xwikiIconPickerIconName').text(iconTheme[i].name); 69 - displayer.append(iconNameDiv); 70 - // Change the input value when the icon is clicked 71 - displayer.on('click', function(event) { 72 - currentInput.val(currentInput.data('xwikiIconPickerSettings').prefix + $(event.currentTarget).children('.xwikiIconPickerIconName').text() ); 73 - closePicker(); 74 - }); 66 + if (selectedIconName === '' || iconTheme[i].name.includes(selectedIconName)) { 67 + var displayer = $(document.createElement('div')); 68 + iconListSection.append(displayer); 69 + displayer.addClass('xwikiIconPickerIcon'); 70 + var imageDiv = $(document.createElement('div')); 71 + imageDiv.addClass('xwikiIconPickerIconImage').html(iconTheme[i].render); 72 + displayer.append(imageDiv); 73 + var iconNameSpan = $(document.createElement('span')); 74 + iconNameSpan.addClass('xwikiIconPickerIconName').text(iconTheme[i].name); 75 + displayer.append(iconNameSpan); 76 + // Change the input value when the icon is clicked 77 + displayer.on('click', function(event) { 78 + currentInput.val(currentInput.data('xwikiIconPickerSettings').prefix + $(event.currentTarget).children('.xwikiIconPickerIconName').text()); 79 + closePicker(); 80 + }); 81 + } 75 75 } 76 76 } 77 77 ... ... @@ -79,7 +79,7 @@ 79 79 * Load the icon list (get the JSON from the server) and display it afterwards 80 80 */ 81 81 var loadIconList = function(iconTheme) { 82 - $.getJSON(getResourceURL('data_icons', 'iconTheme='+iconTheme), function(dataIcons) { 89 + $.getJSON(getResourceURL('data_icons', 'iconTheme=' + iconTheme), function(dataIcons) { 83 83 // Put the result in the icons map 84 84 icons[iconTheme] = dataIcons; 85 85 // Display the list ... ... @@ -242,11 +242,23 @@ 242 242 loadIconList(currentIconTheme); 243 243 } 244 244 } 245 - // Close the picker when the user press 'escape'. 252 + var lastTimeout = 0; 253 + var reloadIconList = function () { 254 + // Remove all the displayed icons 255 + $('.xwikiIconPickerIcon').remove(); 256 + // Display the new ones. We always reload because the filter results are unrelated. 257 + displayList(icons[currentIconTheme]); 258 + }; 246 246 currentInput.on('keyup', function(event) { 260 + // Close the picker when the user press 'escape'. 247 247 // See: http://stackoverflow.com/questions/1160008/which-keycode-for-escape-key-with-jquery 248 248 if (event.which == 27) { 249 249 closePicker(); 264 + } else { 265 + if (lastTimeout!==0) { 266 + clearTimeout(lastTimeout); 267 + } 268 + lastTimeout = setTimeout(reloadIconList, 500); 250 250 } 251 251 }); 252 252 }