1
- /*! JSON Editor v0.7.0 - JSON Schema -> HTML Editor
1
+ /*! JSON Editor v0.7.1 - JSON Schema -> HTML Editor
2
2
* By Jeremy Dorn - https://github.com/jdorn/json-editor/
3
3
* Released under the MIT license
4
4
*
5
- * Date: 2014-07-13
5
+ * Date: 2014-07-24
6
6
*/
7
7
8
8
/**
@@ -370,7 +370,10 @@ JSONEditor.prototype = {
370
370
371
371
// Validate and cache results
372
372
self . validation_results = self . validator . validate ( self . root . getValue ( ) ) ;
373
- self . root . showValidationErrors ( self . validation_results ) ;
373
+
374
+ if ( self . options . show_errors !== "never" ) {
375
+ self . root . showValidationErrors ( self . validation_results ) ;
376
+ }
374
377
375
378
// Fire change event
376
379
self . trigger ( 'change' ) ;
@@ -1759,7 +1762,10 @@ JSONEditor.defaults.editors.string = JSONEditor.AbstractEditor.extend({
1759
1762
var changed = from_template || this . getValue ( ) !== value ;
1760
1763
1761
1764
this . refreshValue ( ) ;
1762
-
1765
+
1766
+ if ( initial ) this . is_dirty = false ;
1767
+ else if ( this . jsoneditor . options . show_errors === "change" ) this . is_dirty = true ;
1768
+
1763
1769
if ( changed ) {
1764
1770
if ( self . parent ) self . parent . onChildEditorChange ( self ) ;
1765
1771
else self . jsoneditor . onChange ( ) ;
@@ -1977,6 +1983,8 @@ JSONEditor.defaults.editors.string = JSONEditor.AbstractEditor.extend({
1977
1983
if ( val !== sanitized ) {
1978
1984
this . value = sanitized ;
1979
1985
}
1986
+
1987
+ self . is_dirty = true ;
1980
1988
1981
1989
self . refreshValue ( ) ;
1982
1990
self . watch_listener ( ) ;
@@ -2053,6 +2061,7 @@ JSONEditor.defaults.editors.string = JSONEditor.AbstractEditor.extend({
2053
2061
// Set the value and update
2054
2062
self . input . value = val . html ( ) ;
2055
2063
self . value = self . input . value ;
2064
+ self . is_dirty = true ;
2056
2065
if ( self . parent ) self . parent . onChildEditorChange ( self ) ;
2057
2066
else self . jsoneditor . onChange ( ) ;
2058
2067
self . jsoneditor . notifyWatchers ( self . path ) ;
@@ -2077,6 +2086,7 @@ JSONEditor.defaults.editors.string = JSONEditor.AbstractEditor.extend({
2077
2086
var val = self . epiceditor . exportFile ( ) ;
2078
2087
self . input . value = val ;
2079
2088
self . value = val ;
2089
+ self . is_dirty = true ;
2080
2090
if ( self . parent ) self . parent . onChildEditorChange ( self ) ;
2081
2091
else self . jsoneditor . onChange ( ) ;
2082
2092
self . jsoneditor . notifyWatchers ( self . path ) ;
@@ -2111,6 +2121,7 @@ JSONEditor.defaults.editors.string = JSONEditor.AbstractEditor.extend({
2111
2121
var val = self . ace_editor . getValue ( ) ;
2112
2122
self . input . value = val ;
2113
2123
self . refreshValue ( ) ;
2124
+ self . is_dirty = true ;
2114
2125
if ( self . parent ) self . parent . onChildEditorChange ( self ) ;
2115
2126
else self . jsoneditor . onChange ( ) ;
2116
2127
self . jsoneditor . notifyWatchers ( self . path ) ;
@@ -2249,6 +2260,11 @@ JSONEditor.defaults.editors.string = JSONEditor.AbstractEditor.extend({
2249
2260
} ,
2250
2261
showValidationErrors : function ( errors ) {
2251
2262
var self = this ;
2263
+
2264
+ if ( this . jsoneditor . options . show_errors === "always" ) { }
2265
+ else if ( ! this . is_dirty ) return ;
2266
+
2267
+
2252
2268
2253
2269
var messages = [ ] ;
2254
2270
$each ( errors , function ( i , error ) {
@@ -2430,11 +2446,12 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({
2430
2446
var row = this . theme . getGridRow ( ) ;
2431
2447
container . appendChild ( row ) ;
2432
2448
for ( j = 0 ; j < rows [ i ] . editors . length ; j ++ ) {
2433
- var editor = this . editors [ rows [ i ] . editors [ j ] . key ] ;
2449
+ var key = rows [ i ] . editors [ j ] . key ;
2450
+ var editor = this . editors [ key ] ;
2434
2451
2435
2452
if ( editor . options . hidden ) editor . container . style . display = 'none' ;
2436
2453
else this . theme . setGridColumnSize ( editor . container , rows [ i ] . editors [ j ] . width ) ;
2437
-
2454
+ editor . container . className += ' container-' + key ;
2438
2455
row . appendChild ( editor . container ) ;
2439
2456
}
2440
2457
}
@@ -2449,7 +2466,7 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({
2449
2466
2450
2467
if ( editor . options . hidden ) editor . container . style . display = 'none' ;
2451
2468
else self . theme . setGridColumnSize ( editor . container , 12 ) ;
2452
-
2469
+ editor . container . className += ' container-' + key ;
2453
2470
row . appendChild ( editor . container ) ;
2454
2471
} ) ;
2455
2472
}
@@ -2577,11 +2594,15 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({
2577
2594
this . editjson_textarea . style . width = '300px' ;
2578
2595
this . editjson_textarea . style . display = 'block' ;
2579
2596
this . editjson_save = this . getButton ( 'Save' , 'save' , 'Save' ) ;
2580
- this . editjson_save . addEventListener ( 'click' , function ( ) {
2597
+ this . editjson_save . addEventListener ( 'click' , function ( e ) {
2598
+ e . preventDefault ( ) ;
2599
+ e . stopPropagation ( ) ;
2581
2600
self . saveJSON ( ) ;
2582
2601
} ) ;
2583
2602
this . editjson_cancel = this . getButton ( 'Cancel' , 'cancel' , 'Cancel' ) ;
2584
- this . editjson_cancel . addEventListener ( 'click' , function ( ) {
2603
+ this . editjson_cancel . addEventListener ( 'click' , function ( e ) {
2604
+ e . preventDefault ( ) ;
2605
+ e . stopPropagation ( ) ;
2585
2606
self . hideEditJSON ( ) ;
2586
2607
} ) ;
2587
2608
this . editjson_holder . appendChild ( this . editjson_textarea ) ;
@@ -2603,7 +2624,9 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({
2603
2624
this . addproperty_input . style . width = '220px' ;
2604
2625
this . addproperty_input . style . marginBottom = '0' ;
2605
2626
this . addproperty_input . style . display = 'inline-block' ;
2606
- this . addproperty_add . addEventListener ( 'click' , function ( ) {
2627
+ this . addproperty_add . addEventListener ( 'click' , function ( e ) {
2628
+ e . preventDefault ( ) ;
2629
+ e . stopPropagation ( ) ;
2607
2630
if ( self . addproperty_input . value ) {
2608
2631
if ( self . editors [ self . addproperty_input . value ] ) {
2609
2632
alert ( 'there is already a property with that name' ) ;
@@ -2664,7 +2687,9 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({
2664
2687
this . collapsed = false ;
2665
2688
this . toggle_button = this . getButton ( '' , 'collapse' , 'Collapse' ) ;
2666
2689
this . title_controls . appendChild ( this . toggle_button ) ;
2667
- this . toggle_button . addEventListener ( 'click' , function ( ) {
2690
+ this . toggle_button . addEventListener ( 'click' , function ( e ) {
2691
+ e . preventDefault ( ) ;
2692
+ e . stopPropagation ( ) ;
2668
2693
if ( self . collapsed ) {
2669
2694
self . editor_holder . style . display = '' ;
2670
2695
self . collapsed = false ;
@@ -2692,7 +2717,9 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({
2692
2717
2693
2718
// Edit JSON Button
2694
2719
this . editjson_button = this . getButton ( 'JSON' , 'edit' , 'Edit JSON' ) ;
2695
- this . editjson_button . addEventListener ( 'click' , function ( ) {
2720
+ this . editjson_button . addEventListener ( 'click' , function ( e ) {
2721
+ e . preventDefault ( ) ;
2722
+ e . stopPropagation ( ) ;
2696
2723
self . toggleEditJSON ( ) ;
2697
2724
} ) ;
2698
2725
this . editjson_controls . appendChild ( this . editjson_button ) ;
@@ -2708,7 +2735,9 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({
2708
2735
2709
2736
// Object Properties Button
2710
2737
this . addproperty_button = this . getButton ( 'Properties' , 'edit' , 'Object Properties' ) ;
2711
- this . addproperty_button . addEventListener ( 'click' , function ( ) {
2738
+ this . addproperty_button . addEventListener ( 'click' , function ( e ) {
2739
+ e . preventDefault ( ) ;
2740
+ e . stopPropagation ( ) ;
2712
2741
self . toggleAddProperty ( ) ;
2713
2742
} ) ;
2714
2743
this . addproperty_controls . appendChild ( this . addproperty_button ) ;
@@ -3558,7 +3587,9 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
3558
3587
self . rows [ i ] . delete_button = this . getButton ( self . getItemTitle ( ) , 'delete' , 'Delete ' + self . getItemTitle ( ) ) ;
3559
3588
self . rows [ i ] . delete_button . className += ' delete' ;
3560
3589
self . rows [ i ] . delete_button . setAttribute ( 'data-i' , i ) ;
3561
- self . rows [ i ] . delete_button . addEventListener ( 'click' , function ( ) {
3590
+ self . rows [ i ] . delete_button . addEventListener ( 'click' , function ( e ) {
3591
+ e . preventDefault ( ) ;
3592
+ e . stopPropagation ( ) ;
3562
3593
var i = this . getAttribute ( 'data-i' ) * 1 ;
3563
3594
3564
3595
var value = self . getValue ( ) ;
@@ -3598,7 +3629,9 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
3598
3629
self . rows [ i ] . moveup_button = this . getButton ( '' , 'moveup' , 'Move up' ) ;
3599
3630
self . rows [ i ] . moveup_button . className += ' moveup' ;
3600
3631
self . rows [ i ] . moveup_button . setAttribute ( 'data-i' , i ) ;
3601
- self . rows [ i ] . moveup_button . addEventListener ( 'click' , function ( ) {
3632
+ self . rows [ i ] . moveup_button . addEventListener ( 'click' , function ( e ) {
3633
+ e . preventDefault ( ) ;
3634
+ e . stopPropagation ( ) ;
3602
3635
var i = this . getAttribute ( 'data-i' ) * 1 ;
3603
3636
3604
3637
if ( i <= 0 ) return ;
@@ -3624,7 +3657,9 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
3624
3657
self . rows [ i ] . movedown_button = this . getButton ( '' , 'movedown' , 'Move down' ) ;
3625
3658
self . rows [ i ] . movedown_button . className += ' movedown' ;
3626
3659
self . rows [ i ] . movedown_button . setAttribute ( 'data-i' , i ) ;
3627
- self . rows [ i ] . movedown_button . addEventListener ( 'click' , function ( ) {
3660
+ self . rows [ i ] . movedown_button . addEventListener ( 'click' , function ( e ) {
3661
+ e . preventDefault ( ) ;
3662
+ e . stopPropagation ( ) ;
3628
3663
var i = this . getAttribute ( 'data-i' ) * 1 ;
3629
3664
3630
3665
var rows = self . getValue ( ) ;
@@ -3656,7 +3691,9 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
3656
3691
this . title_controls . appendChild ( this . toggle_button ) ;
3657
3692
var row_holder_display = self . row_holder . style . display ;
3658
3693
var controls_display = self . controls . style . display ;
3659
- this . toggle_button . addEventListener ( 'click' , function ( ) {
3694
+ this . toggle_button . addEventListener ( 'click' , function ( e ) {
3695
+ e . preventDefault ( ) ;
3696
+ e . stopPropagation ( ) ;
3660
3697
if ( self . collapsed ) {
3661
3698
self . collapsed = false ;
3662
3699
if ( self . panel ) self . panel . style . display = '' ;
@@ -3691,7 +3728,9 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
3691
3728
// Add "new row" and "delete last" buttons below editor
3692
3729
this . add_row_button = this . getButton ( this . getItemTitle ( ) , 'add' , 'Add ' + this . getItemTitle ( ) ) ;
3693
3730
3694
- this . add_row_button . addEventListener ( 'click' , function ( ) {
3731
+ this . add_row_button . addEventListener ( 'click' , function ( e ) {
3732
+ e . preventDefault ( ) ;
3733
+ e . stopPropagation ( ) ;
3695
3734
var i = self . rows . length ;
3696
3735
if ( self . row_cache [ i ] ) {
3697
3736
self . rows [ i ] = self . row_cache [ i ] ;
@@ -3712,7 +3751,9 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
3712
3751
self . controls . appendChild ( this . add_row_button ) ;
3713
3752
3714
3753
this . delete_last_row_button = this . getButton ( 'Last ' + this . getItemTitle ( ) , 'delete' , 'Delete Last ' + this . getItemTitle ( ) ) ;
3715
- this . delete_last_row_button . addEventListener ( 'click' , function ( ) {
3754
+ this . delete_last_row_button . addEventListener ( 'click' , function ( e ) {
3755
+ e . preventDefault ( ) ;
3756
+ e . stopPropagation ( ) ;
3716
3757
var rows = self . getValue ( ) ;
3717
3758
3718
3759
var new_active_tab = null ;
@@ -3730,7 +3771,9 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
3730
3771
self . controls . appendChild ( this . delete_last_row_button ) ;
3731
3772
3732
3773
this . remove_all_rows_button = this . getButton ( 'All' , 'delete' , 'Delete All' ) ;
3733
- this . remove_all_rows_button . addEventListener ( 'click' , function ( ) {
3774
+ this . remove_all_rows_button . addEventListener ( 'click' , function ( e ) {
3775
+ e . preventDefault ( ) ;
3776
+ e . stopPropagation ( ) ;
3734
3777
self . setValue ( [ ] ) ;
3735
3778
if ( self . parent ) self . parent . onChildEditorChange ( self ) ;
3736
3779
else self . jsoneditor . onChange ( ) ;
@@ -4121,7 +4164,9 @@ JSONEditor.defaults.editors.table = JSONEditor.defaults.editors.array.extend({
4121
4164
self . rows [ i ] . delete_button = this . getButton ( '' , 'delete' , 'Delete' ) ;
4122
4165
self . rows [ i ] . delete_button . className += ' delete' ;
4123
4166
self . rows [ i ] . delete_button . setAttribute ( 'data-i' , i ) ;
4124
- self . rows [ i ] . delete_button . addEventListener ( 'click' , function ( ) {
4167
+ self . rows [ i ] . delete_button . addEventListener ( 'click' , function ( e ) {
4168
+ e . preventDefault ( ) ;
4169
+ e . stopPropagation ( ) ;
4125
4170
var i = this . getAttribute ( 'data-i' ) * 1 ;
4126
4171
4127
4172
var value = self . getValue ( ) ;
@@ -4144,7 +4189,9 @@ JSONEditor.defaults.editors.table = JSONEditor.defaults.editors.array.extend({
4144
4189
self . rows [ i ] . moveup_button = this . getButton ( '' , 'moveup' , 'Move up' ) ;
4145
4190
self . rows [ i ] . moveup_button . className += ' moveup' ;
4146
4191
self . rows [ i ] . moveup_button . setAttribute ( 'data-i' , i ) ;
4147
- self . rows [ i ] . moveup_button . addEventListener ( 'click' , function ( ) {
4192
+ self . rows [ i ] . moveup_button . addEventListener ( 'click' , function ( e ) {
4193
+ e . preventDefault ( ) ;
4194
+ e . stopPropagation ( ) ;
4148
4195
var i = this . getAttribute ( 'data-i' ) * 1 ;
4149
4196
4150
4197
if ( i <= 0 ) return ;
@@ -4164,7 +4211,9 @@ JSONEditor.defaults.editors.table = JSONEditor.defaults.editors.array.extend({
4164
4211
self . rows [ i ] . movedown_button = this . getButton ( '' , 'movedown' , 'Move down' ) ;
4165
4212
self . rows [ i ] . movedown_button . className += ' movedown' ;
4166
4213
self . rows [ i ] . movedown_button . setAttribute ( 'data-i' , i ) ;
4167
- self . rows [ i ] . movedown_button . addEventListener ( 'click' , function ( ) {
4214
+ self . rows [ i ] . movedown_button . addEventListener ( 'click' , function ( e ) {
4215
+ e . preventDefault ( ) ;
4216
+ e . stopPropagation ( ) ;
4168
4217
var i = this . getAttribute ( 'data-i' ) * 1 ;
4169
4218
var rows = self . getValue ( ) ;
4170
4219
if ( i >= rows . length - 1 ) return ;
0 commit comments