Wiki source code of Icon Picker
Version 1.1 by Martin Mahr on 2023/11/14 13:30
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 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 = $icon.put('metadata', $services.icon.getMetaData($xwikiIcon, $iconTheme))) | ||
| 25 | #set($discard = $icons.add($icon)) | ||
| 26 | #end | ||
| 27 | #jsonResponse($icons) | ||
| 28 | #else | ||
| 29 | = Presentation = | ||
| 30 | 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. | ||
| 31 | |||
| 32 | == Example == | ||
| 33 | With Velocity and HTML: | ||
| 34 | |||
| 35 | {{code language="none"}} | ||
| 36 | // Enable the CSS of the picker: | ||
| 37 | \#set(\$discard = \$xwiki.ssx.use('IconThemesCode.IconPicker')) | ||
| 38 | |||
| 39 | // JavaScript code: | ||
| 40 | <script> | ||
| 41 | |||
| 42 | // Configure requirejs to load the picker code | ||
| 43 | require.config({ | ||
| 44 | paths: { | ||
| 45 | 'xwiki-icon-picker': '\$xwiki.getURL($services.model.createDocumentReference('', 'IconThemesCode', 'IconPicker'), 'jsx', "minify=$!request.minify")' | ||
| 46 | } | ||
| 47 | }); | ||
| 48 | |||
| 49 | // Require jquery and the icon picker | ||
| 50 | require(['jquery', 'xwiki-icon-picker'], function($) { | ||
| 51 | // Here you can bind the picker to some elements. | ||
| 52 | // Examples: | ||
| 53 | $('#someElement').xwikiIconPicker(); // apply the picker to the field #someElement | ||
| 54 | $('#someElement').xwikiIconPicker({prefix: 'image:icon:'}); // change the prefix inserted before the icon name | ||
| 55 | }); | ||
| 56 | |||
| 57 | </script> | ||
| 58 | {{/code}} | ||
| 59 | #end | ||
| 60 | {{/velocity}} |