diff --git a/src/editors/array.js b/src/editors/array.js index 08e0a943b..003ba3310 100644 --- a/src/editors/array.js +++ b/src/editors/array.js @@ -69,6 +69,7 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({ this.hide_delete_buttons = this.options.disable_array_delete || this.jsoneditor.options.disable_array_delete; this.hide_move_buttons = this.options.disable_array_reorder || this.jsoneditor.options.disable_array_reorder; this.hide_add_button = this.options.disable_array_add || this.jsoneditor.options.disable_array_add; + this.show_copy_button = this.options.enable_array_copy || this.jsoneditor.options.enable_array_copy; }, build: function() { var self = this; @@ -498,6 +499,34 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({ } } + //Button to copy an array element and add it as last element + if(self.show_copy_button){ + self.rows[i].copy_button = this.getButton(self.getItemTitle(),'copy','Copy '+self.getItemTitle()); + self.rows[i].copy_button.className += ' copy'; + self.rows[i].copy_button.setAttribute('data-i',i); + self.rows[i].copy_button.addEventListener('click',function(e) { + var value = self.getValue(); + e.preventDefault(); + e.stopPropagation(); + var i = this.getAttribute('data-i')*1; + + $each(value,function(j,row) { + if(j===i) { + value.push(row); + return; + } + }); + + self.setValue(value); + self.refreshValue(true); + self.onChange(true); + + }); + + controls_holder.appendChild(self.rows[i].copy_button); + } + + if(i && !self.hide_move_buttons) { self.rows[i].moveup_button = this.getButton('','moveup','Move up'); self.rows[i].moveup_button.className += ' moveup'; diff --git a/src/iconlibs/fontawesome4.js b/src/iconlibs/fontawesome4.js index a09c0b180..4de29107a 100644 --- a/src/iconlibs/fontawesome4.js +++ b/src/iconlibs/fontawesome4.js @@ -8,7 +8,8 @@ JSONEditor.defaults.iconlibs.fontawesome4 = JSONEditor.AbstractIconLib.extend({ cancel: 'ban', save: 'save', moveup: 'arrow-up', - movedown: 'arrow-down' + movedown: 'arrow-down', + copy: 'files-o' }, icon_prefix: 'fa fa-' });