Skip to content

Commit

Permalink
Merge branch master
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit a97cc2a
Author: Jeremy Dorn <[email protected]>
Date:   Mon Sep 15 16:17:10 2014 -0700

    Version bump to 0.7.10

commit b75eec9
Author: Jeremy Dorn <[email protected]>
Date:   Mon Sep 15 16:15:30 2014 -0700

    Add option to remove empty object properties from returned JSON. Fixes #220

commit 5dd3627
Author: Jeremy Dorn <[email protected]>
Date:   Mon Sep 15 16:07:07 2014 -0700

    Fix array/minItems bug. Fixes #246

commit e7fbe17
Author: Jeremy Dorn <[email protected]>
Date:   Mon Sep 15 14:49:29 2014 -0700

    Standardize all notify/change/watch calls. Fixes #247 Fixes #248

    Probably fixes a lot more bugs too

commit 4a5bd8a
Merge: ba381f5 941e096
Author: Jeremy Dorn <[email protected]>
Date:   Mon Sep 15 14:39:29 2014 -0700

    Merge branch 'keynslug-patch-1'

commit 941e096
Author: Andrew Majorov <[email protected]>
Date:   Tue Sep 16 01:03:10 2014 +0400

    Properly handle cases when number extremum is 0

    The condition does not hold when `schema.minimum` or `schema.maximum` equals 0, even if the property actually defined.

commit ba381f5
Author: Jeremy <[email protected]>
Date:   Mon Sep 1 07:40:12 2014 -0700

    Register with npm

commit 50f3831
Author: Jeremy <[email protected]>
Date:   Sun Aug 31 19:55:32 2014 -0700

    Fix Select2 bugs, enum_titles support for strings, add Select2 example. Fixes #240
    Related to #231
  • Loading branch information
Andre Kampert committed Sep 17, 2014
1 parent 50b9ccf commit e4d681c
Show file tree
Hide file tree
Showing 18 changed files with 393 additions and 300 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "json-editor",
"version": "0.7.8",
"version": "0.7.10",
"authors": [
"Jeremy Dorn <[email protected]>"
],
Expand Down
84 changes: 84 additions & 0 deletions examples/select2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>JSON Editor Select2 Integration Example</title>
<script src="../dist/jsoneditor.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//cdn.jsdelivr.net/select2/3.4.8/select2.min.js"></script>
<link rel="stylesheet" href="//cdn.jsdelivr.net/select2/3.4.8/select2.css">
</head>
<body>
<h1>JSON Editor Select2 Integration Example</h1>

<p style='margin-bottom:20px;'>This example demonstrates JSONEditor's integration with Select2</p>

<div id='editor_holder'></div>
<button id='submit'>Submit (console.log)</button>

<script>
// Global Select2 options
JSONEditor.plugins.select2.width = "300px";

// Initialize the editor with a JSON schema
var editor = new JSONEditor(document.getElementById('editor_holder'),{
schema: {
type: "object",
title: "Text",
required: ["fontSize","color","font","weight","possibleFonts"],
properties: {
fontSize: {
type: "integer",
enum: [10,11,12,14,16,18,20,22,24,36,48,60,72,100],
default: 24,
options: {
// Override defaullt options
select2_options: {
width: 'off'
}
}
},
color: {
type: "string",
enum: ["black","red","green","blue","yellow","orange","purple","brown","white","cyan","maagenta"]
},
font: {
type: "string",
enumSource: "possible_fonts",
watch: {
"possible_fonts": "root.possibleFonts"
},
},
weight: {
type: "string",
enum: ["normal","bold","bolder","lighter"],
options: {
enum_titles: ["Normal (400)","Bold (700)","Bolder (900)","Lighter (200)"]
}
},
possibleFonts: {
type: "array",
format: 'table',
items: {
type: "string"
},
default: ["Arial","Times","Helvetica","Comic Sans"],
options: {
collapsed: true
}
}
}
},
startval: {
color: "red"
}
});

