comparison src/site.js @ 46:289718f121e4

use bbcode editor
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 14 Nov 2022 18:43:38 -0700
parents 0c1b820fff34
children 78b2d6995244
comparison
equal deleted inserted replaced
45:2d4f00755092 46:289718f121e4
29 err += '\ncolumn = ' + col; 29 err += '\ncolumn = ' + col;
30 if (error && error.stack) 30 if (error && error.stack)
31 err += '\nstack = ' + error.stack; 31 err += '\nstack = ' + error.stack;
32 ajax( '/error_log.js', 'err='+encodeURIComponent(err) ); 32 ajax( '/error_log.js', 'err='+encodeURIComponent(err) );
33 }; 33 };
34
35 function upload(input,callback) {
36 let file = input.files[0];
37 input.value = null;
38 let request = new XMLHttpRequest();
39 let url = 'https://upload.uploadcare.com/base/';
40 request.open( 'POST', url );
41 request.onload = function() {
42 if( request.status !== 200 ) {
43 let err = 'ajax failed: ' + request.status;
44 if( request.responseText ) {
45 err += '\n' + request.responseText;
46 document.write('<pre>'+request.responseText+'</pre>');
47 }
48 console.log(err);
49 ajax( '/error_log.js', 'err='+encodeURIComponent(err) );
50 return;
51 }
52 let response = JSON.parse(request.responseText);
53 let filename = file.name;
54 let url = 'https://ucarecdn.com/' + response.file + '/' + filename;
55 callback(input,url,filename);
56 };
57 let formData = new FormData();
58 formData.append( 'UPLOADCARE_PUB_KEY', 'fe3d30f3088a50941d45' );
59 formData.append( 'file', file );
60 request.send(formData);
61 }
62
63 function fileButtonClick(button) {
64 button.parentNode.querySelector('input[type="file"]').click();
65 }
66
67 function fixTextarea(textarea) {
68 let height = textarea.scrollHeight;
69 if( height > textarea.clientHeight ) {
70 textarea.style.height = height + "px";
71 }
72 }