Merge branch 'iconSelect-modal-selected' of https://github.com/rbeer/NodeBB into rbeer-iconSelect-modal-selected

v1.18.x
Julian Lam 9 years ago
commit 51309890fe

@ -20,6 +20,7 @@ define('iconSelect', function() {
var picker = bootbox.dialog({ var picker = bootbox.dialog({
onEscape: true, onEscape: true,
backdrop: true, backdrop: true,
show: false,
message: html, message: html,
title: 'Select an Icon', title: 'Select an Icon',
buttons: { buttons: {
@ -41,9 +42,11 @@ define('iconSelect', function() {
var iconClass = $('.bootbox .selected').attr('class'); var iconClass = $('.bootbox .selected').attr('class');
var categoryIconClass = $('<div/>').addClass(iconClass).removeClass('fa').removeClass('selected').attr('class'); var categoryIconClass = $('<div/>').addClass(iconClass).removeClass('fa').removeClass('selected').attr('class');
if (categoryIconClass) {
el.attr('class', 'fa ' + (doubleSize ? 'fa-2x ' : '') + categoryIconClass); el.attr('class', 'fa ' + (doubleSize ? 'fa-2x ' : '') + categoryIconClass);
el.val(categoryIconClass); el.val(categoryIconClass);
el.attr('value', categoryIconClass); el.attr('value', categoryIconClass);
}
onModified(el); onModified(el);
} }
@ -51,19 +54,41 @@ define('iconSelect', function() {
} }
}); });
picker.on('show.bs.modal', function() {
var modalEl = $(this),
searchEl = modalEl.find('input');
if (selected) {
modalEl.find('.' + selected).addClass('selected');
searchEl.val(selected.replace('fa-', ''));
}
}).modal('show');
picker.on('shown.bs.modal', function() { picker.on('shown.bs.modal', function() {
var modalEl = $(this), var modalEl = $(this),
searchEl = modalEl.find('input'), searchEl = modalEl.find('input'),
icons = modalEl.find('.fa-icons i'), icons = modalEl.find('.fa-icons i'),
submitEl = modalEl.find('button.btn-primary'); submitEl = modalEl.find('button.btn-primary');
function changeSelection(newSelection) {
modalEl.find('i.selected').removeClass('selected');
if (newSelection) {
newSelection.addClass('selected');
} else if (searchEl.val().length === 0) {
if (selected) {
modalEl.find('.' + selected).addClass('selected');
}
} else {
modalEl.find('i:visible').first().addClass('selected');
}
}
// Focus on the input box // Focus on the input box
searchEl.focus(); searchEl.selectRange(0, searchEl.val().length);
modalEl.find('.icon-container').on('click', 'i', function() { modalEl.find('.icon-container').on('click', 'i', function() {
searchEl.val($(this).attr('class').replace('fa fa-', '')); searchEl.val($(this).attr('class').replace('fa fa-', '').replace('selected', ''));
modalEl.find('.icon-container i').removeClass('selected'); changeSelection($(this));
$(this).addClass('selected');
}); });
searchEl.on('keyup', function(e) { searchEl.on('keyup', function(e) {
@ -75,9 +100,8 @@ define('iconSelect', function() {
$(el).hide(); $(el).hide();
} }
}); });
changeSelection();
} else { } else {
// Pick first match
$('.icon-container i:visible').first().addClass('selected');
submitEl.click(); submitEl.click();
} }
}); });

Loading…
Cancel
Save