// Hook up the submit button to log to the console
document.getElementById('submit').addEventListener('click',function() {
// Get the value from the editor
console.log(editor.getValue());
});
</script>
</body>
</html>
30 changes: 29 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
{
"name": "jquery-jsoneditor",
"name": "json-editor",
"title": "JSONEditor",
"description": "JSON Schema based editor",
"version": "0.7.10",
"main": "dist/jsoneditor.js",
"author": {
"name": "Jeremy Dorn",
"email": "[email protected]",
"url": "http://jeremydorn.com"
},
"bugs": {
"url": "https://github.com/jdorn/json-editor/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/jdorn/json-editor.git"
},
"keywords": [
"json",
"schema",
"jsonschema",
"editor"
],
"license": "MIT",
"engines": {
"node": ">= 0.8.0"
},
Expand All @@ -9,5 +32,10 @@
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-jshint": "^0.10.0",
"grunt": "~0.4.2"
},
"scripts": {
"build": "npm install && grunt",
"start": "grunt watch",
"test": "grunt"
}
}
7 changes: 7 additions & 0 deletions src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ JSONEditor.plugins = {
},
sceditor: {

},
select2: {

}
};

Expand Down Expand Up @@ -220,6 +223,10 @@ JSONEditor.defaults.resolvers.unshift(function(schema) {
return "table";
}
});
// Use the `select` editor for dynamic enumSource enums
JSONEditor.defaults.resolvers.unshift(function(schema) {
if(schema.enumSource) return "select";
});
// Use the `enum` or `select` editors for schemas with enumerated properties
JSONEditor.defaults.resolvers.unshift(function(schema) {
if(schema.enum) {
Expand Down
16 changes: 9 additions & 7 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
*/
JSONEditor.AbstractEditor = Class.extend({
onChildEditorChange: function(editor) {
if(!this.watch_listener) return;
this.watch_listener();
this.notify();
this.change();
this.onChange(true);
},
notify: function() {
this.jsoneditor.notifyWatchers(this.path);
Expand All @@ -15,8 +12,14 @@ JSONEditor.AbstractEditor = Class.extend({
if(this.parent) this.parent.onChildEditorChange(this);
else this.jsoneditor.onChange();
},
onChange: function(bubble) {
this.notify();
if(this.watch_listener) this.watch_listener();
if(bubble) this.change();
},
register: function() {
this.jsoneditor.registerEditor(this);
this.onChange();
},
unregister: function() {
if(!this.jsoneditor) return;
Expand Down Expand Up @@ -62,13 +65,12 @@ JSONEditor.AbstractEditor = Class.extend({

},
postBuild: function() {
this.register();
this.setupWatchListeners();
this.addLinks();
this.setValue(this.getDefault(), true);
this.updateHeaderText();
this.jsoneditor.notifyWatchers(this.path);
this.watch_listener();
this.register();
this.onWatchedFieldChange();
},

setupWatchListeners: function() {
Expand Down
35 changes: 14 additions & 21 deletions src/editors/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,17 +305,17 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
$each(value,function(i,val) {
if(self.rows[i]) {
// TODO: don't set the row's value if it hasn't changed
self.rows[i].setValue(val);
self.rows[i].setValue(val,initial);
}
else if(self.row_cache[i]) {
self.rows[i] = self.row_cache[i];
self.rows[i].setValue(val);
self.rows[i].setValue(val,initial);
self.rows[i].container.style.display = '';
if(self.rows[i].tab) self.rows[i].tab.style.display = '';
self.rows[i].register();
}
else {
self.addRow(val);
self.addRow(val,initial);
}
});

Expand All @@ -339,8 +339,8 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({

self.refreshValue(initial);
self.refreshTabs();
self.jsoneditor.notifyWatchers(self.path);

self.onChange();

// TODO: sortable
},
Expand Down Expand Up @@ -431,7 +431,7 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
}
}
},
addRow: function(value) {
addRow: function(value, initial) {
var self = this;
var i = this.rows.length;

Expand Down Expand Up @@ -488,9 +488,8 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
self.active_tab = new_active_tab;
self.refreshTabs();
}

if(self.parent) self.parent.onChildEditorChange(self);
else self.jsoneditor.onChange();

self.onChange(true);
});

if(controls_holder) {
Expand All @@ -517,8 +516,7 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
self.active_tab = self.rows[i-1].tab;
self.refreshTabs();

if(self.parent) self.parent.onChildEditorChange(self);
else self.jsoneditor.onChange();
self.onChange(true);
});

if(controls_holder) {
Expand All @@ -544,16 +542,15 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
self.setValue(rows);
self.active_tab = self.rows[i+1].tab;
self.refreshTabs();
if(self.parent) self.parent.onChildEditorChange(self);
else self.jsoneditor.onChange();
self.onChange(true);
});

if(controls_holder) {
controls_holder.appendChild(self.rows[i].movedown_button);
}
}

if(value) self.rows[i].setValue(value);
if(value) self.rows[i].setValue(value, initial);
self.refreshTabs();
},
addControls: function() {
Expand Down Expand Up @@ -617,9 +614,7 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
self.active_tab = self.rows[i].tab;
self.refreshTabs();
self.refreshValue();
if(self.parent) self.parent.onChildEditorChange(self);
else self.jsoneditor.onChange();
self.jsoneditor.notifyWatchers(self.path);
self.onChange(true);
});
self.controls.appendChild(this.add_row_button);

Expand All @@ -638,8 +633,7 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
self.active_tab = new_active_tab;
self.refreshTabs();
}
if(self.parent) self.parent.onChildEditorChange(self);
else self.jsoneditor.onChange();
self.onChange(true);
});
self.controls.appendChild(this.delete_last_row_button);

