index.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. (function () {
  2. var jsEditor;
  3. var run = function () {
  4. var blockEditorChange = false;
  5. jsEditor.onKeyDown(function (evt) {
  6. });
  7. jsEditor.onKeyUp(function (evt) {
  8. if (blockEditorChange) {
  9. return;
  10. }
  11. document.getElementById("currentScript").innerHTML = "Custom";
  12. document.getElementById('safemodeToggle').checked = true;
  13. });
  14. var snippetUrl = "https://babylonjs-api2.azurewebsites.net/snippets";
  15. var currentSnippetToken;
  16. var currentSnippetTitle = null;
  17. var currentSnippetDescription = null;
  18. var currentSnippetTags = null;
  19. var engine;
  20. var fpsLabel = document.getElementById("fpsLabel");
  21. var scripts;
  22. var zipCode;
  23. BABYLON.Engine.ShadersRepository = "/src/Shaders/";
  24. var currentVersionElement = document.getElementById("currentVersion");
  25. if (currentVersionElement) {
  26. switch (BABYLON.Engine.Version) {
  27. case "2.5":
  28. currentVersionElement.innerHTML = "Version: " + BABYLON.Engine.Version;
  29. break;
  30. default:
  31. currentVersionElement.innerHTML = "Version: Latest";
  32. break;
  33. }
  34. }
  35. var loadScript = function (scriptURL, title) {
  36. var xhr = new XMLHttpRequest();
  37. xhr.open('GET', scriptURL, true);
  38. xhr.onreadystatechange = function () {
  39. if (xhr.readyState === 4) {
  40. if (xhr.status === 200) {
  41. blockEditorChange = true;
  42. jsEditor.setValue(xhr.responseText);
  43. jsEditor.setPosition({ lineNumber: 0, column: 0 });
  44. blockEditorChange = false;
  45. compileAndRun();
  46. document.getElementById("currentScript").innerHTML = title;
  47. currentSnippetToken = null;
  48. }
  49. }
  50. };
  51. xhr.send(null);
  52. };
  53. var loadScriptFromIndex = function (index) {
  54. if (index === 0) {
  55. index = 1;
  56. }
  57. var script = scripts[index - 1].trim();
  58. loadScript("scripts/" + script + ".js", script);
  59. }
  60. var onScriptClick = function (evt) {
  61. loadScriptFromIndex(evt.target.scriptLinkIndex);
  62. }
  63. var loadScriptsList = function () {
  64. var xhr = new XMLHttpRequest();
  65. xhr.open('GET', 'scripts/scripts.txt', true);
  66. xhr.onreadystatechange = function () {
  67. if (xhr.readyState === 4) {
  68. if (xhr.status === 200) {
  69. scripts = xhr.responseText.split("\n");
  70. var ul = document.getElementById("scriptsList");
  71. var index;
  72. for (index = 0; index < scripts.length; index++) {
  73. var li = document.createElement("li");
  74. var a = document.createElement("a");
  75. li.class = "scriptsListEntry";
  76. a.href = "#";
  77. a.innerHTML = (index + 1) + " - " + scripts[index];
  78. a.scriptLinkIndex = index + 1;
  79. a.onclick = onScriptClick;
  80. li.appendChild(a);
  81. ul.appendChild(li);
  82. }
  83. if (!location.hash) {
  84. // Query string
  85. var queryString = window.location.search;
  86. if (queryString) {
  87. var query = queryString.replace("?", "");
  88. index = parseInt(query);
  89. if (!isNaN(index)) {
  90. loadScriptFromIndex(index);
  91. } else {
  92. loadScript("scripts/" + query + ".js", query);
  93. }
  94. } else {
  95. loadScript("scripts/basic scene.js", "Basic scene");
  96. }
  97. }
  98. }
  99. }
  100. };
  101. xhr.send(null);
  102. }
  103. var createNewScript = function () {
  104. location.hash = "";
  105. currentSnippetToken = null;
  106. currentSnippetTitle = null;
  107. currentSnippetDescription = null;
  108. currentSnippetTags = null;
  109. showNoMetadata();
  110. jsEditor.setValue('// You have to create a function called createScene. This function must return a BABYLON.Scene object\r\n// You can reference the following variables: scene, canvas\r\n// You must at least define a camera\r\n// More info here: https://doc.babylonjs.com/generals/The_Playground_Tutorial\r\n\r\nvar createScene = function() {\r\n\tvar scene = new BABYLON.Scene(engine);\r\n\tvar camera = new BABYLON.ArcRotateCamera("Camera", 0, Math.PI / 2, 12, BABYLON.Vector3.Zero(), scene);\r\n\tcamera.attachControl(canvas, true);\r\n\r\n\r\n\r\n\treturn scene;\r\n};');
  111. jsEditor.setPosition({ lineNumber: 11, column: 0 });
  112. jsEditor.focus();
  113. compileAndRun();
  114. }
  115. var clear = function () {
  116. location.hash = "";
  117. currentSnippetToken = null;
  118. jsEditor.setValue('');
  119. jsEditor.setPosition({ lineNumber: 0, column: 0 });
  120. jsEditor.focus();
  121. }
  122. var showError = function (errorMessage, errorEvent) {
  123. var errorContent =
  124. '<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">&times;</button><h4>Compilation error</h4>'
  125. if (errorEvent) {
  126. var regEx = /\(.+:(\d+):(\d+)\)\n/g;
  127. var match = regEx.exec(errorEvent.stack);
  128. if (match) {
  129. errorContent += "Line ";
  130. var lineNumber = match[1];
  131. var columnNumber = match[2];
  132. errorContent += lineNumber + ':' + columnNumber + ' - ';
  133. }
  134. }
  135. errorContent += errorMessage + '</div>';
  136. document.getElementById("errorZone").innerHTML = errorContent;
  137. }
  138. var showNoMetadata = function() {
  139. document.getElementById("saveFormTitle").value = '';
  140. document.getElementById("saveFormTitle").readOnly = false;
  141. document.getElementById("saveFormDescription").value = '';
  142. document.getElementById("saveFormDescription").readOnly = false;
  143. document.getElementById("saveFormTags").value = '';
  144. document.getElementById("saveFormTags").readOnly = false;
  145. document.getElementById("saveFormButtons").style.display = "block";
  146. document.getElementById("saveMessage").style.display = "block";
  147. document.getElementById("metadataButton").style.display = "none";
  148. };
  149. showNoMetadata();
  150. var hideNoMetadata = function() {
  151. document.getElementById("saveFormTitle").readOnly = true;
  152. document.getElementById("saveFormDescription").readOnly = true;
  153. document.getElementById("saveFormTags").readOnly = true;
  154. document.getElementById("saveFormButtons").style.display = "none";
  155. document.getElementById("saveMessage").style.display = "none";
  156. document.getElementById("metadataButton").style.display = "inline-block";
  157. };
  158. compileAndRun = function () {
  159. try {
  160. if (!BABYLON.Engine.isSupported()) {
  161. showError("Your browser does not support WebGL", null);
  162. return;
  163. }
  164. if (engine) {
  165. engine.dispose();
  166. engine = null;
  167. }
  168. var canvas = document.getElementById("renderCanvas");
  169. engine = new BABYLON.Engine(canvas, true, { preserveDrawingBuffer: true, stencil: true });
  170. document.getElementById("errorZone").innerHTML = "";
  171. document.getElementById("statusBar").innerHTML = "Loading assets...Please wait";
  172. engine.runRenderLoop(function () {
  173. if (engine.scenes.length === 0) {
  174. return;
  175. }
  176. if (canvas.width !== canvas.clientWidth) {
  177. engine.resize();
  178. }
  179. var scene = engine.scenes[0];
  180. if (scene.activeCamera || scene.activeCameras.length > 0) {
  181. scene.render();
  182. }
  183. fpsLabel.innerHTML = engine.getFps().toFixed() + " fps";
  184. });
  185. var code = jsEditor.getValue();
  186. var scene;
  187. if (code.indexOf("createScene") !== -1) { // createScene
  188. eval(code);
  189. scene = createScene();
  190. if (!scene) {
  191. showError("createScene function must return a scene.", null);
  192. return;
  193. }
  194. zipCode = code + "\r\n\r\nvar scene = createScene();";
  195. } else if (code.indexOf("CreateScene") !== -1) { // CreateScene
  196. eval(code);
  197. scene = CreateScene();
  198. if (!scene) {
  199. showError("CreateScene function must return a scene.", null);
  200. return;
  201. }
  202. zipCode = code + "\r\n\r\nvar scene = CreateScene();";
  203. } else if (code.indexOf("createscene") !== -1) { // createscene
  204. eval(code);
  205. scene = createscene();
  206. if (!scene) {
  207. showError("createscene function must return a scene.", null);
  208. return;
  209. }
  210. zipCode = code + "\r\n\r\nvar scene = createscene();";
  211. } else { // Direct code
  212. scene = new BABYLON.Scene(engine);
  213. eval("runScript = function(scene, canvas) {" + code + "}");
  214. runScript(scene, canvas);
  215. zipCode = "var scene = new BABYLON.Scene(engine);\r\n\r\n" + code;
  216. }
  217. if (engine.scenes.length === 0) {
  218. showError("You must at least create a scene.", null);
  219. return;
  220. }
  221. if (engine.scenes[0].activeCamera == null) {
  222. showError("You must at least create a camera.", null);
  223. return;
  224. }
  225. engine.scenes[0].executeWhenReady(function () {
  226. document.getElementById("statusBar").innerHTML = "";
  227. });
  228. } catch (e) {
  229. showError(e.message, e);
  230. }
  231. };
  232. window.addEventListener("resize",
  233. function () {
  234. if (engine) {
  235. engine.resize();
  236. }
  237. });
  238. // Load scripts list
  239. loadScriptsList();
  240. // Zip
  241. var addContentToZip = function (zip, name, url, replace, buffer, then) {
  242. var xhr = new XMLHttpRequest();
  243. xhr.open('GET', url, true);
  244. if (buffer) {
  245. xhr.responseType = "arraybuffer";
  246. }
  247. xhr.onreadystatechange = function () {
  248. if (xhr.readyState === 4) {
  249. if (xhr.status === 200) {
  250. var text;
  251. if (!buffer) {
  252. if (replace) {
  253. var splits = replace.split("\r\n");
  254. for (var index = 0; index < splits.length; index++) {
  255. splits[index] = " " + splits[index];
  256. }
  257. replace = splits.join("\r\n");
  258. text = xhr.responseText.replace("####INJECT####", replace);
  259. } else {
  260. text = xhr.responseText;
  261. }
  262. }
  263. zip.file(name, buffer ? xhr.response : text);
  264. then();
  265. }
  266. }
  267. };
  268. xhr.send(null);
  269. }
  270. var addTexturesToZip = function (zip, index, textures, folder, then) {
  271. if (index === textures.length) {
  272. then();
  273. return;
  274. }
  275. if (textures[index].isRenderTarget || textures[index] instanceof BABYLON.DynamicTexture) {
  276. addTexturesToZip(zip, index + 1, textures, folder, then);
  277. return;
  278. }
  279. if (textures[index].isCube) {
  280. if (textures[index]._extensions) {
  281. for (var i = 0; i < 6; i++) {
  282. textures.push({ name: textures[index].name + textures[index]._extensions[i] });
  283. }
  284. }
  285. else {
  286. textures.push({ name: textures[index].name });
  287. }
  288. addTexturesToZip(zip, index + 1, textures, folder, then);
  289. return;
  290. }
  291. if (folder == null) {
  292. folder = zip.folder("textures");
  293. }
  294. var url;
  295. if (textures[index].video) {
  296. url = textures[index].video.currentSrc;
  297. } else {
  298. url = textures[index].name;
  299. }
  300. var name = url.substr(url.lastIndexOf("/") + 1);
  301. addContentToZip(folder,
  302. name,
  303. url,
  304. null,
  305. true,
  306. function () {
  307. addTexturesToZip(zip, index + 1, textures, folder, then);
  308. });
  309. }
  310. var addImportedFilesToZip = function (zip, index, importedFiles, folder, then) {
  311. if (index === importedFiles.length) {
  312. then();
  313. return;
  314. }
  315. if (!folder) {
  316. folder = zip.folder("scenes");
  317. }
  318. var url = importedFiles[index];
  319. var name = url.substr(url.lastIndexOf("/") + 1);
  320. addContentToZip(folder,
  321. name,
  322. url,
  323. null,
  324. true,
  325. function () {
  326. addImportedFilesToZip(zip, index + 1, importedFiles, folder, then);
  327. });
  328. }
  329. var getZip = function () {
  330. if (engine.scenes.length === 0) {
  331. return;
  332. }
  333. var zip = new JSZip();
  334. var scene = engine.scenes[0];
  335. var textures = scene.textures;
  336. var importedFiles = scene.importedMeshesFiles;
  337. document.getElementById("statusBar").innerHTML = "Creating archive...Please wait";
  338. if (zipCode.indexOf("textures/worldHeightMap.jpg") !== -1) {
  339. textures.push({ name: "textures/worldHeightMap.jpg" });
  340. }
  341. addContentToZip(zip,
  342. "index.html",
  343. "zipContent/index.html",
  344. zipCode,
  345. false,
  346. function () {
  347. addTexturesToZip(zip,
  348. 0,
  349. textures,
  350. null,
  351. function () {
  352. addImportedFilesToZip(zip,
  353. 0,
  354. importedFiles,
  355. null,
  356. function () {
  357. var blob = zip.generate({ type: "blob" });
  358. saveAs(blob, "sample.zip");
  359. document.getElementById("statusBar").innerHTML = "";
  360. });
  361. });
  362. });
  363. }
  364. // Versions
  365. setVersion = function (version) {
  366. switch (version) {
  367. case "2.5":
  368. location.href = "index2_5.html" + location.hash;
  369. break;
  370. default:
  371. location.href = "index.html" + location.hash;
  372. break;
  373. }
  374. }
  375. // Fonts
  376. setFontSize = function (size) {
  377. document.querySelector(".monaco-editor").style.fontSize = size + "px";
  378. document.getElementById("currentFontSize").innerHTML = "Font: " + size;
  379. };
  380. // Fullscreen
  381. var goFullscreen = function () {
  382. if (engine) {
  383. engine.switchFullscreen(true);
  384. }
  385. }
  386. var toggleEditor = function () {
  387. var editorButton = document.getElementById("editorButton");
  388. var scene = engine.scenes[0];
  389. if (editorButton.innerHTML === "-Editor") {
  390. editorButton.innerHTML = "+Editor";
  391. document.getElementById("jsEditor").style.display = "none";
  392. document.getElementById("canvasZone").style.flexBasis = "100%";
  393. } else {
  394. editorButton.innerHTML = "-Editor";
  395. document.getElementById("jsEditor").style.display = "block";
  396. document.getElementById("canvasZone").style.flexBasis = undefined;
  397. }
  398. engine.resize();
  399. if (scene.debugLayer.isVisible()) {
  400. scene.debugLayer.hide();
  401. scene.debugLayer.show();
  402. }
  403. }
  404. var toggleDebug = function () {
  405. var debugButton = document.getElementById("debugButton");
  406. var scene = engine.scenes[0];
  407. if (debugButton.innerHTML === "+Debug layer") {
  408. debugButton.innerHTML = "-Debug layer";
  409. scene.debugLayer.show();
  410. } else {
  411. debugButton.innerHTML = "+Debug layer";
  412. scene.debugLayer.hide();
  413. }
  414. }
  415. var toggleMetadata = function() {
  416. var metadataButton = document.getElementById("metadataButton");
  417. var scene = engine.scenes[0];
  418. if (metadataButton.innerHTML === "+Meta data") {
  419. metadataButton.innerHTML = "-Meta data";
  420. document.getElementById("saveLayer").style.display = "block";
  421. } else {
  422. metadataButton.innerHTML = "+Meta data";
  423. document.getElementById("saveLayer").style.display = "none";
  424. }
  425. }
  426. // UI
  427. document.getElementById("runButton").addEventListener("click", compileAndRun);
  428. document.getElementById("zipButton").addEventListener("click", getZip);
  429. document.getElementById("fullscreenButton").addEventListener("click", goFullscreen);
  430. document.getElementById("newButton").addEventListener("click", createNewScript);
  431. document.getElementById("clearButton").addEventListener("click", clear);
  432. document.getElementById("editorButton").addEventListener("click", toggleEditor);
  433. document.getElementById("debugButton").addEventListener("click", toggleDebug);
  434. document.getElementById("metadataButton").addEventListener("click", toggleMetadata);
  435. //Navigation Overwrites
  436. var exitPrompt = function (e) {
  437. var safeToggle = document.getElementById("safemodeToggle");
  438. if (safeToggle.checked) {
  439. e = e || window.event;
  440. var message =
  441. 'This page is asking you to confirm that you want to leave - data you have entered may not be saved.';
  442. if (e) {
  443. e.returnValue = message;
  444. }
  445. return message;
  446. }
  447. };
  448. window.onbeforeunload = exitPrompt;
  449. // Snippet
  450. var save = function () {
  451. // Retrieve title if necessary
  452. if (document.getElementById("saveLayer")) {
  453. currentSnippetTitle = document.getElementById("saveFormTitle").value;
  454. currentSnippetDescription = document.getElementById("saveFormDescription").value;
  455. currentSnippetTags = document.getElementById("saveFormTags").value;
  456. }
  457. var xmlHttp = new XMLHttpRequest();
  458. xmlHttp.onreadystatechange = function () {
  459. if (xmlHttp.readyState === 4) {
  460. if (xmlHttp.status === 201) {
  461. var baseUrl = location.href.replace(location.hash, "").replace(location.search, "");
  462. var snippet = JSON.parse(xmlHttp.responseText);
  463. var newUrl = baseUrl + "#" + snippet.id;
  464. currentSnippetToken = snippet.id;
  465. if (snippet.version && snippet.version !== "0") {
  466. newUrl += "#" + snippet.version;
  467. }
  468. location.href = newUrl;
  469. // Hide the complete title & co message
  470. hideNoMetadata();
  471. compileAndRun();
  472. } else {
  473. showError("Unable to save your code. It may be too long.", null);
  474. }
  475. }
  476. }
  477. xmlHttp.open("POST", snippetUrl + (currentSnippetToken ? "/" + currentSnippetToken : ""), true);
  478. xmlHttp.setRequestHeader("Content-Type", "application/json");
  479. var dataToSend = {
  480. payload: {
  481. code: jsEditor.getValue()
  482. },
  483. name: currentSnippetTitle,
  484. description: currentSnippetDescription,
  485. tags: currentSnippetTags
  486. };
  487. xmlHttp.send(JSON.stringify(dataToSend));
  488. }
  489. document.getElementById("saveButton").addEventListener("click", function () {
  490. if (currentSnippetTitle == null
  491. && currentSnippetDescription == null
  492. && currentSnippetTags == null) {
  493. document.getElementById("saveLayer").style.display = "block";
  494. }
  495. else {
  496. save();
  497. }
  498. });
  499. document.getElementById("saveFormButtonOk").addEventListener("click", function () {
  500. document.getElementById("saveLayer").style.display = "none";
  501. save();
  502. });
  503. document.getElementById("saveFormButtonCancel").addEventListener("click", function () {
  504. document.getElementById("saveLayer").style.display = "none";
  505. });
  506. document.getElementById("saveMessage").addEventListener("click", function () {
  507. document.getElementById("saveMessage").style.display = "none";
  508. });
  509. document.getElementById("mainTitle").innerHTML = "Babylon.js v" + BABYLON.Engine.Version + " Playground";
  510. var previousHash = "";
  511. var cleanHash = function () {
  512. var splits = decodeURIComponent(location.hash.substr(1)).split("#");
  513. if (splits.length > 2) {
  514. splits.splice(2, splits.length - 2);
  515. }
  516. location.hash = splits.join("#");
  517. }
  518. var checkHash = function (firstTime) {
  519. if (location.hash) {
  520. if (previousHash !== location.hash) {
  521. cleanHash();
  522. previousHash = location.hash;
  523. try {
  524. var xmlHttp = new XMLHttpRequest();
  525. xmlHttp.onreadystatechange = function () {
  526. if (xmlHttp.readyState === 4) {
  527. if (xmlHttp.status === 200) {
  528. var snippet = JSON.parse(xmlHttp.responseText)[0];
  529. blockEditorChange = true;
  530. jsEditor.setValue(JSON.parse(snippet.jsonPayload).code.toString());
  531. // Check if title / descr / tags are already set
  532. if ((snippet.name != null && snippet.name != "")
  533. || (snippet.description != null && snippet.description != "")
  534. || (snippet.tags != null && snippet.tags != "")) {
  535. currentSnippetTitle = snippet.name;
  536. currentSnippetDescription = snippet.description;
  537. currentSnippetTags = snippet.tags;
  538. if (document.getElementById("saveLayer")) {
  539. var elem = document.getElementById("saveLayer");
  540. document.getElementById("saveFormTitle").value = currentSnippetTitle;
  541. document.getElementById("saveFormDescription").value = currentSnippetDescription;
  542. document.getElementById("saveFormTags").value = currentSnippetTags;
  543. hideNoMetadata();
  544. }
  545. }
  546. else {
  547. currentSnippetTitle = null;
  548. currentSnippetDescription = null;
  549. currentSnippetTags = null;
  550. showNoMetadata();
  551. }
  552. jsEditor.setPosition({ lineNumber: 0, column: 0 });
  553. blockEditorChange = false;
  554. compileAndRun();
  555. document.getElementById("currentScript").innerHTML = "Custom";
  556. } else if (firstTime) {
  557. location.href = location.href.replace(location.hash, "");
  558. if (scripts) {
  559. loadScriptFromIndex(0);
  560. }
  561. }
  562. }
  563. };
  564. var hash = location.hash.substr(1);
  565. currentSnippetToken = hash.split("#")[0];
  566. if(!hash.split("#")[1]) hash += "#0";
  567. xmlHttp.open("GET", snippetUrl + "/" + hash.replace("#", "/"));
  568. xmlHttp.send();
  569. } catch (e) {
  570. }
  571. }
  572. }
  573. setTimeout(checkHash, 200);
  574. }
  575. checkHash(true);
  576. }
  577. // Monaco
  578. var xhr = new XMLHttpRequest();
  579. xhr.open('GET', "babylon.d.txt", true);
  580. xhr.onreadystatechange = function () {
  581. if (xhr.readyState === 4) {
  582. if (xhr.status === 200) {
  583. require.config({ paths: { 'vs': 'node_modules/monaco-editor/min/vs' } });
  584. require(['vs/editor/editor.main'], function () {
  585. monaco.languages.typescript.javascriptDefaults.addExtraLib(xhr.responseText, 'babylon.d.ts');
  586. jsEditor = monaco.editor.create(document.getElementById('jsEditor'), {
  587. value: "",
  588. language: "javascript",
  589. lineNumbers: true,
  590. tabSize: "auto",
  591. insertSpaces: "auto",
  592. roundedSelection: true,
  593. scrollBeyondLastLine: false,
  594. automaticLayout: true,
  595. readOnly: false,
  596. theme: "vs",
  597. contextmenu: false
  598. });
  599. run();
  600. });
  601. }
  602. }
  603. };
  604. xhr.send(null);
  605. })();