Skip to content

Commit

Permalink
start of a new icon picker. (#1794)
Browse files Browse the repository at this point in the history
* start of a new icon picker.

* edit dom in one single operation

* rm old file
  • Loading branch information
johrstrom authored Feb 1, 2022
1 parent 7b29678 commit 0dae265
Show file tree
Hide file tree
Showing 13 changed files with 1,145 additions and 10,239 deletions.
4,869 changes: 0 additions & 4,869 deletions apps/dashboard/app/assets/javascripts/fontawesome-iconpicker.js

This file was deleted.

4,997 changes: 0 additions & 4,997 deletions apps/dashboard/app/javascript/packs/fa/faIconInfo.js

This file was deleted.

41 changes: 0 additions & 41 deletions apps/dashboard/app/javascript/packs/fa/faIconPicker.js

This file was deleted.

48 changes: 48 additions & 0 deletions apps/dashboard/app/javascript/packs/icon_picker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict';

import ALL_ICONS from 'icons';

const ICON_SHOW_ID = "product_icon"
const ICON_SELECT_ID = "product_icon_select"

function listItem(name) {
return `<li
id="${iconId(name)}"
class="btn btn-outline-dark"
role='button'>
<i class="fas fa-${name} fa-fw"></i>
</li>`;
}

function iconId(name) {
return `icon_${name.replaceAll('-', '_')}`;
}

function iconFromId(id) {
const m = id.match(/^icon_([\w+_]+)/);
if(m && m[1]) { return m[1].replaceAll('_','-') };
}

function picked(event) {
const icon = iconFromId(event.currentTarget.id);
$(`#${ICON_SHOW_ID}`).attr("class", `fas fa-${icon} fa-fw app-icon`);
$(`#${ICON_SELECT_ID}`).val(`fas://${icon}`)
}

function populateList() {
const list = $("#icon_picker_list");
if(list.length == 0 || ALL_ICONS.length == 0) { return; }

const listContent = ALL_ICONS.map(name => {
return listItem(name);
}).join('');
list.html(listContent);

ALL_ICONS.forEach(name => {
$(`#${iconId(name)}`).on('click', (event) => { picked(event)});
});
};

jQuery(() => {
populateList();
})
Loading

0 comments on commit 0dae265

Please sign in to comment.