| 1 | <!DOCTYPE html> |
|---|
| 2 | <html lang='en' xml:lang='en'> |
|---|
| 3 | <head> |
|---|
| 4 | <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/> |
|---|
| 5 | <script src="https://cdn.ckeditor.com/4.4.2/standard/ckeditor.js"></script> |
|---|
| 6 | <script src="https://raw.githubusercontent.com/eligrey/FileSaver.js/master/FileSaver.js"></script> |
|---|
| 7 | <script type='application/javascript'> |
|---|
| 8 | CKEDITOR.disableAutoInline = true; |
|---|
| 9 | function downloadFile() { |
|---|
| 10 | document.getElementById('editor1').blur(); |
|---|
| 11 | var blob = new Blob(["some string"], { |
|---|
| 12 | type: "text/plain;charset=utf-8" |
|---|
| 13 | }); |
|---|
| 14 | saveAs(blob, "file.txt"); |
|---|
| 15 | } |
|---|
| 16 | window.onload = function () { |
|---|
| 17 | editor = CKEDITOR.inline("editor1", { |
|---|
| 18 | floatSpaceDockedOffsetY: 999999, |
|---|
| 19 | startupFocus: true, |
|---|
| 20 | title: false, |
|---|
| 21 | toolbarGroups: [ |
|---|
| 22 | { name: 'document', groups: [ 'mode', 'document' ] }, // Displays document group with its two subgroups. |
|---|
| 23 | { name: 'clipboard', groups: [ 'clipboard', 'undo' ] }, // Group's name will be used to create voice label. |
|---|
| 24 | '/', // Line break - next group will be placed in new line. |
|---|
| 25 | { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] }, |
|---|
| 26 | { name: 'links' } |
|---|
| 27 | ] |
|---|
| 28 | |
|---|
| 29 | }); |
|---|
| 30 | editor.addCommand('downloadDraft', { |
|---|
| 31 | exec: downloadFile |
|---|
| 32 | }); |
|---|
| 33 | editor.ui.addButton('DownloadDraft', { |
|---|
| 34 | label: 'Download Draft', |
|---|
| 35 | command: 'downloadDraft', |
|---|
| 36 | toolbar: 'document,20' |
|---|
| 37 | }); |
|---|
| 38 | }; |
|---|
| 39 | </script> |
|---|
| 40 | </head> |
|---|
| 41 | <body> |
|---|
| 42 | <div id='maincontainer'> |
|---|
| 43 | <div id='contentwrapper' style="margin-top: 100px;"> |
|---|
| 44 | <!-- Container of editors. --> |
|---|
| 45 | <div id='editor1' contenteditable="true"> |
|---|
| 46 | <p>Some content blah blah</p> |
|---|
| 47 | </div> |
|---|
| 48 | <button onclick="downloadFile()">download file</button> |
|---|
| 49 | </div> |
|---|
| 50 | </div> |
|---|
| 51 | </body> |
|---|
| 52 | </html> |
|---|