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