Chinthakayala,Sheshashailavas(sc2914) | 8f6a6c4 | 2018-06-27 16:11:44 +0000 | [diff] [blame] | 1 | "no use strict"; |
| 2 | !(function(window) { |
| 3 | if (typeof window.window != "undefined" && window.document) |
| 4 | return; |
| 5 | if (window.require && window.define) |
| 6 | return; |
| 7 | |
| 8 | if (!window.console) { |
| 9 | window.console = function() { |
| 10 | var msgs = Array.prototype.slice.call(arguments, 0); |
| 11 | postMessage({type: "log", data: msgs}); |
| 12 | }; |
| 13 | window.console.error = |
| 14 | window.console.warn = |
| 15 | window.console.log = |
| 16 | window.console.trace = window.console; |
| 17 | } |
| 18 | window.window = window; |
| 19 | window.ace = window; |
| 20 | |
| 21 | window.onerror = function(message, file, line, col, err) { |
| 22 | postMessage({type: "error", data: { |
| 23 | message: message, |
| 24 | data: err.data, |
| 25 | file: file, |
| 26 | line: line, |
| 27 | col: col, |
| 28 | stack: err.stack |
| 29 | }}); |
| 30 | }; |
| 31 | |
| 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]); |
| 37 | } |
| 38 | // normalize relative requires |
| 39 | if (moduleName.charAt(0) == ".") { |
| 40 | var base = parentId.split("/").slice(0, -1).join("/"); |
| 41 | moduleName = (base ? base + "/" : "") + moduleName; |
| 42 | |
| 43 | while (moduleName.indexOf(".") !== -1 && previous != moduleName) { |
| 44 | var previous = moduleName; |
| 45 | moduleName = moduleName.replace(/^\.\//, "").replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, ""); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | return moduleName; |
| 50 | }; |
| 51 | |
| 52 | window.require = function require(parentId, id) { |
| 53 | if (!id) { |
| 54 | id = parentId; |
| 55 | parentId = null; |
| 56 | } |
| 57 | if (!id.charAt) |
| 58 | throw new Error("worker.js require() accepts only (parentId, id) as arguments"); |
| 59 | |
| 60 | id = window.normalizeModule(parentId, id); |
| 61 | |
| 62 | var module = window.require.modules[id]; |
| 63 | if (module) { |
| 64 | if (!module.initialized) { |
| 65 | module.initialized = true; |
| 66 | module.exports = module.factory().exports; |
| 67 | } |
| 68 | return module.exports; |
| 69 | } |
| 70 | |
| 71 | if (!window.require.tlns) |
| 72 | return console.log("unable to load " + id); |
| 73 | |
| 74 | var path = resolveModuleId(id, window.require.tlns); |
| 75 | if (path.slice(-3) != ".js") path += ".js"; |
| 76 | |
| 77 | window.require.id = id; |
| 78 | window.require.modules[id] = {}; // prevent infinite loop on broken modules |
| 79 | importScripts(path); |
| 80 | return window.require(parentId, id); |
| 81 | }; |
| 82 | function resolveModuleId(id, paths) { |
| 83 | var testPath = id, tail = ""; |
| 84 | while (testPath) { |
| 85 | var alias = paths[testPath]; |
| 86 | if (typeof alias == "string") { |
| 87 | return alias + tail; |
| 88 | } else if (alias) { |
| 89 | return alias.location.replace(/\/*$/, "/") + (tail || alias.main || alias.name); |
| 90 | } else if (alias === false) { |
| 91 | return ""; |
| 92 | } |
| 93 | var i = testPath.lastIndexOf("/"); |
| 94 | if (i === -1) break; |
| 95 | tail = testPath.substr(i) + tail; |
| 96 | testPath = testPath.slice(0, i); |
| 97 | } |
| 98 | return id; |
| 99 | } |
| 100 | window.require.modules = {}; |
| 101 | window.require.tlns = {}; |
| 102 | |
| 103 | window.define = function(id, deps, factory) { |
| 104 | if (arguments.length == 2) { |
| 105 | factory = deps; |
| 106 | if (typeof id != "string") { |
| 107 | deps = id; |
| 108 | id = window.require.id; |
| 109 | } |
| 110 | } else if (arguments.length == 1) { |
| 111 | factory = id; |
| 112 | deps = []; |
| 113 | id = window.require.id; |
| 114 | } |
| 115 | |
| 116 | if (typeof factory != "function") { |
| 117 | window.require.modules[id] = { |
| 118 | exports: factory, |
| 119 | initialized: true |
| 120 | }; |
| 121 | return; |
| 122 | } |
| 123 | |
| 124 | if (!deps.length) |
| 125 | // If there is no dependencies, we inject "require", "exports" and |
| 126 | // "module" as dependencies, to provide CommonJS compatibility. |
| 127 | deps = ["require", "exports", "module"]; |
| 128 | |
| 129 | var req = function(childId) { |
| 130 | return window.require(id, childId); |
| 131 | }; |
| 132 | |
| 133 | window.require.modules[id] = { |
| 134 | exports: {}, |
| 135 | factory: function() { |
| 136 | var module = this; |
| 137 | var returnExports = factory.apply(this, deps.map(function(dep) { |
| 138 | switch (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 |
| 145 | // require them. |
| 146 | default: return req(dep); |
| 147 | } |
| 148 | })); |
| 149 | if (returnExports) |
| 150 | module.exports = returnExports; |
| 151 | return module; |
| 152 | } |
| 153 | }; |
| 154 | }; |
| 155 | window.define.amd = {}; |
| 156 | require.tlns = {}; |
| 157 | window.initBaseUrls = function initBaseUrls(topLevelNamespaces) { |
| 158 | for (var i in topLevelNamespaces) |
| 159 | require.tlns[i] = topLevelNamespaces[i]; |
| 160 | }; |
| 161 | |
| 162 | window.initSender = function initSender() { |
| 163 | |
| 164 | var EventEmitter = window.require("ace/lib/event_emitter").EventEmitter; |
| 165 | var oop = window.require("ace/lib/oop"); |
| 166 | |
| 167 | var Sender = function() {}; |
| 168 | |
| 169 | (function() { |
| 170 | |
| 171 | oop.implement(this, EventEmitter); |
| 172 | |
| 173 | this.callback = function(data, callbackId) { |
| 174 | postMessage({ |
| 175 | type: "call", |
| 176 | id: callbackId, |
| 177 | data: data |
| 178 | }); |
| 179 | }; |
| 180 | |
| 181 | this.emit = function(name, data) { |
| 182 | postMessage({ |
| 183 | type: "event", |
| 184 | name: name, |
| 185 | data: data |
| 186 | }); |
| 187 | }; |
| 188 | |
| 189 | }).call(Sender.prototype); |
| 190 | |
| 191 | return new Sender(); |
| 192 | }; |
| 193 | |
| 194 | var main = window.main = null; |
| 195 | var sender = window.sender = null; |
| 196 | |
| 197 | window.onmessage = function(e) { |
| 198 | var msg = e.data; |
| 199 | if (msg.event && sender) { |
| 200 | sender._signal(msg.event, msg.data); |
| 201 | } |
| 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); |
| 207 | else |
| 208 | throw new Error("Unknown command:" + msg.command); |
| 209 | } |
| 210 | else if (msg.init) { |
| 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); |
| 216 | } |
| 217 | }; |
| 218 | })(this); |
| 219 | |
| 220 | define("ace/lib/oop",["require","exports","module"], function(require, exports, module) { |
| 221 | "use strict"; |
| 222 | |
| 223 | exports.inherits = function(ctor, superCtor) { |
| 224 | ctor.super_ = superCtor; |
| 225 | ctor.prototype = Object.create(superCtor.prototype, { |
| 226 | constructor: { |
| 227 | value: ctor, |
| 228 | enumerable: false, |
| 229 | writable: true, |
| 230 | configurable: true |
| 231 | } |
| 232 | }); |
| 233 | }; |
| 234 | |
| 235 | exports.mixin = function(obj, mixin) { |
| 236 | for (var key in mixin) { |
| 237 | obj[key] = mixin[key]; |
| 238 | } |
| 239 | return obj; |
| 240 | }; |
| 241 | |
| 242 | exports.implement = function(proto, mixin) { |
| 243 | exports.mixin(proto, mixin); |
| 244 | }; |
| 245 | |
| 246 | }); |
| 247 | |
| 248 | define("ace/lib/lang",["require","exports","module"], function(require, exports, module) { |
| 249 | "use strict"; |
| 250 | |
| 251 | exports.last = function(a) { |
| 252 | return a[a.length - 1]; |
| 253 | }; |
| 254 | |
| 255 | exports.stringReverse = function(string) { |
| 256 | return string.split("").reverse().join(""); |
| 257 | }; |
| 258 | |
| 259 | exports.stringRepeat = function (string, count) { |
| 260 | var result = ''; |
| 261 | while (count > 0) { |
| 262 | if (count & 1) |
| 263 | result += string; |
| 264 | |
| 265 | if (count >>= 1) |
| 266 | string += string; |
| 267 | } |
| 268 | return result; |
| 269 | }; |
| 270 | |
| 271 | var trimBeginRegexp = /^\s\s*/; |
| 272 | var trimEndRegexp = /\s\s*$/; |
| 273 | |
| 274 | exports.stringTrimLeft = function (string) { |
| 275 | return string.replace(trimBeginRegexp, ''); |
| 276 | }; |
| 277 | |
| 278 | exports.stringTrimRight = function (string) { |
| 279 | return string.replace(trimEndRegexp, ''); |
| 280 | }; |
| 281 | |
| 282 | exports.copyObject = function(obj) { |
| 283 | var copy = {}; |
| 284 | for (var key in obj) { |
| 285 | copy[key] = obj[key]; |
| 286 | } |
| 287 | return copy; |
| 288 | }; |
| 289 | |
| 290 | exports.copyArray = function(array){ |
| 291 | var copy = []; |
| 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]); |
| 295 | else |
| 296 | copy[i] = array[i]; |
| 297 | } |
| 298 | return copy; |
| 299 | }; |
| 300 | |
| 301 | exports.deepCopy = function deepCopy(obj) { |
| 302 | if (typeof obj !== "object" || !obj) |
| 303 | return obj; |
| 304 | var copy; |
| 305 | if (Array.isArray(obj)) { |
| 306 | copy = []; |
| 307 | for (var key = 0; key < obj.length; key++) { |
| 308 | copy[key] = deepCopy(obj[key]); |
| 309 | } |
| 310 | return copy; |
| 311 | } |
| 312 | if (Object.prototype.toString.call(obj) !== "[object Object]") |
| 313 | return obj; |
| 314 | |
| 315 | copy = {}; |
| 316 | for (var key in obj) |
| 317 | copy[key] = deepCopy(obj[key]); |
| 318 | return copy; |
| 319 | }; |
| 320 | |
| 321 | exports.arrayToMap = function(arr) { |
| 322 | var map = {}; |
| 323 | for (var i=0; i<arr.length; i++) { |
| 324 | map[arr[i]] = 1; |
| 325 | } |
| 326 | return map; |
| 327 | |
| 328 | }; |
| 329 | |
| 330 | exports.createMap = function(props) { |
| 331 | var map = Object.create(null); |
| 332 | for (var i in props) { |
| 333 | map[i] = props[i]; |
| 334 | } |
| 335 | return map; |
| 336 | }; |
| 337 | exports.arrayRemove = function(array, value) { |
| 338 | for (var i = 0; i <= array.length; i++) { |
| 339 | if (value === array[i]) { |
| 340 | array.splice(i, 1); |
| 341 | } |
| 342 | } |
| 343 | }; |
| 344 | |
| 345 | exports.escapeRegExp = function(str) { |
| 346 | return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1'); |
| 347 | }; |
| 348 | |
| 349 | exports.escapeHTML = function(str) { |
| 350 | return str.replace(/&/g, "&").replace(/"/g, """).replace(/'/g, "'").replace(/</g, "<"); |
| 351 | }; |
| 352 | |
| 353 | exports.getMatchOffsets = function(string, regExp) { |
| 354 | var matches = []; |
| 355 | |
| 356 | string.replace(regExp, function(str) { |
| 357 | matches.push({ |
| 358 | offset: arguments[arguments.length-2], |
| 359 | length: str.length |
| 360 | }); |
| 361 | }); |
| 362 | |
| 363 | return matches; |
| 364 | }; |
| 365 | exports.deferredCall = function(fcn) { |
| 366 | var timer = null; |
| 367 | var callback = function() { |
| 368 | timer = null; |
| 369 | fcn(); |
| 370 | }; |
| 371 | |
| 372 | var deferred = function(timeout) { |
| 373 | deferred.cancel(); |
| 374 | timer = setTimeout(callback, timeout || 0); |
| 375 | return deferred; |
| 376 | }; |
| 377 | |
| 378 | deferred.schedule = deferred; |
| 379 | |
| 380 | deferred.call = function() { |
| 381 | this.cancel(); |
| 382 | fcn(); |
| 383 | return deferred; |
| 384 | }; |
| 385 | |
| 386 | deferred.cancel = function() { |
| 387 | clearTimeout(timer); |
| 388 | timer = null; |
| 389 | return deferred; |
| 390 | }; |
| 391 | |
| 392 | deferred.isPending = function() { |
| 393 | return timer; |
| 394 | }; |
| 395 | |
| 396 | return deferred; |
| 397 | }; |
| 398 | |
| 399 | |
| 400 | exports.delayedCall = function(fcn, defaultTimeout) { |
| 401 | var timer = null; |
| 402 | var callback = function() { |
| 403 | timer = null; |
| 404 | fcn(); |
| 405 | }; |
| 406 | |
| 407 | var _self = function(timeout) { |
| 408 | if (timer == null) |
| 409 | timer = setTimeout(callback, timeout || defaultTimeout); |
| 410 | }; |
| 411 | |
| 412 | _self.delay = function(timeout) { |
| 413 | timer && clearTimeout(timer); |
| 414 | timer = setTimeout(callback, timeout || defaultTimeout); |
| 415 | }; |
| 416 | _self.schedule = _self; |
| 417 | |
| 418 | _self.call = function() { |
| 419 | this.cancel(); |
| 420 | fcn(); |
| 421 | }; |
| 422 | |
| 423 | _self.cancel = function() { |
| 424 | timer && clearTimeout(timer); |
| 425 | timer = null; |
| 426 | }; |
| 427 | |
| 428 | _self.isPending = function() { |
| 429 | return timer; |
| 430 | }; |
| 431 | |
| 432 | return _self; |
| 433 | }; |
| 434 | }); |
| 435 | |
| 436 | define("ace/range",["require","exports","module"], function(require, exports, module) { |
| 437 | "use strict"; |
| 438 | var comparePoints = function(p1, p2) { |
| 439 | return p1.row - p2.row || p1.column - p2.column; |
| 440 | }; |
| 441 | var Range = function(startRow, startColumn, endRow, endColumn) { |
| 442 | this.start = { |
| 443 | row: startRow, |
| 444 | column: startColumn |
| 445 | }; |
| 446 | |
| 447 | this.end = { |
| 448 | row: endRow, |
| 449 | column: endColumn |
| 450 | }; |
| 451 | }; |
| 452 | |
| 453 | (function() { |
| 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; |
| 459 | }; |
| 460 | this.toString = function() { |
| 461 | return ("Range: [" + this.start.row + "/" + this.start.column + |
| 462 | "] -> [" + this.end.row + "/" + this.end.column + "]"); |
| 463 | }; |
| 464 | |
| 465 | this.contains = function(row, column) { |
| 466 | return this.compare(row, column) == 0; |
| 467 | }; |
| 468 | this.compareRange = function(range) { |
| 469 | var cmp, |
| 470 | end = range.end, |
| 471 | start = range.start; |
| 472 | |
| 473 | cmp = this.compare(end.row, end.column); |
| 474 | if (cmp == 1) { |
| 475 | cmp = this.compare(start.row, start.column); |
| 476 | if (cmp == 1) { |
| 477 | return 2; |
| 478 | } else if (cmp == 0) { |
| 479 | return 1; |
| 480 | } else { |
| 481 | return 0; |
| 482 | } |
| 483 | } else if (cmp == -1) { |
| 484 | return -2; |
| 485 | } else { |
| 486 | cmp = this.compare(start.row, start.column); |
| 487 | if (cmp == -1) { |
| 488 | return -1; |
| 489 | } else if (cmp == 1) { |
| 490 | return 42; |
| 491 | } else { |
| 492 | return 0; |
| 493 | } |
| 494 | } |
| 495 | }; |
| 496 | this.comparePoint = function(p) { |
| 497 | return this.compare(p.row, p.column); |
| 498 | }; |
| 499 | this.containsRange = function(range) { |
| 500 | return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0; |
| 501 | }; |
| 502 | this.intersects = function(range) { |
| 503 | var cmp = this.compareRange(range); |
| 504 | return (cmp == -1 || cmp == 0 || cmp == 1); |
| 505 | }; |
| 506 | this.isEnd = function(row, column) { |
| 507 | return this.end.row == row && this.end.column == column; |
| 508 | }; |
| 509 | this.isStart = function(row, column) { |
| 510 | return this.start.row == row && this.start.column == column; |
| 511 | }; |
| 512 | this.setStart = function(row, column) { |
| 513 | if (typeof row == "object") { |
| 514 | this.start.column = row.column; |
| 515 | this.start.row = row.row; |
| 516 | } else { |
| 517 | this.start.row = row; |
| 518 | this.start.column = column; |
| 519 | } |
| 520 | }; |
| 521 | this.setEnd = function(row, column) { |
| 522 | if (typeof row == "object") { |
| 523 | this.end.column = row.column; |
| 524 | this.end.row = row.row; |
| 525 | } else { |
| 526 | this.end.row = row; |
| 527 | this.end.column = column; |
| 528 | } |
| 529 | }; |
| 530 | this.inside = function(row, column) { |
| 531 | if (this.compare(row, column) == 0) { |
| 532 | if (this.isEnd(row, column) || this.isStart(row, column)) { |
| 533 | return false; |
| 534 | } else { |
| 535 | return true; |
| 536 | } |
| 537 | } |
| 538 | return false; |
| 539 | }; |
| 540 | this.insideStart = function(row, column) { |
| 541 | if (this.compare(row, column) == 0) { |
| 542 | if (this.isEnd(row, column)) { |
| 543 | return false; |
| 544 | } else { |
| 545 | return true; |
| 546 | } |
| 547 | } |
| 548 | return false; |
| 549 | }; |
| 550 | this.insideEnd = function(row, column) { |
| 551 | if (this.compare(row, column) == 0) { |
| 552 | if (this.isStart(row, column)) { |
| 553 | return false; |
| 554 | } else { |
| 555 | return true; |
| 556 | } |
| 557 | } |
| 558 | return false; |
| 559 | }; |
| 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); |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | if (row < this.start.row) |
| 568 | return -1; |
| 569 | |
| 570 | if (row > this.end.row) |
| 571 | return 1; |
| 572 | |
| 573 | if (this.start.row === row) |
| 574 | return column >= this.start.column ? 0 : -1; |
| 575 | |
| 576 | if (this.end.row === row) |
| 577 | return column <= this.end.column ? 0 : 1; |
| 578 | |
| 579 | return 0; |
| 580 | }; |
| 581 | this.compareStart = function(row, column) { |
| 582 | if (this.start.row == row && this.start.column == column) { |
| 583 | return -1; |
| 584 | } else { |
| 585 | return this.compare(row, column); |
| 586 | } |
| 587 | }; |
| 588 | this.compareEnd = function(row, column) { |
| 589 | if (this.end.row == row && this.end.column == column) { |
| 590 | return 1; |
| 591 | } else { |
| 592 | return this.compare(row, column); |
| 593 | } |
| 594 | }; |
| 595 | this.compareInside = function(row, column) { |
| 596 | if (this.end.row == row && this.end.column == column) { |
| 597 | return 1; |
| 598 | } else if (this.start.row == row && this.start.column == column) { |
| 599 | return -1; |
| 600 | } else { |
| 601 | return this.compare(row, column); |
| 602 | } |
| 603 | }; |
| 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}; |
| 609 | |
| 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}; |
| 614 | |
| 615 | return Range.fromPoints(start || this.start, end || this.end); |
| 616 | }; |
| 617 | this.extend = function(row, column) { |
| 618 | var cmp = this.compare(row, column); |
| 619 | |
| 620 | if (cmp == 0) |
| 621 | return this; |
| 622 | else if (cmp == -1) |
| 623 | var start = {row: row, column: column}; |
| 624 | else |
| 625 | var end = {row: row, column: column}; |
| 626 | |
| 627 | return Range.fromPoints(start || this.start, end || this.end); |
| 628 | }; |
| 629 | |
| 630 | this.isEmpty = function() { |
| 631 | return (this.start.row === this.end.row && this.start.column === this.end.column); |
| 632 | }; |
| 633 | this.isMultiLine = function() { |
| 634 | return (this.start.row !== this.end.row); |
| 635 | }; |
| 636 | this.clone = function() { |
| 637 | return Range.fromPoints(this.start, this.end); |
| 638 | }; |
| 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); |
| 642 | else |
| 643 | return new Range(this.start.row, 0, this.end.row, 0); |
| 644 | }; |
| 645 | this.toScreenRange = function(session) { |
| 646 | var screenPosStart = session.documentToScreenPosition(this.start); |
| 647 | var screenPosEnd = session.documentToScreenPosition(this.end); |
| 648 | |
| 649 | return new Range( |
| 650 | screenPosStart.row, screenPosStart.column, |
| 651 | screenPosEnd.row, screenPosEnd.column |
| 652 | ); |
| 653 | }; |
| 654 | this.moveBy = function(row, column) { |
| 655 | this.start.row += row; |
| 656 | this.start.column += column; |
| 657 | this.end.row += row; |
| 658 | this.end.column += column; |
| 659 | }; |
| 660 | |
| 661 | }).call(Range.prototype); |
| 662 | Range.fromPoints = function(start, end) { |
| 663 | return new Range(start.row, start.column, end.row, end.column); |
| 664 | }; |
| 665 | Range.comparePoints = comparePoints; |
| 666 | |
| 667 | Range.comparePoints = function(p1, p2) { |
| 668 | return p1.row - p2.row || p1.column - p2.column; |
| 669 | }; |
| 670 | |
| 671 | |
| 672 | exports.Range = Range; |
| 673 | }); |
| 674 | |
| 675 | define("ace/apply_delta",["require","exports","module"], function(require, exports, module) { |
| 676 | "use strict"; |
| 677 | |
| 678 | function throwDeltaError(delta, errorText){ |
| 679 | console.log("Invalid Delta:", delta); |
| 680 | throw "Invalid Delta: " + errorText; |
| 681 | } |
| 682 | |
| 683 | function positionInDocument(docLines, position) { |
| 684 | return position.row >= 0 && position.row < docLines.length && |
| 685 | position.column >= 0 && position.column <= docLines[position.row].length; |
| 686 | } |
| 687 | |
| 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"); |
| 698 | var end = delta.end; |
| 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"); |
| 705 | } |
| 706 | |
| 707 | exports.applyDelta = function(docLines, delta, doNotValidate) { |
| 708 | |
| 709 | var row = delta.start.row; |
| 710 | var startColumn = delta.start.column; |
| 711 | var line = docLines[row] || ""; |
| 712 | switch (delta.action) { |
| 713 | case "insert": |
| 714 | var lines = delta.lines; |
| 715 | if (lines.length === 1) { |
| 716 | docLines[row] = line.substring(0, startColumn) + delta.lines[0] + line.substring(startColumn); |
| 717 | } else { |
| 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); |
| 722 | } |
| 723 | break; |
| 724 | case "remove": |
| 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); |
| 729 | } else { |
| 730 | docLines.splice( |
| 731 | row, endRow - row + 1, |
| 732 | line.substring(0, startColumn) + docLines[endRow].substring(endColumn) |
| 733 | ); |
| 734 | } |
| 735 | break; |
| 736 | } |
| 737 | }; |
| 738 | }); |
| 739 | |
| 740 | define("ace/lib/event_emitter",["require","exports","module"], function(require, exports, module) { |
| 741 | "use strict"; |
| 742 | |
| 743 | var EventEmitter = {}; |
| 744 | var stopPropagation = function() { this.propagationStopped = true; }; |
| 745 | var preventDefault = function() { this.defaultPrevented = true; }; |
| 746 | |
| 747 | EventEmitter._emit = |
| 748 | EventEmitter._dispatchEvent = function(eventName, e) { |
| 749 | this._eventRegistry || (this._eventRegistry = {}); |
| 750 | this._defaultHandlers || (this._defaultHandlers = {}); |
| 751 | |
| 752 | var listeners = this._eventRegistry[eventName] || []; |
| 753 | var defaultHandler = this._defaultHandlers[eventName]; |
| 754 | if (!listeners.length && !defaultHandler) |
| 755 | return; |
| 756 | |
| 757 | if (typeof e != "object" || !e) |
| 758 | e = {}; |
| 759 | |
| 760 | if (!e.type) |
| 761 | e.type = eventName; |
| 762 | if (!e.stopPropagation) |
| 763 | e.stopPropagation = stopPropagation; |
| 764 | if (!e.preventDefault) |
| 765 | e.preventDefault = preventDefault; |
| 766 | |
| 767 | listeners = listeners.slice(); |
| 768 | for (var i=0; i<listeners.length; i++) { |
| 769 | listeners[i](e, this); |
| 770 | if (e.propagationStopped) |
| 771 | break; |
| 772 | } |
| 773 | |
| 774 | if (defaultHandler && !e.defaultPrevented) |
| 775 | return defaultHandler(e, this); |
| 776 | }; |
| 777 | |
| 778 | |
| 779 | EventEmitter._signal = function(eventName, e) { |
| 780 | var listeners = (this._eventRegistry || {})[eventName]; |
| 781 | if (!listeners) |
| 782 | return; |
| 783 | listeners = listeners.slice(); |
| 784 | for (var i=0; i<listeners.length; i++) |
| 785 | listeners[i](e, this); |
| 786 | }; |
| 787 | |
| 788 | EventEmitter.once = function(eventName, callback) { |
| 789 | var _self = this; |
| 790 | callback && this.addEventListener(eventName, function newCallback() { |
| 791 | _self.removeEventListener(eventName, newCallback); |
| 792 | callback.apply(null, arguments); |
| 793 | }); |
| 794 | }; |
| 795 | |
| 796 | |
| 797 | EventEmitter.setDefaultHandler = function(eventName, callback) { |
| 798 | var handlers = this._defaultHandlers; |
| 799 | if (!handlers) |
| 800 | handlers = this._defaultHandlers = {_disabled_: {}}; |
| 801 | |
| 802 | if (handlers[eventName]) { |
| 803 | var old = handlers[eventName]; |
| 804 | var disabled = handlers._disabled_[eventName]; |
| 805 | if (!disabled) |
| 806 | handlers._disabled_[eventName] = disabled = []; |
| 807 | disabled.push(old); |
| 808 | var i = disabled.indexOf(callback); |
| 809 | if (i != -1) |
| 810 | disabled.splice(i, 1); |
| 811 | } |
| 812 | handlers[eventName] = callback; |
| 813 | }; |
| 814 | EventEmitter.removeDefaultHandler = function(eventName, callback) { |
| 815 | var handlers = this._defaultHandlers; |
| 816 | if (!handlers) |
| 817 | return; |
| 818 | var disabled = handlers._disabled_[eventName]; |
| 819 | |
| 820 | if (handlers[eventName] == callback) { |
| 821 | var old = handlers[eventName]; |
| 822 | if (disabled) |
| 823 | this.setDefaultHandler(eventName, disabled.pop()); |
| 824 | } else if (disabled) { |
| 825 | var i = disabled.indexOf(callback); |
| 826 | if (i != -1) |
| 827 | disabled.splice(i, 1); |
| 828 | } |
| 829 | }; |
| 830 | |
| 831 | EventEmitter.on = |
| 832 | EventEmitter.addEventListener = function(eventName, callback, capturing) { |
| 833 | this._eventRegistry = this._eventRegistry || {}; |
| 834 | |
| 835 | var listeners = this._eventRegistry[eventName]; |
| 836 | if (!listeners) |
| 837 | listeners = this._eventRegistry[eventName] = []; |
| 838 | |
| 839 | if (listeners.indexOf(callback) == -1) |
| 840 | listeners[capturing ? "unshift" : "push"](callback); |
| 841 | return callback; |
| 842 | }; |
| 843 | |
| 844 | EventEmitter.off = |
| 845 | EventEmitter.removeListener = |
| 846 | EventEmitter.removeEventListener = function(eventName, callback) { |
| 847 | this._eventRegistry = this._eventRegistry || {}; |
| 848 | |
| 849 | var listeners = this._eventRegistry[eventName]; |
| 850 | if (!listeners) |
| 851 | return; |
| 852 | |
| 853 | var index = listeners.indexOf(callback); |
| 854 | if (index !== -1) |
| 855 | listeners.splice(index, 1); |
| 856 | }; |
| 857 | |
| 858 | EventEmitter.removeAllListeners = function(eventName) { |
| 859 | if (this._eventRegistry) this._eventRegistry[eventName] = []; |
| 860 | }; |
| 861 | |
| 862 | exports.EventEmitter = EventEmitter; |
| 863 | |
| 864 | }); |
| 865 | |
| 866 | define("ace/anchor",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) { |
| 867 | "use strict"; |
| 868 | |
| 869 | var oop = require("./lib/oop"); |
| 870 | var EventEmitter = require("./lib/event_emitter").EventEmitter; |
| 871 | |
| 872 | var Anchor = exports.Anchor = function(doc, row, column) { |
| 873 | this.$onChange = this.onChange.bind(this); |
| 874 | this.attach(doc); |
| 875 | |
| 876 | if (typeof column == "undefined") |
| 877 | this.setPosition(row.row, row.column); |
| 878 | else |
| 879 | this.setPosition(row, column); |
| 880 | }; |
| 881 | |
| 882 | (function() { |
| 883 | |
| 884 | oop.implement(this, EventEmitter); |
| 885 | this.getPosition = function() { |
| 886 | return this.$clipPositionToDocument(this.row, this.column); |
| 887 | }; |
| 888 | this.getDocument = function() { |
| 889 | return this.document; |
| 890 | }; |
| 891 | this.$insertRight = false; |
| 892 | this.onChange = function(delta) { |
| 893 | if (delta.start.row == delta.end.row && delta.start.row != this.row) |
| 894 | return; |
| 895 | |
| 896 | if (delta.start.row > this.row) |
| 897 | return; |
| 898 | |
| 899 | var point = $getTransformedPoint(delta, {row: this.row, column: this.column}, this.$insertRight); |
| 900 | this.setPosition(point.row, point.column, true); |
| 901 | }; |
| 902 | |
| 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); |
| 906 | } |
| 907 | |
| 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)) { |
| 915 | return { |
| 916 | row: point.row, |
| 917 | column: point.column |
| 918 | }; |
| 919 | } |
| 920 | if ($pointsInOrder(deltaEnd, point, !moveIfEqual)) { |
| 921 | return { |
| 922 | row: point.row + deltaRowShift, |
| 923 | column: point.column + (point.row == deltaEnd.row ? deltaColShift : 0) |
| 924 | }; |
| 925 | } |
| 926 | |
| 927 | return { |
| 928 | row: deltaStart.row, |
| 929 | column: deltaStart.column |
| 930 | }; |
| 931 | } |
| 932 | this.setPosition = function(row, column, noClip) { |
| 933 | var pos; |
| 934 | if (noClip) { |
| 935 | pos = { |
| 936 | row: row, |
| 937 | column: column |
| 938 | }; |
| 939 | } else { |
| 940 | pos = this.$clipPositionToDocument(row, column); |
| 941 | } |
| 942 | |
| 943 | if (this.row == pos.row && this.column == pos.column) |
| 944 | return; |
| 945 | |
| 946 | var old = { |
| 947 | row: this.row, |
| 948 | column: this.column |
| 949 | }; |
| 950 | |
| 951 | this.row = pos.row; |
| 952 | this.column = pos.column; |
| 953 | this._signal("change", { |
| 954 | old: old, |
| 955 | value: pos |
| 956 | }); |
| 957 | }; |
| 958 | this.detach = function() { |
| 959 | this.document.removeEventListener("change", this.$onChange); |
| 960 | }; |
| 961 | this.attach = function(doc) { |
| 962 | this.document = doc || this.document; |
| 963 | this.document.on("change", this.$onChange); |
| 964 | }; |
| 965 | this.$clipPositionToDocument = function(row, column) { |
| 966 | var pos = {}; |
| 967 | |
| 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; |
| 971 | } |
| 972 | else if (row < 0) { |
| 973 | pos.row = 0; |
| 974 | pos.column = 0; |
| 975 | } |
| 976 | else { |
| 977 | pos.row = row; |
| 978 | pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column)); |
| 979 | } |
| 980 | |
| 981 | if (column < 0) |
| 982 | pos.column = 0; |
| 983 | |
| 984 | return pos; |
| 985 | }; |
| 986 | |
| 987 | }).call(Anchor.prototype); |
| 988 | |
| 989 | }); |
| 990 | |
| 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) { |
| 992 | "use strict"; |
| 993 | |
| 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; |
| 999 | |
| 1000 | var Document = function(textOrLines) { |
| 1001 | this.$lines = [""]; |
| 1002 | if (textOrLines.length === 0) { |
| 1003 | this.$lines = [""]; |
| 1004 | } else if (Array.isArray(textOrLines)) { |
| 1005 | this.insertMergedLines({row: 0, column: 0}, textOrLines); |
| 1006 | } else { |
| 1007 | this.insert({row: 0, column:0}, textOrLines); |
| 1008 | } |
| 1009 | }; |
| 1010 | |
| 1011 | (function() { |
| 1012 | |
| 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); |
| 1018 | }; |
| 1019 | this.getValue = function() { |
| 1020 | return this.getAllLines().join(this.getNewLineCharacter()); |
| 1021 | }; |
| 1022 | this.createAnchor = function(row, column) { |
| 1023 | return new Anchor(this, row, column); |
| 1024 | }; |
| 1025 | if ("aaa".split(/a/).length === 0) { |
| 1026 | this.$split = function(text) { |
| 1027 | return text.replace(/\r\n|\r/g, "\n").split("\n"); |
| 1028 | }; |
| 1029 | } else { |
| 1030 | this.$split = function(text) { |
| 1031 | return text.split(/\r\n|\r|\n/); |
| 1032 | }; |
| 1033 | } |
| 1034 | |
| 1035 | |
| 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"); |
| 1040 | }; |
| 1041 | this.getNewLineCharacter = function() { |
| 1042 | switch (this.$newLineMode) { |
| 1043 | case "windows": |
| 1044 | return "\r\n"; |
| 1045 | case "unix": |
| 1046 | return "\n"; |
| 1047 | default: |
| 1048 | return this.$autoNewLine || "\n"; |
| 1049 | } |
| 1050 | }; |
| 1051 | |
| 1052 | this.$autoNewLine = ""; |
| 1053 | this.$newLineMode = "auto"; |
| 1054 | this.setNewLineMode = function(newLineMode) { |
| 1055 | if (this.$newLineMode === newLineMode) |
| 1056 | return; |
| 1057 | |
| 1058 | this.$newLineMode = newLineMode; |
| 1059 | this._signal("changeNewLineMode"); |
| 1060 | }; |
| 1061 | this.getNewLineMode = function() { |
| 1062 | return this.$newLineMode; |
| 1063 | }; |
| 1064 | this.isNewLine = function(text) { |
| 1065 | return (text == "\r\n" || text == "\r" || text == "\n"); |
| 1066 | }; |
| 1067 | this.getLine = function(row) { |
| 1068 | return this.$lines[row] || ""; |
| 1069 | }; |
| 1070 | this.getLines = function(firstRow, lastRow) { |
| 1071 | return this.$lines.slice(firstRow, lastRow + 1); |
| 1072 | }; |
| 1073 | this.getAllLines = function() { |
| 1074 | return this.getLines(0, this.getLength()); |
| 1075 | }; |
| 1076 | this.getLength = function() { |
| 1077 | return this.$lines.length; |
| 1078 | }; |
| 1079 | this.getTextRange = function(range) { |
| 1080 | return this.getLinesForRange(range).join(this.getNewLineCharacter()); |
| 1081 | }; |
| 1082 | this.getLinesForRange = function(range) { |
| 1083 | var lines; |
| 1084 | if (range.start.row === range.end.row) { |
| 1085 | lines = [this.getLine(range.start.row).substring(range.start.column, range.end.column)]; |
| 1086 | } else { |
| 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); |
| 1092 | } |
| 1093 | return lines; |
| 1094 | }; |
| 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); |
| 1098 | }; |
| 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); |
| 1102 | }; |
| 1103 | this.insertNewLine = function(position) { |
| 1104 | console.warn("Use of document.insertNewLine is deprecated. Use insertMergedLines(position, ['', '']) instead."); |
| 1105 | return this.insertMergedLines(position, ["", ""]); |
| 1106 | }; |
| 1107 | this.insert = function(position, text) { |
| 1108 | if (this.getLength() <= 1) |
| 1109 | this.$detectNewLine(text); |
| 1110 | |
| 1111 | return this.insertMergedLines(position, this.$split(text)); |
| 1112 | }; |
| 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); |
| 1116 | |
| 1117 | this.applyDelta({ |
| 1118 | start: start, |
| 1119 | end: end, |
| 1120 | action: "insert", |
| 1121 | lines: [text] |
| 1122 | }, true); |
| 1123 | |
| 1124 | return this.clonePos(end); |
| 1125 | }; |
| 1126 | |
| 1127 | this.clippedPos = function(row, column) { |
| 1128 | var length = this.getLength(); |
| 1129 | if (row === undefined) { |
| 1130 | row = length; |
| 1131 | } else if (row < 0) { |
| 1132 | row = 0; |
| 1133 | } else if (row >= length) { |
| 1134 | row = length - 1; |
| 1135 | column = undefined; |
| 1136 | } |
| 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}; |
| 1142 | }; |
| 1143 | |
| 1144 | this.clonePos = function(pos) { |
| 1145 | return {row: pos.row, column: pos.column}; |
| 1146 | }; |
| 1147 | |
| 1148 | this.pos = function(row, column) { |
| 1149 | return {row: row, column: column}; |
| 1150 | }; |
| 1151 | |
| 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; |
| 1157 | } else { |
| 1158 | position.row = Math.max(0, position.row); |
| 1159 | position.column = Math.min(Math.max(position.column, 0), this.getLine(position.row).length); |
| 1160 | } |
| 1161 | return position; |
| 1162 | }; |
| 1163 | this.insertFullLines = function(row, lines) { |
| 1164 | row = Math.min(Math.max(row, 0), this.getLength()); |
| 1165 | var column = 0; |
| 1166 | if (row < this.getLength()) { |
| 1167 | lines = lines.concat([""]); |
| 1168 | column = 0; |
| 1169 | } else { |
| 1170 | lines = [""].concat(lines); |
| 1171 | row--; |
| 1172 | column = this.$lines[row].length; |
| 1173 | } |
| 1174 | this.insertMergedLines({row: row, column: column}, lines); |
| 1175 | }; |
| 1176 | this.insertMergedLines = function(position, lines) { |
| 1177 | var start = this.clippedPos(position.row, position.column); |
| 1178 | var end = { |
| 1179 | row: start.row + lines.length - 1, |
| 1180 | column: (lines.length == 1 ? start.column : 0) + lines[lines.length - 1].length |
| 1181 | }; |
| 1182 | |
| 1183 | this.applyDelta({ |
| 1184 | start: start, |
| 1185 | end: end, |
| 1186 | action: "insert", |
| 1187 | lines: lines |
| 1188 | }); |
| 1189 | |
| 1190 | return this.clonePos(end); |
| 1191 | }; |
| 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); |
| 1195 | this.applyDelta({ |
| 1196 | start: start, |
| 1197 | end: end, |
| 1198 | action: "remove", |
| 1199 | lines: this.getLinesForRange({start: start, end: end}) |
| 1200 | }); |
| 1201 | return this.clonePos(start); |
| 1202 | }; |
| 1203 | this.removeInLine = function(row, startColumn, endColumn) { |
| 1204 | var start = this.clippedPos(row, startColumn); |
| 1205 | var end = this.clippedPos(row, endColumn); |
| 1206 | |
| 1207 | this.applyDelta({ |
| 1208 | start: start, |
| 1209 | end: end, |
| 1210 | action: "remove", |
| 1211 | lines: this.getLinesForRange({start: start, end: end}) |
| 1212 | }, true); |
| 1213 | |
| 1214 | return this.clonePos(start); |
| 1215 | }; |
| 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); |
| 1227 | |
| 1228 | this.applyDelta({ |
| 1229 | start: range.start, |
| 1230 | end: range.end, |
| 1231 | action: "remove", |
| 1232 | lines: this.getLinesForRange(range) |
| 1233 | }); |
| 1234 | return deletedLines; |
| 1235 | }; |
| 1236 | this.removeNewLine = function(row) { |
| 1237 | if (row < this.getLength() - 1 && row >= 0) { |
| 1238 | this.applyDelta({ |
| 1239 | start: this.pos(row, this.getLine(row).length), |
| 1240 | end: this.pos(row + 1, 0), |
| 1241 | action: "remove", |
| 1242 | lines: ["", ""] |
| 1243 | }); |
| 1244 | } |
| 1245 | }; |
| 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()) |
| 1250 | return range.start; |
| 1251 | if (text == this.getTextRange(range)) |
| 1252 | return range.end; |
| 1253 | |
| 1254 | this.remove(range); |
| 1255 | var end; |
| 1256 | if (text) { |
| 1257 | end = this.insert(range.start, text); |
| 1258 | } |
| 1259 | else { |
| 1260 | end = range.start; |
| 1261 | } |
| 1262 | |
| 1263 | return end; |
| 1264 | }; |
| 1265 | this.applyDeltas = function(deltas) { |
| 1266 | for (var i=0; i<deltas.length; i++) { |
| 1267 | this.applyDelta(deltas[i]); |
| 1268 | } |
| 1269 | }; |
| 1270 | this.revertDeltas = function(deltas) { |
| 1271 | for (var i=deltas.length-1; i>=0; i--) { |
| 1272 | this.revertDelta(deltas[i]); |
| 1273 | } |
| 1274 | }; |
| 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)) { |
| 1279 | return; |
| 1280 | } |
| 1281 | |
| 1282 | if (isInsert && delta.lines.length > 20000) |
| 1283 | this.$splitAndapplyLargeDelta(delta, 20000); |
| 1284 | applyDelta(this.$lines, delta, doNotValidate); |
| 1285 | this._signal("change", delta); |
| 1286 | }; |
| 1287 | |
| 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; |
| 1294 | do { |
| 1295 | from = to; |
| 1296 | to += MAX - 1; |
| 1297 | var chunk = lines.slice(from, to); |
| 1298 | if (to > l) { |
| 1299 | delta.lines = chunk; |
| 1300 | delta.start.row = row + from; |
| 1301 | delta.start.column = column; |
| 1302 | break; |
| 1303 | } |
| 1304 | chunk.push(""); |
| 1305 | this.applyDelta({ |
| 1306 | start: this.pos(row + from, column), |
| 1307 | end: this.pos(row + to, column = 0), |
| 1308 | action: delta.action, |
| 1309 | lines: chunk |
| 1310 | }, true); |
| 1311 | } while(true); |
| 1312 | }; |
| 1313 | this.revertDelta = function(delta) { |
| 1314 | this.applyDelta({ |
| 1315 | start: this.clonePos(delta.start), |
| 1316 | end: this.clonePos(delta.end), |
| 1317 | action: (delta.action == "insert" ? "remove" : "insert"), |
| 1318 | lines: delta.lines.slice() |
| 1319 | }); |
| 1320 | }; |
| 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; |
| 1326 | if (index < 0) |
| 1327 | return {row: i, column: index + lines[i].length + newlineLength}; |
| 1328 | } |
| 1329 | return {row: l-1, column: lines[l-1].length}; |
| 1330 | }; |
| 1331 | this.positionToIndex = function(pos, startRow) { |
| 1332 | var lines = this.$lines || this.getAllLines(); |
| 1333 | var newlineLength = this.getNewLineCharacter().length; |
| 1334 | var index = 0; |
| 1335 | var row = Math.min(pos.row, lines.length); |
| 1336 | for (var i = startRow || 0; i < row; ++i) |
| 1337 | index += lines[i].length + newlineLength; |
| 1338 | |
| 1339 | return index + pos.column; |
| 1340 | }; |
| 1341 | |
| 1342 | }).call(Document.prototype); |
| 1343 | |
| 1344 | exports.Document = Document; |
| 1345 | }); |
| 1346 | |
| 1347 | define("ace/worker/mirror",["require","exports","module","ace/range","ace/document","ace/lib/lang"], function(require, exports, module) { |
| 1348 | "use strict"; |
| 1349 | |
| 1350 | var Range = require("../range").Range; |
| 1351 | var Document = require("../document").Document; |
| 1352 | var lang = require("../lib/lang"); |
| 1353 | |
| 1354 | var Mirror = exports.Mirror = function(sender) { |
| 1355 | this.sender = sender; |
| 1356 | var doc = this.doc = new Document(""); |
| 1357 | |
| 1358 | var deferredUpdate = this.deferredUpdate = lang.delayedCall(this.onUpdate.bind(this)); |
| 1359 | |
| 1360 | var _self = this; |
| 1361 | sender.on("change", function(e) { |
| 1362 | var data = e.data; |
| 1363 | if (data[0].start) { |
| 1364 | doc.applyDeltas(data); |
| 1365 | } else { |
| 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]}; |
| 1369 | } else { |
| 1370 | var d = {action: "remove", start: data[i], end: data[i+1]}; |
| 1371 | } |
| 1372 | doc.applyDelta(d, true); |
| 1373 | } |
| 1374 | } |
| 1375 | if (_self.$timeout) |
| 1376 | return deferredUpdate.schedule(_self.$timeout); |
| 1377 | _self.onUpdate(); |
| 1378 | }); |
| 1379 | }; |
| 1380 | |
| 1381 | (function() { |
| 1382 | |
| 1383 | this.$timeout = 500; |
| 1384 | |
| 1385 | this.setTimeout = function(timeout) { |
| 1386 | this.$timeout = timeout; |
| 1387 | }; |
| 1388 | |
| 1389 | this.setValue = function(value) { |
| 1390 | this.doc.setValue(value); |
| 1391 | this.deferredUpdate.schedule(this.$timeout); |
| 1392 | }; |
| 1393 | |
| 1394 | this.getValue = function(callbackId) { |
| 1395 | this.sender.callback(this.doc.getValue(), callbackId); |
| 1396 | }; |
| 1397 | |
| 1398 | this.onUpdate = function() { |
| 1399 | }; |
| 1400 | |
| 1401 | this.isPending = function() { |
| 1402 | return this.deferredUpdate.isPending(); |
| 1403 | }; |
| 1404 | |
| 1405 | }).call(Mirror.prototype); |
| 1406 | |
| 1407 | }); |
| 1408 | |
| 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 /> |
| 1421 | |
| 1422 | function XMLReader(){ |
| 1423 | |
| 1424 | } |
| 1425 | |
| 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(); |
| 1434 | } |
| 1435 | } |
| 1436 | function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){ |
| 1437 | function fixedFromCharCode(code) { |
| 1438 | if (code > 0xffff) { |
| 1439 | code -= 0x10000; |
| 1440 | var surrogate1 = 0xd800 + (code >> 10) |
| 1441 | , surrogate2 = 0xdc00 + (code & 0x3ff); |
| 1442 | |
| 1443 | return String.fromCharCode(surrogate1, surrogate2); |
| 1444 | } else { |
| 1445 | return String.fromCharCode(code); |
| 1446 | } |
| 1447 | } |
| 1448 | function entityReplacer(a){ |
| 1449 | var k = a.slice(1,-1); |
| 1450 | if(k in entityMap){ |
| 1451 | return entityMap[k]; |
| 1452 | }else if(k.charAt(0) === '#'){ |
| 1453 | return fixedFromCharCode(parseInt(k.substr(1).replace('x','0x'))) |
| 1454 | }else{ |
| 1455 | errorHandler.error('entity not found:'+a); |
| 1456 | return a; |
| 1457 | } |
| 1458 | } |
| 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); |
| 1463 | start = end |
| 1464 | } |
| 1465 | function position(start,m){ |
| 1466 | while(start>=endPos && (m = linePattern.exec(source))){ |
| 1467 | startPos = m.index; |
| 1468 | endPos = startPos + m[0].length; |
| 1469 | locator.lineNumber++; |
| 1470 | } |
| 1471 | locator.columnNumber = start-startPos+1; |
| 1472 | } |
| 1473 | var startPos = 0; |
| 1474 | var endPos = 0; |
| 1475 | var linePattern = /.+(?:\r\n?|\n)|.*$/g |
| 1476 | var locator = domBuilder.locator; |
| 1477 | |
| 1478 | var parseStack = [{currentNSMap:defaultNSMapCopy}] |
| 1479 | var closeMap = {}; |
| 1480 | var start = 0; |
| 1481 | while(true){ |
| 1482 | var i = source.indexOf('<',start); |
| 1483 | if(i<0){ |
| 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; |
| 1489 | } |
| 1490 | return; |
| 1491 | } |
| 1492 | if(i>start){ |
| 1493 | appendText(i); |
| 1494 | } |
| 1495 | switch(source.charAt(i+1)){ |
| 1496 | case '/': |
| 1497 | var end = source.indexOf('>',i+3); |
| 1498 | var tagName = source.substring(i+2,end); |
| 1499 | var config; |
| 1500 | if (parseStack.length > 1) { |
| 1501 | config = parseStack.pop(); |
| 1502 | } else { |
| 1503 | errorHandler.fatalError("end tag name not found for: "+tagName); |
| 1504 | break; |
| 1505 | } |
| 1506 | var localNSMap = config.localNSMap; |
| 1507 | |
| 1508 | if(config.tagName != tagName){ |
| 1509 | errorHandler.fatalError("end tag name: " + tagName + " does not match the current start tagName: "+config.tagName ); |
| 1510 | } |
| 1511 | domBuilder.endElement(config.uri,config.localName,tagName); |
| 1512 | if(localNSMap){ |
| 1513 | for(var prefix in localNSMap){ |
| 1514 | domBuilder.endPrefixMapping(prefix) ; |
| 1515 | } |
| 1516 | } |
| 1517 | end++; |
| 1518 | break; |
| 1519 | case '?':// <?...?> |
| 1520 | locator&&position(i); |
| 1521 | end = parseInstruction(source,i,domBuilder); |
| 1522 | break; |
| 1523 | case '!':// <!doctype,<![CDATA,<!-- |
| 1524 | locator&&position(i); |
| 1525 | end = parseDCC(source,i,domBuilder,errorHandler); |
| 1526 | break; |
| 1527 | default: |
| 1528 | try{ |
| 1529 | locator&&position(i); |
| 1530 | |
| 1531 | var el = new ElementAttributes(); |
| 1532 | var end = parseElementStartPart(source,i,el,entityReplacer,errorHandler); |
| 1533 | var len = el.length; |
| 1534 | if(len && locator){ |
| 1535 | var backup = copyLocator(locator,{}); |
| 1536 | for(var i = 0;i<len;i++){ |
| 1537 | var a = el[i]; |
| 1538 | position(a.offset); |
| 1539 | a.offset = copyLocator(locator,{}); |
| 1540 | } |
| 1541 | copyLocator(backup,locator); |
| 1542 | } |
| 1543 | if(!el.closed && fixSelfClosed(source,end,el.tagName,closeMap)){ |
| 1544 | el.closed = true; |
| 1545 | if(!entityMap.nbsp){ |
| 1546 | errorHandler.warning('unclosed xml attribute'); |
| 1547 | } |
| 1548 | } |
| 1549 | appendElement(el,domBuilder,parseStack); |
| 1550 | |
| 1551 | |
| 1552 | if(el.uri === 'http://www.w3.org/1999/xhtml' && !el.closed){ |
| 1553 | end = parseHtmlSpecialContent(source,end,el.tagName,entityReplacer,domBuilder) |
| 1554 | }else{ |
| 1555 | end++; |
| 1556 | } |
| 1557 | }catch(e){ |
| 1558 | errorHandler.error('element parse error: '+e); |
| 1559 | end = -1; |
| 1560 | } |
| 1561 | |
| 1562 | } |
| 1563 | if(end<0){ |
| 1564 | appendText(i+1); |
| 1565 | }else{ |
| 1566 | start = end; |
| 1567 | } |
| 1568 | } |
| 1569 | } |
| 1570 | function copyLocator(f,t){ |
| 1571 | t.lineNumber = f.lineNumber; |
| 1572 | t.columnNumber = f.columnNumber; |
| 1573 | return t; |
| 1574 | |
| 1575 | } |
| 1576 | function parseElementStartPart(source,start,el,entityReplacer,errorHandler){ |
| 1577 | var attrName; |
| 1578 | var value; |
| 1579 | var p = ++start; |
| 1580 | var s = S_TAG;//status |
| 1581 | while(true){ |
| 1582 | var c = source.charAt(p); |
| 1583 | switch(c){ |
| 1584 | case '=': |
| 1585 | if(s === S_ATTR){//attrName |
| 1586 | attrName = source.slice(start,p); |
| 1587 | s = S_EQ; |
| 1588 | }else if(s === S_ATTR_S){ |
| 1589 | s = S_EQ; |
| 1590 | }else{ |
| 1591 | throw new Error('attribute equal must after attrName'); |
| 1592 | } |
| 1593 | break; |
| 1594 | case '\'': |
| 1595 | case '"': |
| 1596 | if(s === S_EQ){//equal |
| 1597 | start = p+1; |
| 1598 | p = source.indexOf(c,start) |
| 1599 | if(p>0){ |
| 1600 | value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer); |
| 1601 | el.add(attrName,value,start-1); |
| 1602 | s = S_E; |
| 1603 | }else{ |
| 1604 | throw new Error('attribute value no end \''+c+'\' match'); |
| 1605 | } |
| 1606 | }else if(s == S_V){ |
| 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+')!!'); |
| 1610 | start = p+1; |
| 1611 | s = S_E |
| 1612 | }else{ |
| 1613 | throw new Error('attribute value must after "="'); |
| 1614 | } |
| 1615 | break; |
| 1616 | case '/': |
| 1617 | switch(s){ |
| 1618 | case S_TAG: |
| 1619 | el.setTagName(source.slice(start,p)); |
| 1620 | case S_E: |
| 1621 | case S_S: |
| 1622 | case S_C: |
| 1623 | s = S_C; |
| 1624 | el.closed = true; |
| 1625 | case S_V: |
| 1626 | case S_ATTR: |
| 1627 | case S_ATTR_S: |
| 1628 | break; |
| 1629 | default: |
| 1630 | throw new Error("attribute invalid close char('/')") |
| 1631 | } |
| 1632 | break; |
| 1633 | case ''://end document |
| 1634 | errorHandler.error('unexpected end of input'); |
| 1635 | case '>': |
| 1636 | switch(s){ |
| 1637 | case S_TAG: |
| 1638 | el.setTagName(source.slice(start,p)); |
| 1639 | case S_E: |
| 1640 | case S_S: |
| 1641 | case S_C: |
| 1642 | break;//normal |
| 1643 | case S_V://Compatible state |
| 1644 | case S_ATTR: |
| 1645 | value = source.slice(start,p); |
| 1646 | if(value.slice(-1) === '/'){ |
| 1647 | el.closed = true; |
| 1648 | value = value.slice(0,-1) |
| 1649 | } |
| 1650 | case S_ATTR_S: |
| 1651 | if(s === S_ATTR_S){ |
| 1652 | value = attrName; |
| 1653 | } |
| 1654 | if(s == S_V){ |
| 1655 | errorHandler.warning('attribute "'+value+'" missed quot(")!!'); |
| 1656 | el.add(attrName,value.replace(/&#?\w+;/g,entityReplacer),start) |
| 1657 | }else{ |
| 1658 | errorHandler.warning('attribute "'+value+'" missed value!! "'+value+'" instead!!') |
| 1659 | el.add(value,value,start) |
| 1660 | } |
| 1661 | break; |
| 1662 | case S_EQ: |
| 1663 | throw new Error('attribute value missed!!'); |
| 1664 | } |
| 1665 | return p; |
| 1666 | case '\u0080': |
| 1667 | c = ' '; |
| 1668 | default: |
| 1669 | if(c<= ' '){//space |
| 1670 | switch(s){ |
| 1671 | case S_TAG: |
| 1672 | el.setTagName(source.slice(start,p));//tagName |
| 1673 | s = S_S; |
| 1674 | break; |
| 1675 | case S_ATTR: |
| 1676 | attrName = source.slice(start,p) |
| 1677 | s = S_ATTR_S; |
| 1678 | break; |
| 1679 | case S_V: |
| 1680 | var value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer); |
| 1681 | errorHandler.warning('attribute "'+value+'" missed quot(")!!'); |
| 1682 | el.add(attrName,value,start) |
| 1683 | case S_E: |
| 1684 | s = S_S; |
| 1685 | break; |
| 1686 | } |
| 1687 | }else{//not space |
| 1688 | switch(s){ |
| 1689 | case S_ATTR_S: |
| 1690 | errorHandler.warning('attribute "'+attrName+'" missed value!! "'+attrName+'" instead!!') |
| 1691 | el.add(attrName,attrName,start); |
| 1692 | start = p; |
| 1693 | s = S_ATTR; |
| 1694 | break; |
| 1695 | case S_E: |
| 1696 | errorHandler.warning('attribute space is required"'+attrName+'"!!') |
| 1697 | case S_S: |
| 1698 | s = S_ATTR; |
| 1699 | start = p; |
| 1700 | break; |
| 1701 | case S_EQ: |
| 1702 | s = S_V; |
| 1703 | start = p; |
| 1704 | break; |
| 1705 | case S_C: |
| 1706 | throw new Error("elements closed character '/' and '>' must be connected to"); |
| 1707 | } |
| 1708 | } |
| 1709 | } |
| 1710 | p++; |
| 1711 | } |
| 1712 | } |
| 1713 | function appendElement(el,domBuilder,parseStack){ |
| 1714 | var tagName = el.tagName; |
| 1715 | var localNSMap = null; |
| 1716 | var currentNSMap = parseStack[parseStack.length-1].currentNSMap; |
| 1717 | var i = el.length; |
| 1718 | while(i--){ |
| 1719 | var a = el[i]; |
| 1720 | var qName = a.qName; |
| 1721 | var value = a.value; |
| 1722 | var nsp = qName.indexOf(':'); |
| 1723 | if(nsp>0){ |
| 1724 | var prefix = a.prefix = qName.slice(0,nsp); |
| 1725 | var localName = qName.slice(nsp+1); |
| 1726 | var nsPrefix = prefix === 'xmlns' && localName |
| 1727 | }else{ |
| 1728 | localName = qName; |
| 1729 | prefix = null |
| 1730 | nsPrefix = qName === 'xmlns' && '' |
| 1731 | } |
| 1732 | a.localName = localName ; |
| 1733 | if(nsPrefix !== false){//hack!! |
| 1734 | if(localNSMap == null){ |
| 1735 | localNSMap = {} |
| 1736 | _copy(currentNSMap,currentNSMap={}) |
| 1737 | } |
| 1738 | currentNSMap[nsPrefix] = localNSMap[nsPrefix] = value; |
| 1739 | a.uri = 'http://www.w3.org/2000/xmlns/' |
| 1740 | domBuilder.startPrefixMapping(nsPrefix, value) |
| 1741 | } |
| 1742 | } |
| 1743 | var i = el.length; |
| 1744 | while(i--){ |
| 1745 | a = el[i]; |
| 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] |
| 1752 | } |
| 1753 | } |
| 1754 | } |
| 1755 | var nsp = tagName.indexOf(':'); |
| 1756 | if(nsp>0){ |
| 1757 | prefix = el.prefix = tagName.slice(0,nsp); |
| 1758 | localName = el.localName = tagName.slice(nsp+1); |
| 1759 | }else{ |
| 1760 | prefix = null;//important!! |
| 1761 | localName = el.localName = tagName; |
| 1762 | } |
| 1763 | var ns = el.uri = currentNSMap[prefix || '']; |
| 1764 | domBuilder.startElement(ns,localName,tagName,el); |
| 1765 | if(el.closed){ |
| 1766 | domBuilder.endElement(ns,localName,tagName); |
| 1767 | if(localNSMap){ |
| 1768 | for(prefix in localNSMap){ |
| 1769 | domBuilder.endPrefixMapping(prefix) |
| 1770 | } |
| 1771 | } |
| 1772 | }else{ |
| 1773 | el.currentNSMap = currentNSMap; |
| 1774 | el.localNSMap = localNSMap; |
| 1775 | parseStack.push(el); |
| 1776 | } |
| 1777 | } |
| 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); |
| 1785 | return elEndStart; |
| 1786 | }//}else{//text area |
| 1787 | text = text.replace(/&#?\w+;/g,entityReplacer); |
| 1788 | domBuilder.characters(text,0,text.length); |
| 1789 | return elEndStart; |
| 1790 | |
| 1791 | } |
| 1792 | } |
| 1793 | return elStartEnd+1; |
| 1794 | } |
| 1795 | function fixSelfClosed(source,elStartEnd,tagName,closeMap){ |
| 1796 | var pos = closeMap[tagName]; |
| 1797 | if(pos == null){ |
| 1798 | pos = closeMap[tagName] = source.lastIndexOf('</'+tagName+'>') |
| 1799 | } |
| 1800 | return pos<elStartEnd; |
| 1801 | } |
| 1802 | function _copy(source,target){ |
| 1803 | for(var n in source){target[n] = source[n]} |
| 1804 | } |
| 1805 | function parseDCC(source,start,domBuilder,errorHandler){//sure start with '<!' |
| 1806 | var next= source.charAt(start+2) |
| 1807 | switch(next){ |
| 1808 | case '-': |
| 1809 | if(source.charAt(start + 3) === '-'){ |
| 1810 | var end = source.indexOf('-->',start+4); |
| 1811 | if(end>start){ |
| 1812 | domBuilder.comment(source,start+4,end-start-4); |
| 1813 | return end+3; |
| 1814 | }else{ |
| 1815 | errorHandler.error("Unclosed comment"); |
| 1816 | return -1; |
| 1817 | } |
| 1818 | }else{ |
| 1819 | return -1; |
| 1820 | } |
| 1821 | default: |
| 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() |
| 1827 | return end+3; |
| 1828 | } |
| 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(); |
| 1839 | |
| 1840 | return lastMatch.index+lastMatch[0].length |
| 1841 | } |
| 1842 | } |
| 1843 | return -1; |
| 1844 | } |
| 1845 | |
| 1846 | |
| 1847 | |
| 1848 | function parseInstruction(source,start,domBuilder){ |
| 1849 | var end = source.indexOf('?>',start); |
| 1850 | if(end){ |
| 1851 | var match = source.substring(start,end).match(/^<\?(\S*)\s*([\s\S]*?)\s*$/); |
| 1852 | if(match){ |
| 1853 | var len = match[0].length; |
| 1854 | domBuilder.processingInstruction(match[1], match[2]) ; |
| 1855 | return end+2; |
| 1856 | }else{//error |
| 1857 | return -1; |
| 1858 | } |
| 1859 | } |
| 1860 | return -1; |
| 1861 | } |
| 1862 | function ElementAttributes(source){ |
| 1863 | |
| 1864 | } |
| 1865 | ElementAttributes.prototype = { |
| 1866 | setTagName:function(tagName){ |
| 1867 | if(!tagNamePattern.test(tagName)){ |
| 1868 | throw new Error('invalid tagName:'+tagName) |
| 1869 | } |
| 1870 | this.tagName = tagName |
| 1871 | }, |
| 1872 | add:function(qName,value,offset){ |
| 1873 | if(!tagNamePattern.test(qName)){ |
| 1874 | throw new Error('invalid attribute:'+qName) |
| 1875 | } |
| 1876 | this[this.length++] = {qName:qName,value:value,offset:offset} |
| 1877 | }, |
| 1878 | length:0, |
| 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} |
| 1884 | } |
| 1885 | |
| 1886 | |
| 1887 | |
| 1888 | |
| 1889 | function _set_proto_(thiz,parent){ |
| 1890 | thiz.__proto__ = parent; |
| 1891 | return thiz; |
| 1892 | } |
| 1893 | if(!(_set_proto_({},_set_proto_.prototype) instanceof _set_proto_)){ |
| 1894 | _set_proto_ = function(thiz,parent){ |
| 1895 | function p(){}; |
| 1896 | p.prototype = parent; |
| 1897 | p = new p(); |
| 1898 | for(parent in thiz){ |
| 1899 | p[parent] = thiz[parent]; |
| 1900 | } |
| 1901 | return p; |
| 1902 | } |
| 1903 | } |
| 1904 | |
| 1905 | function split(source,start){ |
| 1906 | var match; |
| 1907 | var buf = []; |
| 1908 | var reg = /'[^']+'|"[^"]+"|[^\s<>\/=]+=?|(\/?\s*>|<)/g; |
| 1909 | reg.lastIndex = start; |
| 1910 | reg.exec(source);//skip < |
| 1911 | while(match = reg.exec(source)){ |
| 1912 | buf.push(match); |
| 1913 | if(match[1])return buf; |
| 1914 | } |
| 1915 | } |
| 1916 | |
| 1917 | return XMLReader; |
| 1918 | }); |
| 1919 | |
| 1920 | define("ace/mode/xml/dom",["require","exports","module"], function(require, exports, module) { |
| 1921 | |
| 1922 | function copy(src,dest){ |
| 1923 | for(var p in src){ |
| 1924 | dest[p] = src[p]; |
| 1925 | } |
| 1926 | } |
| 1927 | function _extends(Class,Super){ |
| 1928 | var pt = Class.prototype; |
| 1929 | if(Object.create){ |
| 1930 | var ppt = Object.create(Super.prototype) |
| 1931 | pt.__proto__ = ppt; |
| 1932 | } |
| 1933 | if(!(pt instanceof Super)){ |
| 1934 | function t(){}; |
| 1935 | t.prototype = Super.prototype; |
| 1936 | t = new t(); |
| 1937 | copy(pt,t); |
| 1938 | Class.prototype = pt = t; |
| 1939 | } |
| 1940 | if(pt.constructor != Class){ |
| 1941 | if(typeof Class != 'function'){ |
| 1942 | console.error("unknow Class:"+Class) |
| 1943 | } |
| 1944 | pt.constructor = Class |
| 1945 | } |
| 1946 | } |
| 1947 | var htmlns = 'http://www.w3.org/1999/xhtml' ; |
| 1948 | var NodeType = {} |
| 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); |
| 1978 | |
| 1979 | |
| 1980 | function DOMException(code, message) { |
| 1981 | if(message instanceof Error){ |
| 1982 | var error = message; |
| 1983 | }else{ |
| 1984 | error = this; |
| 1985 | Error.call(this, ExceptionMessage[code]); |
| 1986 | this.message = ExceptionMessage[code]; |
| 1987 | if(Error.captureStackTrace) Error.captureStackTrace(this, DOMException); |
| 1988 | } |
| 1989 | error.code = code; |
| 1990 | if(message) this.message = this.message + ": " + message; |
| 1991 | return error; |
| 1992 | }; |
| 1993 | DOMException.prototype = Error.prototype; |
| 1994 | copy(ExceptionCode,DOMException) |
| 1995 | function NodeList() { |
| 1996 | }; |
| 1997 | NodeList.prototype = { |
| 1998 | length:0, |
| 1999 | item: function(index) { |
| 2000 | return this[index] || null; |
| 2001 | } |
| 2002 | }; |
| 2003 | function LiveNodeList(node,refresh){ |
| 2004 | this._node = node; |
| 2005 | this._refresh = refresh |
| 2006 | _updateLiveList(this); |
| 2007 | } |
| 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); |
| 2013 | copy(ls,list); |
| 2014 | list._inc = inc; |
| 2015 | } |
| 2016 | } |
| 2017 | LiveNodeList.prototype.item = function(i){ |
| 2018 | _updateLiveList(this); |
| 2019 | return this[i]; |
| 2020 | } |
| 2021 | |
| 2022 | _extends(LiveNodeList,NodeList); |
| 2023 | function NamedNodeMap() { |
| 2024 | }; |
| 2025 | |
| 2026 | function _findNodeIndex(list,node){ |
| 2027 | var i = list.length; |
| 2028 | while(i--){ |
| 2029 | if(list[i] === node){return i} |
| 2030 | } |
| 2031 | } |
| 2032 | |
| 2033 | function _addNamedNode(el,list,newAttr,oldAttr){ |
| 2034 | if(oldAttr){ |
| 2035 | list[_findNodeIndex(list,oldAttr)] = newAttr; |
| 2036 | }else{ |
| 2037 | list[list.length++] = newAttr; |
| 2038 | } |
| 2039 | if(el){ |
| 2040 | newAttr.ownerElement = el; |
| 2041 | var doc = el.ownerDocument; |
| 2042 | if(doc){ |
| 2043 | oldAttr && _onRemoveAttribute(doc,el,oldAttr); |
| 2044 | _onAddAttribute(doc,el,newAttr); |
| 2045 | } |
| 2046 | } |
| 2047 | } |
| 2048 | function _removeNamedNode(el,list,attr){ |
| 2049 | var i = _findNodeIndex(list,attr); |
| 2050 | if(i>=0){ |
| 2051 | var lastIndex = list.length-1 |
| 2052 | while(i<lastIndex){ |
| 2053 | list[i] = list[++i] |
| 2054 | } |
| 2055 | list.length = lastIndex; |
| 2056 | if(el){ |
| 2057 | var doc = el.ownerDocument; |
| 2058 | if(doc){ |
| 2059 | _onRemoveAttribute(doc,el,attr); |
| 2060 | attr.ownerElement = null; |
| 2061 | } |
| 2062 | } |
| 2063 | }else{ |
| 2064 | throw DOMException(NOT_FOUND_ERR,new Error()) |
| 2065 | } |
| 2066 | } |
| 2067 | NamedNodeMap.prototype = { |
| 2068 | length:0, |
| 2069 | item:NodeList.prototype.item, |
| 2070 | getNamedItem: function(key) { |
| 2071 | var i = this.length; |
| 2072 | while(i--){ |
| 2073 | var attr = this[i]; |
| 2074 | if(attr.nodeName == key){ |
| 2075 | return attr; |
| 2076 | } |
| 2077 | } |
| 2078 | }, |
| 2079 | setNamedItem: function(attr) { |
| 2080 | var el = attr.ownerElement; |
| 2081 | if(el && el!=this._ownerElement){ |
| 2082 | throw new DOMException(INUSE_ATTRIBUTE_ERR); |
| 2083 | } |
| 2084 | var oldAttr = this.getNamedItem(attr.nodeName); |
| 2085 | _addNamedNode(this._ownerElement,this,attr,oldAttr); |
| 2086 | return oldAttr; |
| 2087 | }, |
| 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); |
| 2092 | } |
| 2093 | oldAttr = this.getNamedItemNS(attr.namespaceURI,attr.localName); |
| 2094 | _addNamedNode(this._ownerElement,this,attr,oldAttr); |
| 2095 | return oldAttr; |
| 2096 | }, |
| 2097 | removeNamedItem: function(key) { |
| 2098 | var attr = this.getNamedItem(key); |
| 2099 | _removeNamedNode(this._ownerElement,this,attr); |
| 2100 | return attr; |
| 2101 | |
| 2102 | |
| 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); |
| 2107 | return attr; |
| 2108 | }, |
| 2109 | getNamedItemNS: function(namespaceURI, localName) { |
| 2110 | var i = this.length; |
| 2111 | while(i--){ |
| 2112 | var node = this[i]; |
| 2113 | if(node.localName == localName && node.namespaceURI == namespaceURI){ |
| 2114 | return node; |
| 2115 | } |
| 2116 | } |
| 2117 | return null; |
| 2118 | } |
| 2119 | }; |
| 2120 | function DOMImplementation(/* Object */ features) { |
| 2121 | this._features = {}; |
| 2122 | if (features) { |
| 2123 | for (var feature in features) { |
| 2124 | this._features = features[feature]; |
| 2125 | } |
| 2126 | } |
| 2127 | }; |
| 2128 | |
| 2129 | DOMImplementation.prototype = { |
| 2130 | hasFeature: function(/* string */ feature, /* string */ version) { |
| 2131 | var versions = this._features[feature.toLowerCase()]; |
| 2132 | if (versions && (!version || version in versions)) { |
| 2133 | return true; |
| 2134 | } else { |
| 2135 | return false; |
| 2136 | } |
| 2137 | }, |
| 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; |
| 2143 | if(doctype){ |
| 2144 | doc.appendChild(doctype); |
| 2145 | } |
| 2146 | if(qualifiedName){ |
| 2147 | var root = doc.createElementNS(namespaceURI,qualifiedName); |
| 2148 | doc.appendChild(root); |
| 2149 | } |
| 2150 | return doc; |
| 2151 | }, |
| 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; |
| 2158 | return node; |
| 2159 | } |
| 2160 | }; |
| 2161 | |
| 2162 | function Node() { |
| 2163 | }; |
| 2164 | |
| 2165 | Node.prototype = { |
| 2166 | firstChild : null, |
| 2167 | lastChild : null, |
| 2168 | previousSibling : null, |
| 2169 | nextSibling : null, |
| 2170 | attributes : null, |
| 2171 | parentNode : null, |
| 2172 | childNodes : null, |
| 2173 | ownerDocument : null, |
| 2174 | nodeValue : null, |
| 2175 | namespaceURI : null, |
| 2176 | prefix : null, |
| 2177 | localName : null, |
| 2178 | insertBefore:function(newChild, refChild){//raises |
| 2179 | return _insertBefore(this,newChild,refChild); |
| 2180 | }, |
| 2181 | replaceChild:function(newChild, oldChild){//raises |
| 2182 | this.insertBefore(newChild,oldChild); |
| 2183 | if(oldChild){ |
| 2184 | this.removeChild(oldChild); |
| 2185 | } |
| 2186 | }, |
| 2187 | removeChild:function(oldChild){ |
| 2188 | return _removeChild(this,oldChild); |
| 2189 | }, |
| 2190 | appendChild:function(newChild){ |
| 2191 | return this.insertBefore(newChild,null); |
| 2192 | }, |
| 2193 | hasChildNodes:function(){ |
| 2194 | return this.firstChild != null; |
| 2195 | }, |
| 2196 | cloneNode:function(deep){ |
| 2197 | return cloneNode(this.ownerDocument||this,this,deep); |
| 2198 | }, |
| 2199 | normalize:function(){ |
| 2200 | var child = this.firstChild; |
| 2201 | while(child){ |
| 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); |
| 2206 | }else{ |
| 2207 | child.normalize(); |
| 2208 | child = next; |
| 2209 | } |
| 2210 | } |
| 2211 | }, |
| 2212 | isSupported:function(feature, version){ |
| 2213 | return this.ownerDocument.implementation.hasFeature(feature,version); |
| 2214 | }, |
| 2215 | hasAttributes:function(){ |
| 2216 | return this.attributes.length>0; |
| 2217 | }, |
| 2218 | lookupPrefix:function(namespaceURI){ |
| 2219 | var el = this; |
| 2220 | while(el){ |
| 2221 | var map = el._nsMap; |
| 2222 | if(map){ |
| 2223 | for(var n in map){ |
| 2224 | if(map[n] == namespaceURI){ |
| 2225 | return n; |
| 2226 | } |
| 2227 | } |
| 2228 | } |
| 2229 | el = el.nodeType == 2?el.ownerDocument : el.parentNode; |
| 2230 | } |
| 2231 | return null; |
| 2232 | }, |
| 2233 | lookupNamespaceURI:function(prefix){ |
| 2234 | var el = this; |
| 2235 | while(el){ |
| 2236 | var map = el._nsMap; |
| 2237 | if(map){ |
| 2238 | if(prefix in map){ |
| 2239 | return map[prefix] ; |
| 2240 | } |
| 2241 | } |
| 2242 | el = el.nodeType == 2?el.ownerDocument : el.parentNode; |
| 2243 | } |
| 2244 | return null; |
| 2245 | }, |
| 2246 | isDefaultNamespace:function(namespaceURI){ |
| 2247 | var prefix = this.lookupPrefix(namespaceURI); |
| 2248 | return prefix == null; |
| 2249 | } |
| 2250 | }; |
| 2251 | |
| 2252 | |
| 2253 | function _xmlEncoder(c){ |
| 2254 | return c == '<' && '<' || |
| 2255 | c == '>' && '>' || |
| 2256 | c == '&' && '&' || |
| 2257 | c == '"' && '"' || |
| 2258 | '&#'+c.charCodeAt()+';' |
| 2259 | } |
| 2260 | |
| 2261 | |
| 2262 | copy(NodeType,Node); |
| 2263 | copy(NodeType,Node.prototype); |
| 2264 | function _visitNode(node,callback){ |
| 2265 | if(callback(node)){ |
| 2266 | return true; |
| 2267 | } |
| 2268 | if(node = node.firstChild){ |
| 2269 | do{ |
| 2270 | if(_visitNode(node,callback)){return true} |
| 2271 | }while(node=node.nextSibling) |
| 2272 | } |
| 2273 | } |
| 2274 | |
| 2275 | |
| 2276 | |
| 2277 | function Document(){ |
| 2278 | } |
| 2279 | function _onAddAttribute(doc,el,newAttr){ |
| 2280 | doc && doc._inc++; |
| 2281 | var ns = newAttr.namespaceURI ; |
| 2282 | if(ns == 'http://www.w3.org/2000/xmlns/'){ |
| 2283 | el._nsMap[newAttr.prefix?newAttr.localName:''] = newAttr.value |
| 2284 | } |
| 2285 | } |
| 2286 | function _onRemoveAttribute(doc,el,newAttr,remove){ |
| 2287 | doc && doc._inc++; |
| 2288 | var ns = newAttr.namespaceURI ; |
| 2289 | if(ns == 'http://www.w3.org/2000/xmlns/'){ |
| 2290 | delete el._nsMap[newAttr.prefix?newAttr.localName:''] |
| 2291 | } |
| 2292 | } |
| 2293 | function _onUpdateChild(doc,el,newChild){ |
| 2294 | if(doc && doc._inc){ |
| 2295 | doc._inc++; |
| 2296 | var cs = el.childNodes; |
| 2297 | if(newChild){ |
| 2298 | cs[cs.length++] = newChild; |
| 2299 | }else{ |
| 2300 | var child = el.firstChild; |
| 2301 | var i = 0; |
| 2302 | while(child){ |
| 2303 | cs[i++] = child; |
| 2304 | child =child.nextSibling; |
| 2305 | } |
| 2306 | cs.length = i; |
| 2307 | } |
| 2308 | } |
| 2309 | } |
| 2310 | function _removeChild(parentNode,child){ |
| 2311 | var previous = child.previousSibling; |
| 2312 | var next = child.nextSibling; |
| 2313 | if(previous){ |
| 2314 | previous.nextSibling = next; |
| 2315 | }else{ |
| 2316 | parentNode.firstChild = next |
| 2317 | } |
| 2318 | if(next){ |
| 2319 | next.previousSibling = previous; |
| 2320 | }else{ |
| 2321 | parentNode.lastChild = previous; |
| 2322 | } |
| 2323 | _onUpdateChild(parentNode.ownerDocument,parentNode); |
| 2324 | return child; |
| 2325 | } |
| 2326 | function _insertBefore(parentNode,newChild,nextChild){ |
| 2327 | var cp = newChild.parentNode; |
| 2328 | if(cp){ |
| 2329 | cp.removeChild(newChild);//remove and update |
| 2330 | } |
| 2331 | if(newChild.nodeType === DOCUMENT_FRAGMENT_NODE){ |
| 2332 | var newFirst = newChild.firstChild; |
| 2333 | if (newFirst == null) { |
| 2334 | return newChild; |
| 2335 | } |
| 2336 | var newLast = newChild.lastChild; |
| 2337 | }else{ |
| 2338 | newFirst = newLast = newChild; |
| 2339 | } |
| 2340 | var pre = nextChild ? nextChild.previousSibling : parentNode.lastChild; |
| 2341 | |
| 2342 | newFirst.previousSibling = pre; |
| 2343 | newLast.nextSibling = nextChild; |
| 2344 | |
| 2345 | |
| 2346 | if(pre){ |
| 2347 | pre.nextSibling = newFirst; |
| 2348 | }else{ |
| 2349 | parentNode.firstChild = newFirst; |
| 2350 | } |
| 2351 | if(nextChild == null){ |
| 2352 | parentNode.lastChild = newLast; |
| 2353 | }else{ |
| 2354 | nextChild.previousSibling = newLast; |
| 2355 | } |
| 2356 | do{ |
| 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; |
| 2362 | } |
| 2363 | return newChild; |
| 2364 | } |
| 2365 | function _appendSingleChild(parentNode,newChild){ |
| 2366 | var cp = newChild.parentNode; |
| 2367 | if(cp){ |
| 2368 | var pre = parentNode.lastChild; |
| 2369 | cp.removeChild(newChild);//remove and update |
| 2370 | var pre = parentNode.lastChild; |
| 2371 | } |
| 2372 | var pre = parentNode.lastChild; |
| 2373 | newChild.parentNode = parentNode; |
| 2374 | newChild.previousSibling = pre; |
| 2375 | newChild.nextSibling = null; |
| 2376 | if(pre){ |
| 2377 | pre.nextSibling = newChild; |
| 2378 | }else{ |
| 2379 | parentNode.firstChild = newChild; |
| 2380 | } |
| 2381 | parentNode.lastChild = newChild; |
| 2382 | _onUpdateChild(parentNode.ownerDocument,parentNode,newChild); |
| 2383 | return newChild; |
| 2384 | } |
| 2385 | Document.prototype = { |
| 2386 | nodeName : '#document', |
| 2387 | nodeType : DOCUMENT_NODE, |
| 2388 | doctype : null, |
| 2389 | documentElement : null, |
| 2390 | _inc : 1, |
| 2391 | |
| 2392 | insertBefore : function(newChild, refChild){//raises |
| 2393 | if(newChild.nodeType == DOCUMENT_FRAGMENT_NODE){ |
| 2394 | var child = newChild.firstChild; |
| 2395 | while(child){ |
| 2396 | var next = child.nextSibling; |
| 2397 | this.insertBefore(child,refChild); |
| 2398 | child = next; |
| 2399 | } |
| 2400 | return newChild; |
| 2401 | } |
| 2402 | if(this.documentElement == null && newChild.nodeType == 1){ |
| 2403 | this.documentElement = newChild; |
| 2404 | } |
| 2405 | |
| 2406 | return _insertBefore(this,newChild,refChild),(newChild.ownerDocument = this),newChild; |
| 2407 | }, |
| 2408 | removeChild : function(oldChild){ |
| 2409 | if(this.documentElement == oldChild){ |
| 2410 | this.documentElement = null; |
| 2411 | } |
| 2412 | return _removeChild(this,oldChild); |
| 2413 | }, |
| 2414 | importNode : function(importedNode,deep){ |
| 2415 | return importNode(this,importedNode,deep); |
| 2416 | }, |
| 2417 | getElementById : function(id){ |
| 2418 | var rtv = null; |
| 2419 | _visitNode(this.documentElement,function(node){ |
| 2420 | if(node.nodeType == 1){ |
| 2421 | if(node.getAttribute('id') == id){ |
| 2422 | rtv = node; |
| 2423 | return true; |
| 2424 | } |
| 2425 | } |
| 2426 | }) |
| 2427 | return rtv; |
| 2428 | }, |
| 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; |
| 2437 | return node; |
| 2438 | }, |
| 2439 | createDocumentFragment : function(){ |
| 2440 | var node = new DocumentFragment(); |
| 2441 | node.ownerDocument = this; |
| 2442 | node.childNodes = new NodeList(); |
| 2443 | return node; |
| 2444 | }, |
| 2445 | createTextNode : function(data){ |
| 2446 | var node = new Text(); |
| 2447 | node.ownerDocument = this; |
| 2448 | node.appendData(data) |
| 2449 | return node; |
| 2450 | }, |
| 2451 | createComment : function(data){ |
| 2452 | var node = new Comment(); |
| 2453 | node.ownerDocument = this; |
| 2454 | node.appendData(data) |
| 2455 | return node; |
| 2456 | }, |
| 2457 | createCDATASection : function(data){ |
| 2458 | var node = new CDATASection(); |
| 2459 | node.ownerDocument = this; |
| 2460 | node.appendData(data) |
| 2461 | return node; |
| 2462 | }, |
| 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; |
| 2468 | return node; |
| 2469 | }, |
| 2470 | createAttribute : function(name){ |
| 2471 | var node = new Attr(); |
| 2472 | node.ownerDocument = this; |
| 2473 | node.name = name; |
| 2474 | node.nodeName = name; |
| 2475 | node.localName = name; |
| 2476 | node.specified = true; |
| 2477 | return node; |
| 2478 | }, |
| 2479 | createEntityReference : function(name){ |
| 2480 | var node = new EntityReference(); |
| 2481 | node.ownerDocument = this; |
| 2482 | node.nodeName = name; |
| 2483 | return node; |
| 2484 | }, |
| 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; |
| 2494 | if(pl.length == 2){ |
| 2495 | node.prefix = pl[0]; |
| 2496 | node.localName = pl[1]; |
| 2497 | }else{ |
| 2498 | node.localName = qualifiedName; |
| 2499 | } |
| 2500 | attrs._ownerElement = node; |
| 2501 | return node; |
| 2502 | }, |
| 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; |
| 2511 | if(pl.length == 2){ |
| 2512 | node.prefix = pl[0]; |
| 2513 | node.localName = pl[1]; |
| 2514 | }else{ |
| 2515 | node.localName = qualifiedName; |
| 2516 | } |
| 2517 | return node; |
| 2518 | } |
| 2519 | }; |
| 2520 | _extends(Document,Node); |
| 2521 | |
| 2522 | |
| 2523 | function Element() { |
| 2524 | this._nsMap = {}; |
| 2525 | }; |
| 2526 | Element.prototype = { |
| 2527 | nodeType : ELEMENT_NODE, |
| 2528 | hasAttribute : function(name){ |
| 2529 | return this.getAttributeNode(name)!=null; |
| 2530 | }, |
| 2531 | getAttribute : function(name){ |
| 2532 | var attr = this.getAttributeNode(name); |
| 2533 | return attr && attr.value || ''; |
| 2534 | }, |
| 2535 | getAttributeNode : function(name){ |
| 2536 | return this.attributes.getNamedItem(name); |
| 2537 | }, |
| 2538 | setAttribute : function(name, value){ |
| 2539 | var attr = this.ownerDocument.createAttribute(name); |
| 2540 | attr.value = attr.nodeValue = "" + value; |
| 2541 | this.setAttributeNode(attr) |
| 2542 | }, |
| 2543 | removeAttribute : function(name){ |
| 2544 | var attr = this.getAttributeNode(name) |
| 2545 | attr && this.removeAttributeNode(attr); |
| 2546 | }, |
| 2547 | appendChild:function(newChild){ |
| 2548 | if(newChild.nodeType === DOCUMENT_FRAGMENT_NODE){ |
| 2549 | return this.insertBefore(newChild,null); |
| 2550 | }else{ |
| 2551 | return _appendSingleChild(this,newChild); |
| 2552 | } |
| 2553 | }, |
| 2554 | setAttributeNode : function(newAttr){ |
| 2555 | return this.attributes.setNamedItem(newAttr); |
| 2556 | }, |
| 2557 | setAttributeNodeNS : function(newAttr){ |
| 2558 | return this.attributes.setNamedItemNS(newAttr); |
| 2559 | }, |
| 2560 | removeAttributeNode : function(oldAttr){ |
| 2561 | return this.attributes.removeNamedItem(oldAttr.nodeName); |
| 2562 | }, |
| 2563 | removeAttributeNS : function(namespaceURI, localName){ |
| 2564 | var old = this.getAttributeNodeNS(namespaceURI, localName); |
| 2565 | old && this.removeAttributeNode(old); |
| 2566 | }, |
| 2567 | |
| 2568 | hasAttributeNS : function(namespaceURI, localName){ |
| 2569 | return this.getAttributeNodeNS(namespaceURI, localName)!=null; |
| 2570 | }, |
| 2571 | getAttributeNS : function(namespaceURI, localName){ |
| 2572 | var attr = this.getAttributeNodeNS(namespaceURI, localName); |
| 2573 | return attr && attr.value || ''; |
| 2574 | }, |
| 2575 | setAttributeNS : function(namespaceURI, qualifiedName, value){ |
| 2576 | var attr = this.ownerDocument.createAttributeNS(namespaceURI, qualifiedName); |
| 2577 | attr.value = attr.nodeValue = "" + value; |
| 2578 | this.setAttributeNode(attr) |
| 2579 | }, |
| 2580 | getAttributeNodeNS : function(namespaceURI, localName){ |
| 2581 | return this.attributes.getNamedItemNS(namespaceURI, localName); |
| 2582 | }, |
| 2583 | |
| 2584 | getElementsByTagName : function(tagName){ |
| 2585 | return new LiveNodeList(this,function(base){ |
| 2586 | var ls = []; |
| 2587 | _visitNode(base,function(node){ |
| 2588 | if(node !== base && node.nodeType == ELEMENT_NODE && (tagName === '*' || node.tagName == tagName)){ |
| 2589 | ls.push(node); |
| 2590 | } |
| 2591 | }); |
| 2592 | return ls; |
| 2593 | }); |
| 2594 | }, |
| 2595 | getElementsByTagNameNS : function(namespaceURI, localName){ |
| 2596 | return new LiveNodeList(this,function(base){ |
| 2597 | var ls = []; |
| 2598 | _visitNode(base,function(node){ |
| 2599 | if(node !== base && node.nodeType === ELEMENT_NODE && (namespaceURI === '*' || node.namespaceURI === namespaceURI) && (localName === '*' || node.localName == localName)){ |
| 2600 | ls.push(node); |
| 2601 | } |
| 2602 | }); |
| 2603 | return ls; |
| 2604 | }); |
| 2605 | } |
| 2606 | }; |
| 2607 | Document.prototype.getElementsByTagName = Element.prototype.getElementsByTagName; |
| 2608 | Document.prototype.getElementsByTagNameNS = Element.prototype.getElementsByTagNameNS; |
| 2609 | |
| 2610 | |
| 2611 | _extends(Element,Node); |
| 2612 | function Attr() { |
| 2613 | }; |
| 2614 | Attr.prototype.nodeType = ATTRIBUTE_NODE; |
| 2615 | _extends(Attr,Node); |
| 2616 | |
| 2617 | |
| 2618 | function CharacterData() { |
| 2619 | }; |
| 2620 | CharacterData.prototype = { |
| 2621 | data : '', |
| 2622 | substringData : function(offset, count) { |
| 2623 | return this.data.substring(offset, offset+count); |
| 2624 | }, |
| 2625 | appendData: function(text) { |
| 2626 | text = this.data+text; |
| 2627 | this.nodeValue = this.data = text; |
| 2628 | this.length = text.length; |
| 2629 | }, |
| 2630 | insertData: function(offset,text) { |
| 2631 | this.replaceData(offset,0,text); |
| 2632 | |
| 2633 | }, |
| 2634 | appendChild:function(newChild){ |
| 2635 | throw new Error(ExceptionMessage[3]) |
| 2636 | return Node.prototype.appendChild.apply(this,arguments) |
| 2637 | }, |
| 2638 | deleteData: function(offset, count) { |
| 2639 | this.replaceData(offset,count,""); |
| 2640 | }, |
| 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; |
| 2647 | } |
| 2648 | } |
| 2649 | _extends(CharacterData,Node); |
| 2650 | function Text() { |
| 2651 | }; |
| 2652 | Text.prototype = { |
| 2653 | nodeName : "#text", |
| 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); |
| 2664 | } |
| 2665 | return newNode; |
| 2666 | } |
| 2667 | } |
| 2668 | _extends(Text,CharacterData); |
| 2669 | function Comment() { |
| 2670 | }; |
| 2671 | Comment.prototype = { |
| 2672 | nodeName : "#comment", |
| 2673 | nodeType : COMMENT_NODE |
| 2674 | } |
| 2675 | _extends(Comment,CharacterData); |
| 2676 | |
| 2677 | function CDATASection() { |
| 2678 | }; |
| 2679 | CDATASection.prototype = { |
| 2680 | nodeName : "#cdata-section", |
| 2681 | nodeType : CDATA_SECTION_NODE |
| 2682 | } |
| 2683 | _extends(CDATASection,CharacterData); |
| 2684 | |
| 2685 | |
| 2686 | function DocumentType() { |
| 2687 | }; |
| 2688 | DocumentType.prototype.nodeType = DOCUMENT_TYPE_NODE; |
| 2689 | _extends(DocumentType,Node); |
| 2690 | |
| 2691 | function Notation() { |
| 2692 | }; |
| 2693 | Notation.prototype.nodeType = NOTATION_NODE; |
| 2694 | _extends(Notation,Node); |
| 2695 | |
| 2696 | function Entity() { |
| 2697 | }; |
| 2698 | Entity.prototype.nodeType = ENTITY_NODE; |
| 2699 | _extends(Entity,Node); |
| 2700 | |
| 2701 | function EntityReference() { |
| 2702 | }; |
| 2703 | EntityReference.prototype.nodeType = ENTITY_REFERENCE_NODE; |
| 2704 | _extends(EntityReference,Node); |
| 2705 | |
| 2706 | function DocumentFragment() { |
| 2707 | }; |
| 2708 | DocumentFragment.prototype.nodeName = "#document-fragment"; |
| 2709 | DocumentFragment.prototype.nodeType = DOCUMENT_FRAGMENT_NODE; |
| 2710 | _extends(DocumentFragment,Node); |
| 2711 | |
| 2712 | |
| 2713 | function ProcessingInstruction() { |
| 2714 | } |
| 2715 | ProcessingInstruction.prototype.nodeType = PROCESSING_INSTRUCTION_NODE; |
| 2716 | _extends(ProcessingInstruction,Node); |
| 2717 | function XMLSerializer(){} |
| 2718 | XMLSerializer.prototype.serializeToString = function(node){ |
| 2719 | var buf = []; |
| 2720 | serializeToString(node,buf); |
| 2721 | return buf.join(''); |
| 2722 | } |
| 2723 | Node.prototype.toString =function(){ |
| 2724 | return XMLSerializer.prototype.serializeToString(this); |
| 2725 | } |
| 2726 | function serializeToString(node,buf){ |
| 2727 | switch(node.nodeType){ |
| 2728 | case ELEMENT_NODE: |
| 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); |
| 2737 | } |
| 2738 | if(child || isHTML && !/^(?:meta|link|img|br|hr|input|button)$/i.test(nodeName)){ |
| 2739 | buf.push('>'); |
| 2740 | if(isHTML && /^script$/i.test(nodeName)){ |
| 2741 | if(child){ |
| 2742 | buf.push(child.data); |
| 2743 | } |
| 2744 | }else{ |
| 2745 | while(child){ |
| 2746 | serializeToString(child,buf); |
| 2747 | child = child.nextSibling; |
| 2748 | } |
| 2749 | } |
| 2750 | buf.push('</',nodeName,'>'); |
| 2751 | }else{ |
| 2752 | buf.push('/>'); |
| 2753 | } |
| 2754 | return; |
| 2755 | case DOCUMENT_NODE: |
| 2756 | case DOCUMENT_FRAGMENT_NODE: |
| 2757 | var child = node.firstChild; |
| 2758 | while(child){ |
| 2759 | serializeToString(child,buf); |
| 2760 | child = child.nextSibling; |
| 2761 | } |
| 2762 | return; |
| 2763 | case ATTRIBUTE_NODE: |
| 2764 | return buf.push(' ',node.name,'="',node.value.replace(/[<&"]/g,_xmlEncoder),'"'); |
| 2765 | case TEXT_NODE: |
| 2766 | return buf.push(node.data.replace(/[<&]/g,_xmlEncoder)); |
| 2767 | case CDATA_SECTION_NODE: |
| 2768 | return buf.push( '<![CDATA[',node.data,']]>'); |
| 2769 | case COMMENT_NODE: |
| 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); |
| 2775 | if(pubid){ |
| 2776 | buf.push(' PUBLIC "',pubid); |
| 2777 | if (sysid && sysid!='.') { |
| 2778 | buf.push( '" "',sysid); |
| 2779 | } |
| 2780 | buf.push('">'); |
| 2781 | }else if(sysid && sysid!='.'){ |
| 2782 | buf.push(' SYSTEM "',sysid,'">'); |
| 2783 | }else{ |
| 2784 | var sub = node.internalSubset; |
| 2785 | if(sub){ |
| 2786 | buf.push(" [",sub,"]"); |
| 2787 | } |
| 2788 | buf.push(">"); |
| 2789 | } |
| 2790 | return; |
| 2791 | case PROCESSING_INSTRUCTION_NODE: |
| 2792 | return buf.push( "<?",node.target," ",node.data,"?>"); |
| 2793 | case ENTITY_REFERENCE_NODE: |
| 2794 | return buf.push( '&',node.nodeName,';'); |
| 2795 | default: |
| 2796 | buf.push('??',node.nodeName); |
| 2797 | } |
| 2798 | } |
| 2799 | function importNode(doc,node,deep){ |
| 2800 | var node2; |
| 2801 | switch (node.nodeType) { |
| 2802 | case ELEMENT_NODE: |
| 2803 | node2 = node.cloneNode(false); |
| 2804 | node2.ownerDocument = doc; |
| 2805 | case DOCUMENT_FRAGMENT_NODE: |
| 2806 | break; |
| 2807 | case ATTRIBUTE_NODE: |
| 2808 | deep = true; |
| 2809 | break; |
| 2810 | } |
| 2811 | if(!node2){ |
| 2812 | node2 = node.cloneNode(false);//false |
| 2813 | } |
| 2814 | node2.ownerDocument = doc; |
| 2815 | node2.parentNode = null; |
| 2816 | if(deep){ |
| 2817 | var child = node.firstChild; |
| 2818 | while(child){ |
| 2819 | node2.appendChild(importNode(doc,child,deep)); |
| 2820 | child = child.nextSibling; |
| 2821 | } |
| 2822 | } |
| 2823 | return node2; |
| 2824 | } |
| 2825 | function cloneNode(doc,node,deep){ |
| 2826 | var node2 = new node.constructor(); |
| 2827 | for(var n in node){ |
| 2828 | var v = node[n]; |
| 2829 | if(typeof v != 'object' ){ |
| 2830 | if(v != node2[n]){ |
| 2831 | node2[n] = v; |
| 2832 | } |
| 2833 | } |
| 2834 | } |
| 2835 | if(node.childNodes){ |
| 2836 | node2.childNodes = new NodeList(); |
| 2837 | } |
| 2838 | node2.ownerDocument = doc; |
| 2839 | switch (node2.nodeType) { |
| 2840 | case ELEMENT_NODE: |
| 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)); |
| 2847 | } |
| 2848 | break;; |
| 2849 | case ATTRIBUTE_NODE: |
| 2850 | deep = true; |
| 2851 | } |
| 2852 | if(deep){ |
| 2853 | var child = node.firstChild; |
| 2854 | while(child){ |
| 2855 | node2.appendChild(cloneNode(doc,child,deep)); |
| 2856 | child = child.nextSibling; |
| 2857 | } |
| 2858 | } |
| 2859 | return node2; |
| 2860 | } |
| 2861 | |
| 2862 | function __set__(object,key,value){ |
| 2863 | object[key] = value |
| 2864 | } |
| 2865 | try{ |
| 2866 | if(Object.defineProperty){ |
| 2867 | Object.defineProperty(LiveNodeList.prototype,'length',{ |
| 2868 | get:function(){ |
| 2869 | _updateLiveList(this); |
| 2870 | return this.$$length; |
| 2871 | } |
| 2872 | }); |
| 2873 | Object.defineProperty(Node.prototype,'textContent',{ |
| 2874 | get:function(){ |
| 2875 | return getTextContent(this); |
| 2876 | }, |
| 2877 | set:function(data){ |
| 2878 | switch(this.nodeType){ |
| 2879 | case 1: |
| 2880 | case 11: |
| 2881 | while(this.firstChild){ |
| 2882 | this.removeChild(this.firstChild); |
| 2883 | } |
| 2884 | if(data || String(data)){ |
| 2885 | this.appendChild(this.ownerDocument.createTextNode(data)); |
| 2886 | } |
| 2887 | break; |
| 2888 | default: |
| 2889 | this.data = data; |
| 2890 | this.value = value; |
| 2891 | this.nodeValue = data; |
| 2892 | } |
| 2893 | } |
| 2894 | }) |
| 2895 | |
| 2896 | function getTextContent(node){ |
| 2897 | switch(node.nodeType){ |
| 2898 | case 1: |
| 2899 | case 11: |
| 2900 | var buf = []; |
| 2901 | node = node.firstChild; |
| 2902 | while(node){ |
| 2903 | if(node.nodeType!==7 && node.nodeType !==8){ |
| 2904 | buf.push(getTextContent(node)); |
| 2905 | } |
| 2906 | node = node.nextSibling; |
| 2907 | } |
| 2908 | return buf.join(''); |
| 2909 | default: |
| 2910 | return node.nodeValue; |
| 2911 | } |
| 2912 | } |
| 2913 | __set__ = function(object,key,value){ |
| 2914 | object['$$'+key] = value |
| 2915 | } |
| 2916 | } |
| 2917 | }catch(e){//ie8 |
| 2918 | } |
| 2919 | |
| 2920 | return DOMImplementation; |
| 2921 | }); |
| 2922 | |
| 2923 | define("ace/mode/xml/dom-parser",["require","exports","module","ace/mode/xml/sax","ace/mode/xml/dom"], function(require, exports, module) { |
| 2924 | 'use strict'; |
| 2925 | |
| 2926 | var XMLReader = require('./sax'), |
| 2927 | DOMImplementation = require('./dom'); |
| 2928 | |
| 2929 | function DOMParser(options){ |
| 2930 | this.options = options ||{locator:{}}; |
| 2931 | |
| 2932 | } |
| 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':"'"} |
| 2941 | if(locator){ |
| 2942 | domBuilder.setDocumentLocator(locator) |
| 2943 | } |
| 2944 | |
| 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'; |
| 2951 | } |
| 2952 | if(source){ |
| 2953 | sax.parse(source,defaultNSMap,entityMap); |
| 2954 | }else{ |
| 2955 | sax.errorHandler.error("invalid document source"); |
| 2956 | } |
| 2957 | return domBuilder.document; |
| 2958 | } |
| 2959 | function buildErrorHandler(errorImpl,domBuilder,locator){ |
| 2960 | if(!errorImpl){ |
| 2961 | if(domBuilder instanceof DOMHandler){ |
| 2962 | return domBuilder; |
| 2963 | } |
| 2964 | errorImpl = domBuilder ; |
| 2965 | } |
| 2966 | var errorHandler = {} |
| 2967 | var isCallback = errorImpl instanceof Function; |
| 2968 | locator = locator||{} |
| 2969 | function build(key){ |
| 2970 | var fn = errorImpl[key]; |
| 2971 | if(!fn){ |
| 2972 | if(isCallback){ |
| 2973 | fn = errorImpl.length == 2?function(msg){errorImpl(key,msg)}:errorImpl; |
| 2974 | }else{ |
| 2975 | var i=arguments.length; |
| 2976 | while(--i){ |
| 2977 | if(fn = errorImpl[arguments[i]]){ |
| 2978 | break; |
| 2979 | } |
| 2980 | } |
| 2981 | } |
| 2982 | } |
| 2983 | errorHandler[key] = fn && function(msg){ |
| 2984 | fn(msg+_locator(locator), msg, locator); |
| 2985 | }||function(){}; |
| 2986 | } |
| 2987 | build('warning','warn'); |
| 2988 | build('error','warn','warning'); |
| 2989 | build('fatalError','warn','warning','error'); |
| 2990 | return errorHandler; |
| 2991 | } |
| 2992 | function DOMHandler() { |
| 2993 | this.cdata = false; |
| 2994 | } |
| 2995 | function position(locator,node){ |
| 2996 | node.lineNumber = locator.lineNumber; |
| 2997 | node.columnNumber = locator.columnNumber; |
| 2998 | } |
| 2999 | DOMHandler.prototype = { |
| 3000 | startDocument : function() { |
| 3001 | this.document = new DOMImplementation().createDocument(null, null, null); |
| 3002 | if (this.locator) { |
| 3003 | this.document.documentURI = this.locator.systemId; |
| 3004 | } |
| 3005 | }, |
| 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; |
| 3012 | |
| 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) |
| 3021 | } |
| 3022 | attr.value = attr.nodeValue = value; |
| 3023 | el.setAttributeNode(attr) |
| 3024 | } |
| 3025 | }, |
| 3026 | endElement:function(namespaceURI, localName, qName) { |
| 3027 | var current = this.currentElement |
| 3028 | var tagName = current.tagName; |
| 3029 | this.currentElement = current.parentNode; |
| 3030 | }, |
| 3031 | startPrefixMapping:function(prefix, uri) { |
| 3032 | }, |
| 3033 | endPrefixMapping:function(prefix) { |
| 3034 | }, |
| 3035 | processingInstruction:function(target, data) { |
| 3036 | var ins = this.document.createProcessingInstruction(target, data); |
| 3037 | this.locator && position(this.locator,ins) |
| 3038 | appendElement(this, ins); |
| 3039 | }, |
| 3040 | ignorableWhitespace:function(ch, start, length) { |
| 3041 | }, |
| 3042 | characters:function(chars, start, length) { |
| 3043 | chars = _toString.apply(this,arguments) |
| 3044 | if(this.currentElement && chars){ |
| 3045 | if (this.cdata) { |
| 3046 | var charNode = this.document.createCDATASection(chars); |
| 3047 | this.currentElement.appendChild(charNode); |
| 3048 | } else { |
| 3049 | var charNode = this.document.createTextNode(chars); |
| 3050 | this.currentElement.appendChild(charNode); |
| 3051 | } |
| 3052 | this.locator && position(this.locator,charNode) |
| 3053 | } |
| 3054 | }, |
| 3055 | skippedEntity:function(name) { |
| 3056 | }, |
| 3057 | endDocument:function() { |
| 3058 | this.document.normalize(); |
| 3059 | }, |
| 3060 | setDocumentLocator:function (locator) { |
| 3061 | if(this.locator = locator){// && !('lineNumber' in locator)){ |
| 3062 | locator.lineNumber = 0; |
| 3063 | } |
| 3064 | }, |
| 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); |
| 3070 | }, |
| 3071 | |
| 3072 | startCDATA:function() { |
| 3073 | this.cdata = true; |
| 3074 | }, |
| 3075 | endCDATA:function() { |
| 3076 | this.cdata = false; |
| 3077 | }, |
| 3078 | |
| 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); |
| 3085 | } |
| 3086 | }, |
| 3087 | warning:function(error) { |
| 3088 | console.warn(error,_locator(this.locator)); |
| 3089 | }, |
| 3090 | error:function(error) { |
| 3091 | console.error(error,_locator(this.locator)); |
| 3092 | }, |
| 3093 | fatalError:function(error) { |
| 3094 | console.error(error,_locator(this.locator)); |
| 3095 | throw error; |
| 3096 | } |
| 3097 | } |
| 3098 | function _locator(l){ |
| 3099 | if(l){ |
| 3100 | return '\n@'+(l.systemId ||'')+'#[line:'+l.lineNumber+',col:'+l.columnNumber+']' |
| 3101 | } |
| 3102 | } |
| 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)+''; |
| 3109 | } |
| 3110 | return chars; |
| 3111 | } |
| 3112 | } |
| 3113 | "endDTD,startEntity,endEntity,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,resolveEntity,getExternalSubset,notationDecl,unparsedEntityDecl".replace(/\w+/g,function(key){ |
| 3114 | DOMHandler.prototype[key] = function(){return null} |
| 3115 | }) |
| 3116 | function appendElement (hander,node) { |
| 3117 | if (!hander.currentElement) { |
| 3118 | hander.document.appendChild(node); |
| 3119 | } else { |
| 3120 | hander.currentElement.appendChild(node); |
| 3121 | } |
| 3122 | }//appendChild and setAttributeNS are preformance key |
| 3123 | |
| 3124 | return { |
| 3125 | DOMParser: DOMParser |
| 3126 | }; |
| 3127 | }); |
| 3128 | |
| 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) { |
| 3130 | "use strict"; |
| 3131 | |
| 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; |
| 3136 | |
| 3137 | var Worker = exports.Worker = function(sender) { |
| 3138 | Mirror.call(this, sender); |
| 3139 | this.setTimeout(400); |
| 3140 | this.context = null; |
| 3141 | }; |
| 3142 | |
| 3143 | oop.inherits(Worker, Mirror); |
| 3144 | |
| 3145 | (function() { |
| 3146 | |
| 3147 | this.setOptions = function(options) { |
| 3148 | this.context = options.context; |
| 3149 | }; |
| 3150 | |
| 3151 | this.onUpdate = function() { |
| 3152 | var value = this.doc.getValue(); |
| 3153 | if (!value) |
| 3154 | return; |
| 3155 | var parser = new DOMParser(); |
| 3156 | var errors = []; |
| 3157 | parser.options.errorHandler = { |
| 3158 | fatalError: function(fullMsg, errorMsg, locator) { |
| 3159 | errors.push({ |
| 3160 | row: locator.lineNumber, |
| 3161 | column: locator.columnNumber, |
| 3162 | text: errorMsg, |
| 3163 | type: "error" |
| 3164 | }); |
| 3165 | }, |
| 3166 | error: function(fullMsg, errorMsg, locator) { |
| 3167 | errors.push({ |
| 3168 | row: locator.lineNumber, |
| 3169 | column: locator.columnNumber, |
| 3170 | text: errorMsg, |
| 3171 | type: "error" |
| 3172 | }); |
| 3173 | }, |
| 3174 | warning: function(fullMsg, errorMsg, locator) { |
| 3175 | errors.push({ |
| 3176 | row: locator.lineNumber, |
| 3177 | column: locator.columnNumber, |
| 3178 | text: errorMsg, |
| 3179 | type: "warning" |
| 3180 | }); |
| 3181 | } |
| 3182 | }; |
| 3183 | |
| 3184 | parser.parseFromString(value); |
| 3185 | this.sender.emit("error", errors); |
| 3186 | }; |
| 3187 | |
| 3188 | }).call(Worker.prototype); |
| 3189 | |
| 3190 | }); |
| 3191 | |
| 3192 | define("ace/lib/es5-shim",["require","exports","module"], function(require, exports, module) { |
| 3193 | |
| 3194 | function Empty() {} |
| 3195 | |
| 3196 | if (!Function.prototype.bind) { |
| 3197 | Function.prototype.bind = function bind(that) { // .length is 1 |
| 3198 | var target = this; |
| 3199 | if (typeof target != "function") { |
| 3200 | throw new TypeError("Function.prototype.bind called on incompatible " + target); |
| 3201 | } |
| 3202 | var args = slice.call(arguments, 1); // for normal call |
| 3203 | var bound = function () { |
| 3204 | |
| 3205 | if (this instanceof bound) { |
| 3206 | |
| 3207 | var result = target.apply( |
| 3208 | this, |
| 3209 | args.concat(slice.call(arguments)) |
| 3210 | ); |
| 3211 | if (Object(result) === result) { |
| 3212 | return result; |
| 3213 | } |
| 3214 | return this; |
| 3215 | |
| 3216 | } else { |
| 3217 | return target.apply( |
| 3218 | that, |
| 3219 | args.concat(slice.call(arguments)) |
| 3220 | ); |
| 3221 | |
| 3222 | } |
| 3223 | |
| 3224 | }; |
| 3225 | if(target.prototype) { |
| 3226 | Empty.prototype = target.prototype; |
| 3227 | bound.prototype = new Empty(); |
| 3228 | Empty.prototype = null; |
| 3229 | } |
| 3230 | return bound; |
| 3231 | }; |
| 3232 | } |
| 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); |
| 3239 | var defineGetter; |
| 3240 | var defineSetter; |
| 3241 | var lookupGetter; |
| 3242 | var lookupSetter; |
| 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__); |
| 3249 | } |
| 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); |
| 3254 | a[0] = a[1] = 0; |
| 3255 | return a; |
| 3256 | } |
| 3257 | var array = [], lengthBefore; |
| 3258 | |
| 3259 | array.splice.apply(array, makeArray(20)); |
| 3260 | array.splice.apply(array, makeArray(26)); |
| 3261 | |
| 3262 | lengthBefore = array.length; //46 |
| 3263 | array.splice(5, 0, "XXX"); // add one element |
| 3264 | |
| 3265 | lengthBefore + 1 == array.length |
| 3266 | |
| 3267 | if (lengthBefore + 1 == array.length) { |
| 3268 | return true;// has right splice implementation without bugs |
| 3269 | } |
| 3270 | }()) {//IE 6/7 |
| 3271 | var array_splice = Array.prototype.splice; |
| 3272 | Array.prototype.splice = function(start, deleteCount) { |
| 3273 | if (!arguments.length) { |
| 3274 | return []; |
| 3275 | } else { |
| 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))) |
| 3280 | } |
| 3281 | }; |
| 3282 | } else {//IE8 |
| 3283 | Array.prototype.splice = function(pos, removeCount){ |
| 3284 | var length = this.length; |
| 3285 | if (pos > 0) { |
| 3286 | if (pos > length) |
| 3287 | pos = length; |
| 3288 | } else if (pos == void 0) { |
| 3289 | pos = 0; |
| 3290 | } else if (pos < 0) { |
| 3291 | pos = Math.max(length + pos, 0); |
| 3292 | } |
| 3293 | |
| 3294 | if (!(pos+removeCount < length)) |
| 3295 | removeCount = length - pos; |
| 3296 | |
| 3297 | var removed = this.slice(pos, pos+removeCount); |
| 3298 | var insert = slice.call(arguments, 2); |
| 3299 | var add = insert.length; |
| 3300 | if (pos === length) { |
| 3301 | if (add) { |
| 3302 | this.push.apply(this, insert); |
| 3303 | } |
| 3304 | } else { |
| 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; |
| 3310 | |
| 3311 | if (tailNewPos < tailOldPos) { // case A |
| 3312 | for (var i = 0; i < tailCount; ++i) { |
| 3313 | this[tailNewPos+i] = this[tailOldPos+i]; |
| 3314 | } |
| 3315 | } else if (tailNewPos > tailOldPos) { // case B |
| 3316 | for (i = tailCount; i--; ) { |
| 3317 | this[tailNewPos+i] = this[tailOldPos+i]; |
| 3318 | } |
| 3319 | } // else, add == remove (nothing to do) |
| 3320 | |
| 3321 | if (add && pos === lengthAfterRemove) { |
| 3322 | this.length = lengthAfterRemove; // truncate array |
| 3323 | this.push.apply(this, insert); |
| 3324 | } else { |
| 3325 | this.length = lengthAfterRemove + add; // reserves space |
| 3326 | for (i = 0; i < add; ++i) { |
| 3327 | this[pos+i] = insert[i]; |
| 3328 | } |
| 3329 | } |
| 3330 | } |
| 3331 | return removed; |
| 3332 | }; |
| 3333 | } |
| 3334 | } |
| 3335 | if (!Array.isArray) { |
| 3336 | Array.isArray = function isArray(obj) { |
| 3337 | return _toString(obj) == "[object Array]"; |
| 3338 | }; |
| 3339 | } |
| 3340 | var boxedString = Object("a"), |
| 3341 | splitString = boxedString[0] != "a" || !(0 in boxedString); |
| 3342 | |
| 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]" ? |
| 3347 | this.split("") : |
| 3348 | object, |
| 3349 | thisp = arguments[1], |
| 3350 | i = -1, |
| 3351 | length = self.length >>> 0; |
| 3352 | if (_toString(fun) != "[object Function]") { |
| 3353 | throw new TypeError(); // TODO message |
| 3354 | } |
| 3355 | |
| 3356 | while (++i < length) { |
| 3357 | if (i in self) { |
| 3358 | fun.call(thisp, self[i], i, object); |
| 3359 | } |
| 3360 | } |
| 3361 | }; |
| 3362 | } |
| 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]" ? |
| 3367 | this.split("") : |
| 3368 | object, |
| 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"); |
| 3374 | } |
| 3375 | |
| 3376 | for (var i = 0; i < length; i++) { |
| 3377 | if (i in self) |
| 3378 | result[i] = fun.call(thisp, self[i], i, object); |
| 3379 | } |
| 3380 | return result; |
| 3381 | }; |
| 3382 | } |
| 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]" ? |
| 3387 | this.split("") : |
| 3388 | object, |
| 3389 | length = self.length >>> 0, |
| 3390 | result = [], |
| 3391 | value, |
| 3392 | thisp = arguments[1]; |
| 3393 | if (_toString(fun) != "[object Function]") { |
| 3394 | throw new TypeError(fun + " is not a function"); |
| 3395 | } |
| 3396 | |
| 3397 | for (var i = 0; i < length; i++) { |
| 3398 | if (i in self) { |
| 3399 | value = self[i]; |
| 3400 | if (fun.call(thisp, value, i, object)) { |
| 3401 | result.push(value); |
| 3402 | } |
| 3403 | } |
| 3404 | } |
| 3405 | return result; |
| 3406 | }; |
| 3407 | } |
| 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]" ? |
| 3412 | this.split("") : |
| 3413 | object, |
| 3414 | length = self.length >>> 0, |
| 3415 | thisp = arguments[1]; |
| 3416 | if (_toString(fun) != "[object Function]") { |
| 3417 | throw new TypeError(fun + " is not a function"); |
| 3418 | } |
| 3419 | |
| 3420 | for (var i = 0; i < length; i++) { |
| 3421 | if (i in self && !fun.call(thisp, self[i], i, object)) { |
| 3422 | return false; |
| 3423 | } |
| 3424 | } |
| 3425 | return true; |
| 3426 | }; |
| 3427 | } |
| 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]" ? |
| 3432 | this.split("") : |
| 3433 | object, |
| 3434 | length = self.length >>> 0, |
| 3435 | thisp = arguments[1]; |
| 3436 | if (_toString(fun) != "[object Function]") { |
| 3437 | throw new TypeError(fun + " is not a function"); |
| 3438 | } |
| 3439 | |
| 3440 | for (var i = 0; i < length; i++) { |
| 3441 | if (i in self && fun.call(thisp, self[i], i, object)) { |
| 3442 | return true; |
| 3443 | } |
| 3444 | } |
| 3445 | return false; |
| 3446 | }; |
| 3447 | } |
| 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]" ? |
| 3452 | this.split("") : |
| 3453 | object, |
| 3454 | length = self.length >>> 0; |
| 3455 | if (_toString(fun) != "[object Function]") { |
| 3456 | throw new TypeError(fun + " is not a function"); |
| 3457 | } |
| 3458 | if (!length && arguments.length == 1) { |
| 3459 | throw new TypeError("reduce of empty array with no initial value"); |
| 3460 | } |
| 3461 | |
| 3462 | var i = 0; |
| 3463 | var result; |
| 3464 | if (arguments.length >= 2) { |
| 3465 | result = arguments[1]; |
| 3466 | } else { |
| 3467 | do { |
| 3468 | if (i in self) { |
| 3469 | result = self[i++]; |
| 3470 | break; |
| 3471 | } |
| 3472 | if (++i >= length) { |
| 3473 | throw new TypeError("reduce of empty array with no initial value"); |
| 3474 | } |
| 3475 | } while (true); |
| 3476 | } |
| 3477 | |
| 3478 | for (; i < length; i++) { |
| 3479 | if (i in self) { |
| 3480 | result = fun.call(void 0, result, self[i], i, object); |
| 3481 | } |
| 3482 | } |
| 3483 | |
| 3484 | return result; |
| 3485 | }; |
| 3486 | } |
| 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]" ? |
| 3491 | this.split("") : |
| 3492 | object, |
| 3493 | length = self.length >>> 0; |
| 3494 | if (_toString(fun) != "[object Function]") { |
| 3495 | throw new TypeError(fun + " is not a function"); |
| 3496 | } |
| 3497 | if (!length && arguments.length == 1) { |
| 3498 | throw new TypeError("reduceRight of empty array with no initial value"); |
| 3499 | } |
| 3500 | |
| 3501 | var result, i = length - 1; |
| 3502 | if (arguments.length >= 2) { |
| 3503 | result = arguments[1]; |
| 3504 | } else { |
| 3505 | do { |
| 3506 | if (i in self) { |
| 3507 | result = self[i--]; |
| 3508 | break; |
| 3509 | } |
| 3510 | if (--i < 0) { |
| 3511 | throw new TypeError("reduceRight of empty array with no initial value"); |
| 3512 | } |
| 3513 | } while (true); |
| 3514 | } |
| 3515 | |
| 3516 | do { |
| 3517 | if (i in this) { |
| 3518 | result = fun.call(void 0, result, self[i], i, object); |
| 3519 | } |
| 3520 | } while (i--); |
| 3521 | |
| 3522 | return result; |
| 3523 | }; |
| 3524 | } |
| 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]" ? |
| 3528 | this.split("") : |
| 3529 | toObject(this), |
| 3530 | length = self.length >>> 0; |
| 3531 | |
| 3532 | if (!length) { |
| 3533 | return -1; |
| 3534 | } |
| 3535 | |
| 3536 | var i = 0; |
| 3537 | if (arguments.length > 1) { |
| 3538 | i = toInteger(arguments[1]); |
| 3539 | } |
| 3540 | i = i >= 0 ? i : Math.max(0, length + i); |
| 3541 | for (; i < length; i++) { |
| 3542 | if (i in self && self[i] === sought) { |
| 3543 | return i; |
| 3544 | } |
| 3545 | } |
| 3546 | return -1; |
| 3547 | }; |
| 3548 | } |
| 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]" ? |
| 3552 | this.split("") : |
| 3553 | toObject(this), |
| 3554 | length = self.length >>> 0; |
| 3555 | |
| 3556 | if (!length) { |
| 3557 | return -1; |
| 3558 | } |
| 3559 | var i = length - 1; |
| 3560 | if (arguments.length > 1) { |
| 3561 | i = Math.min(i, toInteger(arguments[1])); |
| 3562 | } |
| 3563 | i = i >= 0 ? i : length - Math.abs(i); |
| 3564 | for (; i >= 0; i--) { |
| 3565 | if (i in self && sought === self[i]) { |
| 3566 | return i; |
| 3567 | } |
| 3568 | } |
| 3569 | return -1; |
| 3570 | }; |
| 3571 | } |
| 3572 | if (!Object.getPrototypeOf) { |
| 3573 | Object.getPrototypeOf = function getPrototypeOf(object) { |
| 3574 | return object.__proto__ || ( |
| 3575 | object.constructor ? |
| 3576 | object.constructor.prototype : |
| 3577 | prototypeOfObject |
| 3578 | ); |
| 3579 | }; |
| 3580 | } |
| 3581 | if (!Object.getOwnPropertyDescriptor) { |
| 3582 | var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a " + |
| 3583 | "non-object: "; |
| 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)) |
| 3588 | return; |
| 3589 | |
| 3590 | var descriptor, getter, setter; |
| 3591 | descriptor = { enumerable: true, configurable: true }; |
| 3592 | if (supportsAccessors) { |
| 3593 | var prototype = object.__proto__; |
| 3594 | object.__proto__ = prototypeOfObject; |
| 3595 | |
| 3596 | var getter = lookupGetter(object, property); |
| 3597 | var setter = lookupSetter(object, property); |
| 3598 | object.__proto__ = prototype; |
| 3599 | |
| 3600 | if (getter || setter) { |
| 3601 | if (getter) descriptor.get = getter; |
| 3602 | if (setter) descriptor.set = setter; |
| 3603 | return descriptor; |
| 3604 | } |
| 3605 | } |
| 3606 | descriptor.value = object[property]; |
| 3607 | return descriptor; |
| 3608 | }; |
| 3609 | } |
| 3610 | if (!Object.getOwnPropertyNames) { |
| 3611 | Object.getOwnPropertyNames = function getOwnPropertyNames(object) { |
| 3612 | return Object.keys(object); |
| 3613 | }; |
| 3614 | } |
| 3615 | if (!Object.create) { |
| 3616 | var createEmpty; |
| 3617 | if (Object.prototype.__proto__ === null) { |
| 3618 | createEmpty = function () { |
| 3619 | return { "__proto__": null }; |
| 3620 | }; |
| 3621 | } else { |
| 3622 | createEmpty = function () { |
| 3623 | var empty = {}; |
| 3624 | for (var i in empty) |
| 3625 | empty[i] = null; |
| 3626 | empty.constructor = |
| 3627 | empty.hasOwnProperty = |
| 3628 | empty.propertyIsEnumerable = |
| 3629 | empty.isPrototypeOf = |
| 3630 | empty.toLocaleString = |
| 3631 | empty.toString = |
| 3632 | empty.valueOf = |
| 3633 | empty.__proto__ = null; |
| 3634 | return empty; |
| 3635 | } |
| 3636 | } |
| 3637 | |
| 3638 | Object.create = function create(prototype, properties) { |
| 3639 | var object; |
| 3640 | if (prototype === null) { |
| 3641 | object = createEmpty(); |
| 3642 | } else { |
| 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; |
| 3649 | } |
| 3650 | if (properties !== void 0) |
| 3651 | Object.defineProperties(object, properties); |
| 3652 | return object; |
| 3653 | }; |
| 3654 | } |
| 3655 | |
| 3656 | function doesDefinePropertyWork(object) { |
| 3657 | try { |
| 3658 | Object.defineProperty(object, "sentinel", {}); |
| 3659 | return "sentinel" in object; |
| 3660 | } catch (exception) { |
| 3661 | } |
| 3662 | } |
| 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; |
| 3669 | } |
| 3670 | } |
| 3671 | |
| 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"; |
| 3677 | |
| 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) { |
| 3684 | try { |
| 3685 | return definePropertyFallback.call(Object, object, property, descriptor); |
| 3686 | } catch (exception) { |
| 3687 | } |
| 3688 | } |
| 3689 | if (owns(descriptor, "value")) { |
| 3690 | |
| 3691 | if (supportsAccessors && (lookupGetter(object, property) || |
| 3692 | lookupSetter(object, property))) |
| 3693 | { |
| 3694 | var prototype = object.__proto__; |
| 3695 | object.__proto__ = prototypeOfObject; |
| 3696 | delete object[property]; |
| 3697 | object[property] = descriptor.value; |
| 3698 | object.__proto__ = prototype; |
| 3699 | } else { |
| 3700 | object[property] = descriptor.value; |
| 3701 | } |
| 3702 | } else { |
| 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); |
| 3709 | } |
| 3710 | |
| 3711 | return object; |
| 3712 | }; |
| 3713 | } |
| 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]); |
| 3719 | } |
| 3720 | return object; |
| 3721 | }; |
| 3722 | } |
| 3723 | if (!Object.seal) { |
| 3724 | Object.seal = function seal(object) { |
| 3725 | return object; |
| 3726 | }; |
| 3727 | } |
| 3728 | if (!Object.freeze) { |
| 3729 | Object.freeze = function freeze(object) { |
| 3730 | return object; |
| 3731 | }; |
| 3732 | } |
| 3733 | try { |
| 3734 | Object.freeze(function () {}); |
| 3735 | } catch (exception) { |
| 3736 | Object.freeze = (function freeze(freezeObject) { |
| 3737 | return function freeze(object) { |
| 3738 | if (typeof object == "function") { |
| 3739 | return object; |
| 3740 | } else { |
| 3741 | return freezeObject(object); |
| 3742 | } |
| 3743 | }; |
| 3744 | })(Object.freeze); |
| 3745 | } |
| 3746 | if (!Object.preventExtensions) { |
| 3747 | Object.preventExtensions = function preventExtensions(object) { |
| 3748 | return object; |
| 3749 | }; |
| 3750 | } |
| 3751 | if (!Object.isSealed) { |
| 3752 | Object.isSealed = function isSealed(object) { |
| 3753 | return false; |
| 3754 | }; |
| 3755 | } |
| 3756 | if (!Object.isFrozen) { |
| 3757 | Object.isFrozen = function isFrozen(object) { |
| 3758 | return false; |
| 3759 | }; |
| 3760 | } |
| 3761 | if (!Object.isExtensible) { |
| 3762 | Object.isExtensible = function isExtensible(object) { |
| 3763 | if (Object(object) === object) { |
| 3764 | throw new TypeError(); // TODO message |
| 3765 | } |
| 3766 | var name = ''; |
| 3767 | while (owns(object, name)) { |
| 3768 | name += '?'; |
| 3769 | } |
| 3770 | object[name] = true; |
| 3771 | var returnValue = owns(object, name); |
| 3772 | delete object[name]; |
| 3773 | return returnValue; |
| 3774 | }; |
| 3775 | } |
| 3776 | if (!Object.keys) { |
| 3777 | var hasDontEnumBug = true, |
| 3778 | dontEnums = [ |
| 3779 | "toString", |
| 3780 | "toLocaleString", |
| 3781 | "valueOf", |
| 3782 | "hasOwnProperty", |
| 3783 | "isPrototypeOf", |
| 3784 | "propertyIsEnumerable", |
| 3785 | "constructor" |
| 3786 | ], |
| 3787 | dontEnumsLength = dontEnums.length; |
| 3788 | |
| 3789 | for (var key in {"toString": null}) { |
| 3790 | hasDontEnumBug = false; |
| 3791 | } |
| 3792 | |
| 3793 | Object.keys = function keys(object) { |
| 3794 | |
| 3795 | if ( |
| 3796 | (typeof object != "object" && typeof object != "function") || |
| 3797 | object === null |
| 3798 | ) { |
| 3799 | throw new TypeError("Object.keys called on a non-object"); |
| 3800 | } |
| 3801 | |
| 3802 | var keys = []; |
| 3803 | for (var name in object) { |
| 3804 | if (owns(object, name)) { |
| 3805 | keys.push(name); |
| 3806 | } |
| 3807 | } |
| 3808 | |
| 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); |
| 3814 | } |
| 3815 | } |
| 3816 | } |
| 3817 | return keys; |
| 3818 | }; |
| 3819 | |
| 3820 | } |
| 3821 | if (!Date.now) { |
| 3822 | Date.now = function now() { |
| 3823 | return new Date().getTime(); |
| 3824 | }; |
| 3825 | } |
| 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" + |
| 3828 | "\u2029\uFEFF"; |
| 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, ""); |
| 3835 | }; |
| 3836 | } |
| 3837 | |
| 3838 | function toInteger(n) { |
| 3839 | n = +n; |
| 3840 | if (n !== n) { // isNaN |
| 3841 | n = 0; |
| 3842 | } else if (n !== 0 && n !== (1/0) && n !== -(1/0)) { |
| 3843 | n = (n > 0 || -1) * Math.floor(Math.abs(n)); |
| 3844 | } |
| 3845 | return n; |
| 3846 | } |
| 3847 | |
| 3848 | function isPrimitive(input) { |
| 3849 | var type = typeof input; |
| 3850 | return ( |
| 3851 | input === null || |
| 3852 | type === "undefined" || |
| 3853 | type === "boolean" || |
| 3854 | type === "number" || |
| 3855 | type === "string" |
| 3856 | ); |
| 3857 | } |
| 3858 | |
| 3859 | function toPrimitive(input) { |
| 3860 | var val, valueOf, toString; |
| 3861 | if (isPrimitive(input)) { |
| 3862 | return input; |
| 3863 | } |
| 3864 | valueOf = input.valueOf; |
| 3865 | if (typeof valueOf === "function") { |
| 3866 | val = valueOf.call(input); |
| 3867 | if (isPrimitive(val)) { |
| 3868 | return val; |
| 3869 | } |
| 3870 | } |
| 3871 | toString = input.toString; |
| 3872 | if (typeof toString === "function") { |
| 3873 | val = toString.call(input); |
| 3874 | if (isPrimitive(val)) { |
| 3875 | return val; |
| 3876 | } |
| 3877 | } |
| 3878 | throw new TypeError(); |
| 3879 | } |
| 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"); |
| 3883 | } |
| 3884 | return Object(o); |
| 3885 | }; |
| 3886 | |
| 3887 | }); |