Skip to content

Commit

Permalink
Merge branch 'Reggino-Allow-to-be-wrapped-in-form-tags'
Browse files Browse the repository at this point in the history
  • Loading branch information
jdorn committed Jul 14, 2014
2 parents 3231fac + c018f2c commit f46ed33
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 16 deletions.
28 changes: 21 additions & 7 deletions src/editors/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,9 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
self.rows[i].delete_button = this.getButton(self.getItemTitle(),'delete','Delete '+self.getItemTitle());
self.rows[i].delete_button.className += ' delete';
self.rows[i].delete_button.setAttribute('data-i',i);
self.rows[i].delete_button.addEventListener('click',function() {
self.rows[i].delete_button.addEventListener('click',function(e) {
e.preventDefault();
e.stopPropagation();
var i = this.getAttribute('data-i')*1;

var value = self.getValue();
Expand Down Expand Up @@ -499,7 +501,9 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
self.rows[i].moveup_button = this.getButton('','moveup','Move up');
self.rows[i].moveup_button.className += ' moveup';
self.rows[i].moveup_button.setAttribute('data-i',i);
self.rows[i].moveup_button.addEventListener('click',function() {
self.rows[i].moveup_button.addEventListener('click',function(e) {
e.preventDefault();
e.stopPropagation();
var i = this.getAttribute('data-i')*1;

if(i<=0) return;
Expand All @@ -525,7 +529,9 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
self.rows[i].movedown_button = this.getButton('','movedown','Move down');
self.rows[i].movedown_button.className += ' movedown';
self.rows[i].movedown_button.setAttribute('data-i',i);
self.rows[i].movedown_button.addEventListener('click',function() {
self.rows[i].movedown_button.addEventListener('click',function(e) {
e.preventDefault();
e.stopPropagation();
var i = this.getAttribute('data-i')*1;

var rows = self.getValue();
Expand Down Expand Up @@ -557,7 +563,9 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
this.title_controls.appendChild(this.toggle_button);
var row_holder_display = self.row_holder.style.display;
var controls_display = self.controls.style.display;
this.toggle_button.addEventListener('click',function() {
this.toggle_button.addEventListener('click',function(e) {
e.preventDefault();
e.stopPropagation();
if(self.collapsed) {
self.collapsed = false;
if(self.panel) self.panel.style.display = '';
Expand Down Expand Up @@ -592,7 +600,9 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
// Add "new row" and "delete last" buttons below editor
this.add_row_button = this.getButton(this.getItemTitle(),'add','Add '+this.getItemTitle());

this.add_row_button.addEventListener('click',function() {
this.add_row_button.addEventListener('click',function(e) {
e.preventDefault();
e.stopPropagation();
var i = self.rows.length;
if(self.row_cache[i]) {
self.rows[i] = self.row_cache[i];
Expand All @@ -613,7 +623,9 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
self.controls.appendChild(this.add_row_button);

this.delete_last_row_button = this.getButton('Last '+this.getItemTitle(),'delete','Delete Last '+this.getItemTitle());
this.delete_last_row_button.addEventListener('click',function() {
this.delete_last_row_button.addEventListener('click',function(e) {
e.preventDefault();
e.stopPropagation();
var rows = self.getValue();

var new_active_tab = null;
Expand All @@ -631,7 +643,9 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
self.controls.appendChild(this.delete_last_row_button);

this.remove_all_rows_button = this.getButton('All','delete','Delete All');
this.remove_all_rows_button.addEventListener('click',function() {
this.remove_all_rows_button.addEventListener('click',function(e) {
e.preventDefault();
e.stopPropagation();
self.setValue([]);
if(self.parent) self.parent.onChildEditorChange(self);
else self.jsoneditor.onChange();
Expand Down
24 changes: 18 additions & 6 deletions src/editors/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,15 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({
this.editjson_textarea.style.width = '300px';
this.editjson_textarea.style.display = 'block';
this.editjson_save = this.getButton('Save','save','Save');
this.editjson_save.addEventListener('click',function() {
this.editjson_save.addEventListener('click',function(e) {
e.preventDefault();
e.stopPropagation();
self.saveJSON();
});
this.editjson_cancel = this.getButton('Cancel','cancel','Cancel');
this.editjson_cancel.addEventListener('click',function() {
this.editjson_cancel.addEventListener('click',function(e) {
e.preventDefault();
e.stopPropagation();
self.hideEditJSON();
});
this.editjson_holder.appendChild(this.editjson_textarea);
Expand All @@ -314,7 +318,9 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({
this.addproperty_input.style.width = '220px';
this.addproperty_input.style.marginBottom = '0';
this.addproperty_input.style.display = 'inline-block';
this.addproperty_add.addEventListener('click',function() {
this.addproperty_add.addEventListener('click',function(e) {
e.preventDefault();
e.stopPropagation();
if(self.addproperty_input.value) {
if(self.editors[self.addproperty_input.value]) {
alert('there is already a property with that name');
Expand Down Expand Up @@ -375,7 +381,9 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({
this.collapsed = false;
this.toggle_button = this.getButton('','collapse','Collapse');
this.title_controls.appendChild(this.toggle_button);
this.toggle_button.addEventListener('click',function() {
this.toggle_button.addEventListener('click',function(e) {
e.preventDefault();
e.stopPropagation();
if(self.collapsed) {
self.editor_holder.style.display = '';
self.collapsed = false;
Expand Down Expand Up @@ -403,7 +411,9 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({

// Edit JSON Button
this.editjson_button = this.getButton('JSON','edit','Edit JSON');
this.editjson_button.addEventListener('click',function() {
this.editjson_button.addEventListener('click',function(e) {
e.preventDefault();
e.stopPropagation();
self.toggleEditJSON();
});
this.editjson_controls.appendChild(this.editjson_button);
Expand All @@ -419,7 +429,9 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({

// Object Properties Button
this.addproperty_button = this.getButton('Properties','edit','Object Properties');
this.addproperty_button.addEventListener('click',function() {
this.addproperty_button.addEventListener('click',function(e) {
e.preventDefault();
e.stopPropagation();
self.toggleAddProperty();
});
this.addproperty_controls.appendChild(this.addproperty_button);
Expand Down
12 changes: 9 additions & 3 deletions src/editors/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,9 @@ JSONEditor.defaults.editors.table = JSONEditor.defaults.editors.array.extend({
self.rows[i].delete_button = this.getButton('','delete','Delete');
self.rows[i].delete_button.className += ' delete';
self.rows[i].delete_button.setAttribute('data-i',i);
self.rows[i].delete_button.addEventListener('click',function() {
self.rows[i].delete_button.addEventListener('click',function(e) {
e.preventDefault();
e.stopPropagation();
var i = this.getAttribute('data-i')*1;

var value = self.getValue();
Expand All @@ -353,7 +355,9 @@ JSONEditor.defaults.editors.table = JSONEditor.defaults.editors.array.extend({
self.rows[i].moveup_button = this.getButton('','moveup','Move up');
self.rows[i].moveup_button.className += ' moveup';
self.rows[i].moveup_button.setAttribute('data-i',i);
self.rows[i].moveup_button.addEventListener('click',function() {
self.rows[i].moveup_button.addEventListener('click',function(e) {
e.preventDefault();
e.stopPropagation();
var i = this.getAttribute('data-i')*1;

if(i<=0) return;
Expand All @@ -373,7 +377,9 @@ JSONEditor.defaults.editors.table = JSONEditor.defaults.editors.array.extend({
self.rows[i].movedown_button = this.getButton('','movedown','Move down');
self.rows[i].movedown_button.className += ' movedown';
self.rows[i].movedown_button.setAttribute('data-i',i);
self.rows[i].movedown_button.addEventListener('click',function() {
self.rows[i].movedown_button.addEventListener('click',function(e) {
e.preventDefault();
e.stopPropagation();
var i = this.getAttribute('data-i')*1;
var rows = self.getValue();
if(i>=rows.length-1) return;
Expand Down

0 comments on commit f46ed33

Please sign in to comment.