worker-xml.js 110 KB

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