Expand All @@ -648,8 +642,7 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
e.preventDefault();
e.stopPropagation();
self.setValue([]);
if(self.parent) self.parent.onChildEditorChange(self);
else self.jsoneditor.onChange();
self.onChange(true);
});
self.controls.appendChild(this.remove_all_rows_button);

Expand Down
8 changes: 2 additions & 6 deletions src/editors/base64.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ JSONEditor.defaults.editors.base64 = JSONEditor.AbstractEditor.extend({
fr.onload = function(evt) {
self.value = evt.target.result;
self.refreshPreview();
self.watch_listener();
self.jsoneditor.notifyWatchers(self.path);
if(self.parent) self.parent.onChildEditorChange(self);
else self.jsoneditor.onChange();
self.onChange(true);
fr = null;
};
fr.readAsDataURL(this.files[0]);
Expand Down Expand Up @@ -82,8 +79,7 @@ JSONEditor.defaults.editors.base64 = JSONEditor.AbstractEditor.extend({
this.value = val;
this.input.value = this.value;
this.refreshPreview();
this.watch_listener();
this.jsoneditor.notifyWatchers(this.path);
this.onChange();
}
},
destroy: function() {
Expand Down
6 changes: 2 additions & 4 deletions src/editors/enum.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ JSONEditor.defaults.editors.enum = JSONEditor.AbstractEditor.extend({
self.selected = self.select_options.indexOf(this.value);
self.value = self.enum[self.selected];
self.refreshValue();

if(self.parent) self.parent.onChildEditorChange(self);
else self.jsoneditor.onChange();
self.onChange(true);
});
this.value = this.enum[0];
this.refreshValue();
Expand Down Expand Up @@ -123,7 +121,7 @@ JSONEditor.defaults.editors.enum = JSONEditor.AbstractEditor.extend({
if(this.value !== val) {
this.value = val;
this.refreshValue();
this.jsoneditor.notifyWatchers(this.path);
this.onChange();
}
},
destroy: function() {
Expand Down
14 changes: 4 additions & 10 deletions src/editors/multiple.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ JSONEditor.defaults.editors.multiple = JSONEditor.AbstractEditor.extend({
else editor.container.style.display = 'none';
});
self.refreshValue();
if(self.watch_listener) self.watch_listener();
self.notify();
self.change();
self.refreshHeaderText();
},
buildChildEditor: function(i) {
var self = this;
Expand Down Expand Up @@ -173,6 +171,7 @@ JSONEditor.defaults.editors.multiple = JSONEditor.AbstractEditor.extend({
e.stopPropagation();

self.switchEditor(self.display_text.indexOf(this.value));
self.onChange(true);
});
this.switcher.style.marginBottom = 0;
this.switcher.style.width = 'auto';
Expand Down Expand Up @@ -205,14 +204,11 @@ JSONEditor.defaults.editors.multiple = JSONEditor.AbstractEditor.extend({
});

this.switchEditor(0);

this.refreshValue();
this.refreshHeaderText();
},
onChildEditorChange: function(editor) {
if(this.editors[this.type]) {
this.refreshHeaderText();
this.refreshValue();
this.refreshHeaderText();
}

this._super();
Expand Down Expand Up @@ -242,9 +238,7 @@ JSONEditor.defaults.editors.multiple = JSONEditor.AbstractEditor.extend({
this.editors[this.type].setValue(val,initial);

this.refreshValue();
this.watch_listener();
this.notify();

self.onChange();
},
destroy: function() {
$each(this.editors, function(type,editor) {
Expand Down
Loading

0 comments on commit e4d681c

Please sign in to comment.