Skip to content

Commit f3b0347

Browse files
committed
tweaks
1 parent b947012 commit f3b0347

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

indigo_app/static/javascript/indigo/models.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
* @param mutation MutationRecord
6565
* @param element Element in this XML document
6666
* @returns 'changed' if the mutation impacts the element, 'removed' if the element was removed from the tree,
67+
* 'replaced', if the element has been replaced (with a node in mutation.addedNodes),
6768
* or null if there is no impact
6869
*/
6970
getMutationImpact(mutation, element) {
@@ -98,7 +99,7 @@
9899
let root = null;
99100

100101
try {
101-
root = $.parseXML(newValue);
102+
root = Indigo.parseXml(newValue);
102103
} catch(e) {
103104
Indigo.errorView.show("The document has invalid XML.");
104105
return;

indigo_app/static/javascript/indigo/utils.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,19 @@ $(function() {
3030
}
3131
}
3232
setTimeout(nukeToasts, 3 * 1000);
33+
34+
/**
35+
* Parses text into an XML document.
36+
* @param text
37+
* @returns {Document}
38+
* @throws {Error} if the text is not valid XML
39+
*/
40+
Indigo.parseXml = function(text) {
41+
const parser = new DOMParser();
42+
const doc = parser.parseFromString(text, "application/xml");
43+
if (doc.querySelector("parsererror")) {
44+
throw Error("Invalid XML: " + new XMLSerializer().serializeToString(doc));
45+
}
46+
return doc;
47+
}
3348
});

indigo_app/static/javascript/indigo/views/document_xml_editor.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -436,14 +436,16 @@ class XMLEditor {
436436
onEditorChanged() {
437437
const text = this.editor.getValue().trim();
438438
if (text) {
439-
console.log('Parsing changes to XML');
440-
const parser = new DOMParser();
441-
const doc = parser.parseFromString(text, "application/xml");
442-
if (doc.querySelector("parsererror")) {
443-
console.log("Invalid XML:" + new XMLSerializer().serializeToString(doc));
444-
} else {
445-
this.onElementParsed(doc.documentElement);
439+
let doc;
440+
try {
441+
console.log('Parsing changes to XML');
442+
doc = Indigo.parseXml(text);
443+
} catch (err) {
444+
// squash errors
445+
console.log(err);
446+
return;
446447
}
448+
this.onElementParsed(doc.documentElement);
447449
}
448450
}
449451
}

0 commit comments

Comments
 (0)