Wiki source code of Icon Picker

Version 2.1 by Thomas Coelho (local) on 2023/07/26 11:22

Show last authors
1 {{velocity}}
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 ## DATA: ICON THEMES
8 ###########################
9 #if($request.action == 'data_iconthemes')
10 #set($map = {})
11 #set($discard = $map.put('iconThemes', $services.icon.iconSetNames))
12 #set($discard = $map.put('currentIconTheme', $services.icon.currentIconSetName))
13 #jsonResponse($map)
14 ###########################
15 ## DATA: ICONS
16 ###########################
17 #elseif($request.action == 'data_icons')
18 #set($icons = [])
19 #set($iconTheme = $request.iconTheme)
20 #foreach($xwikiIcon in $xwikiIcons)
21 #set($icon = {})
22 #set($discard = $icon.put('name', $xwikiIcon))
23 #set($discard = $icon.put('render', $services.icon.renderHTML($xwikiIcon, $iconTheme)))
24 #set($discard = $icons.add($icon))
25 #end
26 #jsonResponse($icons)
27 #else
28 = Presentation =
29 The Icon Picker is a jQuery plugin written by XWiki to help user selecting an icon. See [[IconPickerMacro]] for using this picker easily. If you want to use it manually, read the following.
30
31 == Example ==
32 With Velocity and HTML:
33
34 {{code language="none"}}
35 // Enable the CSS of the picker:
36 \#set(\$discard = \$xwiki.ssx.use('IconThemesCode.IconPicker'))
37
38 // JavaScript code:
39 <script>
40
41 // Configure requirejs to load the picker code
42 require.config({
43 paths: {
44 'xwiki-icon-picker': '\$xwiki.getURL($services.model.createDocumentReference('', 'IconThemesCode', 'IconPicker'), 'jsx', "minify=$!request.minify")'
45 }
46 });
47
48 // Require jquery and the icon picker
49 require(['jquery', 'xwiki-icon-picker'], function($) {
50 // Here you can bind the picker to some elements.
51 // Examples:
52 $('#someElement').xwikiIconPicker(); // apply the picker to the field #someElement
53 $('#someElement').xwikiIconPicker({prefix: 'image:icon:'}); // change the prefix inserted before the icon name
54 });
55
56 </script>
57 {{/code}}
58 #end
59 {{/velocity}}