worker-xml.js 110 KB

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