1
- /*! JSON Editor v0.7.13 - JSON Schema -> HTML Editor
1
+ /*! JSON Editor v0.7.14 - 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-11-11
5
+ * Date: 2015-01-25
6
6
*/
7
7
8
8
/**
@@ -1795,6 +1795,8 @@ JSONEditor.defaults.editors.string = JSONEditor.AbstractEditor.extend({
1795
1795
1796
1796
if ( initial ) this . is_dirty = false ;
1797
1797
else if ( this . jsoneditor . options . show_errors === "change" ) this . is_dirty = true ;
1798
+
1799
+ if ( this . adjust_height ) this . adjust_height ( this . input ) ;
1798
1800
1799
1801
// Bubble this setValue to parents if the value changed
1800
1802
this . onChange ( changed ) ;
@@ -1921,7 +1923,12 @@ JSONEditor.defaults.editors.string = JSONEditor.AbstractEditor.extend({
1921
1923
if ( typeof this . schema . pattern !== "undefined" ) this . input . setAttribute ( 'pattern' , this . schema . pattern ) ;
1922
1924
else if ( typeof this . schema . minLength !== "undefined" ) this . input . setAttribute ( 'pattern' , '.{' + this . schema . minLength + ',}' ) ;
1923
1925
1924
- if ( this . options . compact ) this . container . setAttribute ( 'class' , this . container . getAttribute ( 'class' ) + ' compact' ) ;
1926
+ if ( this . options . compact ) {
1927
+ this . container . className += ' compact' ;
1928
+ }
1929
+ else {
1930
+ if ( this . options . input_width ) this . input . style . width = this . options . input_width ;
1931
+ }
1925
1932
1926
1933
if ( this . schema . readOnly || this . schema . readonly || this . schema . template ) {
1927
1934
this . always_disabled = true ;
@@ -1952,6 +1959,42 @@ JSONEditor.defaults.editors.string = JSONEditor.AbstractEditor.extend({
1952
1959
self . refreshValue ( ) ;
1953
1960
self . onChange ( true ) ;
1954
1961
} ) ;
1962
+
1963
+ if ( this . options . input_height ) this . input . style . height = this . options . input_height ;
1964
+ if ( this . options . expand_height ) {
1965
+ this . adjust_height = function ( el ) {
1966
+ if ( ! el ) return ;
1967
+ var i , ch = el . offsetHeight ;
1968
+ // Input too short
1969
+ if ( el . offsetHeight < el . scrollHeight ) {
1970
+ i = 0 ;
1971
+ while ( el . offsetHeight < el . scrollHeight + 3 ) {
1972
+ if ( i > 100 ) break ;
1973
+ i ++ ;
1974
+ ch ++ ;
1975
+ el . style . height = ch + 'px' ;
1976
+ }
1977
+ }
1978
+ else {
1979
+ i = 0 ;
1980
+ while ( el . offsetHeight >= el . scrollHeight + 3 ) {
1981
+ if ( i > 100 ) break ;
1982
+ i ++ ;
1983
+ ch -- ;
1984
+ el . style . height = ch + 'px' ;
1985
+ }
1986
+ el . style . height = ( ch + 1 ) + 'px' ;
1987
+ }
1988
+ } ;
1989
+
1990
+ this . input . addEventListener ( 'keyup' , function ( e ) {
1991
+ self . adjust_height ( this ) ;
1992
+ } ) ;
1993
+ this . input . addEventListener ( 'change' , function ( e ) {
1994
+ self . adjust_height ( this ) ;
1995
+ } ) ;
1996
+ this . adjust_height ( ) ;
1997
+ }
1955
1998
1956
1999
if ( this . format ) this . input . setAttribute ( 'data-schemaformat' , this . format ) ;
1957
2000
@@ -1964,6 +2007,7 @@ JSONEditor.defaults.editors.string = JSONEditor.AbstractEditor.extend({
1964
2007
// otherwise, in the case of an ace_editor creation,
1965
2008
// it will generate an error trying to append it to the missing parentNode
1966
2009
if ( self . input . parentNode ) self . afterInputReady ( ) ;
2010
+ if ( self . adjust_height ) self . adjust_height ( self . input ) ;
1967
2011
} ) ;
1968
2012
1969
2013
// Compile and store the template
@@ -2248,7 +2292,7 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({
2248
2292
var editor = self . editors [ key ] ;
2249
2293
if ( editor . property_removed ) return ;
2250
2294
var found = false ;
2251
- var width = editor . options . hidden ? 0 : editor . getNumColumns ( ) ;
2295
+ var width = editor . options . hidden ? 0 : ( editor . options . grid_columns || editor . getNumColumns ( ) ) ;
2252
2296
var height = editor . options . hidden ? 0 : editor . container . offsetHeight ;
2253
2297
// See if the editor will fit in any of the existing rows first
2254
2298
for ( var i = 0 ; i < rows . length ; i ++ ) {
@@ -2389,7 +2433,7 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({
2389
2433
} ) ;
2390
2434
self . editors [ key ] . preBuild ( ) ;
2391
2435
2392
- var width = self . editors [ key ] . options . hidden ? 0 : self . editors [ key ] . getNumColumns ( ) ;
2436
+ var width = self . editors [ key ] . options . hidden ? 0 : ( self . editors [ key ] . options . grid_columns || self . editors [ key ] . getNumColumns ( ) ) ;
2393
2437
2394
2438
self . minwidth += width ;
2395
2439
self . maxwidth += width ;
@@ -2412,8 +2456,8 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({
2412
2456
self . addObjectProperty ( key , true ) ;
2413
2457
2414
2458
if ( self . editors [ key ] ) {
2415
- self . minwidth = Math . max ( self . minwidth , self . editors [ key ] . getNumColumns ( ) ) ;
2416
- self . maxwidth += self . editors [ key ] . getNumColumns ( ) ;
2459
+ self . minwidth = Math . max ( self . minwidth , ( self . editors [ key ] . options . grid_columns || self . editors [ key ] . getNumColumns ( ) ) ) ;
2460
+ self . maxwidth += ( self . editors [ key ] . options . grid_columns || self . editors [ key ] . getNumColumns ( ) ) ;
2417
2461
}
2418
2462
} ) ;
2419
2463
}
@@ -2446,6 +2490,9 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({
2446
2490
if ( self . editors [ key ] . options . hidden ) {
2447
2491
holder . style . display = 'none' ;
2448
2492
}
2493
+ if ( self . editors [ key ] . options . input_width ) {
2494
+ holder . style . width = self . editors [ key ] . options . input_width ;
2495
+ }
2449
2496
} ) ;
2450
2497
}
2451
2498
// If the object should be rendered as a table
@@ -3369,6 +3416,7 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
3369
3416
self . active_tab = new_active_tab ;
3370
3417
3371
3418
self . refreshValue ( initial ) ;
3419
+ self . refreshTabs ( true ) ;
3372
3420
self . refreshTabs ( ) ;
3373
3421
3374
3422
self . onChange ( ) ;
@@ -3798,11 +3846,13 @@ JSONEditor.defaults.editors.table = JSONEditor.defaults.editors.array.extend({
3798
3846
this . panel . appendChild ( this . controls ) ;
3799
3847
3800
3848
if ( this . item_has_child_editors ) {
3801
- $each ( tmp . getChildEditors ( ) , function ( i , editor ) {
3802
- var th = self . theme . getTableHeaderCell ( editor . getTitle ( ) ) ;
3803
- if ( editor . options . hidden ) th . style . display = 'none' ;
3849
+ var ce = tmp . getChildEditors ( ) ;
3850
+ var order = tmp . property_order || Object . keys ( ce ) ;
3851
+ for ( var i = 0 ; i < order . length ; i ++ ) {
3852
+ var th = self . theme . getTableHeaderCell ( ce [ order [ i ] ] . getTitle ( ) ) ;
3853
+ if ( ce [ order [ i ] ] . options . hidden ) th . style . display = 'none' ;
3804
3854
self . header_row . appendChild ( th ) ;
3805
- } ) ;
3855
+ }
3806
3856
}
3807
3857
else {
3808
3858
self . header_row . appendChild ( self . theme . getTableHeaderCell ( this . item_title ) ) ;
@@ -4672,7 +4722,7 @@ JSONEditor.defaults.editors.select = JSONEditor.AbstractEditor.extend({
4672
4722
}
4673
4723
// Boolean
4674
4724
else if ( this . schema . type === "boolean" ) {
4675
- self . enum_display = [ 'true' , 'false' ] ;
4725
+ self . enum_display = this . schema . options && this . schema . options . enum_titles || [ 'true' , 'false' ] ;
4676
4726
self . enum_options = [ '1' , '' ] ;
4677
4727
self . enum_values = [ true , false ] ;
4678
4728
}
@@ -4743,7 +4793,7 @@ JSONEditor.defaults.editors.select = JSONEditor.AbstractEditor.extend({
4743
4793
if ( ! this . options . compact ) this . header = this . label = this . theme . getFormInputLabel ( this . getTitle ( ) ) ;
4744
4794
if ( this . schema . description ) this . description = this . theme . getFormInputDescription ( this . schema . description ) ;
4745
4795
4746
- if ( this . options . compact ) this . container . setAttribute ( 'class' , this . container . getAttribute ( 'class' ) + ' compact' ) ;
4796
+ if ( this . options . compact ) this . container . className += ' compact' ;
4747
4797
4748
4798
this . input = this . theme . getSelectInput ( this . enum_options ) ;
4749
4799
this . theme . setSelectOptions ( this . input , this . enum_options , this . enum_display ) ;
0 commit comments