{{ message }}
Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
607 lines (567 loc) · 15 KB
/
Copy pathscript.js
File metadata and controls
607 lines (567 loc) · 15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
79
80
81
82
83
84
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
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
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
/*
* @source: https://github.com/validator/validator/blob/main/site/script.js
*
* @licstart The following is the entire license notice for the JavaScript
* code in this file.
*
* Copyright (c) 2005-2007 Henri Sivonen
* Copyright (c) 2007-2010 Mozilla Foundation
* Copyright (c) 2007 Simon Pieters
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* @licend The above is the entire license notice for the JavaScript code
* in this file.
*
*/
var hasDuplicateMessages = false
var currentOl = null
var ungroupedOl = null
var groupedOl = null
var urlInput = null
var fileInput = null
var textarea = null
var textareaHidden = null
var dynamicStyle = null
var prevHash = null
var hasTextContent = (createHtmlElement('code').textContent != undefined)
var linePattern = /^#l-?[0-9]+$/
var rangePattern = /^#l-?[0-9]+c[0-9]+$/
var exactPattern = /^#cl-?[0-9]+c[0-9]+$/
function boot() {
schemaChanged()
parserChanged()
installHandlers()
}
function reboot() {
boot()
initFieldHolders()
installDynamicStyle()
updateFragmentIdHilite()
window.setInterval(emulateHashChanged, 50)
initGrouping()
}
function installDynamicStyle() {
dynamicStyle = createHtmlElement('style')
document.documentElement.firstChild.appendChild(dynamicStyle)
}
function installHandlers() {
if (document.forms && document.forms.length) {
document.forms[0].onsubmit = formSubmission
}
var schema = document.getElementById("schema")
if (schema) {
schema.onchange = schemaChanged
}
var preset = document.getElementById("preset")
if (preset) {
preset.onchange = presetChanged
}
var parser = document.getElementById("parser")
if (parser) {
parser.onchange = parserChanged
}
}
function initFieldHolders() {
urlInput = document.getElementById('doc')
urlInput.setAttribute('aria-labelledby', 'docselect')
textareaHidden = createHtmlElement('input')
textarea = createHtmlElement('textarea')
if (textarea && textareaHidden) {
textareaHidden.type = 'hidden'
textareaHidden.name = 'content'
textarea.cols = 72
textarea.rows = 15
textarea.id = 'doc'
textarea.setAttribute('aria-labelledby', 'docselect')
copySourceIntoTextArea()
if (textarea.value == '') {
textarea.value = '<!DOCTYPE html>\n<html lang="">\n<head>\n<title>Test</title>\n</head>\n<body>\n<p></p>\n</body>\n</html>'
}
}
fileInput = createHtmlElement('input')
if (fileInput) {
fileInput.type = 'file'
fileInput.id = 'doc'
fileInput.name = 'file'
fileInput.setAttribute('aria-labelledby', 'docselect')
}
var td = urlInput.parentNode
if (td) {
var th = td.previousSibling
var label = th.firstChild
var modeSelect = createHtmlElement("select")
modeSelect.id = 'docselect'
modeSelect.appendChild(createOption('Address', ''))
modeSelect.appendChild(createOption('File Upload', 'file'))
modeSelect.appendChild(createOption('Text Field', 'textarea'))
modeSelect.onchange = function() {
if (this.value == 'file') {
installFileUpload()
}
else
if (this.value == 'textarea') {
installTextarea()
}
else {
installUrlInput()
}
}
th.replaceChild(modeSelect, label)
}
if (urlInput.className == 'file') {
installFileUpload()
modeSelect.value = 'file'
} else if (urlInput.className == 'textarea') {
installTextarea()
modeSelect.value = 'textarea'
}
}
function createOption(text, value) {
var rv = createHtmlElement('option')
rv.value = value
var tn = document.createTextNode(text)
rv.appendChild(tn)
return rv
}
function schemaChanged() {
var input = document.getElementById("schema")
var select = document.getElementById("preset")
if (input) {
var value = input.value
if (select) {
if (select.firstChild) {
for (var n = select.firstChild; n != null; n = n.nextSibling) {
if (n.value == value) {
n.selected = true
toggleParsers(value)
return
}
}
select.firstChild.selected = true
toggleParsers("")
}
}
}
}
function presetChanged() {
var input = document.getElementById("schema")
var select = document.getElementById("preset")
if (input && select) {
input.value = select.value
}
toggleParsers(select.value)
}
function toggleParsers(newValue) {
var preset = document.getElementById("preset")
if (preset) {
if (isHtmlCompatiblePreset(newValue)) {
var select = document.getElementById("parser")
if (select) {
if (select.firstChild) {
for (var n = select.firstChild; n != null; n = n.nextSibling) {
n.disabled = false
}
if (document.getElementById('doc').name == 'content') {
// text area case
if (select.firstChild.selected) {
select.firstChild.nextSibling.nextSibling.nextSibling.selected = true
disableById('nsfilter')
}
select.firstChild.disabled = true
}
}
}
}
else {
var select = document.getElementById("parser")
if (select) {
if (select.firstChild) {
if (select.firstChild.selected) {
select.firstChild.nextSibling.selected = true
}
for (var n = select.firstChild; n != null; n = n.nextSibling) {
n.disabled = (n.value == "" || isHtmlParserValue(n.value))
}
}
}
}
}
}
function isHtmlParserValue(parser) {
return (parser.indexOf("html") == 0)
}
function isHtmlCompatiblePreset(preset) {
return (preset == "" ||
preset.indexOf("http://s.validator.nu/xhtml10/xhtml-basic.rnc") == 0 ||
preset.indexOf("http://s.validator.nu/xhtml10/xhtml-frameset.rnc") == 0 ||
preset.indexOf("http://s.validator.nu/xhtml10/xhtml-strict.rnc") == 0 ||
preset.indexOf("http://s.validator.nu/xhtml10/xhtml-transitional.rnc") == 0 ||
preset.indexOf("http://s.validator.nu/html5.rnc") == 0 ||
preset.indexOf("http://s.validator.nu/html5-its.rnc") == 0 ||
preset.indexOf("http://s.validator.nu/html5-rdfalite.rnc") == 0)
}
function parserChanged() {
var parser = document.getElementById("parser")
if (parser) {
if (isHtmlParserValue(parser.value)) {
var select = document.getElementById("preset")
if (select) {
if (select.firstChild) {
for (var n = select.firstChild; n != null; n = n.nextSibling) {
n.disabled = !isHtmlCompatiblePreset(n.value)
}
}
}
var nsfilter = document.getElementById("nsfilter")
if (nsfilter) {
nsfilter.disabled = true
}
}
else {
var select = document.getElementById("preset")
if (select) {
if (select.firstChild) {
for (var n = select.firstChild; n != null; n = n.nextSibling) {
n.disabled = false
}
}
}
var nsfilter = document.getElementById("nsfilter")
if (nsfilter) {
nsfilter.disabled = false
}
}
}
}
function formSubmission() {
if (document.getElementsByTagName) {
var form = document.getElementsByTagName("form")[0]
if (form.checkValidity) {
if (!form.checkValidity()) {
return true
}
}
}
// disableById("submit")
disableById("preset")
disableByIdIfEmptyString("doc")
disableByIdIfEmptyString("parser")
disableByIdIfEmptyString("schema")
disableByIdIfEmptyString("charset")
disableByIdIfEmptyString("profile")
disableByIdIfEmptyString("nsfilter")
maybeMoveDocumentRowDown()
if (textareaHidden && textarea) {
textareaHidden.value = textarea.value
}
return true
}
function undoFormSubmission() {
// enableById("submit")
enableById("preset")
enableById("doc")
enableById("parser")
enableById("schema")
enableById("charset")
enableById("profile")
enableById("nsfilter")
maybeMoveDocumentRowUp()
schemaChanged()
parserChanged()
return true
}
function maybeMoveDocumentRowDown() {
var field = document.getElementById('doc')
if (field && field.name == 'file') {
var td = field.parentNode
if (td) {
var tr = td.parentNode
var tbody = tr.parentNode
tbody.appendChild(tr)
}
}
}
function maybeMoveDocumentRowUp() {
var field = document.getElementById('doc')
if (field) {
var td = field.parentNode
if (td) {
var tr = td.parentNode
if (tr && tr.previousSibling) {
var tbody = tr.parentNode
tbody.insertBefore(tr, tbody.firstChild)
}
}
}
}
function disableById(id) {
var field = document.getElementById(id)
if (field) {
field.disabled = true
}
}
function disableByIdIfEmptyString(id) {
var field = document.getElementById(id)
if (field) {
if ("" == field.value) {
field.disabled = true
}
}
}
function enableById(id) {
var field = document.getElementById(id)
if (field) {
field.disabled = false
}
}
function createHtmlElement(tagName) {
return document.createElementNS ? document.createElementNS("http://www.w3.org/1999/xhtml", tagName) : document.createElement(tagName)
}
function installGroupingToggle() {
var para = createHtmlElement('p')
var button = createHtmlElement('input')
button.type = 'button'
button.value = 'Group Messages'
para.appendChild(button)
if (hasDuplicateMessages) {
button.onclick = function() {
if (currentOl == ungroupedOl) {
currentOl.parentNode.replaceChild(groupedOl, currentOl)
currentOl = groupedOl
this.value = 'Ungroup Messages'
}
else {
currentOl.parentNode.replaceChild(ungroupedOl, currentOl)
currentOl = ungroupedOl
this.value = 'Group Messages'
}
}
}
else {
button.disabled = true
}
currentOl.parentNode.insertBefore(para, currentOl)
}
function initGrouping() {
var n = document.documentElement.lastChild.firstChild
while (n) {
// The line below protects IE users from a crash
if (n instanceof HTMLOListElement && n.className != 'source') { // deliberately IE-incompatible
// if (n.start) { // cross-browser compatible
currentOl = n
break
}
n = n.nextSibling
}
if (!currentOl) {
return
}
ungroupedOl = currentOl
groupedOl = buildGrouped(ungroupedOl)
installGroupingToggle()
}
function buildGrouped(ol) {
var locListByMsg = {}
var rv = createHtmlElement('ol')
var li = ol.firstChild
var i = 1
while (li) {
var msgPara = li.firstChild
var locExtract = createHtmlElement('li')
locExtract.value = i
var loc = msgPara.nextSibling
var elaboration = null
if (loc && loc.className && loc.className == 'location') {
locExtract.appendChild(loc.cloneNode(true))
var extract = loc.nextSibling
if (extract && extract.className && extract.className == 'extract') {
locExtract.appendChild(extract.cloneNode(true))
elaboration = extract.nextSibling
}
else {
elaboration = extract
}
}
else {
elaboration = loc
var noLoc = createHtmlElement('p')
noLoc.appendChild(document.createTextNode("(No location)"))
locExtract.appendChild(noLoc)
}
var locList = null
var msgText = msgPara.innerHTML
locList = locListByMsg[msgText]
if (locList) {
hasDuplicateMessages = true
}
else {
locList = createHtmlElement('ol')
locListByMsg[msgText] = locList
var msgItem = createHtmlElement('li')
msgItem.className = li.className
msgItem.appendChild(msgPara.cloneNode(true))
if (elaboration) {
msgItem.appendChild(elaboration.cloneNode(true))
}
msgItem.appendChild(locList)
rv.appendChild(msgItem)
}
locList.appendChild(locExtract)
li = li.nextSibling
i++
}
return rv
}
function reflow(element) {
if (element.offsetHeight) {
var reflow = element.offsetHeight
}
}
function installTextarea() {
var input = document.getElementById('doc')
if (input && textarea) {
var form = document.forms[0]
if (form) {
form.method = 'post'
form.enctype = 'multipart/form-data'
input.parentNode.replaceChild(textarea, input)
reflow(textarea)
disableById('charset')
schemaChanged()
}
}
if (textareaHidden) {
var submit = document.getElementById("submit")
if (submit) {
submit.parentNode.appendChild(textareaHidden)
}
}
var showSource = document.getElementById("showsource")
if (showSource) {
showSource.checked = true
}
}
function installFileUpload() {
var input = document.getElementById('doc')
if (input && fileInput) {
var form = document.forms[0]
if (form) {
form.method = 'post'
form.enctype = 'multipart/form-data'
input.parentNode.replaceChild(fileInput, input)
reflow(fileInput)
enableById('charset')
schemaChanged()
}
}
if (textareaHidden && textareaHidden.parentNode) {
textareaHidden.parentNode.removeChild(textareaHidden)
}
}
function installUrlInput() {
var input = document.getElementById('doc')
if (input && urlInput) {
var form = document.forms[0]
if (form) {
form.method = 'get'
form.enctype = ''
input.parentNode.replaceChild(urlInput, input)
reflow(urlInput)
enableById('charset')
schemaChanged()
}
}
if (textareaHidden && textareaHidden.parentNode) {
textareaHidden.parentNode.removeChild(textareaHidden)
}
}
function copySourceIntoTextArea() {
var strings = []
var source = null
var n = document.documentElement.lastChild.firstChild
while (n) {
if (n.className == 'source') {
source = n
break
}
n = n.nextSibling
}
if (source && textarea) {
var li = source.firstChild
while (li) {
var code = li.firstChild
if (hasTextContent) {
strings.push(code.textContent)
}
else {
strings.push(code.innerText)
}
li = li.nextSibling
}
textarea.value = strings.join('\n')
}
}
function updateFragmentIdHilite() {
var fragment = window.location.hash
var selector = null
if (linePattern.exec(fragment)) {
selector = fragment + " *"
} else if (exactPattern.exec(fragment)) {
selector = fragment
} else if (rangePattern.exec(fragment)) {
selector = "html b." + fragment.substring(1)
}
var rule = ''
if (selector) {
rule = selector + " { background-color: #FF6666; font-weight: bold; }"
}
var newStyle = createHtmlElement('style')
var ex
try {
newStyle.appendChild(document.createTextNode(rule))
} catch (ex) {
if (ex.number == -0x7FFF0001) {
newStyle.styleSheet.cssText = rule
} else {
throw ex
}
}
dynamicStyle.parentNode.replaceChild(newStyle, dynamicStyle)
dynamicStyle = newStyle
}
function emulateHashChanged() {
var hash = window.location.hash
if (prevHash != hash) {
updateFragmentIdHilite()
prevHash = hash
}
}
if (document.getElementById) {
window.onload = reboot
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded", function() {
window.onload = undefined
reboot()
}, false)
}
window.onunload = undoFormSubmission
window.onabort = undoFormSubmission
boot()
}
You can’t perform that action at this time.
