| | @@ -10,63 +10,78 @@ |
| 10 | 10 | 'use strict'; |
| 11 | 11 | if(!F || !F.page || F.page.name!=='wikiedit') return; |
| 12 | 12 | |
| 13 | 13 | const D = F.dom; |
| 14 | 14 | |
| 15 | + //////////////////////////////////////////////////////////////////////// |
| 16 | + // Install an app-specific stylesheet... |
| 15 | 17 | (function(){ |
| 16 | 18 | const head = document.head || document.querySelector('head'), |
| 17 | 19 | styleTag = document.createElement('style'), |
| 18 | 20 | styleCSS = ` |
| 19 | 21 | .intLink { cursor: pointer; } |
| 20 | 22 | img.intLink { border: 0; } |
| 21 | 23 | #wysiwyg-container { |
| 22 | | - max-width: calc(100% - 1em); |
| 23 | 24 | display: flex; |
| 24 | 25 | flex-direction: column; |
| 26 | + max-width: 100% /* w/o this, toolbars don't wrap properly! */ |
| 25 | 27 | } |
| 26 | 28 | #wysiwygBox { |
| 27 | 29 | border: 1px #000000 solid; |
| 28 | 30 | padding: 0 1em; |
| 31 | + margin: 0; |
| 29 | 32 | overflow: auto; |
| 30 | 33 | min-height: 20em; |
| 34 | +} |
| 35 | +#wysiwygEditMode { /* wrapper for radio buttons */ |
| 36 | + border: 1px solid rgba(127,127,127,0.3); |
| 37 | + border-radius: 0.25em; |
| 38 | + padding: 0 0.35em 0 0.35em |
| 39 | +} |
| 40 | +#wysiwygEditMode > * { |
| 41 | + vertical-align: text-top; |
| 31 | 42 | } |
| 32 | 43 | #wysiwygEditMode label { cursor: pointer; } |
| 33 | 44 | #wysiwyg-toolbars { |
| 34 | 45 | margin: 0 0 0.25em 0; |
| 35 | 46 | display: flex; |
| 36 | 47 | flex-wrap: wrap; |
| 37 | | - flex-direction: row; |
| 48 | + flex-direction: column; |
| 38 | 49 | align-items: flex-start; |
| 39 | 50 | } |
| 40 | 51 | #wysiwyg-toolbars > * { |
| 41 | 52 | margin: 0 0.5em 0.25em 0; |
| 42 | | - align-self: center; |
| 43 | 53 | } |
| 44 | 54 | #wysiwyg-toolBar1, #wysiwyg-toolBar2 { |
| 55 | + margin: 0 0.2em 0.2em 0; |
| 56 | + display: flex; |
| 57 | + flex-flow: row wrap; |
| 45 | 58 | } |
| 46 | 59 | #wysiwyg-toolBar1 > * { /* formatting buttons */ |
| 47 | | - margin: 0 0.2em 0.2em 0; |
| 60 | + vertical-align: middle; |
| 61 | + margin: 0 0.25em 0.25em 0; |
| 48 | 62 | } |
| 49 | 63 | #wysiwyg-toolBar2 > * { /* icons */ |
| 50 | | - margin: 0 0.2em 0.2em 0; |
| 51 | 64 | border: 1px solid rgba(127,127,127,0.3); |
| 52 | | - align-self: end; |
| 65 | + vertical-align: baseline; |
| 66 | + margin: 0.1em; |
| 53 | 67 | } |
| 54 | 68 | `; |
| 55 | 69 | head.appendChild(styleTag); |
| 56 | 70 | /* Adapted from https://stackoverflow.com/a/524721 */ |
| 57 | 71 | styleTag.type = 'text/css'; |
| 58 | 72 | D.append(styleTag, styleCSS); |
| 59 | 73 | })(); |
| 60 | 74 | |
| 61 | | - const outerContainer = D.attr(D.div(), 'id', 'wysiwyg-container'); |
| 62 | | - |
| 63 | | - const toolbars = D.attr(D.div(), 'id', 'wysiwyg-toolbars'), |
| 75 | + const outerContainer = D.attr(D.div(), 'id', 'wysiwyg-container'), |
| 76 | + toolbars = D.attr(D.div(), 'id', 'wysiwyg-toolbars'), |
| 64 | 77 | toolbar1 = D.attr(D.div(), 'id', 'wysiwyg-toolBar1'), |
| 65 | | - toolbar2 = D.attr(D.div(), 'id', 'wysiwyg-toolBar2'); |
| 66 | | - D.append(outerContainer, |
| 67 | | - D.append(toolbars, toolbar1, toolbar2)); |
| 78 | + // ^^^ formatting options |
| 79 | + toolbar2 = D.attr(D.div(), 'id', 'wysiwyg-toolBar2') |
| 80 | + // ^^^^ action icon buttons |
| 81 | + ; |
| 82 | + D.append(outerContainer, D.append(toolbars, toolbar1, toolbar2)); |
| 68 | 83 | |
| 69 | 84 | /** Returns a function which simplifies adding a list of options |
| 70 | 85 | to the given select element. See below for example usage. */ |
| 71 | 86 | const addOptions = function(select){ |
| 72 | 87 | return function ff(value, label){ |
| | @@ -74,26 +89,43 @@ |
| 74 | 89 | return ff; |
| 75 | 90 | }; |
| 76 | 91 | }; |
| 77 | 92 | |
| 78 | 93 | //////////////////////////////////////////////////////////////////////// |
| 79 | | - // Edit mode selection button |
| 80 | | - var select; |
| 81 | | - const selectEditMode = select = D.attr( |
| 82 | | - D.attr(D.select(), 'id', 'wysiwygEditMode'), |
| 83 | | - 'size', |
| 84 | | - 1 |
| 85 | | - ); |
| 86 | | - D.append(toolbar1, select); |
| 87 | | - addOptions(select)( |
| 88 | | - 0, "WYSIWYG")( |
| 89 | | - 1, "Raw HTML"); |
| 90 | | - select.selectedIndex = 0; |
| 94 | + // Edit mode selection (radio buttons). |
| 95 | + const radio0 = |
| 96 | + D.attr( |
| 97 | + D.input('radio'), |
| 98 | + 'name','wysiwyg-mode', |
| 99 | + 'id', 'wysiwyg-mode-0', |
| 100 | + 'value',0, |
| 101 | + 'checked',true), |
| 102 | + radio1 = D.attr( |
| 103 | + D.input('radio'), |
| 104 | + 'id','wysiwyg-mode-1', |
| 105 | + 'name','wysiwyg-mode', |
| 106 | + 'value',1), |
| 107 | + radios = D.append( |
| 108 | + D.attr(D.span(), 'id', 'wysiwygEditMode'), |
| 109 | + radio0, D.append( |
| 110 | + D.attr(D.label(), 'for', 'wysiwyg-mode-0'), |
| 111 | + "WYSIWYG" |
| 112 | + ), |
| 113 | + radio1, D.append( |
| 114 | + D.attr(D.label(), 'for', 'wysiwyg-mode-1'), |
| 115 | + "Raw HTML" |
| 116 | + ) |
| 117 | + ); |
| 118 | + D.append(toolbar1, radios); |
| 119 | + const radioHandler = function(){setDocMode(+this.value)}; |
| 120 | + radio0.addEventListener('change',radioHandler, false); |
| 121 | + radio1.addEventListener('change',radioHandler, false); |
| 91 | 122 | |
| 92 | 123 | |
| 93 | 124 | //////////////////////////////////////////////////////////////////////// |
| 94 | 125 | // Text formatting options... |
| 126 | + var select; |
| 95 | 127 | select = D.addClass(D.select(), 'format'); |
| 96 | 128 | select.dataset.format = "formatblock"; |
| 97 | 129 | D.append(toolbar1, select); |
| 98 | 130 | addOptions(select)( |
| 99 | 131 | '', '- formatting -')( |
| | @@ -163,11 +195,11 @@ |
| 163 | 195 | characters in the DOM element data attributes have been mangled |
| 164 | 196 | to work around that: we simply use \u002f for every 2nd slash. |
| 165 | 197 | */ |
| 166 | 198 | (function f(title,format,src){ |
| 167 | 199 | const img = D.img(); |
| 168 | | - D.append(toolbar2, ' ', img); |
| 200 | + D.append(toolbar2, img); |
| 169 | 201 | D.addClass(img, 'intLink'); |
| 170 | 202 | D.attr(img, 'title', title); |
| 171 | 203 | img.dataset.format = format; |
| 172 | 204 | D.attr(img, 'src', 'string'===typeof src ? src : src.join('')); |
| 173 | 205 | return f; |
| | @@ -337,13 +369,10 @@ |
| 337 | 369 | break; |
| 338 | 370 | } |
| 339 | 371 | formatDoc(this.dataset.format, extra); |
| 340 | 372 | }; |
| 341 | 373 | |
| 342 | | - selectEditMode.addEventListener('change',function() { |
| 343 | | - setDocMode(this.selectedIndex) |
| 344 | | - },false); |
| 345 | 374 | var i, controls = outerContainer.querySelectorAll('select.format'); |
| 346 | 375 | for(i = 0; i < controls.length; i++) { |
| 347 | 376 | controls[i].addEventListener('change', handleDropDown, false);; |
| 348 | 377 | } |
| 349 | 378 | controls = outerContainer.querySelectorAll('.intLink'); |
| | @@ -353,11 +382,11 @@ |
| 353 | 382 | } |
| 354 | 383 | |
| 355 | 384 | /* Return true if the document editor is in WYSIWYG mode. Return |
| 356 | 385 | ** false if it is in Markup mode */ |
| 357 | 386 | function isWysiwyg() { |
| 358 | | - return 0===selectEditMode.selectedIndex; |
| 387 | + return radio0.checked; |
| 359 | 388 | } |
| 360 | 389 | |
| 361 | 390 | /* Invoke this routine prior to submitting the HTML content back |
| 362 | 391 | ** to the server */ |
| 363 | 392 | /*function wysiwygSubmit() { |
| | @@ -434,20 +463,16 @@ |
| 434 | 463 | initDoc(); |
| 435 | 464 | const content = F.page.wikiContent() || ''; |
| 436 | 465 | var isDirty = false /* keep from stashing too often */; |
| 437 | 466 | F.page.setContentMethods( |
| 438 | 467 | function(){ |
| 439 | | - //selectEditMode.selectedIndex = 1; |
| 440 | 468 | const rc = isWysiwyg() ? oDoc.innerHTML : oDoc.innerText; |
| 441 | | - //setDocMode(selectEditMode.selectedIndex, rc); |
| 442 | 469 | return rc; |
| 443 | 470 | }, |
| 444 | 471 | function(content){ |
| 445 | | - //selectEditMode.selectedIndex = 1; |
| 446 | | - //oDoc.innerText = content; |
| 447 | 472 | isDirty = false; |
| 448 | | - setDocMode(selectEditMode.selectedIndex, content); |
| 473 | + setDocMode(radio0.checked ? 0 : 1, content); |
| 449 | 474 | } |
| 450 | 475 | ); |
| 451 | 476 | oDoc.addEventListener('blur', function(){ |
| 452 | 477 | if(isDirty) F.page.notifyOfChange(); |
| 453 | 478 | }, false); |
| 454 | 479 | |