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 // collapse all nodes except for the new element 32 if(!$config.parents('.new').length) { 33 editor.collapseAll(); 34 } 35 }); 36 37 /** 38 * Autoload the correct configuration 39 */ 40 $schema_editor.find('td.class select').change(function () { 41 var type = jQuery(this).val(); 42 var $editor = jQuery(this).parents('tr').find('textarea.config'); 43 var conf = $editor.val(); 44 $editor.val('"..."')[0].updateEditor(); 45 46 jQuery.post( 47 DOKU_BASE + 'lib/exe/ajax.php', 48 { 49 call: 'plugin_struct_config', 50 type: type, 51 conf: conf 52 }, 53 function (conf) { 54 $editor.val(conf)[0].updateEditor(); 55 } 56 ) 57 }); 58}); 59