1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| // editable
if (options.editable) {
$(easyTree).find('.easy-tree-toolbar').append('<div class="edit"><button class="btn btn-default btn-sm btn-primary disabled"><span class="glyphicon glyphicon-edit"></span></button></div> ');
$(easyTree).find('.easy-tree-toolbar .edit > button').attr('title', options.i18n.editTip).click(function () {
$(easyTree).find('input.easy-tree-editor').remove();
$(easyTree).find('li > span > a:hidden').show();
var selected = getSelectedItems();
if (selected.length <= 0) {
$(easyTree).prepend(warningAlert);
$(easyTree).find('.alert .alert-content').html(options.i18n.editNull);
}
else if (selected.length > 1) {
$(easyTree).prepend(warningAlert);
$(easyTree).find('.alert .alert-content').html(options.i18n.editMultiple);
}
else {
var value = $(selected).find(' > span > a').text();
$(selected).find(' > span > a').hide();
$(selected).find(' > span').append('<input type="text" class="easy-tree-editor">');
var editor = $(selected).find(' > span > input.easy-tree-editor');
$(editor).val(value);
$(editor).focus();
$(editor).keydown(function (e) {
if (e.which == 13) {
if ($(editor).val() !== '') {
$(selected).find(' > span > a').text($(editor).val());
$(editor).remove();
$(selected).find(' > span > a').show();
}
}
});
}
});
} |
Partager