| | @@ -32,27 +32,45 @@ |
| 32 | 32 | taContent: E('#content'), |
| 33 | 33 | taPreviewText: D.attr(D.textarea(), 'rows', 20, 'cols', 60, |
| 34 | 34 | 'readonly', true), |
| 35 | 35 | uiControls: E('#pikchrshow-controls'), |
| 36 | 36 | previewModeToggle: D.button("Preview mode"), |
| 37 | | - markupAlignCenter: D.attr(D.checkbox(), 'id','markup-align-center'), |
| 38 | | - markupAlignWrapper: D.span() |
| 37 | + markupAlignDefault: D.attr(D.radio('markup-align','',true), |
| 38 | + 'id','markup-align-default'), |
| 39 | + markupAlignCenter: D.attr(D.radio('markup-align','center'), |
| 40 | + 'id','markup-align-center'), |
| 41 | + markupAlignIndent: D.attr(D.radio('markup-align','indent'), |
| 42 | + 'id','markup-align-indent'), |
| 43 | + markupAlignWrapper: D.addClass(D.span(), 'input-with-label') |
| 39 | 44 | }; |
| 40 | 45 | |
| 41 | 46 | //////////////////////////////////////////////////////////// |
| 42 | 47 | // Setup markup alignment selection... |
| 43 | | - P.e.markupAlignCenter.addEventListener('change', function(ev){ |
| 48 | + const alignEvent = function(ev){ |
| 44 | 49 | /* Update markdown/fossil wiki preview if it's active */ |
| 45 | 50 | if(P.previewMode==1 || P.previewMode==2){ |
| 46 | 51 | P.renderPreview(); |
| 47 | 52 | } |
| 48 | | - }, false); |
| 53 | + }; |
| 54 | + P.e.markupAlignRadios = [ |
| 55 | + P.e.markupAlignDefault, |
| 56 | + P.e.markupAlignCenter, |
| 57 | + P.e.markupAlignIndent |
| 58 | + ]; |
| 49 | 59 | D.append(P.e.markupAlignWrapper, |
| 50 | | - D.addClass([ |
| 51 | | - P.e.markupAlignCenter, |
| 52 | | - D.label(P.e.markupAlignCenter, "Align center?") |
| 53 | | - ], 'v-align-middle') ); |
| 60 | + D.addClass(D.append(D.span(),"align:"), |
| 61 | + 'v-align-middle')); |
| 62 | + P.e.markupAlignRadios.forEach( |
| 63 | + function(e){ |
| 64 | + e.addEventListener('change', alignEvent, false); |
| 65 | + D.append(P.e.markupAlignWrapper, |
| 66 | + D.addClass([ |
| 67 | + e, |
| 68 | + D.label(e, e.value || "left") |
| 69 | + ], 'v-align-middle')); |
| 70 | + } |
| 71 | + ); |
| 54 | 72 | |
| 55 | 73 | //////////////////////////////////////////////////////////// |
| 56 | 74 | // Setup the preview fieldset's LEGEND element... |
| 57 | 75 | D.append( P.e.previewLegend, |
| 58 | 76 | P.e.previewModeToggle, |
| | @@ -87,11 +105,11 @@ |
| 87 | 105 | //////////////////////////////////////////////////////////// |
| 88 | 106 | // Set up selection list of predefined scripts... |
| 89 | 107 | if(true){ |
| 90 | 108 | const selectScript = P.e.selectScript = D.select(), |
| 91 | 109 | cbAutoPreview = P.e.cbAutoPreview = |
| 92 | | - D.attr(D.checkbox(),'id', 'cb-auto-preview','checked',true), |
| 110 | + D.attr(D.checkbox(true),'id', 'cb-auto-preview'), |
| 93 | 111 | cbWrap = D.addClass(D.div(),'input-with-label') |
| 94 | 112 | ; |
| 95 | 113 | D.append( |
| 96 | 114 | cbWrap, |
| 97 | 115 | selectScript, |
| | @@ -103,12 +121,13 @@ |
| 103 | 121 | 'built-in pikchr scripts by sending them to ', |
| 104 | 122 | 'the server for rendering. Not recommended on a ', |
| 105 | 123 | 'slow connection/server.', |
| 106 | 124 | D.br(),D.br(), |
| 107 | 125 | 'Pikchr scripts may also be dragged/dropped from ', |
| 108 | | - 'the local filesystem into the text area, but ', |
| 109 | | - 'the auto-preview option does not apply to them.' |
| 126 | + 'the local filesystem into the text area, if the ', |
| 127 | + 'environment supports it, but the auto-preview ', |
| 128 | + 'option does not apply to them.' |
| 110 | 129 | ) |
| 111 | 130 | ) |
| 112 | 131 | )/*.childNodes.forEach(function(ch){ |
| 113 | 132 | ch.style.margin = "0 0.25em"; |
| 114 | 133 | })*/; |
| | @@ -223,63 +242,68 @@ |
| 223 | 242 | P.renderPreview()/*it's already rendered, but this gets all |
| 224 | 243 | labels/headers in sync.*/; |
| 225 | 244 | } |
| 226 | 245 | }/*F.onPageLoad()*/); |
| 227 | 246 | |
| 228 | | - /* Shows or hides P.e.markupAlignWrapper */ |
| 229 | | - const showMarkupAlignment = function(showIt){ |
| 230 | | - P.e.markupAlignWrapper.classList[showIt ? 'remove' : 'add']('hidden'); |
| 231 | | - }; |
| 232 | | - |
| 233 | 247 | /** |
| 234 | 248 | Updates the preview view based on the current preview mode and |
| 235 | 249 | error state. |
| 236 | 250 | */ |
| 237 | 251 | P.renderPreview = function f(){ |
| 238 | 252 | if(!f.hasOwnProperty('rxNonce')){ |
| 239 | 253 | f.rxNonce = /<!--.+-->\r?\n?/g /*pikchr nonce comments*/; |
| 254 | + f.showMarkupAlignment = function(showIt){ |
| 255 | + P.e.markupAlignWrapper.classList[showIt ? 'remove' : 'add']('hidden'); |
| 256 | + }; |
| 257 | + f.getMarkupAlignmentClass = function(){ |
| 258 | + if(P.e.markupAlignCenter.checked) return ' center'; |
| 259 | + else if(P.e.markupAlignIndent.checked) return ' indent'; |
| 260 | + return ''; |
| 261 | + }; |
| 240 | 262 | } |
| 241 | 263 | const preTgt = this.e.previewTarget; |
| 242 | 264 | if(this.response.isError){ |
| 243 | 265 | preTgt.innerHTML = this.response.raw; |
| 244 | 266 | D.addClass(preTgt, 'error'); |
| 245 | 267 | this.e.previewModeLabel.innerText = "Error"; |
| 246 | 268 | return; |
| 247 | 269 | } |
| 248 | 270 | D.removeClass(preTgt, 'error'); |
| 249 | | - D.removeClass(P.e.previewCopyButton, 'disabled'); |
| 250 | | - D.enable(this.e.previewModeToggle, this.e.markupAlignCenter); |
| 271 | + D.removeClass(this.e.previewCopyButton, 'disabled'); |
| 272 | + D.removeClass(this.e.markupAlignWrapper, 'hidden'); |
| 273 | + D.enable(this.e.previewModeToggle, this.e.markupAlignRadios); |
| 251 | 274 | let label; |
| 252 | 275 | switch(this.previewMode){ |
| 253 | 276 | case 0: |
| 254 | 277 | label = "SVG"; |
| 255 | | - showMarkupAlignment(false); |
| 278 | + f.showMarkupAlignment(false); |
| 256 | 279 | preTgt.innerHTML = this.response.raw; |
| 257 | | - this.e.taPreviewText.value = this.response.raw.replace(f.rxNonce, '')/*for copy button*/; |
| 280 | + this.e.taPreviewText.value = |
| 281 | + this.response.raw.replace(f.rxNonce, '')/*for copy button*/; |
| 258 | 282 | break; |
| 259 | 283 | case 1: |
| 260 | 284 | label = "Markdown"; |
| 261 | | - showMarkupAlignment(true); |
| 285 | + f.showMarkupAlignment(true); |
| 262 | 286 | this.e.taPreviewText.value = [ |
| 263 | | - '```pikchr'+(this.e.markupAlignCenter.checked? ' center' : ''), |
| 287 | + '```pikchr'+f.getMarkupAlignmentClass(), |
| 264 | 288 | this.response.inputText, '```' |
| 265 | 289 | ].join('\n'); |
| 266 | 290 | D.append(D.clearElement(preTgt), this.e.taPreviewText); |
| 267 | 291 | break; |
| 268 | 292 | case 2: |
| 269 | 293 | label = "Fossil wiki"; |
| 270 | | - showMarkupAlignment(true); |
| 294 | + f.showMarkupAlignment(true); |
| 271 | 295 | this.e.taPreviewText.value = [ |
| 272 | 296 | '<verbatim type="pikchr', |
| 273 | | - this.e.markupAlignCenter.checked ? ' center' : '', |
| 297 | + f.getMarkupAlignmentClass(), |
| 274 | 298 | '">', this.response.inputText, '</verbatim>' |
| 275 | 299 | ].join(''); |
| 276 | 300 | D.append(D.clearElement(preTgt), this.e.taPreviewText); |
| 277 | 301 | break; |
| 278 | 302 | case 3: |
| 279 | 303 | label = "Raw SVG"; |
| 280 | | - showMarkupAlignment(false); |
| 304 | + f.showMarkupAlignment(false); |
| 281 | 305 | this.e.taPreviewText.value = this.response.raw.replace(f.rxNonce, ''); |
| 282 | 306 | D.append(D.clearElement(preTgt), this.e.taPreviewText); |
| 283 | 307 | break; |
| 284 | 308 | } |
| 285 | 309 | this.e.previewModeLabel.innerText = label; |
| | @@ -294,11 +318,11 @@ |
| 294 | 318 | fp.toDisable = [ |
| 295 | 319 | /* input elements to disable during ajax operations */ |
| 296 | 320 | this.e.btnSubmit, this.e.taContent, |
| 297 | 321 | this.e.cbAutoPreview, this.e.selectScript |
| 298 | 322 | /* handled separately: previewModeToggle, previewCopyButton, |
| 299 | | - markupAlignCenter */ |
| 323 | + markupAlignRadios */ |
| 300 | 324 | ]; |
| 301 | 325 | fp.target = this.e.previewTarget; |
| 302 | 326 | fp.updateView = function(c,isError){ |
| 303 | 327 | P.previewMode = 0; |
| 304 | 328 | P.response.raw = c; |
| | @@ -305,11 +329,12 @@ |
| 305 | 329 | P.response.isError = isError; |
| 306 | 330 | D.enable(fp.toDisable); |
| 307 | 331 | P.renderPreview(); |
| 308 | 332 | }; |
| 309 | 333 | } |
| 310 | | - D.disable(fp.toDisable, this.e.previewModeToggle, this.e.markupAlignCenter); |
| 334 | + D.disable(fp.toDisable, this.e.previewModeToggle, this.e.markupAlignRadios); |
| 335 | + D.addClass(this.e.markupAlignWrapper, 'hidden'); |
| 311 | 336 | D.addClass(this.e.previewCopyButton, 'disabled'); |
| 312 | 337 | const content = this.e.taContent.value.trim(); |
| 313 | 338 | this.response.raw = undefined; |
| 314 | 339 | this.response.inputText = content; |
| 315 | 340 | const sampleScript = fp.$_sampleScript; |
| 316 | 341 | |