Skip to content

Commit d2cf5d6

Browse files
amosfolzlcharette
authored andcommitted
Feature: Font Awesome 5 Icon Picker (#1019)
1 parent 52e7673 commit d2cf5d6

5 files changed

Lines changed: 40 additions & 11 deletions

File tree

app/sprinkles/admin/assets/userfrosting/js/pages/group.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@ $(document).ready(function() {
2121
$("#widget-group-users").on("pagerComplete.ufTable", function () {
2222
bindUserButtons($(this));
2323
});
24+
25+
$('.icp').iconpicker();
26+
2427
});

app/sprinkles/admin/assets/userfrosting/js/widgets/groups.js

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Set up the form in a modal after being successfully attached to the body.
77
*/
88
function attachGroupForm() {
9-
$("body").on('renderSuccess.ufModal', function (data) {
9+
$("body").on('renderSuccess.ufModal', function(data) {
1010
var modal = $(this).ufModal('getModal');
1111
var form = modal.find('.js-form');
1212

@@ -36,11 +36,34 @@ function attachGroupForm() {
3636
}
3737
});
3838

39+
// Fontawesome-iconpicker
40+
// Starcraft icons
41+
var sc_icons = [{
42+
title: "sc sc-terran",
43+
searchTerms: ['starcraft', 'terran']
44+
},
45+
{
46+
title: "sc sc-zerg",
47+
searchTerms: ['starcraft', 'zerg']
48+
}, {
49+
title: "sc sc-protoss",
50+
searchTerms: ['starcraft', 'protoss']
51+
},
52+
]
53+
54+
$('.icp-auto').iconpicker({
55+
// this is a hacky way to add in our custom icons to the default FA5 icons.
56+
// See https://github.com/farbelous/fontawesome-iconpicker/issues/77
57+
icons: typeof sc_icons != 'undefined' ? $.merge(sc_icons, $.iconpicker.defaultOptions.icons) : null,
58+
});
59+
3960
// Set icon when changed
4061
form.find('input[name=icon]').on('input change', function() {
4162
$(this).prev(".icon-preview").find("i").removeClass().addClass($(this).val());
4263
});
4364

65+
$('.icp-auto').iconpicker();
66+
4467
// Set up the form for submission
4568
form.ufForm({
4669
validator: page.validators
@@ -93,16 +116,16 @@ function bindGroupButtons(el, options) {
93116
msgTarget: $("#alerts-page")
94117
});
95118

96-
$("body").on('renderSuccess.ufModal', function () {
119+
$("body").on('renderSuccess.ufModal', function() {
97120
var modal = $(this).ufModal('getModal');
98121
var form = modal.find('.js-form');
99122

100123
form.ufForm()
101-
.on("submitSuccess.ufForm", function() {
102-
// Navigate or reload page on success
103-
if (options.delete_redirect) window.location.href = options.delete_redirect;
104-
else window.location.reload();
105-
});
124+
.on("submitSuccess.ufForm", function() {
125+
// Navigate or reload page on success
126+
if (options.delete_redirect) window.location.href = options.delete_redirect;
127+
else window.location.reload();
128+
});
106129
});
107130
});
108131
}
@@ -119,4 +142,4 @@ function bindGroupCreationButton(el) {
119142

120143
attachGroupForm();
121144
});
122-
};
145+
};

app/sprinkles/admin/templates/forms/group.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535
{% endif %}
3636
{% if 'icon' not in fields.hidden %}
3737
<div class="col-sm-12">
38-
<div class="form-group">
38+
<div class="form-group iconpicker-container">
3939
<label>{{translate("GROUP.ICON")}}</label>
4040
<div class="input-group">
4141
<span class="input-group-addon icon-preview"><i class="{{group.icon}} fa-fw"></i></span>
42-
<input type="text" class="form-control" name="icon" autocomplete="off" value="{{group.icon}}" placeholder="{{translate("GROUP.ICON_EXPLAIN")}}" {% if 'icon' in form.fields.disabled %}disabled{% endif %}>
42+
<input type="text" class="form-control icp icp-auto" name="icon" autocomplete="off" value="{{group.icon}}" placeholder="{{translate("GROUP.ICON_EXPLAIN")}}" {% if 'icon' in form.fields.disabled %}disabled{% endif %}>
4343
</div>
4444
</div>
4545
</div>

app/sprinkles/core/asset-bundles.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
"js/form-widgets": {
3434
"scripts": [
3535
"vendor/speakingurl/speakingurl.min.js",
36-
"userfrosting/js/uf-collection.js"
36+
"userfrosting/js/uf-collection.js",
37+
"vendor/fontawesome-iconpicker/dist/js/fontawesome-iconpicker.js"
3738
],
3839
"options": {
3940
"result": {
@@ -45,6 +46,7 @@
4546
},
4647
"css/main": {
4748
"styles": [
49+
"vendor/fontawesome-iconpicker/dist/css/fontawesome-iconpicker.css",
4850
"vendor/@fortawesome/fontawesome-free/css/all.css",
4951
"vendor/bootstrap/dist/css/bootstrap.css",
5052
"vendor/select2/dist/css/select2.css",

app/sprinkles/core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"bootstrap": "^3.3.6",
66
"clipboard": "^1.5.16",
77
"fastclick": "^1.0.6",
8+
"fontawesome-iconpicker": "^3.2.0",
89
"handlebars": "^4.1.2",
910
"icheck": "^1.0.1",
1011
"ionicons": "^2.0.1",

0 commit comments

Comments
 (0)