var modifiers_changed = new Event("modifiers:changed", {"bubbles":true, "cancelable":false}); $(document).ready(function() { var timer; $(document).on('input','#modifiers div.additional input, #modifiers div.additional textarea, #modifiers div.additional [contenteditable]',function(e){ clearTimeout(timer); timer = setTimeout(function(){ do_mod_save(e.target) }, 5000); }); $(document).on('change','#modifiers div.additional select',function(e){ clearTimeout(timer); do_mod_save(e.target); }); $(document).on('blur','#modifiers div.additional input, #modifiers div.additional textarea, #modifiers div.additional [contenteditable]',function(e){ clearTimeout(timer); do_mod_save(e.target); }); $(document).on('keypress','#modifiers div.additional input',function(e){ if (e.keyCode == 13) { clearTimeout(timer); do_mod_save(e.target); } }); $(document).on('keypress','#modifiers div.additional [contenteditable]',function(e){ if (e.keyCode == 13) { document.execCommand('insertText', false, '\n'); return false; } }); $(document).on('relaxngui_remove', '#modifiers div.additional', function(e){ clearTimeout(timer); do_mod_save(e.target); }); $(document).on('relaxngui_move', '#modifiers div.additional', function(e){ clearTimeout(timer); do_mod_save(e.target); }); }); function do_mod_save(target) { let div = $(target).parents('div[data-resource]'); let top = div.attr('data-resource'); let doc = save['modifiers_additional'][top].save(); let rep = $('body').attr('current-resources'); let now = encodeURIComponent($('div.select select',div).val()); var tset = $X(''); tset.append(doc.documentElement); set_testset(tset,false); document.dispatchEvent(modifiers_changed); } async function modifiers_display() { let promises = []; let rep = $('body').attr('current-resources'); $('#modifiers > div').remove(); promises.push( $.ajax({ url: rep + 'modifiers/' }).then(async function(res) { let ipromises = []; $('resource',res).each(function(_,r) { ipromises.push( $.ajax({ url: rep + 'modifiers/' + $(r).text() }).then(async function(ses){ let clone = document.importNode(document.querySelector('#modifiers template').content,true); let t = $(r).text(); $('> div',clone).attr('data-resource',t); $('div.title *',clone).text(decodeURIComponent(t)); let cpromises = []; $('resource',ses).each(function(_,s) { let opt = $('