| | @@ -29,37 +29,34 @@ |
| 29 | 29 | taContent: E('#content'), |
| 30 | 30 | taPreviewText: D.attr(D.textarea(), 'rows', 20, 'cols', 60, |
| 31 | 31 | 'readonly', true), |
| 32 | 32 | uiControls: E('#pikchrshow-controls'), |
| 33 | 33 | previewModeToggle: D.button("Preview mode"), |
| 34 | | - selectAlignment: D.append( |
| 35 | | - D.select(/*alignment for markup blocks*/), |
| 36 | | - D.option('', 'Markup Alignment'), |
| 37 | | - D.option('', 'left (default)'), |
| 38 | | - D.option('center', 'center') |
| 39 | | - ) |
| 34 | + markupAlignCenter: D.attr(D.checkbox(), 'id','markup-align-center'), |
| 35 | + markupAlignWrapper: D.span()//D.addClass(D.span(), 'input-with-label') |
| 40 | 36 | }; |
| 41 | 37 | |
| 42 | 38 | //////////////////////////////////////////////////////////// |
| 43 | 39 | // Setup markup alignment selection... |
| 44 | | - D.disable(P.e.selectAlignment.options[0] |
| 45 | | - /*has to be done after creation for default selection to work*/ |
| 46 | | - ); |
| 47 | | - P.e.selectAlignment.addEventListener('change', function(ev){ |
| 40 | + P.e.markupAlignCenter.addEventListener('change', function(ev){ |
| 48 | 41 | /* Update markdown/fossil wiki preview if it's active */ |
| 49 | 42 | if(P.previewMode==1 || P.previewMode==2){ |
| 50 | 43 | P.renderPreview(); |
| 51 | 44 | } |
| 52 | 45 | }, false); |
| 46 | + D.append(P.e.markupAlignWrapper, |
| 47 | + P.e.markupAlignCenter, |
| 48 | + D.label(P.e.markupAlignCenter, "Align center?")); |
| 53 | 49 | |
| 54 | 50 | //////////////////////////////////////////////////////////// |
| 55 | 51 | // Setup the preview fieldset's LEGEND element... |
| 56 | 52 | D.append( P.e.previewLegend, |
| 57 | 53 | P.e.previewModeToggle, |
| 58 | | - P.e.previewModeLabel, |
| 54 | + '\u00a0', |
| 59 | 55 | P.e.previewCopyButton, |
| 60 | | - D.addClass(P.e.selectAlignment, 'hidden') ); |
| 56 | + P.e.previewModeLabel, |
| 57 | + P.e.markupAlignWrapper ); |
| 61 | 58 | |
| 62 | 59 | //////////////////////////////////////////////////////////// |
| 63 | 60 | // Setup clipboard-copy of markup/SVG... |
| 64 | 61 | F.copyButton(P.e.previewCopyButton, {copyFromElement: P.e.taPreviewText}); |
| 65 | 62 | P.e.previewCopyButton.addEventListener('text-copied', D.flashOnce.eventHandler, false); |
| | @@ -104,13 +101,13 @@ |
| 104 | 101 | 'Pikchr scripts may also be dragged/dropped from ', |
| 105 | 102 | 'the local filesystem into the text area, but ', |
| 106 | 103 | 'the auto-preview option does not apply to them.' |
| 107 | 104 | ) |
| 108 | 105 | ) |
| 109 | | - ).childNodes.forEach(function(ch){ |
| 106 | + )/*.childNodes.forEach(function(ch){ |
| 110 | 107 | ch.style.margin = "0 0.25em"; |
| 111 | | - }); |
| 108 | + })*/; |
| 112 | 109 | D.append(P.e.uiControls, cbWrap); |
| 113 | 110 | P.predefinedPiks.forEach(function(script,ndx){ |
| 114 | 111 | const opt = D.option(script.code ? script.code.trim() :'', script.name); |
| 115 | 112 | D.append(selectScript, opt); |
| 116 | 113 | if(!ndx) selectScript.selectedIndex = 0 /*timing/ordering workaround*/; |
| | @@ -179,13 +176,13 @@ |
| 179 | 176 | P.renderPreview()/*it's already rendered, but this gets all |
| 180 | 177 | labels/headers in sync.*/; |
| 181 | 178 | } |
| 182 | 179 | }/*F.onPageLoad()*/); |
| 183 | 180 | |
| 184 | | - /* Shows or hides P.e.selectAlignment */ |
| 181 | + /* Shows or hides P.e.markupAlignWrapper */ |
| 185 | 182 | const showMarkupAlignment = function(showIt){ |
| 186 | | - P.e.selectAlignment.classList[showIt ? 'remove' : 'add']('hidden'); |
| 183 | + P.e.markupAlignWrapper.classList[showIt ? 'remove' : 'add']('hidden'); |
| 187 | 184 | }; |
| 188 | 185 | |
| 189 | 186 | /** |
| 190 | 187 | Updates the preview view based on the current preview mode and |
| 191 | 188 | error state. |
| | @@ -201,35 +198,34 @@ |
| 201 | 198 | this.e.previewModeLabel.innerText = "Error"; |
| 202 | 199 | return; |
| 203 | 200 | } |
| 204 | 201 | D.removeClass(preTgt, 'error'); |
| 205 | 202 | D.removeClass(P.e.previewCopyButton, 'disabled'); |
| 206 | | - D.enable(this.e.previewModeToggle); |
| 203 | + D.enable(this.e.previewModeToggle, this.e.markupAlignCenter); |
| 207 | 204 | let label; |
| 208 | 205 | switch(this.previewMode){ |
| 209 | 206 | case 0: |
| 210 | | - label = "Rendered SVG"; |
| 207 | + label = "SVG"; |
| 211 | 208 | showMarkupAlignment(false); |
| 212 | 209 | preTgt.innerHTML = this.response.raw; |
| 213 | 210 | this.e.taPreviewText.value = this.response.raw.replace(f.rxNonce, '')/*for copy button*/; |
| 214 | 211 | break; |
| 215 | 212 | case 1: |
| 216 | 213 | label = "Markdown"; |
| 217 | 214 | showMarkupAlignment(true); |
| 218 | 215 | this.e.taPreviewText.value = [ |
| 219 | | - '```pikchr'+(this.e.selectAlignment.value |
| 220 | | - ? ' '+this.e.selectAlignment.value : ''), |
| 216 | + '```pikchr'+(this.e.markupAlignCenter.checked? ' center' : ''), |
| 221 | 217 | this.response.inputText, '```' |
| 222 | 218 | ].join('\n'); |
| 223 | 219 | D.append(D.clearElement(preTgt), this.e.taPreviewText); |
| 224 | 220 | break; |
| 225 | 221 | case 2: |
| 226 | 222 | label = "Fossil wiki"; |
| 227 | 223 | showMarkupAlignment(true); |
| 228 | 224 | this.e.taPreviewText.value = [ |
| 229 | 225 | '<verbatim type="pikchr', |
| 230 | | - this.e.selectAlignment.value ? ' '+this.e.selectAlignment.value : '', |
| 226 | + this.e.markupAlignCenter.checked ? ' center' : '', |
| 231 | 227 | '">', this.response.inputText, '</verbatim>' |
| 232 | 228 | ].join(''); |
| 233 | 229 | D.append(D.clearElement(preTgt), this.e.taPreviewText); |
| 234 | 230 | break; |
| 235 | 231 | case 3: |
| | @@ -249,13 +245,13 @@ |
| 249 | 245 | P.preview = function fp(){ |
| 250 | 246 | if(!fp.hasOwnProperty('toDisable')){ |
| 251 | 247 | fp.toDisable = [ |
| 252 | 248 | /* input elements to disable during ajax operations */ |
| 253 | 249 | this.e.btnSubmit, this.e.taContent, |
| 254 | | - this.e.selectAlignment, |
| 255 | 250 | this.e.cbAutoPreview, this.e.selectScript |
| 256 | | - /* handled separately: previewModeToggle, previewCopyButton */ |
| 251 | + /* handled separately: previewModeToggle, previewCopyButton, |
| 252 | + markupAlignCenter */ |
| 257 | 253 | ]; |
| 258 | 254 | fp.target = this.e.previewTarget; |
| 259 | 255 | fp.updateView = function(c,isError){ |
| 260 | 256 | P.previewMode = 0; |
| 261 | 257 | P.response.raw = c; |
| | @@ -262,11 +258,11 @@ |
| 262 | 258 | P.response.isError = isError; |
| 263 | 259 | D.enable(fp.toDisable); |
| 264 | 260 | P.renderPreview(); |
| 265 | 261 | }; |
| 266 | 262 | } |
| 267 | | - D.disable(fp.toDisable, this.e.previewModeToggle); |
| 263 | + D.disable(fp.toDisable, this.e.previewModeToggle, this.e.markupAlignCenter); |
| 268 | 264 | D.addClass(this.e.previewCopyButton, 'disabled'); |
| 269 | 265 | const content = this.e.taContent.value.trim(); |
| 270 | 266 | this.response.raw = undefined; |
| 271 | 267 | this.response.inputText = content; |
| 272 | 268 | if(!content){ |
| 273 | 269 | |