3 if (typeof window.window != "undefined" && window.document)
5 if (window.require && window.define)
9 window.console = function() {
10 var msgs = Array.prototype.slice.call(arguments, 0);
11 postMessage({type: "log", data: msgs});
13 window.console.error =
16 window.console.trace = window.console;
18 window.window = window;
21 window.onerror = function(message, file, line, col, err) {
22 postMessage({type: "error", data: {
32 window.normalizeModule = function(parentId, moduleName) {
33 // normalize plugin requires
34 if (moduleName.indexOf("!") !== -1) {
35 var chunks = moduleName.split("!");
36 return window.normalizeModule(parentId, chunks[0]) + "!" + window.normalizeModule(parentId, chunks[1]);
38 // normalize relative requires
39 if (moduleName.charAt(0) == ".") {
40 var base = parentId.split("/").slice(0, -1).join("/");
41 moduleName = (base ? base + "/" : "") + moduleName;
43 while (moduleName.indexOf(".") !== -1 && previous != moduleName) {
44 var previous = moduleName;
45 moduleName = moduleName.replace(/^\.\//, "").replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, "");
52 window.require = function require(parentId, id) {
58 throw new Error("worker.js require() accepts only (parentId, id) as arguments");
60 id = window.normalizeModule(parentId, id);
62 var module = window.require.modules[id];
64 if (!module.initialized) {
65 module.initialized = true;
66 module.exports = module.factory().exports;
68 return module.exports;
71 if (!window.require.tlns)
72 return console.log("unable to load " + id);
74 var path = resolveModuleId(id, window.require.tlns);
75 if (path.slice(-3) != ".js") path += ".js";
77 window.require.id = id;
78 window.require.modules[id] = {}; // prevent infinite loop on broken modules
80 return window.require(parentId, id);
82 function resolveModuleId(id, paths) {
83 var testPath = id, tail = "";
85 var alias = paths[testPath];
86 if (typeof alias == "string") {
89 return alias.location.replace(/\/*$/, "/") + (tail || alias.main || alias.name);
90 } else if (alias === false) {
93 var i = testPath.lastIndexOf("/");
95 tail = testPath.substr(i) + tail;
96 testPath = testPath.slice(0, i);
100 window.require.modules = {};
101 window.require.tlns = {};
103 window.define = function(id, deps, factory) {
104 if (arguments.length == 2) {
106 if (typeof id != "string") {
108 id = window.require.id;
110 } else if (arguments.length == 1) {
113 id = window.require.id;
116 if (typeof factory != "function") {
117 window.require.modules[id] = {
125 // If there is no dependencies, we inject "require", "exports" and
126 // "module" as dependencies, to provide CommonJS compatibility.
127 deps = ["require", "exports", "module"];
129 var req = function(childId) {
130 return window.require(id, childId);
133 window.require.modules[id] = {
135 factory: function() {
137 var returnExports = factory.apply(this, deps.map(function(dep) {
139 // Because "require", "exports" and "module" aren't actual
140 // dependencies, we must handle them seperately.
141 case "require": return req;
142 case "exports": return module.exports;
143 case "module": return module;
144 // But for all other dependencies, we can just go ahead and
146 default: return req(dep);
150 module.exports = returnExports;
155 window.define.amd = {};
157 window.initBaseUrls = function initBaseUrls(topLevelNamespaces) {
158 for (var i in topLevelNamespaces)
159 require.tlns[i] = topLevelNamespaces[i];
162 window.initSender = function initSender() {
164 var EventEmitter = window.require("ace/lib/event_emitter").EventEmitter;
165 var oop = window.require("ace/lib/oop");
167 var Sender = function() {};
171 oop.implement(this, EventEmitter);
173 this.callback = function(data, callbackId) {
181 this.emit = function(name, data) {
189 }).call(Sender.prototype);
194 var main = window.main = null;
195 var sender = window.sender = null;
197 window.onmessage = function(e) {
199 if (msg.event && sender) {
200 sender._signal(msg.event, msg.data);
202 else if (msg.command) {
203 if (main[msg.command])
204 main[msg.command].apply(main, msg.args);
205 else if (window[msg.command])
206 window[msg.command].apply(window, msg.args);
208 throw new Error("Unknown command:" + msg.command);
211 window.initBaseUrls(msg.tlns);
212 require("ace/lib/es5-shim");
213 sender = window.sender = window.initSender();
214 var clazz = require(msg.module)[msg.classname];
215 main = window.main = new clazz(sender);
220 define("ace/lib/oop",["require","exports","module"], function(require, exports, module) {
223 exports.inherits = function(ctor, superCtor) {
224 ctor.super_ = superCtor;
225 ctor.prototype = Object.create(superCtor.prototype, {
235 exports.mixin = function(obj, mixin) {
236 for (var key in mixin) {
237 obj[key] = mixin[key];
242 exports.implement = function(proto, mixin) {
243 exports.mixin(proto, mixin);
248 define("ace/lib/lang",["require","exports","module"], function(require, exports, module) {
251 exports.last = function(a) {
252 return a[a.length - 1];
255 exports.stringReverse = function(string) {
256 return string.split("").reverse().join("");
259 exports.stringRepeat = function (string, count) {
271 var trimBeginRegexp = /^\s\s*/;
272 var trimEndRegexp = /\s\s*$/;
274 exports.stringTrimLeft = function (string) {
275 return string.replace(trimBeginRegexp, '');
278 exports.stringTrimRight = function (string) {
279 return string.replace(trimEndRegexp, '');
282 exports.copyObject = function(obj) {
284 for (var key in obj) {
285 copy[key] = obj[key];
290 exports.copyArray = function(array){
292 for (var i=0, l=array.length; i<l; i++) {
293 if (array[i] && typeof array[i] == "object")
294 copy[i] = this.copyObject(array[i]);
301 exports.deepCopy = function deepCopy(obj) {
302 if (typeof obj !== "object" || !obj)
305 if (Array.isArray(obj)) {
307 for (var key = 0; key < obj.length; key++) {
308 copy[key] = deepCopy(obj[key]);
312 if (Object.prototype.toString.call(obj) !== "[object Object]")
317 copy[key] = deepCopy(obj[key]);
321 exports.arrayToMap = function(arr) {
323 for (var i=0; i<arr.length; i++) {
330 exports.createMap = function(props) {
331 var map = Object.create(null);
332 for (var i in props) {
337 exports.arrayRemove = function(array, value) {
338 for (var i = 0; i <= array.length; i++) {
339 if (value === array[i]) {
345 exports.escapeRegExp = function(str) {
346 return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
349 exports.escapeHTML = function(str) {
350 return str.replace(/&/g, "&").replace(/"/g, """).replace(/'/g, "'").replace(/</g, "<");
353 exports.getMatchOffsets = function(string, regExp) {
356 string.replace(regExp, function(str) {
358 offset: arguments[arguments.length-2],
365 exports.deferredCall = function(fcn) {
367 var callback = function() {
372 var deferred = function(timeout) {
374 timer = setTimeout(callback, timeout || 0);
378 deferred.schedule = deferred;
380 deferred.call = function() {
386 deferred.cancel = function() {
392 deferred.isPending = function() {
400 exports.delayedCall = function(fcn, defaultTimeout) {
402 var callback = function() {
407 var _self = function(timeout) {
409 timer = setTimeout(callback, timeout || defaultTimeout);
412 _self.delay = function(timeout) {
413 timer && clearTimeout(timer);
414 timer = setTimeout(callback, timeout || defaultTimeout);
416 _self.schedule = _self;
418 _self.call = function() {
423 _self.cancel = function() {
424 timer && clearTimeout(timer);
428 _self.isPending = function() {
436 define("ace/range",["require","exports","module"], function(require, exports, module) {
438 var comparePoints = function(p1, p2) {
439 return p1.row - p2.row || p1.column - p2.column;
441 var Range = function(startRow, startColumn, endRow, endColumn) {
454 this.isEqual = function(range) {
455 return this.start.row === range.start.row &&
456 this.end.row === range.end.row &&
457 this.start.column === range.start.column &&
458 this.end.column === range.end.column;
460 this.toString = function() {
461 return ("Range: [" + this.start.row + "/" + this.start.column +
462 "] -> [" + this.end.row + "/" + this.end.column + "]");
465 this.contains = function(row, column) {
466 return this.compare(row, column) == 0;
468 this.compareRange = function(range) {
473 cmp = this.compare(end.row, end.column);
475 cmp = this.compare(start.row, start.column);
478 } else if (cmp == 0) {
483 } else if (cmp == -1) {
486 cmp = this.compare(start.row, start.column);
489 } else if (cmp == 1) {
496 this.comparePoint = function(p) {
497 return this.compare(p.row, p.column);
499 this.containsRange = function(range) {
500 return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
502 this.intersects = function(range) {
503 var cmp = this.compareRange(range);
504 return (cmp == -1 || cmp == 0 || cmp == 1);
506 this.isEnd = function(row, column) {
507 return this.end.row == row && this.end.column == column;
509 this.isStart = function(row, column) {
510 return this.start.row == row && this.start.column == column;
512 this.setStart = function(row, column) {
513 if (typeof row == "object") {
514 this.start.column = row.column;
515 this.start.row = row.row;
517 this.start.row = row;
518 this.start.column = column;
521 this.setEnd = function(row, column) {
522 if (typeof row == "object") {
523 this.end.column = row.column;
524 this.end.row = row.row;
527 this.end.column = column;
530 this.inside = function(row, column) {
531 if (this.compare(row, column) == 0) {
532 if (this.isEnd(row, column) || this.isStart(row, column)) {
540 this.insideStart = function(row, column) {
541 if (this.compare(row, column) == 0) {
542 if (this.isEnd(row, column)) {
550 this.insideEnd = function(row, column) {
551 if (this.compare(row, column) == 0) {
552 if (this.isStart(row, column)) {
560 this.compare = function(row, column) {
561 if (!this.isMultiLine()) {
562 if (row === this.start.row) {
563 return column < this.start.column ? -1 : (column > this.end.column ? 1 : 0);
567 if (row < this.start.row)
570 if (row > this.end.row)
573 if (this.start.row === row)
574 return column >= this.start.column ? 0 : -1;
576 if (this.end.row === row)
577 return column <= this.end.column ? 0 : 1;
581 this.compareStart = function(row, column) {
582 if (this.start.row == row && this.start.column == column) {
585 return this.compare(row, column);
588 this.compareEnd = function(row, column) {
589 if (this.end.row == row && this.end.column == column) {
592 return this.compare(row, column);
595 this.compareInside = function(row, column) {
596 if (this.end.row == row && this.end.column == column) {
598 } else if (this.start.row == row && this.start.column == column) {
601 return this.compare(row, column);
604 this.clipRows = function(firstRow, lastRow) {
605 if (this.end.row > lastRow)
606 var end = {row: lastRow + 1, column: 0};
607 else if (this.end.row < firstRow)
608 var end = {row: firstRow, column: 0};
610 if (this.start.row > lastRow)
611 var start = {row: lastRow + 1, column: 0};
612 else if (this.start.row < firstRow)
613 var start = {row: firstRow, column: 0};
615 return Range.fromPoints(start || this.start, end || this.end);
617 this.extend = function(row, column) {
618 var cmp = this.compare(row, column);
623 var start = {row: row, column: column};
625 var end = {row: row, column: column};
627 return Range.fromPoints(start || this.start, end || this.end);
630 this.isEmpty = function() {
631 return (this.start.row === this.end.row && this.start.column === this.end.column);
633 this.isMultiLine = function() {
634 return (this.start.row !== this.end.row);
636 this.clone = function() {
637 return Range.fromPoints(this.start, this.end);
639 this.collapseRows = function() {
640 if (this.end.column == 0)
641 return new Range(this.start.row, 0, Math.max(this.start.row, this.end.row-1), 0);
643 return new Range(this.start.row, 0, this.end.row, 0);
645 this.toScreenRange = function(session) {
646 var screenPosStart = session.documentToScreenPosition(this.start);
647 var screenPosEnd = session.documentToScreenPosition(this.end);
650 screenPosStart.row, screenPosStart.column,
651 screenPosEnd.row, screenPosEnd.column
654 this.moveBy = function(row, column) {
655 this.start.row += row;
656 this.start.column += column;
658 this.end.column += column;
661 }).call(Range.prototype);
662 Range.fromPoints = function(start, end) {
663 return new Range(start.row, start.column, end.row, end.column);
665 Range.comparePoints = comparePoints;
667 Range.comparePoints = function(p1, p2) {
668 return p1.row - p2.row || p1.column - p2.column;
672 exports.Range = Range;
675 define("ace/apply_delta",["require","exports","module"], function(require, exports, module) {
678 function throwDeltaError(delta, errorText){
679 console.log("Invalid Delta:", delta);
680 throw "Invalid Delta: " + errorText;
683 function positionInDocument(docLines, position) {
684 return position.row >= 0 && position.row < docLines.length &&
685 position.column >= 0 && position.column <= docLines[position.row].length;
688 function validateDelta(docLines, delta) {
689 if (delta.action != "insert" && delta.action != "remove")
690 throwDeltaError(delta, "delta.action must be 'insert' or 'remove'");
691 if (!(delta.lines instanceof Array))
692 throwDeltaError(delta, "delta.lines must be an Array");
693 if (!delta.start || !delta.end)
694 throwDeltaError(delta, "delta.start/end must be an present");
695 var start = delta.start;
696 if (!positionInDocument(docLines, delta.start))
697 throwDeltaError(delta, "delta.start must be contained in document");
699 if (delta.action == "remove" && !positionInDocument(docLines, end))
700 throwDeltaError(delta, "delta.end must contained in document for 'remove' actions");
701 var numRangeRows = end.row - start.row;
702 var numRangeLastLineChars = (end.column - (numRangeRows == 0 ? start.column : 0));
703 if (numRangeRows != delta.lines.length - 1 || delta.lines[numRangeRows].length != numRangeLastLineChars)
704 throwDeltaError(delta, "delta.range must match delta lines");
707 exports.applyDelta = function(docLines, delta, doNotValidate) {
709 var row = delta.start.row;
710 var startColumn = delta.start.column;
711 var line = docLines[row] || "";
712 switch (delta.action) {
714 var lines = delta.lines;
715 if (lines.length === 1) {
716 docLines[row] = line.substring(0, startColumn) + delta.lines[0] + line.substring(startColumn);
718 var args = [row, 1].concat(delta.lines);
719 docLines.splice.apply(docLines, args);
720 docLines[row] = line.substring(0, startColumn) + docLines[row];
721 docLines[row + delta.lines.length - 1] += line.substring(startColumn);
725 var endColumn = delta.end.column;
726 var endRow = delta.end.row;
727 if (row === endRow) {
728 docLines[row] = line.substring(0, startColumn) + line.substring(endColumn);
731 row, endRow - row + 1,
732 line.substring(0, startColumn) + docLines[endRow].substring(endColumn)
740 define("ace/lib/event_emitter",["require","exports","module"], function(require, exports, module) {
743 var EventEmitter = {};
744 var stopPropagation = function() { this.propagationStopped = true; };
745 var preventDefault = function() { this.defaultPrevented = true; };
748 EventEmitter._dispatchEvent = function(eventName, e) {
749 this._eventRegistry || (this._eventRegistry = {});
750 this._defaultHandlers || (this._defaultHandlers = {});
752 var listeners = this._eventRegistry[eventName] || [];
753 var defaultHandler = this._defaultHandlers[eventName];
754 if (!listeners.length && !defaultHandler)
757 if (typeof e != "object" || !e)
762 if (!e.stopPropagation)
763 e.stopPropagation = stopPropagation;
764 if (!e.preventDefault)
765 e.preventDefault = preventDefault;
767 listeners = listeners.slice();
768 for (var i=0; i<listeners.length; i++) {
769 listeners[i](e, this);
770 if (e.propagationStopped)
774 if (defaultHandler && !e.defaultPrevented)
775 return defaultHandler(e, this);
779 EventEmitter._signal = function(eventName, e) {
780 var listeners = (this._eventRegistry || {})[eventName];
783 listeners = listeners.slice();
784 for (var i=0; i<listeners.length; i++)
785 listeners[i](e, this);
788 EventEmitter.once = function(eventName, callback) {
790 callback && this.addEventListener(eventName, function newCallback() {
791 _self.removeEventListener(eventName, newCallback);
792 callback.apply(null, arguments);
797 EventEmitter.setDefaultHandler = function(eventName, callback) {
798 var handlers = this._defaultHandlers;
800 handlers = this._defaultHandlers = {_disabled_: {}};
802 if (handlers[eventName]) {
803 var old = handlers[eventName];
804 var disabled = handlers._disabled_[eventName];
806 handlers._disabled_[eventName] = disabled = [];
808 var i = disabled.indexOf(callback);
810 disabled.splice(i, 1);
812 handlers[eventName] = callback;
814 EventEmitter.removeDefaultHandler = function(eventName, callback) {
815 var handlers = this._defaultHandlers;
818 var disabled = handlers._disabled_[eventName];
820 if (handlers[eventName] == callback) {
821 var old = handlers[eventName];
823 this.setDefaultHandler(eventName, disabled.pop());
824 } else if (disabled) {
825 var i = disabled.indexOf(callback);
827 disabled.splice(i, 1);
832 EventEmitter.addEventListener = function(eventName, callback, capturing) {
833 this._eventRegistry = this._eventRegistry || {};
835 var listeners = this._eventRegistry[eventName];
837 listeners = this._eventRegistry[eventName] = [];
839 if (listeners.indexOf(callback) == -1)
840 listeners[capturing ? "unshift" : "push"](callback);
845 EventEmitter.removeListener =
846 EventEmitter.removeEventListener = function(eventName, callback) {
847 this._eventRegistry = this._eventRegistry || {};
849 var listeners = this._eventRegistry[eventName];
853 var index = listeners.indexOf(callback);
855 listeners.splice(index, 1);
858 EventEmitter.removeAllListeners = function(eventName) {
859 if (this._eventRegistry) this._eventRegistry[eventName] = [];
862 exports.EventEmitter = EventEmitter;
866 define("ace/anchor",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
869 var oop = require("./lib/oop");
870 var EventEmitter = require("./lib/event_emitter").EventEmitter;
872 var Anchor = exports.Anchor = function(doc, row, column) {
873 this.$onChange = this.onChange.bind(this);
876 if (typeof column == "undefined")
877 this.setPosition(row.row, row.column);
879 this.setPosition(row, column);
884 oop.implement(this, EventEmitter);
885 this.getPosition = function() {
886 return this.$clipPositionToDocument(this.row, this.column);
888 this.getDocument = function() {
889 return this.document;
891 this.$insertRight = false;
892 this.onChange = function(delta) {
893 if (delta.start.row == delta.end.row && delta.start.row != this.row)
896 if (delta.start.row > this.row)
899 var point = $getTransformedPoint(delta, {row: this.row, column: this.column}, this.$insertRight);
900 this.setPosition(point.row, point.column, true);
903 function $pointsInOrder(point1, point2, equalPointsInOrder) {
904 var bColIsAfter = equalPointsInOrder ? point1.column <= point2.column : point1.column < point2.column;
905 return (point1.row < point2.row) || (point1.row == point2.row && bColIsAfter);
908 function $getTransformedPoint(delta, point, moveIfEqual) {
909 var deltaIsInsert = delta.action == "insert";
910 var deltaRowShift = (deltaIsInsert ? 1 : -1) * (delta.end.row - delta.start.row);
911 var deltaColShift = (deltaIsInsert ? 1 : -1) * (delta.end.column - delta.start.column);
912 var deltaStart = delta.start;
913 var deltaEnd = deltaIsInsert ? deltaStart : delta.end; // Collapse insert range.
914 if ($pointsInOrder(point, deltaStart, moveIfEqual)) {
920 if ($pointsInOrder(deltaEnd, point, !moveIfEqual)) {
922 row: point.row + deltaRowShift,
923 column: point.column + (point.row == deltaEnd.row ? deltaColShift : 0)
929 column: deltaStart.column
932 this.setPosition = function(row, column, noClip) {
940 pos = this.$clipPositionToDocument(row, column);
943 if (this.row == pos.row && this.column == pos.column)
952 this.column = pos.column;
953 this._signal("change", {
958 this.detach = function() {
959 this.document.removeEventListener("change", this.$onChange);
961 this.attach = function(doc) {
962 this.document = doc || this.document;
963 this.document.on("change", this.$onChange);
965 this.$clipPositionToDocument = function(row, column) {
968 if (row >= this.document.getLength()) {
969 pos.row = Math.max(0, this.document.getLength() - 1);
970 pos.column = this.document.getLine(pos.row).length;
978 pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column));
987 }).call(Anchor.prototype);
991 define("ace/document",["require","exports","module","ace/lib/oop","ace/apply_delta","ace/lib/event_emitter","ace/range","ace/anchor"], function(require, exports, module) {
994 var oop = require("./lib/oop");
995 var applyDelta = require("./apply_delta").applyDelta;
996 var EventEmitter = require("./lib/event_emitter").EventEmitter;
997 var Range = require("./range").Range;
998 var Anchor = require("./anchor").Anchor;
1000 var Document = function(textOrLines) {
1002 if (textOrLines.length === 0) {
1004 } else if (Array.isArray(textOrLines)) {
1005 this.insertMergedLines({row: 0, column: 0}, textOrLines);
1007 this.insert({row: 0, column:0}, textOrLines);
1013 oop.implement(this, EventEmitter);
1014 this.setValue = function(text) {
1015 var len = this.getLength() - 1;
1016 this.remove(new Range(0, 0, len, this.getLine(len).length));
1017 this.insert({row: 0, column: 0}, text);
1019 this.getValue = function() {
1020 return this.getAllLines().join(this.getNewLineCharacter());
1022 this.createAnchor = function(row, column) {
1023 return new Anchor(this, row, column);
1025 if ("aaa".split(/a/).length === 0) {
1026 this.$split = function(text) {
1027 return text.replace(/\r\n|\r/g, "\n").split("\n");
1030 this.$split = function(text) {
1031 return text.split(/\r\n|\r|\n/);
1036 this.$detectNewLine = function(text) {
1037 var match = text.match(/^.*?(\r\n|\r|\n)/m);
1038 this.$autoNewLine = match ? match[1] : "\n";
1039 this._signal("changeNewLineMode");
1041 this.getNewLineCharacter = function() {
1042 switch (this.$newLineMode) {
1048 return this.$autoNewLine || "\n";
1052 this.$autoNewLine = "";
1053 this.$newLineMode = "auto";
1054 this.setNewLineMode = function(newLineMode) {
1055 if (this.$newLineMode === newLineMode)
1058 this.$newLineMode = newLineMode;
1059 this._signal("changeNewLineMode");
1061 this.getNewLineMode = function() {
1062 return this.$newLineMode;
1064 this.isNewLine = function(text) {
1065 return (text == "\r\n" || text == "\r" || text == "\n");
1067 this.getLine = function(row) {
1068 return this.$lines[row] || "";
1070 this.getLines = function(firstRow, lastRow) {
1071 return this.$lines.slice(firstRow, lastRow + 1);
1073 this.getAllLines = function() {
1074 return this.getLines(0, this.getLength());
1076 this.getLength = function() {
1077 return this.$lines.length;
1079 this.getTextRange = function(range) {
1080 return this.getLinesForRange(range).join(this.getNewLineCharacter());
1082 this.getLinesForRange = function(range) {
1084 if (range.start.row === range.end.row) {
1085 lines = [this.getLine(range.start.row).substring(range.start.column, range.end.column)];
1087 lines = this.getLines(range.start.row, range.end.row);
1088 lines[0] = (lines[0] || "").substring(range.start.column);
1089 var l = lines.length - 1;
1090 if (range.end.row - range.start.row == l)
1091 lines[l] = lines[l].substring(0, range.end.column);
1095 this.insertLines = function(row, lines) {
1096 console.warn("Use of document.insertLines is deprecated. Use the insertFullLines method instead.");
1097 return this.insertFullLines(row, lines);
1099 this.removeLines = function(firstRow, lastRow) {
1100 console.warn("Use of document.removeLines is deprecated. Use the removeFullLines method instead.");
1101 return this.removeFullLines(firstRow, lastRow);
1103 this.insertNewLine = function(position) {
1104 console.warn("Use of document.insertNewLine is deprecated. Use insertMergedLines(position, ['', '']) instead.");
1105 return this.insertMergedLines(position, ["", ""]);
1107 this.insert = function(position, text) {
1108 if (this.getLength() <= 1)
1109 this.$detectNewLine(text);
1111 return this.insertMergedLines(position, this.$split(text));
1113 this.insertInLine = function(position, text) {
1114 var start = this.clippedPos(position.row, position.column);
1115 var end = this.pos(position.row, position.column + text.length);
1124 return this.clonePos(end);
1127 this.clippedPos = function(row, column) {
1128 var length = this.getLength();
1129 if (row === undefined) {
1131 } else if (row < 0) {
1133 } else if (row >= length) {
1137 var line = this.getLine(row);
1138 if (column == undefined)
1139 column = line.length;
1140 column = Math.min(Math.max(column, 0), line.length);
1141 return {row: row, column: column};
1144 this.clonePos = function(pos) {
1145 return {row: pos.row, column: pos.column};
1148 this.pos = function(row, column) {
1149 return {row: row, column: column};
1152 this.$clipPosition = function(position) {
1153 var length = this.getLength();
1154 if (position.row >= length) {
1155 position.row = Math.max(0, length - 1);
1156 position.column = this.getLine(length - 1).length;
1158 position.row = Math.max(0, position.row);
1159 position.column = Math.min(Math.max(position.column, 0), this.getLine(position.row).length);
1163 this.insertFullLines = function(row, lines) {
1164 row = Math.min(Math.max(row, 0), this.getLength());
1166 if (row < this.getLength()) {
1167 lines = lines.concat([""]);
1170 lines = [""].concat(lines);
1172 column = this.$lines[row].length;
1174 this.insertMergedLines({row: row, column: column}, lines);
1176 this.insertMergedLines = function(position, lines) {
1177 var start = this.clippedPos(position.row, position.column);
1179 row: start.row + lines.length - 1,
1180 column: (lines.length == 1 ? start.column : 0) + lines[lines.length - 1].length
1190 return this.clonePos(end);
1192 this.remove = function(range) {
1193 var start = this.clippedPos(range.start.row, range.start.column);
1194 var end = this.clippedPos(range.end.row, range.end.column);
1199 lines: this.getLinesForRange({start: start, end: end})
1201 return this.clonePos(start);
1203 this.removeInLine = function(row, startColumn, endColumn) {
1204 var start = this.clippedPos(row, startColumn);
1205 var end = this.clippedPos(row, endColumn);
1211 lines: this.getLinesForRange({start: start, end: end})
1214 return this.clonePos(start);
1216 this.removeFullLines = function(firstRow, lastRow) {
1217 firstRow = Math.min(Math.max(0, firstRow), this.getLength() - 1);
1218 lastRow = Math.min(Math.max(0, lastRow ), this.getLength() - 1);
1219 var deleteFirstNewLine = lastRow == this.getLength() - 1 && firstRow > 0;
1220 var deleteLastNewLine = lastRow < this.getLength() - 1;
1221 var startRow = ( deleteFirstNewLine ? firstRow - 1 : firstRow );
1222 var startCol = ( deleteFirstNewLine ? this.getLine(startRow).length : 0 );
1223 var endRow = ( deleteLastNewLine ? lastRow + 1 : lastRow );
1224 var endCol = ( deleteLastNewLine ? 0 : this.getLine(endRow).length );
1225 var range = new Range(startRow, startCol, endRow, endCol);
1226 var deletedLines = this.$lines.slice(firstRow, lastRow + 1);
1232 lines: this.getLinesForRange(range)
1234 return deletedLines;
1236 this.removeNewLine = function(row) {
1237 if (row < this.getLength() - 1 && row >= 0) {
1239 start: this.pos(row, this.getLine(row).length),
1240 end: this.pos(row + 1, 0),
1246 this.replace = function(range, text) {
1247 if (!(range instanceof Range))
1248 range = Range.fromPoints(range.start, range.end);
1249 if (text.length === 0 && range.isEmpty())
1251 if (text == this.getTextRange(range))
1257 end = this.insert(range.start, text);
1265 this.applyDeltas = function(deltas) {
1266 for (var i=0; i<deltas.length; i++) {
1267 this.applyDelta(deltas[i]);
1270 this.revertDeltas = function(deltas) {
1271 for (var i=deltas.length-1; i>=0; i--) {
1272 this.revertDelta(deltas[i]);
1275 this.applyDelta = function(delta, doNotValidate) {
1276 var isInsert = delta.action == "insert";
1277 if (isInsert ? delta.lines.length <= 1 && !delta.lines[0]
1278 : !Range.comparePoints(delta.start, delta.end)) {
1282 if (isInsert && delta.lines.length > 20000)
1283 this.$splitAndapplyLargeDelta(delta, 20000);
1284 applyDelta(this.$lines, delta, doNotValidate);
1285 this._signal("change", delta);
1288 this.$splitAndapplyLargeDelta = function(delta, MAX) {
1289 var lines = delta.lines;
1290 var l = lines.length;
1291 var row = delta.start.row;
1292 var column = delta.start.column;
1293 var from = 0, to = 0;
1297 var chunk = lines.slice(from, to);
1299 delta.lines = chunk;
1300 delta.start.row = row + from;
1301 delta.start.column = column;
1306 start: this.pos(row + from, column),
1307 end: this.pos(row + to, column = 0),
1308 action: delta.action,
1313 this.revertDelta = function(delta) {
1315 start: this.clonePos(delta.start),
1316 end: this.clonePos(delta.end),
1317 action: (delta.action == "insert" ? "remove" : "insert"),
1318 lines: delta.lines.slice()
1321 this.indexToPosition = function(index, startRow) {
1322 var lines = this.$lines || this.getAllLines();
1323 var newlineLength = this.getNewLineCharacter().length;
1324 for (var i = startRow || 0, l = lines.length; i < l; i++) {
1325 index -= lines[i].length + newlineLength;
1327 return {row: i, column: index + lines[i].length + newlineLength};
1329 return {row: l-1, column: lines[l-1].length};
1331 this.positionToIndex = function(pos, startRow) {
1332 var lines = this.$lines || this.getAllLines();
1333 var newlineLength = this.getNewLineCharacter().length;
1335 var row = Math.min(pos.row, lines.length);
1336 for (var i = startRow || 0; i < row; ++i)
1337 index += lines[i].length + newlineLength;
1339 return index + pos.column;
1342 }).call(Document.prototype);
1344 exports.Document = Document;
1347 define("ace/worker/mirror",["require","exports","module","ace/range","ace/document","ace/lib/lang"], function(require, exports, module) {
1350 var Range = require("../range").Range;
1351 var Document = require("../document").Document;
1352 var lang = require("../lib/lang");
1354 var Mirror = exports.Mirror = function(sender) {
1355 this.sender = sender;
1356 var doc = this.doc = new Document("");
1358 var deferredUpdate = this.deferredUpdate = lang.delayedCall(this.onUpdate.bind(this));
1361 sender.on("change", function(e) {
1363 if (data[0].start) {
1364 doc.applyDeltas(data);
1366 for (var i = 0; i < data.length; i += 2) {
1367 if (Array.isArray(data[i+1])) {
1368 var d = {action: "insert", start: data[i], lines: data[i+1]};
1370 var d = {action: "remove", start: data[i], end: data[i+1]};
1372 doc.applyDelta(d, true);
1376 return deferredUpdate.schedule(_self.$timeout);
1383 this.$timeout = 500;
1385 this.setTimeout = function(timeout) {
1386 this.$timeout = timeout;
1389 this.setValue = function(value) {
1390 this.doc.setValue(value);
1391 this.deferredUpdate.schedule(this.$timeout);
1394 this.getValue = function(callbackId) {
1395 this.sender.callback(this.doc.getValue(), callbackId);
1398 this.onUpdate = function() {
1401 this.isPending = function() {
1402 return this.deferredUpdate.isPending();
1405 }).call(Mirror.prototype);
1409 define("ace/mode/xml/sax",["require","exports","module"], function(require, exports, module) {
1410 var nameStartChar = /[A-Z_a-z\xC0-\xD6\xD8-\xF6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]///\u10000-\uEFFFF
1411 var nameChar = new RegExp("[\\-\\.0-9"+nameStartChar.source.slice(1,-1)+"\u00B7\u0300-\u036F\\ux203F-\u2040]");
1412 var tagNamePattern = new RegExp('^'+nameStartChar.source+nameChar.source+'*(?:\:'+nameStartChar.source+nameChar.source+'*)?$');
1413 var S_TAG = 0;//tag name offerring
1414 var S_ATTR = 1;//attr name offerring
1415 var S_ATTR_S=2;//attr name end and space offer
1416 var S_EQ = 3;//=space?
1417 var S_V = 4;//attr value(no quot value only)
1418 var S_E = 5;//attr value end and no space(quot end)
1419 var S_S = 6;//(attr value end || tag end ) && (space offer)
1420 var S_C = 7;//closed el<el />
1422 function XMLReader(){
1426 XMLReader.prototype = {
1427 parse:function(source,defaultNSMap,entityMap){
1428 var domBuilder = this.domBuilder;
1429 domBuilder.startDocument();
1430 _copy(defaultNSMap ,defaultNSMap = {})
1431 parse(source,defaultNSMap,entityMap,
1432 domBuilder,this.errorHandler);
1433 domBuilder.endDocument();
1436 function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
1437 function fixedFromCharCode(code) {
1438 if (code > 0xffff) {
1440 var surrogate1 = 0xd800 + (code >> 10)
1441 , surrogate2 = 0xdc00 + (code & 0x3ff);
1443 return String.fromCharCode(surrogate1, surrogate2);
1445 return String.fromCharCode(code);
1448 function entityReplacer(a){
1449 var k = a.slice(1,-1);
1451 return entityMap[k];
1452 }else if(k.charAt(0) === '#'){
1453 return fixedFromCharCode(parseInt(k.substr(1).replace('x','0x')))
1455 errorHandler.error('entity not found:'+a);
1459 function appendText(end){//has some bugs
1460 var xt = source.substring(start,end).replace(/&#?\w+;/g,entityReplacer);
1461 locator&&position(start);
1462 domBuilder.characters(xt,0,end-start);
1465 function position(start,m){
1466 while(start>=endPos && (m = linePattern.exec(source))){
1468 endPos = startPos + m[0].length;
1469 locator.lineNumber++;
1471 locator.columnNumber = start-startPos+1;
1475 var linePattern = /.+(?:\r\n?|\n)|.*$/g
1476 var locator = domBuilder.locator;
1478 var parseStack = [{currentNSMap:defaultNSMapCopy}]
1482 var i = source.indexOf('<',start);
1484 if(!source.substr(start).match(/^\s*$/)){
1485 var doc = domBuilder.document;
1486 var text = doc.createTextNode(source.substr(start));
1487 doc.appendChild(text);
1488 domBuilder.currentElement = text;
1495 switch(source.charAt(i+1)){
1497 var end = source.indexOf('>',i+3);
1498 var tagName = source.substring(i+2,end);
1500 if (parseStack.length > 1) {
1501 config = parseStack.pop();
1503 errorHandler.fatalError("end tag name not found for: "+tagName);
1506 var localNSMap = config.localNSMap;
1508 if(config.tagName != tagName){
1509 errorHandler.fatalError("end tag name: " + tagName + " does not match the current start tagName: "+config.tagName );
1511 domBuilder.endElement(config.uri,config.localName,tagName);
1513 for(var prefix in localNSMap){
1514 domBuilder.endPrefixMapping(prefix) ;
1520 locator&&position(i);
1521 end = parseInstruction(source,i,domBuilder);
1523 case '!':// <!doctype,<![CDATA,<!--
1524 locator&&position(i);
1525 end = parseDCC(source,i,domBuilder,errorHandler);
1529 locator&&position(i);
1531 var el = new ElementAttributes();
1532 var end = parseElementStartPart(source,i,el,entityReplacer,errorHandler);
1533 var len = el.length;
1535 var backup = copyLocator(locator,{});
1536 for(var i = 0;i<len;i++){
1539 a.offset = copyLocator(locator,{});
1541 copyLocator(backup,locator);
1543 if(!el.closed && fixSelfClosed(source,end,el.tagName,closeMap)){
1545 if(!entityMap.nbsp){
1546 errorHandler.warning('unclosed xml attribute');
1549 appendElement(el,domBuilder,parseStack);
1552 if(el.uri === 'http://www.w3.org/1999/xhtml' && !el.closed){
1553 end = parseHtmlSpecialContent(source,end,el.tagName,entityReplacer,domBuilder)
1558 errorHandler.error('element parse error: '+e);
1570 function copyLocator(f,t){
1571 t.lineNumber = f.lineNumber;
1572 t.columnNumber = f.columnNumber;
1576 function parseElementStartPart(source,start,el,entityReplacer,errorHandler){
1580 var s = S_TAG;//status
1582 var c = source.charAt(p);
1585 if(s === S_ATTR){//attrName
1586 attrName = source.slice(start,p);
1588 }else if(s === S_ATTR_S){
1591 throw new Error('attribute equal must after attrName');
1596 if(s === S_EQ){//equal
1598 p = source.indexOf(c,start)
1600 value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
1601 el.add(attrName,value,start-1);
1604 throw new Error('attribute value no end \''+c+'\' match');
1607 value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
1608 el.add(attrName,value,start);
1609 errorHandler.warning('attribute "'+attrName+'" missed start quot('+c+')!!');
1613 throw new Error('attribute value must after "="');
1619 el.setTagName(source.slice(start,p));
1630 throw new Error("attribute invalid close char('/')")
1633 case ''://end document
1634 errorHandler.error('unexpected end of input');
1638 el.setTagName(source.slice(start,p));
1643 case S_V://Compatible state
1645 value = source.slice(start,p);
1646 if(value.slice(-1) === '/'){
1648 value = value.slice(0,-1)
1655 errorHandler.warning('attribute "'+value+'" missed quot(")!!');
1656 el.add(attrName,value.replace(/&#?\w+;/g,entityReplacer),start)
1658 errorHandler.warning('attribute "'+value+'" missed value!! "'+value+'" instead!!')
1659 el.add(value,value,start)
1663 throw new Error('attribute value missed!!');
1672 el.setTagName(source.slice(start,p));//tagName
1676 attrName = source.slice(start,p)
1680 var value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
1681 errorHandler.warning('attribute "'+value+'" missed quot(")!!');
1682 el.add(attrName,value,start)
1690 errorHandler.warning('attribute "'+attrName+'" missed value!! "'+attrName+'" instead!!')
1691 el.add(attrName,attrName,start);
1696 errorHandler.warning('attribute space is required"'+attrName+'"!!')
1706 throw new Error("elements closed character '/' and '>' must be connected to");
1713 function appendElement(el,domBuilder,parseStack){
1714 var tagName = el.tagName;
1715 var localNSMap = null;
1716 var currentNSMap = parseStack[parseStack.length-1].currentNSMap;
1720 var qName = a.qName;
1721 var value = a.value;
1722 var nsp = qName.indexOf(':');
1724 var prefix = a.prefix = qName.slice(0,nsp);
1725 var localName = qName.slice(nsp+1);
1726 var nsPrefix = prefix === 'xmlns' && localName
1730 nsPrefix = qName === 'xmlns' && ''
1732 a.localName = localName ;
1733 if(nsPrefix !== false){//hack!!
1734 if(localNSMap == null){
1736 _copy(currentNSMap,currentNSMap={})
1738 currentNSMap[nsPrefix] = localNSMap[nsPrefix] = value;
1739 a.uri = 'http://www.w3.org/2000/xmlns/'
1740 domBuilder.startPrefixMapping(nsPrefix, value)
1746 var prefix = a.prefix;
1747 if(prefix){//no prefix attribute has no namespace
1748 if(prefix === 'xml'){
1749 a.uri = 'http://www.w3.org/XML/1998/namespace';
1750 }if(prefix !== 'xmlns'){
1751 a.uri = currentNSMap[prefix]
1755 var nsp = tagName.indexOf(':');
1757 prefix = el.prefix = tagName.slice(0,nsp);
1758 localName = el.localName = tagName.slice(nsp+1);
1760 prefix = null;//important!!
1761 localName = el.localName = tagName;
1763 var ns = el.uri = currentNSMap[prefix || ''];
1764 domBuilder.startElement(ns,localName,tagName,el);
1766 domBuilder.endElement(ns,localName,tagName);
1768 for(prefix in localNSMap){
1769 domBuilder.endPrefixMapping(prefix)
1773 el.currentNSMap = currentNSMap;
1774 el.localNSMap = localNSMap;
1775 parseStack.push(el);
1778 function parseHtmlSpecialContent(source,elStartEnd,tagName,entityReplacer,domBuilder){
1779 if(/^(?:script|textarea)$/i.test(tagName)){
1780 var elEndStart = source.indexOf('</'+tagName+'>',elStartEnd);
1781 var text = source.substring(elStartEnd+1,elEndStart);
1782 if(/[&<]/.test(text)){
1783 if(/^script$/i.test(tagName)){
1784 domBuilder.characters(text,0,text.length);
1786 }//}else{//text area
1787 text = text.replace(/&#?\w+;/g,entityReplacer);
1788 domBuilder.characters(text,0,text.length);
1793 return elStartEnd+1;
1795 function fixSelfClosed(source,elStartEnd,tagName,closeMap){
1796 var pos = closeMap[tagName];
1798 pos = closeMap[tagName] = source.lastIndexOf('</'+tagName+'>')
1800 return pos<elStartEnd;
1802 function _copy(source,target){
1803 for(var n in source){target[n] = source[n]}
1805 function parseDCC(source,start,domBuilder,errorHandler){//sure start with '<!'
1806 var next= source.charAt(start+2)
1809 if(source.charAt(start + 3) === '-'){
1810 var end = source.indexOf('-->',start+4);
1812 domBuilder.comment(source,start+4,end-start-4);
1815 errorHandler.error("Unclosed comment");
1822 if(source.substr(start+3,6) == 'CDATA['){
1823 var end = source.indexOf(']]>',start+9);
1824 domBuilder.startCDATA();
1825 domBuilder.characters(source,start+9,end-start-9);
1826 domBuilder.endCDATA()
1829 var matchs = split(source,start);
1830 var len = matchs.length;
1831 if(len>1 && /!doctype/i.test(matchs[0][0])){
1832 var name = matchs[1][0];
1833 var pubid = len>3 && /^public$/i.test(matchs[2][0]) && matchs[3][0]
1834 var sysid = len>4 && matchs[4][0];
1835 var lastMatch = matchs[len-1]
1836 domBuilder.startDTD(name,pubid && pubid.replace(/^(['"])(.*?)\1$/,'$2'),
1837 sysid && sysid.replace(/^(['"])(.*?)\1$/,'$2'));
1838 domBuilder.endDTD();
1840 return lastMatch.index+lastMatch[0].length
1848 function parseInstruction(source,start,domBuilder){
1849 var end = source.indexOf('?>',start);
1851 var match = source.substring(start,end).match(/^<\?(\S*)\s*([\s\S]*?)\s*$/);
1853 var len = match[0].length;
1854 domBuilder.processingInstruction(match[1], match[2]) ;
1862 function ElementAttributes(source){
1865 ElementAttributes.prototype = {
1866 setTagName:function(tagName){
1867 if(!tagNamePattern.test(tagName)){
1868 throw new Error('invalid tagName:'+tagName)
1870 this.tagName = tagName
1872 add:function(qName,value,offset){
1873 if(!tagNamePattern.test(qName)){
1874 throw new Error('invalid attribute:'+qName)
1876 this[this.length++] = {qName:qName,value:value,offset:offset}
1879 getLocalName:function(i){return this[i].localName},
1880 getOffset:function(i){return this[i].offset},
1881 getQName:function(i){return this[i].qName},
1882 getURI:function(i){return this[i].uri},
1883 getValue:function(i){return this[i].value}
1889 function _set_proto_(thiz,parent){
1890 thiz.__proto__ = parent;
1893 if(!(_set_proto_({},_set_proto_.prototype) instanceof _set_proto_)){
1894 _set_proto_ = function(thiz,parent){
1896 p.prototype = parent;
1898 for(parent in thiz){
1899 p[parent] = thiz[parent];
1905 function split(source,start){
1908 var reg = /'[^']+'|"[^"]+"|[^\s<>\/=]+=?|(\/?\s*>|<)/g;
1909 reg.lastIndex = start;
1910 reg.exec(source);//skip <
1911 while(match = reg.exec(source)){
1913 if(match[1])return buf;
1920 define("ace/mode/xml/dom",["require","exports","module"], function(require, exports, module) {
1922 function copy(src,dest){
1927 function _extends(Class,Super){
1928 var pt = Class.prototype;
1930 var ppt = Object.create(Super.prototype)
1933 if(!(pt instanceof Super)){
1935 t.prototype = Super.prototype;
1938 Class.prototype = pt = t;
1940 if(pt.constructor != Class){
1941 if(typeof Class != 'function'){
1942 console.error("unknow Class:"+Class)
1944 pt.constructor = Class
1947 var htmlns = 'http://www.w3.org/1999/xhtml' ;
1949 var ELEMENT_NODE = NodeType.ELEMENT_NODE = 1;
1950 var ATTRIBUTE_NODE = NodeType.ATTRIBUTE_NODE = 2;
1951 var TEXT_NODE = NodeType.TEXT_NODE = 3;
1952 var CDATA_SECTION_NODE = NodeType.CDATA_SECTION_NODE = 4;
1953 var ENTITY_REFERENCE_NODE = NodeType.ENTITY_REFERENCE_NODE = 5;
1954 var ENTITY_NODE = NodeType.ENTITY_NODE = 6;
1955 var PROCESSING_INSTRUCTION_NODE = NodeType.PROCESSING_INSTRUCTION_NODE = 7;
1956 var COMMENT_NODE = NodeType.COMMENT_NODE = 8;
1957 var DOCUMENT_NODE = NodeType.DOCUMENT_NODE = 9;
1958 var DOCUMENT_TYPE_NODE = NodeType.DOCUMENT_TYPE_NODE = 10;
1959 var DOCUMENT_FRAGMENT_NODE = NodeType.DOCUMENT_FRAGMENT_NODE = 11;
1960 var NOTATION_NODE = NodeType.NOTATION_NODE = 12;
1961 var ExceptionCode = {}
1962 var ExceptionMessage = {};
1963 var INDEX_SIZE_ERR = ExceptionCode.INDEX_SIZE_ERR = ((ExceptionMessage[1]="Index size error"),1);
1964 var DOMSTRING_SIZE_ERR = ExceptionCode.DOMSTRING_SIZE_ERR = ((ExceptionMessage[2]="DOMString size error"),2);
1965 var HIERARCHY_REQUEST_ERR = ExceptionCode.HIERARCHY_REQUEST_ERR = ((ExceptionMessage[3]="Hierarchy request error"),3);
1966 var WRONG_DOCUMENT_ERR = ExceptionCode.WRONG_DOCUMENT_ERR = ((ExceptionMessage[4]="Wrong document"),4);
1967 var INVALID_CHARACTER_ERR = ExceptionCode.INVALID_CHARACTER_ERR = ((ExceptionMessage[5]="Invalid character"),5);
1968 var NO_DATA_ALLOWED_ERR = ExceptionCode.NO_DATA_ALLOWED_ERR = ((ExceptionMessage[6]="No data allowed"),6);
1969 var NO_MODIFICATION_ALLOWED_ERR = ExceptionCode.NO_MODIFICATION_ALLOWED_ERR = ((ExceptionMessage[7]="No modification allowed"),7);
1970 var NOT_FOUND_ERR = ExceptionCode.NOT_FOUND_ERR = ((ExceptionMessage[8]="Not found"),8);
1971 var NOT_SUPPORTED_ERR = ExceptionCode.NOT_SUPPORTED_ERR = ((ExceptionMessage[9]="Not supported"),9);
1972 var INUSE_ATTRIBUTE_ERR = ExceptionCode.INUSE_ATTRIBUTE_ERR = ((ExceptionMessage[10]="Attribute in use"),10);
1973 var INVALID_STATE_ERR = ExceptionCode.INVALID_STATE_ERR = ((ExceptionMessage[11]="Invalid state"),11);
1974 var SYNTAX_ERR = ExceptionCode.SYNTAX_ERR = ((ExceptionMessage[12]="Syntax error"),12);
1975 var INVALID_MODIFICATION_ERR = ExceptionCode.INVALID_MODIFICATION_ERR = ((ExceptionMessage[13]="Invalid modification"),13);
1976 var NAMESPACE_ERR = ExceptionCode.NAMESPACE_ERR = ((ExceptionMessage[14]="Invalid namespace"),14);
1977 var INVALID_ACCESS_ERR = ExceptionCode.INVALID_ACCESS_ERR = ((ExceptionMessage[15]="Invalid access"),15);
1980 function DOMException(code, message) {
1981 if(message instanceof Error){
1982 var error = message;
1985 Error.call(this, ExceptionMessage[code]);
1986 this.message = ExceptionMessage[code];
1987 if(Error.captureStackTrace) Error.captureStackTrace(this, DOMException);
1990 if(message) this.message = this.message + ": " + message;
1993 DOMException.prototype = Error.prototype;
1994 copy(ExceptionCode,DOMException)
1995 function NodeList() {
1997 NodeList.prototype = {
1999 item: function(index) {
2000 return this[index] || null;
2003 function LiveNodeList(node,refresh){
2005 this._refresh = refresh
2006 _updateLiveList(this);
2008 function _updateLiveList(list){
2009 var inc = list._node._inc || list._node.ownerDocument._inc;
2010 if(list._inc != inc){
2011 var ls = list._refresh(list._node);
2012 __set__(list,'length',ls.length);
2017 LiveNodeList.prototype.item = function(i){
2018 _updateLiveList(this);
2022 _extends(LiveNodeList,NodeList);
2023 function NamedNodeMap() {
2026 function _findNodeIndex(list,node){
2027 var i = list.length;
2029 if(list[i] === node){return i}
2033 function _addNamedNode(el,list,newAttr,oldAttr){
2035 list[_findNodeIndex(list,oldAttr)] = newAttr;
2037 list[list.length++] = newAttr;
2040 newAttr.ownerElement = el;
2041 var doc = el.ownerDocument;
2043 oldAttr && _onRemoveAttribute(doc,el,oldAttr);
2044 _onAddAttribute(doc,el,newAttr);
2048 function _removeNamedNode(el,list,attr){
2049 var i = _findNodeIndex(list,attr);
2051 var lastIndex = list.length-1
2055 list.length = lastIndex;
2057 var doc = el.ownerDocument;
2059 _onRemoveAttribute(doc,el,attr);
2060 attr.ownerElement = null;
2064 throw DOMException(NOT_FOUND_ERR,new Error())
2067 NamedNodeMap.prototype = {
2069 item:NodeList.prototype.item,
2070 getNamedItem: function(key) {
2071 var i = this.length;
2074 if(attr.nodeName == key){
2079 setNamedItem: function(attr) {
2080 var el = attr.ownerElement;
2081 if(el && el!=this._ownerElement){
2082 throw new DOMException(INUSE_ATTRIBUTE_ERR);
2084 var oldAttr = this.getNamedItem(attr.nodeName);
2085 _addNamedNode(this._ownerElement,this,attr,oldAttr);
2088 setNamedItemNS: function(attr) {// raises: WRONG_DOCUMENT_ERR,NO_MODIFICATION_ALLOWED_ERR,INUSE_ATTRIBUTE_ERR
2089 var el = attr.ownerElement, oldAttr;
2090 if(el && el!=this._ownerElement){
2091 throw new DOMException(INUSE_ATTRIBUTE_ERR);
2093 oldAttr = this.getNamedItemNS(attr.namespaceURI,attr.localName);
2094 _addNamedNode(this._ownerElement,this,attr,oldAttr);
2097 removeNamedItem: function(key) {
2098 var attr = this.getNamedItem(key);
2099 _removeNamedNode(this._ownerElement,this,attr);
2103 },// raises: NOT_FOUND_ERR,NO_MODIFICATION_ALLOWED_ERR
2104 removeNamedItemNS:function(namespaceURI,localName){
2105 var attr = this.getNamedItemNS(namespaceURI,localName);
2106 _removeNamedNode(this._ownerElement,this,attr);
2109 getNamedItemNS: function(namespaceURI, localName) {
2110 var i = this.length;
2113 if(node.localName == localName && node.namespaceURI == namespaceURI){
2120 function DOMImplementation(/* Object */ features) {
2121 this._features = {};
2123 for (var feature in features) {
2124 this._features = features[feature];
2129 DOMImplementation.prototype = {
2130 hasFeature: function(/* string */ feature, /* string */ version) {
2131 var versions = this._features[feature.toLowerCase()];
2132 if (versions && (!version || version in versions)) {
2138 createDocument:function(namespaceURI, qualifiedName, doctype){// raises:INVALID_CHARACTER_ERR,NAMESPACE_ERR,WRONG_DOCUMENT_ERR
2139 var doc = new Document();
2140 doc.implementation = this;
2141 doc.childNodes = new NodeList();
2142 doc.doctype = doctype;
2144 doc.appendChild(doctype);
2147 var root = doc.createElementNS(namespaceURI,qualifiedName);
2148 doc.appendChild(root);
2152 createDocumentType:function(qualifiedName, publicId, systemId){// raises:INVALID_CHARACTER_ERR,NAMESPACE_ERR
2153 var node = new DocumentType();
2154 node.name = qualifiedName;
2155 node.nodeName = qualifiedName;
2156 node.publicId = publicId;
2157 node.systemId = systemId;
2168 previousSibling : null,
2173 ownerDocument : null,
2175 namespaceURI : null,
2178 insertBefore:function(newChild, refChild){//raises
2179 return _insertBefore(this,newChild,refChild);
2181 replaceChild:function(newChild, oldChild){//raises
2182 this.insertBefore(newChild,oldChild);
2184 this.removeChild(oldChild);
2187 removeChild:function(oldChild){
2188 return _removeChild(this,oldChild);
2190 appendChild:function(newChild){
2191 return this.insertBefore(newChild,null);
2193 hasChildNodes:function(){
2194 return this.firstChild != null;
2196 cloneNode:function(deep){
2197 return cloneNode(this.ownerDocument||this,this,deep);
2199 normalize:function(){
2200 var child = this.firstChild;
2202 var next = child.nextSibling;
2203 if(next && next.nodeType == TEXT_NODE && child.nodeType == TEXT_NODE){
2204 this.removeChild(next);
2205 child.appendData(next.data);
2212 isSupported:function(feature, version){
2213 return this.ownerDocument.implementation.hasFeature(feature,version);
2215 hasAttributes:function(){
2216 return this.attributes.length>0;
2218 lookupPrefix:function(namespaceURI){
2221 var map = el._nsMap;
2224 if(map[n] == namespaceURI){
2229 el = el.nodeType == 2?el.ownerDocument : el.parentNode;
2233 lookupNamespaceURI:function(prefix){
2236 var map = el._nsMap;
2239 return map[prefix] ;
2242 el = el.nodeType == 2?el.ownerDocument : el.parentNode;
2246 isDefaultNamespace:function(namespaceURI){
2247 var prefix = this.lookupPrefix(namespaceURI);
2248 return prefix == null;
2253 function _xmlEncoder(c){
2254 return c == '<' && '<' ||
2255 c == '>' && '>' ||
2256 c == '&' && '&' ||
2257 c == '"' && '"' ||
2258 '&#'+c.charCodeAt()+';'
2262 copy(NodeType,Node);
2263 copy(NodeType,Node.prototype);
2264 function _visitNode(node,callback){
2268 if(node = node.firstChild){
2270 if(_visitNode(node,callback)){return true}
2271 }while(node=node.nextSibling)
2277 function Document(){
2279 function _onAddAttribute(doc,el,newAttr){
2281 var ns = newAttr.namespaceURI ;
2282 if(ns == 'http://www.w3.org/2000/xmlns/'){
2283 el._nsMap[newAttr.prefix?newAttr.localName:''] = newAttr.value
2286 function _onRemoveAttribute(doc,el,newAttr,remove){
2288 var ns = newAttr.namespaceURI ;
2289 if(ns == 'http://www.w3.org/2000/xmlns/'){
2290 delete el._nsMap[newAttr.prefix?newAttr.localName:'']
2293 function _onUpdateChild(doc,el,newChild){
2294 if(doc && doc._inc){
2296 var cs = el.childNodes;
2298 cs[cs.length++] = newChild;
2300 var child = el.firstChild;
2304 child =child.nextSibling;
2310 function _removeChild(parentNode,child){
2311 var previous = child.previousSibling;
2312 var next = child.nextSibling;
2314 previous.nextSibling = next;
2316 parentNode.firstChild = next
2319 next.previousSibling = previous;
2321 parentNode.lastChild = previous;
2323 _onUpdateChild(parentNode.ownerDocument,parentNode);
2326 function _insertBefore(parentNode,newChild,nextChild){
2327 var cp = newChild.parentNode;
2329 cp.removeChild(newChild);//remove and update
2331 if(newChild.nodeType === DOCUMENT_FRAGMENT_NODE){
2332 var newFirst = newChild.firstChild;
2333 if (newFirst == null) {
2336 var newLast = newChild.lastChild;
2338 newFirst = newLast = newChild;
2340 var pre = nextChild ? nextChild.previousSibling : parentNode.lastChild;
2342 newFirst.previousSibling = pre;
2343 newLast.nextSibling = nextChild;
2347 pre.nextSibling = newFirst;
2349 parentNode.firstChild = newFirst;
2351 if(nextChild == null){
2352 parentNode.lastChild = newLast;
2354 nextChild.previousSibling = newLast;
2357 newFirst.parentNode = parentNode;
2358 }while(newFirst !== newLast && (newFirst= newFirst.nextSibling))
2359 _onUpdateChild(parentNode.ownerDocument||parentNode,parentNode);
2360 if (newChild.nodeType == DOCUMENT_FRAGMENT_NODE) {
2361 newChild.firstChild = newChild.lastChild = null;
2365 function _appendSingleChild(parentNode,newChild){
2366 var cp = newChild.parentNode;
2368 var pre = parentNode.lastChild;
2369 cp.removeChild(newChild);//remove and update
2370 var pre = parentNode.lastChild;
2372 var pre = parentNode.lastChild;
2373 newChild.parentNode = parentNode;
2374 newChild.previousSibling = pre;
2375 newChild.nextSibling = null;
2377 pre.nextSibling = newChild;
2379 parentNode.firstChild = newChild;
2381 parentNode.lastChild = newChild;
2382 _onUpdateChild(parentNode.ownerDocument,parentNode,newChild);
2385 Document.prototype = {
2386 nodeName : '#document',
2387 nodeType : DOCUMENT_NODE,
2389 documentElement : null,
2392 insertBefore : function(newChild, refChild){//raises
2393 if(newChild.nodeType == DOCUMENT_FRAGMENT_NODE){
2394 var child = newChild.firstChild;
2396 var next = child.nextSibling;
2397 this.insertBefore(child,refChild);
2402 if(this.documentElement == null && newChild.nodeType == 1){
2403 this.documentElement = newChild;
2406 return _insertBefore(this,newChild,refChild),(newChild.ownerDocument = this),newChild;
2408 removeChild : function(oldChild){
2409 if(this.documentElement == oldChild){
2410 this.documentElement = null;
2412 return _removeChild(this,oldChild);
2414 importNode : function(importedNode,deep){
2415 return importNode(this,importedNode,deep);
2417 getElementById : function(id){
2419 _visitNode(this.documentElement,function(node){
2420 if(node.nodeType == 1){
2421 if(node.getAttribute('id') == id){
2429 createElement : function(tagName){
2430 var node = new Element();
2431 node.ownerDocument = this;
2432 node.nodeName = tagName;
2433 node.tagName = tagName;
2434 node.childNodes = new NodeList();
2435 var attrs = node.attributes = new NamedNodeMap();
2436 attrs._ownerElement = node;
2439 createDocumentFragment : function(){
2440 var node = new DocumentFragment();
2441 node.ownerDocument = this;
2442 node.childNodes = new NodeList();
2445 createTextNode : function(data){
2446 var node = new Text();
2447 node.ownerDocument = this;
2448 node.appendData(data)
2451 createComment : function(data){
2452 var node = new Comment();
2453 node.ownerDocument = this;
2454 node.appendData(data)
2457 createCDATASection : function(data){
2458 var node = new CDATASection();
2459 node.ownerDocument = this;
2460 node.appendData(data)
2463 createProcessingInstruction : function(target,data){
2464 var node = new ProcessingInstruction();
2465 node.ownerDocument = this;
2466 node.tagName = node.target = target;
2467 node.nodeValue= node.data = data;
2470 createAttribute : function(name){
2471 var node = new Attr();
2472 node.ownerDocument = this;
2474 node.nodeName = name;
2475 node.localName = name;
2476 node.specified = true;
2479 createEntityReference : function(name){
2480 var node = new EntityReference();
2481 node.ownerDocument = this;
2482 node.nodeName = name;
2485 createElementNS : function(namespaceURI,qualifiedName){
2486 var node = new Element();
2487 var pl = qualifiedName.split(':');
2488 var attrs = node.attributes = new NamedNodeMap();
2489 node.childNodes = new NodeList();
2490 node.ownerDocument = this;
2491 node.nodeName = qualifiedName;
2492 node.tagName = qualifiedName;
2493 node.namespaceURI = namespaceURI;
2495 node.prefix = pl[0];
2496 node.localName = pl[1];
2498 node.localName = qualifiedName;
2500 attrs._ownerElement = node;
2503 createAttributeNS : function(namespaceURI,qualifiedName){
2504 var node = new Attr();
2505 var pl = qualifiedName.split(':');
2506 node.ownerDocument = this;
2507 node.nodeName = qualifiedName;
2508 node.name = qualifiedName;
2509 node.namespaceURI = namespaceURI;
2510 node.specified = true;
2512 node.prefix = pl[0];
2513 node.localName = pl[1];
2515 node.localName = qualifiedName;
2520 _extends(Document,Node);
2523 function Element() {
2526 Element.prototype = {
2527 nodeType : ELEMENT_NODE,
2528 hasAttribute : function(name){
2529 return this.getAttributeNode(name)!=null;
2531 getAttribute : function(name){
2532 var attr = this.getAttributeNode(name);
2533 return attr && attr.value || '';
2535 getAttributeNode : function(name){
2536 return this.attributes.getNamedItem(name);
2538 setAttribute : function(name, value){
2539 var attr = this.ownerDocument.createAttribute(name);
2540 attr.value = attr.nodeValue = "" + value;
2541 this.setAttributeNode(attr)
2543 removeAttribute : function(name){
2544 var attr = this.getAttributeNode(name)
2545 attr && this.removeAttributeNode(attr);
2547 appendChild:function(newChild){
2548 if(newChild.nodeType === DOCUMENT_FRAGMENT_NODE){
2549 return this.insertBefore(newChild,null);
2551 return _appendSingleChild(this,newChild);
2554 setAttributeNode : function(newAttr){
2555 return this.attributes.setNamedItem(newAttr);
2557 setAttributeNodeNS : function(newAttr){
2558 return this.attributes.setNamedItemNS(newAttr);
2560 removeAttributeNode : function(oldAttr){
2561 return this.attributes.removeNamedItem(oldAttr.nodeName);
2563 removeAttributeNS : function(namespaceURI, localName){
2564 var old = this.getAttributeNodeNS(namespaceURI, localName);
2565 old && this.removeAttributeNode(old);
2568 hasAttributeNS : function(namespaceURI, localName){
2569 return this.getAttributeNodeNS(namespaceURI, localName)!=null;
2571 getAttributeNS : function(namespaceURI, localName){
2572 var attr = this.getAttributeNodeNS(namespaceURI, localName);
2573 return attr && attr.value || '';
2575 setAttributeNS : function(namespaceURI, qualifiedName, value){
2576 var attr = this.ownerDocument.createAttributeNS(namespaceURI, qualifiedName);
2577 attr.value = attr.nodeValue = "" + value;
2578 this.setAttributeNode(attr)
2580 getAttributeNodeNS : function(namespaceURI, localName){
2581 return this.attributes.getNamedItemNS(namespaceURI, localName);
2584 getElementsByTagName : function(tagName){
2585 return new LiveNodeList(this,function(base){
2587 _visitNode(base,function(node){
2588 if(node !== base && node.nodeType == ELEMENT_NODE && (tagName === '*' || node.tagName == tagName)){
2595 getElementsByTagNameNS : function(namespaceURI, localName){
2596 return new LiveNodeList(this,function(base){
2598 _visitNode(base,function(node){
2599 if(node !== base && node.nodeType === ELEMENT_NODE && (namespaceURI === '*' || node.namespaceURI === namespaceURI) && (localName === '*' || node.localName == localName)){
2607 Document.prototype.getElementsByTagName = Element.prototype.getElementsByTagName;
2608 Document.prototype.getElementsByTagNameNS = Element.prototype.getElementsByTagNameNS;
2611 _extends(Element,Node);
2614 Attr.prototype.nodeType = ATTRIBUTE_NODE;
2615 _extends(Attr,Node);
2618 function CharacterData() {
2620 CharacterData.prototype = {
2622 substringData : function(offset, count) {
2623 return this.data.substring(offset, offset+count);
2625 appendData: function(text) {
2626 text = this.data+text;
2627 this.nodeValue = this.data = text;
2628 this.length = text.length;
2630 insertData: function(offset,text) {
2631 this.replaceData(offset,0,text);
2634 appendChild:function(newChild){
2635 throw new Error(ExceptionMessage[3])
2636 return Node.prototype.appendChild.apply(this,arguments)
2638 deleteData: function(offset, count) {
2639 this.replaceData(offset,count,"");
2641 replaceData: function(offset, count, text) {
2642 var start = this.data.substring(0,offset);
2643 var end = this.data.substring(offset+count);
2644 text = start + text + end;
2645 this.nodeValue = this.data = text;
2646 this.length = text.length;
2649 _extends(CharacterData,Node);
2654 nodeType : TEXT_NODE,
2655 splitText : function(offset) {
2656 var text = this.data;
2657 var newText = text.substring(offset);
2658 text = text.substring(0, offset);
2659 this.data = this.nodeValue = text;
2660 this.length = text.length;
2661 var newNode = this.ownerDocument.createTextNode(newText);
2662 if(this.parentNode){
2663 this.parentNode.insertBefore(newNode, this.nextSibling);
2668 _extends(Text,CharacterData);
2669 function Comment() {
2671 Comment.prototype = {
2672 nodeName : "#comment",
2673 nodeType : COMMENT_NODE
2675 _extends(Comment,CharacterData);
2677 function CDATASection() {
2679 CDATASection.prototype = {
2680 nodeName : "#cdata-section",
2681 nodeType : CDATA_SECTION_NODE
2683 _extends(CDATASection,CharacterData);
2686 function DocumentType() {
2688 DocumentType.prototype.nodeType = DOCUMENT_TYPE_NODE;
2689 _extends(DocumentType,Node);
2691 function Notation() {
2693 Notation.prototype.nodeType = NOTATION_NODE;
2694 _extends(Notation,Node);
2698 Entity.prototype.nodeType = ENTITY_NODE;
2699 _extends(Entity,Node);
2701 function EntityReference() {
2703 EntityReference.prototype.nodeType = ENTITY_REFERENCE_NODE;
2704 _extends(EntityReference,Node);
2706 function DocumentFragment() {
2708 DocumentFragment.prototype.nodeName = "#document-fragment";
2709 DocumentFragment.prototype.nodeType = DOCUMENT_FRAGMENT_NODE;
2710 _extends(DocumentFragment,Node);
2713 function ProcessingInstruction() {
2715 ProcessingInstruction.prototype.nodeType = PROCESSING_INSTRUCTION_NODE;
2716 _extends(ProcessingInstruction,Node);
2717 function XMLSerializer(){}
2718 XMLSerializer.prototype.serializeToString = function(node){
2720 serializeToString(node,buf);
2721 return buf.join('');
2723 Node.prototype.toString =function(){
2724 return XMLSerializer.prototype.serializeToString(this);
2726 function serializeToString(node,buf){
2727 switch(node.nodeType){
2729 var attrs = node.attributes;
2730 var len = attrs.length;
2731 var child = node.firstChild;
2732 var nodeName = node.tagName;
2733 var isHTML = htmlns === node.namespaceURI
2734 buf.push('<',nodeName);
2735 for(var i=0;i<len;i++){
2736 serializeToString(attrs.item(i),buf,isHTML);
2738 if(child || isHTML && !/^(?:meta|link|img|br|hr|input|button)$/i.test(nodeName)){
2740 if(isHTML && /^script$/i.test(nodeName)){
2742 buf.push(child.data);
2746 serializeToString(child,buf);
2747 child = child.nextSibling;
2750 buf.push('</',nodeName,'>');
2756 case DOCUMENT_FRAGMENT_NODE:
2757 var child = node.firstChild;
2759 serializeToString(child,buf);
2760 child = child.nextSibling;
2763 case ATTRIBUTE_NODE:
2764 return buf.push(' ',node.name,'="',node.value.replace(/[<&"]/g,_xmlEncoder),'"');
2766 return buf.push(node.data.replace(/[<&]/g,_xmlEncoder));
2767 case CDATA_SECTION_NODE:
2768 return buf.push( '<![CDATA[',node.data,']]>');
2770 return buf.push( "<!--",node.data,"-->");
2771 case DOCUMENT_TYPE_NODE:
2772 var pubid = node.publicId;
2773 var sysid = node.systemId;
2774 buf.push('<!DOCTYPE ',node.name);
2776 buf.push(' PUBLIC "',pubid);
2777 if (sysid && sysid!='.') {
2778 buf.push( '" "',sysid);
2781 }else if(sysid && sysid!='.'){
2782 buf.push(' SYSTEM "',sysid,'">');
2784 var sub = node.internalSubset;
2786 buf.push(" [",sub,"]");
2791 case PROCESSING_INSTRUCTION_NODE:
2792 return buf.push( "<?",node.target," ",node.data,"?>");
2793 case ENTITY_REFERENCE_NODE:
2794 return buf.push( '&',node.nodeName,';');
2796 buf.push('??',node.nodeName);
2799 function importNode(doc,node,deep){
2801 switch (node.nodeType) {
2803 node2 = node.cloneNode(false);
2804 node2.ownerDocument = doc;
2805 case DOCUMENT_FRAGMENT_NODE:
2807 case ATTRIBUTE_NODE:
2812 node2 = node.cloneNode(false);//false
2814 node2.ownerDocument = doc;
2815 node2.parentNode = null;
2817 var child = node.firstChild;
2819 node2.appendChild(importNode(doc,child,deep));
2820 child = child.nextSibling;
2825 function cloneNode(doc,node,deep){
2826 var node2 = new node.constructor();
2829 if(typeof v != 'object' ){
2835 if(node.childNodes){
2836 node2.childNodes = new NodeList();
2838 node2.ownerDocument = doc;
2839 switch (node2.nodeType) {
2841 var attrs = node.attributes;
2842 var attrs2 = node2.attributes = new NamedNodeMap();
2843 var len = attrs.length
2844 attrs2._ownerElement = node2;
2845 for(var i=0;i<len;i++){
2846 node2.setAttributeNode(cloneNode(doc,attrs.item(i),true));
2849 case ATTRIBUTE_NODE:
2853 var child = node.firstChild;
2855 node2.appendChild(cloneNode(doc,child,deep));
2856 child = child.nextSibling;
2862 function __set__(object,key,value){
2866 if(Object.defineProperty){
2867 Object.defineProperty(LiveNodeList.prototype,'length',{
2869 _updateLiveList(this);
2870 return this.$$length;
2873 Object.defineProperty(Node.prototype,'textContent',{
2875 return getTextContent(this);
2878 switch(this.nodeType){
2881 while(this.firstChild){
2882 this.removeChild(this.firstChild);
2884 if(data || String(data)){
2885 this.appendChild(this.ownerDocument.createTextNode(data));
2891 this.nodeValue = data;
2896 function getTextContent(node){
2897 switch(node.nodeType){
2901 node = node.firstChild;
2903 if(node.nodeType!==7 && node.nodeType !==8){
2904 buf.push(getTextContent(node));
2906 node = node.nextSibling;
2908 return buf.join('');
2910 return node.nodeValue;
2913 __set__ = function(object,key,value){
2914 object['$$'+key] = value
2920 return DOMImplementation;
2923 define("ace/mode/xml/dom-parser",["require","exports","module","ace/mode/xml/sax","ace/mode/xml/dom"], function(require, exports, module) {
2926 var XMLReader = require('./sax'),
2927 DOMImplementation = require('./dom');
2929 function DOMParser(options){
2930 this.options = options ||{locator:{}};
2933 DOMParser.prototype.parseFromString = function(source,mimeType){
2934 var options = this.options;
2935 var sax = new XMLReader();
2936 var domBuilder = options.domBuilder || new DOMHandler();//contentHandler and LexicalHandler
2937 var errorHandler = options.errorHandler;
2938 var locator = options.locator;
2939 var defaultNSMap = options.xmlns||{};
2940 var entityMap = {'lt':'<','gt':'>','amp':'&','quot':'"','apos':"'"}
2942 domBuilder.setDocumentLocator(locator)
2945 sax.errorHandler = buildErrorHandler(errorHandler,domBuilder,locator);
2946 sax.domBuilder = options.domBuilder || domBuilder;
2947 if(/\/x?html?$/.test(mimeType)){
2948 entityMap.nbsp = '\xa0';
2949 entityMap.copy = '\xa9';
2950 defaultNSMap['']= 'http://www.w3.org/1999/xhtml';
2953 sax.parse(source,defaultNSMap,entityMap);
2955 sax.errorHandler.error("invalid document source");
2957 return domBuilder.document;
2959 function buildErrorHandler(errorImpl,domBuilder,locator){
2961 if(domBuilder instanceof DOMHandler){
2964 errorImpl = domBuilder ;
2966 var errorHandler = {}
2967 var isCallback = errorImpl instanceof Function;
2968 locator = locator||{}
2969 function build(key){
2970 var fn = errorImpl[key];
2973 fn = errorImpl.length == 2?function(msg){errorImpl(key,msg)}:errorImpl;
2975 var i=arguments.length;
2977 if(fn = errorImpl[arguments[i]]){
2983 errorHandler[key] = fn && function(msg){
2984 fn(msg+_locator(locator), msg, locator);
2987 build('warning','warn');
2988 build('error','warn','warning');
2989 build('fatalError','warn','warning','error');
2990 return errorHandler;
2992 function DOMHandler() {
2995 function position(locator,node){
2996 node.lineNumber = locator.lineNumber;
2997 node.columnNumber = locator.columnNumber;
2999 DOMHandler.prototype = {
3000 startDocument : function() {
3001 this.document = new DOMImplementation().createDocument(null, null, null);
3003 this.document.documentURI = this.locator.systemId;
3006 startElement:function(namespaceURI, localName, qName, attrs) {
3007 var doc = this.document;
3008 var el = doc.createElementNS(namespaceURI, qName||localName);
3009 var len = attrs.length;
3010 appendElement(this, el);
3011 this.currentElement = el;
3013 this.locator && position(this.locator,el)
3014 for (var i = 0 ; i < len; i++) {
3015 var namespaceURI = attrs.getURI(i);
3016 var value = attrs.getValue(i);
3017 var qName = attrs.getQName(i);
3018 var attr = doc.createAttributeNS(namespaceURI, qName);
3019 if( attr.getOffset){
3020 position(attr.getOffset(1),attr)
3022 attr.value = attr.nodeValue = value;
3023 el.setAttributeNode(attr)
3026 endElement:function(namespaceURI, localName, qName) {
3027 var current = this.currentElement
3028 var tagName = current.tagName;
3029 this.currentElement = current.parentNode;
3031 startPrefixMapping:function(prefix, uri) {
3033 endPrefixMapping:function(prefix) {
3035 processingInstruction:function(target, data) {
3036 var ins = this.document.createProcessingInstruction(target, data);
3037 this.locator && position(this.locator,ins)
3038 appendElement(this, ins);
3040 ignorableWhitespace:function(ch, start, length) {
3042 characters:function(chars, start, length) {
3043 chars = _toString.apply(this,arguments)
3044 if(this.currentElement && chars){
3046 var charNode = this.document.createCDATASection(chars);
3047 this.currentElement.appendChild(charNode);
3049 var charNode = this.document.createTextNode(chars);
3050 this.currentElement.appendChild(charNode);
3052 this.locator && position(this.locator,charNode)
3055 skippedEntity:function(name) {
3057 endDocument:function() {
3058 this.document.normalize();
3060 setDocumentLocator:function (locator) {
3061 if(this.locator = locator){// && !('lineNumber' in locator)){
3062 locator.lineNumber = 0;
3065 comment:function(chars, start, length) {
3066 chars = _toString.apply(this,arguments)
3067 var comm = this.document.createComment(chars);
3068 this.locator && position(this.locator,comm)
3069 appendElement(this, comm);
3072 startCDATA:function() {
3075 endCDATA:function() {
3079 startDTD:function(name, publicId, systemId) {
3080 var impl = this.document.implementation;
3081 if (impl && impl.createDocumentType) {
3082 var dt = impl.createDocumentType(name, publicId, systemId);
3083 this.locator && position(this.locator,dt)
3084 appendElement(this, dt);
3087 warning:function(error) {
3088 console.warn(error,_locator(this.locator));
3090 error:function(error) {
3091 console.error(error,_locator(this.locator));
3093 fatalError:function(error) {
3094 console.error(error,_locator(this.locator));
3098 function _locator(l){
3100 return '\n@'+(l.systemId ||'')+'#[line:'+l.lineNumber+',col:'+l.columnNumber+']'
3103 function _toString(chars,start,length){
3104 if(typeof chars == 'string'){
3105 return chars.substr(start,length)
3106 }else{//java sax connect width xmldom on rhino(what about: "? && !(chars instanceof String)")
3107 if(chars.length >= start+length || start){
3108 return new java.lang.String(chars,start,length)+'';
3113 "endDTD,startEntity,endEntity,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,resolveEntity,getExternalSubset,notationDecl,unparsedEntityDecl".replace(/\w+/g,function(key){
3114 DOMHandler.prototype[key] = function(){return null}
3116 function appendElement (hander,node) {
3117 if (!hander.currentElement) {
3118 hander.document.appendChild(node);
3120 hander.currentElement.appendChild(node);
3122 }//appendChild and setAttributeNS are preformance key
3125 DOMParser: DOMParser
3129 define("ace/mode/xml_worker",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/worker/mirror","ace/mode/xml/dom-parser"], function(require, exports, module) {
3132 var oop = require("../lib/oop");
3133 var lang = require("../lib/lang");
3134 var Mirror = require("../worker/mirror").Mirror;
3135 var DOMParser = require("./xml/dom-parser").DOMParser;
3137 var Worker = exports.Worker = function(sender) {
3138 Mirror.call(this, sender);
3139 this.setTimeout(400);
3140 this.context = null;
3143 oop.inherits(Worker, Mirror);
3147 this.setOptions = function(options) {
3148 this.context = options.context;
3151 this.onUpdate = function() {
3152 var value = this.doc.getValue();
3155 var parser = new DOMParser();
3157 parser.options.errorHandler = {
3158 fatalError: function(fullMsg, errorMsg, locator) {
3160 row: locator.lineNumber,
3161 column: locator.columnNumber,
3166 error: function(fullMsg, errorMsg, locator) {
3168 row: locator.lineNumber,
3169 column: locator.columnNumber,
3174 warning: function(fullMsg, errorMsg, locator) {
3176 row: locator.lineNumber,
3177 column: locator.columnNumber,
3184 parser.parseFromString(value);
3185 this.sender.emit("error", errors);
3188 }).call(Worker.prototype);
3192 define("ace/lib/es5-shim",["require","exports","module"], function(require, exports, module) {
3196 if (!Function.prototype.bind) {
3197 Function.prototype.bind = function bind(that) { // .length is 1
3199 if (typeof target != "function") {
3200 throw new TypeError("Function.prototype.bind called on incompatible " + target);
3202 var args = slice.call(arguments, 1); // for normal call
3203 var bound = function () {
3205 if (this instanceof bound) {
3207 var result = target.apply(
3209 args.concat(slice.call(arguments))
3211 if (Object(result) === result) {
3217 return target.apply(
3219 args.concat(slice.call(arguments))
3225 if(target.prototype) {
3226 Empty.prototype = target.prototype;
3227 bound.prototype = new Empty();
3228 Empty.prototype = null;
3233 var call = Function.prototype.call;
3234 var prototypeOfArray = Array.prototype;
3235 var prototypeOfObject = Object.prototype;
3236 var slice = prototypeOfArray.slice;
3237 var _toString = call.bind(prototypeOfObject.toString);
3238 var owns = call.bind(prototypeOfObject.hasOwnProperty);
3243 var supportsAccessors;
3244 if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
3245 defineGetter = call.bind(prototypeOfObject.__defineGetter__);
3246 defineSetter = call.bind(prototypeOfObject.__defineSetter__);
3247 lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
3248 lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
3250 if ([1,2].splice(0).length != 2) {
3251 if(function() { // test IE < 9 to splice bug - see issue #138
3252 function makeArray(l) {
3253 var a = new Array(l+2);
3257 var array = [], lengthBefore;
3259 array.splice.apply(array, makeArray(20));
3260 array.splice.apply(array, makeArray(26));
3262 lengthBefore = array.length; //46
3263 array.splice(5, 0, "XXX"); // add one element
3265 lengthBefore + 1 == array.length
3267 if (lengthBefore + 1 == array.length) {
3268 return true;// has right splice implementation without bugs
3271 var array_splice = Array.prototype.splice;
3272 Array.prototype.splice = function(start, deleteCount) {
3273 if (!arguments.length) {
3276 return array_splice.apply(this, [
3277 start === void 0 ? 0 : start,
3278 deleteCount === void 0 ? (this.length - start) : deleteCount
3279 ].concat(slice.call(arguments, 2)))
3283 Array.prototype.splice = function(pos, removeCount){
3284 var length = this.length;
3288 } else if (pos == void 0) {
3290 } else if (pos < 0) {
3291 pos = Math.max(length + pos, 0);
3294 if (!(pos+removeCount < length))
3295 removeCount = length - pos;
3297 var removed = this.slice(pos, pos+removeCount);
3298 var insert = slice.call(arguments, 2);
3299 var add = insert.length;
3300 if (pos === length) {
3302 this.push.apply(this, insert);
3305 var remove = Math.min(removeCount, length - pos);
3306 var tailOldPos = pos + remove;
3307 var tailNewPos = tailOldPos + add - remove;
3308 var tailCount = length - tailOldPos;
3309 var lengthAfterRemove = length - remove;
3311 if (tailNewPos < tailOldPos) { // case A
3312 for (var i = 0; i < tailCount; ++i) {
3313 this[tailNewPos+i] = this[tailOldPos+i];
3315 } else if (tailNewPos > tailOldPos) { // case B
3316 for (i = tailCount; i--; ) {
3317 this[tailNewPos+i] = this[tailOldPos+i];
3319 } // else, add == remove (nothing to do)
3321 if (add && pos === lengthAfterRemove) {
3322 this.length = lengthAfterRemove; // truncate array
3323 this.push.apply(this, insert);
3325 this.length = lengthAfterRemove + add; // reserves space
3326 for (i = 0; i < add; ++i) {
3327 this[pos+i] = insert[i];
3335 if (!Array.isArray) {
3336 Array.isArray = function isArray(obj) {
3337 return _toString(obj) == "[object Array]";
3340 var boxedString = Object("a"),
3341 splitString = boxedString[0] != "a" || !(0 in boxedString);
3343 if (!Array.prototype.forEach) {
3344 Array.prototype.forEach = function forEach(fun /*, thisp*/) {
3345 var object = toObject(this),
3346 self = splitString && _toString(this) == "[object String]" ?
3349 thisp = arguments[1],
3351 length = self.length >>> 0;
3352 if (_toString(fun) != "[object Function]") {
3353 throw new TypeError(); // TODO message
3356 while (++i < length) {
3358 fun.call(thisp, self[i], i, object);
3363 if (!Array.prototype.map) {
3364 Array.prototype.map = function map(fun /*, thisp*/) {
3365 var object = toObject(this),
3366 self = splitString && _toString(this) == "[object String]" ?
3369 length = self.length >>> 0,
3370 result = Array(length),
3371 thisp = arguments[1];
3372 if (_toString(fun) != "[object Function]") {
3373 throw new TypeError(fun + " is not a function");
3376 for (var i = 0; i < length; i++) {
3378 result[i] = fun.call(thisp, self[i], i, object);
3383 if (!Array.prototype.filter) {
3384 Array.prototype.filter = function filter(fun /*, thisp */) {
3385 var object = toObject(this),
3386 self = splitString && _toString(this) == "[object String]" ?
3389 length = self.length >>> 0,
3392 thisp = arguments[1];
3393 if (_toString(fun) != "[object Function]") {
3394 throw new TypeError(fun + " is not a function");
3397 for (var i = 0; i < length; i++) {
3400 if (fun.call(thisp, value, i, object)) {
3408 if (!Array.prototype.every) {
3409 Array.prototype.every = function every(fun /*, thisp */) {
3410 var object = toObject(this),
3411 self = splitString && _toString(this) == "[object String]" ?
3414 length = self.length >>> 0,
3415 thisp = arguments[1];
3416 if (_toString(fun) != "[object Function]") {
3417 throw new TypeError(fun + " is not a function");
3420 for (var i = 0; i < length; i++) {
3421 if (i in self && !fun.call(thisp, self[i], i, object)) {
3428 if (!Array.prototype.some) {
3429 Array.prototype.some = function some(fun /*, thisp */) {
3430 var object = toObject(this),
3431 self = splitString && _toString(this) == "[object String]" ?
3434 length = self.length >>> 0,
3435 thisp = arguments[1];
3436 if (_toString(fun) != "[object Function]") {
3437 throw new TypeError(fun + " is not a function");
3440 for (var i = 0; i < length; i++) {
3441 if (i in self && fun.call(thisp, self[i], i, object)) {
3448 if (!Array.prototype.reduce) {
3449 Array.prototype.reduce = function reduce(fun /*, initial*/) {
3450 var object = toObject(this),
3451 self = splitString && _toString(this) == "[object String]" ?
3454 length = self.length >>> 0;
3455 if (_toString(fun) != "[object Function]") {
3456 throw new TypeError(fun + " is not a function");
3458 if (!length && arguments.length == 1) {
3459 throw new TypeError("reduce of empty array with no initial value");
3464 if (arguments.length >= 2) {
3465 result = arguments[1];
3472 if (++i >= length) {
3473 throw new TypeError("reduce of empty array with no initial value");
3478 for (; i < length; i++) {
3480 result = fun.call(void 0, result, self[i], i, object);
3487 if (!Array.prototype.reduceRight) {
3488 Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
3489 var object = toObject(this),
3490 self = splitString && _toString(this) == "[object String]" ?
3493 length = self.length >>> 0;
3494 if (_toString(fun) != "[object Function]") {
3495 throw new TypeError(fun + " is not a function");
3497 if (!length && arguments.length == 1) {
3498 throw new TypeError("reduceRight of empty array with no initial value");
3501 var result, i = length - 1;
3502 if (arguments.length >= 2) {
3503 result = arguments[1];
3511 throw new TypeError("reduceRight of empty array with no initial value");
3518 result = fun.call(void 0, result, self[i], i, object);
3525 if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) {
3526 Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
3527 var self = splitString && _toString(this) == "[object String]" ?
3530 length = self.length >>> 0;
3537 if (arguments.length > 1) {
3538 i = toInteger(arguments[1]);
3540 i = i >= 0 ? i : Math.max(0, length + i);
3541 for (; i < length; i++) {
3542 if (i in self && self[i] === sought) {
3549 if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
3550 Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
3551 var self = splitString && _toString(this) == "[object String]" ?
3554 length = self.length >>> 0;
3560 if (arguments.length > 1) {
3561 i = Math.min(i, toInteger(arguments[1]));
3563 i = i >= 0 ? i : length - Math.abs(i);
3564 for (; i >= 0; i--) {
3565 if (i in self && sought === self[i]) {
3572 if (!Object.getPrototypeOf) {
3573 Object.getPrototypeOf = function getPrototypeOf(object) {
3574 return object.__proto__ || (
3575 object.constructor ?
3576 object.constructor.prototype :
3581 if (!Object.getOwnPropertyDescriptor) {
3582 var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a " +
3584 Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) {
3585 if ((typeof object != "object" && typeof object != "function") || object === null)
3586 throw new TypeError(ERR_NON_OBJECT + object);
3587 if (!owns(object, property))
3590 var descriptor, getter, setter;
3591 descriptor = { enumerable: true, configurable: true };
3592 if (supportsAccessors) {
3593 var prototype = object.__proto__;
3594 object.__proto__ = prototypeOfObject;
3596 var getter = lookupGetter(object, property);
3597 var setter = lookupSetter(object, property);
3598 object.__proto__ = prototype;
3600 if (getter || setter) {
3601 if (getter) descriptor.get = getter;
3602 if (setter) descriptor.set = setter;
3606 descriptor.value = object[property];
3610 if (!Object.getOwnPropertyNames) {
3611 Object.getOwnPropertyNames = function getOwnPropertyNames(object) {
3612 return Object.keys(object);
3615 if (!Object.create) {
3617 if (Object.prototype.__proto__ === null) {
3618 createEmpty = function () {
3619 return { "__proto__": null };
3622 createEmpty = function () {
3624 for (var i in empty)
3627 empty.hasOwnProperty =
3628 empty.propertyIsEnumerable =
3629 empty.isPrototypeOf =
3630 empty.toLocaleString =
3633 empty.__proto__ = null;
3638 Object.create = function create(prototype, properties) {
3640 if (prototype === null) {
3641 object = createEmpty();
3643 if (typeof prototype != "object")
3644 throw new TypeError("typeof prototype["+(typeof prototype)+"] != 'object'");
3645 var Type = function () {};
3646 Type.prototype = prototype;
3647 object = new Type();
3648 object.__proto__ = prototype;
3650 if (properties !== void 0)
3651 Object.defineProperties(object, properties);
3656 function doesDefinePropertyWork(object) {
3658 Object.defineProperty(object, "sentinel", {});
3659 return "sentinel" in object;
3660 } catch (exception) {
3663 if (Object.defineProperty) {
3664 var definePropertyWorksOnObject = doesDefinePropertyWork({});
3665 var definePropertyWorksOnDom = typeof document == "undefined" ||
3666 doesDefinePropertyWork(document.createElement("div"));
3667 if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) {
3668 var definePropertyFallback = Object.defineProperty;
3672 if (!Object.defineProperty || definePropertyFallback) {
3673 var ERR_NON_OBJECT_DESCRIPTOR = "Property description must be an object: ";
3674 var ERR_NON_OBJECT_TARGET = "Object.defineProperty called on non-object: "
3675 var ERR_ACCESSORS_NOT_SUPPORTED = "getters & setters can not be defined " +
3676 "on this javascript engine";
3678 Object.defineProperty = function defineProperty(object, property, descriptor) {
3679 if ((typeof object != "object" && typeof object != "function") || object === null)
3680 throw new TypeError(ERR_NON_OBJECT_TARGET + object);
3681 if ((typeof descriptor != "object" && typeof descriptor != "function") || descriptor === null)
3682 throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor);
3683 if (definePropertyFallback) {
3685 return definePropertyFallback.call(Object, object, property, descriptor);
3686 } catch (exception) {
3689 if (owns(descriptor, "value")) {
3691 if (supportsAccessors && (lookupGetter(object, property) ||
3692 lookupSetter(object, property)))
3694 var prototype = object.__proto__;
3695 object.__proto__ = prototypeOfObject;
3696 delete object[property];
3697 object[property] = descriptor.value;
3698 object.__proto__ = prototype;
3700 object[property] = descriptor.value;
3703 if (!supportsAccessors)
3704 throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
3705 if (owns(descriptor, "get"))
3706 defineGetter(object, property, descriptor.get);
3707 if (owns(descriptor, "set"))
3708 defineSetter(object, property, descriptor.set);
3714 if (!Object.defineProperties) {
3715 Object.defineProperties = function defineProperties(object, properties) {
3716 for (var property in properties) {
3717 if (owns(properties, property))
3718 Object.defineProperty(object, property, properties[property]);
3724 Object.seal = function seal(object) {
3728 if (!Object.freeze) {
3729 Object.freeze = function freeze(object) {
3734 Object.freeze(function () {});
3735 } catch (exception) {
3736 Object.freeze = (function freeze(freezeObject) {
3737 return function freeze(object) {
3738 if (typeof object == "function") {
3741 return freezeObject(object);
3746 if (!Object.preventExtensions) {
3747 Object.preventExtensions = function preventExtensions(object) {
3751 if (!Object.isSealed) {
3752 Object.isSealed = function isSealed(object) {
3756 if (!Object.isFrozen) {
3757 Object.isFrozen = function isFrozen(object) {
3761 if (!Object.isExtensible) {
3762 Object.isExtensible = function isExtensible(object) {
3763 if (Object(object) === object) {
3764 throw new TypeError(); // TODO message
3767 while (owns(object, name)) {
3770 object[name] = true;
3771 var returnValue = owns(object, name);
3772 delete object[name];
3777 var hasDontEnumBug = true,
3784 "propertyIsEnumerable",
3787 dontEnumsLength = dontEnums.length;
3789 for (var key in {"toString": null}) {
3790 hasDontEnumBug = false;
3793 Object.keys = function keys(object) {
3796 (typeof object != "object" && typeof object != "function") ||
3799 throw new TypeError("Object.keys called on a non-object");
3803 for (var name in object) {
3804 if (owns(object, name)) {
3809 if (hasDontEnumBug) {
3810 for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
3811 var dontEnum = dontEnums[i];
3812 if (owns(object, dontEnum)) {
3813 keys.push(dontEnum);
3822 Date.now = function now() {
3823 return new Date().getTime();
3826 var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
3827 "\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
3829 if (!String.prototype.trim || ws.trim()) {
3830 ws = "[" + ws + "]";
3831 var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
3832 trimEndRegexp = new RegExp(ws + ws + "*$");
3833 String.prototype.trim = function trim() {
3834 return String(this).replace(trimBeginRegexp, "").replace(trimEndRegexp, "");
3838 function toInteger(n) {
3840 if (n !== n) { // isNaN
3842 } else if (n !== 0 && n !== (1/0) && n !== -(1/0)) {
3843 n = (n > 0 || -1) * Math.floor(Math.abs(n));
3848 function isPrimitive(input) {
3849 var type = typeof input;
3852 type === "undefined" ||
3853 type === "boolean" ||
3854 type === "number" ||
3859 function toPrimitive(input) {
3860 var val, valueOf, toString;
3861 if (isPrimitive(input)) {
3864 valueOf = input.valueOf;
3865 if (typeof valueOf === "function") {
3866 val = valueOf.call(input);
3867 if (isPrimitive(val)) {
3871 toString = input.toString;
3872 if (typeof toString === "function") {
3873 val = toString.call(input);
3874 if (isPrimitive(val)) {
3878 throw new TypeError();
3880 var toObject = function (o) {
3881 if (o == null) { // this matches both null and undefined
3882 throw new TypeError("can't convert "+o+" to object");