1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| <!DOCTYPE html> <html> <head> <script src='tinymce.min.js'></script> <script> tinymce.init({ selector: '#mytextarea', language: 'zh_CN', plugins: 'preview searchreplace autolink directionality visualblocks visualchars fullscreen image link media template code codesample table charmap pagebreak nonbreaking anchor insertdatetime advlist lists wordcount help emoticons autosave autoresize', toolbar: 'code undo redo restoredraft | cut copy paste pastetext | forecolor backcolor bold italic underline strikethrough link anchor | alignleft aligncenter alignright alignjustify outdent indent | \ styleselect formatselect fontselect fontsizeselect | bullist numlist | blockquote subscript superscript removeformat | \ table image media charmap emoticons pagebreak insertdatetime preview | fullscreen | lineheight ', images_upload_url: '/upload/tinyImage', images_upload_base_path: '', max_height: 750, fontsize_formats: '12px 14px 16px 18px 24px 36px 48px 56px 72px', font_formats: '微软雅黑=Microsoft YaHei,Helvetica Neue,PingFang SC,sans-serif;苹果苹方=PingFang SC,Microsoft YaHei,sans-serif;宋体=simsun,serif;仿宋体=FangSong,serif;黑体=SimHei,sans-serif;Arial=arial,helvetica,sans-serif;Arial Black=arial black,avant garde;Book Antiqua=book antiqua,palatino;', toolbar_sticky: true, autosave_ask_before_unload: false, file_picker_callback: function (callback, value, meta) { let filetype = '.pdf, .txt, .zip, .rar, .7z, .doc, .docx, .xls, .xlsx, .ppt, .pptx, .mp3, .mp4'; let upurl = '/upload/tinyFile'; switch (meta.filetype) { case 'image': filetype = '.jpg, .jpeg, .png, .gif'; break; case 'media': filetype = '.mp3, .mp4'; break; case 'file': default: } let input = document.createElement('input'); input.setAttribute('type', 'file'); input.setAttribute('accept', filetype); input.click(); input.onchange = function () { let file = this.files[0];
let xhr, formData; console.log(file.name); xhr = new XMLHttpRequest(); xhr.withCredentials = false; xhr.open('POST', upurl); xhr.onload = function () { let json; if (xhr.status != 200) { failure('HTTP Error: ' + xhr.status); return; } json = JSON.parse(xhr.responseText); if (!json || typeof json.location != 'string') { failure('Invalid JSON: ' + xhr.responseText); return; } callback(json.location); }; formData = new FormData(); formData.append('file', file, file.name); xhr.send(formData); } } }); let content = tinymce.activeEditor.getContent(); </script> </head>
<body> <h1>TinyMCE快速开始示例</h1> <form method="post"> <textarea id="mytextarea">Hello, World!</textarea> </form> </body> </html>
|