OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * | 10 * |
(...skipping 12 matching lines...) Expand all Loading... |
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 */ | 27 */ |
28 | 28 |
29 var nodeParentPairs = []; | 29 var nodeParentPairs = []; |
30 | 30 |
31 // Script entry point. | 31 // Script entry point. |
32 | 32 |
| 33 var tree; |
| 34 |
33 function prepareWebKitXMLViewer(noStyleMessage) | 35 function prepareWebKitXMLViewer(noStyleMessage) |
34 { | 36 { |
35 var html = createHTMLElement('html'); | 37 var html = createHTMLElement('html'); |
36 var head = createHTMLElement('head'); | 38 var head = createHTMLElement('head'); |
37 html.appendChild(head); | 39 html.appendChild(head); |
38 var style = createHTMLElement('style'); | 40 var style = createHTMLElement('style'); |
39 style.id = 'xml-viewer-style'; | 41 style.id = 'xml-viewer-style'; |
40 head.appendChild(style); | 42 head.appendChild(style); |
41 var body = createHTMLElement('body'); | 43 var body = createHTMLElement('body'); |
42 html.appendChild(body); | 44 html.appendChild(body); |
(...skipping 10 matching lines...) Expand all Loading... |
53 document.appendChild(html); | 55 document.appendChild(html); |
54 | 56 |
55 var header = createHTMLElement('div'); | 57 var header = createHTMLElement('div'); |
56 body.appendChild(header); | 58 body.appendChild(header); |
57 header.classList.add('header'); | 59 header.classList.add('header'); |
58 var headerSpan = createHTMLElement('span'); | 60 var headerSpan = createHTMLElement('span'); |
59 header.appendChild(headerSpan); | 61 header.appendChild(headerSpan); |
60 headerSpan.textContent = noStyleMessage; | 62 headerSpan.textContent = noStyleMessage; |
61 header.appendChild(createHTMLElement('br')); | 63 header.appendChild(createHTMLElement('br')); |
62 | 64 |
63 var tree = createHTMLElement('div'); | 65 tree = createHTMLElement('div'); |
64 body.appendChild(tree); | 66 body.appendChild(tree); |
65 tree.classList.add('pretty-print'); | 67 tree.classList.add('pretty-print'); |
66 tree.id = 'tree'; | |
67 window.onload = sourceXMLLoaded; | 68 window.onload = sourceXMLLoaded; |
68 } | 69 } |
69 | 70 |
70 function sourceXMLLoaded() | 71 function sourceXMLLoaded() |
71 { | 72 { |
72 var sourceXML = document.getElementById('webkit-xml-viewer-source-xml'); | 73 var sourceXML = document.getElementById('webkit-xml-viewer-source-xml'); |
73 if (!sourceXML) | 74 if (!sourceXML) |
74 return; // Stop if some XML tree extension is already processing this do
cument | 75 return; // Stop if some XML tree extension is already processing this do
cument |
75 var root = document.getElementById('tree'); | |
76 | 76 |
77 for (var child = sourceXML.firstChild; child; child = child.nextSibling) | 77 for (var child = sourceXML.firstChild; child; child = child.nextSibling) |
78 nodeParentPairs.push({parentElement: root, node: child}); | 78 nodeParentPairs.push({parentElement: tree, node: child}); |
79 | 79 |
80 for (var i = 0; i < nodeParentPairs.length; i++) | 80 for (var i = 0; i < nodeParentPairs.length; i++) |
81 processNode(nodeParentPairs[i].parentElement, nodeParentPairs[i].node); | 81 processNode(nodeParentPairs[i].parentElement, nodeParentPairs[i].node); |
82 | 82 |
83 drawArrows(); | 83 drawArrows(); |
84 initButtons(); | 84 initButtons(); |
85 | 85 |
86 if (typeof(onAfterWebkitXMLViewerLoaded) == 'function') | 86 if (typeof(onAfterWebkitXMLViewerLoaded) == 'function') |
87 onAfterWebkitXMLViewerLoaded(); | 87 onAfterWebkitXMLViewerLoaded(); |
88 } | 88 } |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 expandButton.onmousedown = handleButtonMouseDown; | 423 expandButton.onmousedown = handleButtonMouseDown; |
424 } | 424 } |
425 | 425 |
426 } | 426 } |
427 | 427 |
428 function handleButtonMouseDown(e) | 428 function handleButtonMouseDown(e) |
429 { | 429 { |
430 // To prevent selection on double click | 430 // To prevent selection on double click |
431 e.preventDefault(); | 431 e.preventDefault(); |
432 } | 432 } |
OLD | NEW |