-
Notifications
You must be signed in to change notification settings - Fork 1
/
jquery.json_editor.js
70 lines (70 loc) · 1.92 KB
/
jquery.json_editor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
(function($){
$.widget("ui.json_editor", {
options: {
search: false
},
_create: function(){
var $$ = this,
o = $$.options,
v = $$.element.val(),
trigger = true;
$$.h = parseInt($$.element.css("height"));
if ( !($$.h > 50) ){
$$.h = 400;
}
$$.element.addClass($$.widgetFullName).wrap('<div></div>');
$$.container = $$.element.parent();
$$.editor_options = {
mode: $$.element.is('[readonly]') || $$.element.is(':disabled') ? "view" : "tree",
change: function(){
trigger = false,
$$.element.val(JSON.stringify($$.editor.get())).trigger("change");
},
name: "Objet de configuration"
};
if ( !$$.element.is('[readonly]') && !$$.element.is(':disabled') ){
$$.editor_options.modes = ["tree", "text"];
}
$$._make();
if ( v ){
$$.editor.set(JSON.parse(v));
}
$$.element.on("change", function(){
if ( trigger ){
$$.editor.set(JSON.parse($$.element.val()));
}
else{
trigger = true;
}
});
},
_make: function(){
var $$ = this;
$$.container.prepend('<div></div>');
$$.editor_container = $$.container.children("div").height($$.h);
$$.editor = new JSONEditor($$.editor_container.get(0), $$.editor_options);
},
enable: function(a){
var $$ = this,
v = $$.editor.get(),
newMode = a ? "tree" : "view";
if ( newMode !== $$.editor_options.mode ){
$$.container.children("div:first").remove()
$$.editor_options.mode = newMode;
$$._make();
}
/*
this.set('readOnly', a ? true : false);
if ( a ){
this.element.removeAttr("disabled");
}
else{
this.element.prop("disabled", true);
}
*/
}
});
$.extend($.ui.json_editor, {
version: "0.2"
});
})(jQuery);