1/** 2 * Initializes the JSON Editor for the schema editor 3 * 4 * This script and the editor script itself is only loaded on the admin screen. 5 */ 6jQuery(function () { 7 var $schema_editor = jQuery('#plugin__struct_editor'); 8 9 /** 10 * Initialize the Editor 11 */ 12 $schema_editor.find('textarea.config').each(function () { 13 var $config = jQuery(this); 14 var container = document.createElement('DIV'); 15 $config.before(container); 16 var editor = new JSONEditor(container, { 17 onChange: function () { 18 $config.val(editor.getText()); 19 }, 20 history: false, 21 mode: 'form', 22 search: false, 23 name: 'config' 24 }); 25 editor.setText($config.val()); 26 $config.hide(); 27 // define a function to reload later 28 this.updateEditor = function () { 29 editor.setText($config.val()); 30 }; 31 }); 32 33 /** 34 * Autoload the correct configuration 35 */ 36 $schema_editor.find('td.class select').change(function () { 37 var type = jQuery(this).val(); 38 var $editor = jQuery(this).parents('tr').find('textarea.config'); 39 var conf = $editor.val(); 40 $editor.val('"..."')[0].updateEditor(); 41 42 jQuery.post( 43 DOKU_BASE + 'lib/exe/ajax.php', 44 { 45 call: 'plugin_struct_config', 46 type: type, 47 conf: conf 48 }, 49 function (conf) { 50 $editor.val(conf)[0].updateEditor(); 51 } 52 ) 53 }); 54}); 55