var rels; var defRid = 0; var staticUrl; function init() { var data = jsonParse(getText(byId('screendata'))) || {}; rels = data.rel; rels.unshift([ 0, '-- select release --' ]); staticUrl = data.staticurl; var scr = jsonParse(byId('screenshots').value) || {}; for(i=0; i= 10; var rel = genRels(defRid); rel.onchange = function() { defRid = this.options[this.selectedIndex].value }; rel.id = 'scradd_relsel'; byId('scr_table').appendChild(tag('tr', {id:'scr_last'}, tag('td', {'class': 'thumb'}), full ? tag('td', tag('b', 'Enough screenshots'), tag('br', null), 'The limit of 10 screenshots per visual novel has been reached.\nIf you want to add a new screenshot, please remove an existing one first.' ) : tag('td', tag('b', 'Add screenshot'), tag('br', null), 'Image must be smaller than 5MB and in PNG or JPEG format.', tag('br', null), rel, tag('br', null), tag('input', {name:'scr_upload', id:'scr_upload', type:'file', 'class':'text', multiple:true}), tag('br', null), tag('input', {type:'button', value:'Upload!', 'class':'submit', onclick:upload}) ) )); } function del(what) { var tr = what && what.scr_id != null ? what : this; while(tr.scr_id == null) tr = tr.parentNode; if(tr.scr_ajax) tr.scr_ajax.abort(); byId('scr_table').removeChild(tr); addLast(); ivInit(); return false; } function uploadFile(f) { var tr = add(0, defRid); var fname = f.name; var frm = new FormData(); frm.append('file', f); tr.scr_ajax = ajax('/xml/screenshots.xml', function(hr) { tr.scr_ajax = null; var img = hr.responseXML.getElementsByTagName('image')[0]; var id = img.getAttribute('id'); if(id < 0) { alert(fname + ":\n" + ( id == -1 ? 'Upload failed!\nOnly JPEG or PNG images are accepted.' : 'Upload failed!\nNo file selected, or an empty file?')); del(tr); } else { loaded(tr, id, img.getAttribute('width'), img.getAttribute('height')); ivInit(); } }, true, frm); } function upload() { var files = byId('scr_upload').files; if(files.length < 1) { alert('Upload failed!\nNo file selected, or an empty file?'); return false; } else if(files.length + byName(byId('scr_table'), 'tr').length - 1 > 10) { alert('Too many files selected. The total number of screenshots may not exceed 10.'); return false; } for(var i=0; i