Permalink
Browse files

Added example code.

  • Loading branch information...
1 parent f88ec34 commit b60e01fd5be193318663888afef340e80d9bbf21 @leonardr leonardr committed Sep 23, 2013
Showing with 73,096 additions and 2 deletions.
  1. +101 −0 Maze/server/100-rooms.txt
  2. +1 −0 Maze/server/Procfile
  3. +199 −0 Maze/server/app.js
  4. +31 −0 Maze/server/data/01-a-beginner-maze.js
  5. +107 −0 Maze/server/data/02-for-experts-only.js
  6. +64 −0 Maze/server/mazes.js
  7. +8 −0 Maze/server/package.json
  8. +11 −0 Maze/the-boaster/node_modules/xmldom/.project
  9. +4 −0 Maze/the-boaster/node_modules/xmldom/__package__.js
  10. +5 −0 Maze/the-boaster/node_modules/xmldom/changelog
  11. +253 −0 Maze/the-boaster/node_modules/xmldom/dom-parser.js
  12. +1,135 −0 Maze/the-boaster/node_modules/xmldom/dom.js
  13. +70 −0 Maze/the-boaster/node_modules/xmldom/package.json
  14. +213 −0 Maze/the-boaster/node_modules/xmldom/readme.md
  15. +551 −0 Maze/the-boaster/node_modules/xmldom/sax.js
  16. +1 −0 Maze/the-boaster/node_modules/xmldom/test/3rd-cases/index.js
  17. +1 −0 Maze/the-boaster/node_modules/xmldom/test/3rd-cases/mock.js
  18. +21 −0 Maze/the-boaster/node_modules/xmldom/test/3rd-cases/o3xml.js
  19. +152 −0 Maze/the-boaster/node_modules/xmldom/test/big-file-performance.js
  20. +64 −0 Maze/the-boaster/node_modules/xmldom/test/dom/attr.js
  21. +22 −0 Maze/the-boaster/node_modules/xmldom/test/dom/clone.js
  22. +139 −0 Maze/the-boaster/node_modules/xmldom/test/dom/element.js
  23. +5 −0 Maze/the-boaster/node_modules/xmldom/test/dom/index.js
  24. +8 −0 Maze/the-boaster/node_modules/xmldom/test/dom/level3.js
  25. +14 −0 Maze/the-boaster/node_modules/xmldom/test/dom/serializer.js
  26. +71 −0 Maze/the-boaster/node_modules/xmldom/test/error.js
  27. +89 −0 Maze/the-boaster/node_modules/xmldom/test/html/normalize.js
  28. +63 −0 Maze/the-boaster/node_modules/xmldom/test/index.js
  29. +50 −0 Maze/the-boaster/node_modules/xmldom/test/locator.js
  30. +32 −0 Maze/the-boaster/node_modules/xmldom/test/namespace.js
  31. +102 −0 Maze/the-boaster/node_modules/xmldom/test/node.js
  32. +31 −0 Maze/the-boaster/node_modules/xmldom/test/parse-element.js
  33. +11 −0 Maze/the-boaster/node_modules/xmldom/test/simple.js
  34. +24 −0 Maze/the-boaster/node_modules/xmldom/test/test.js
  35. +19,719 −0 Maze/the-boaster/node_modules/xmldom/test/test.xml
  36. +11 −0 Maze/the-boaster/package.json
  37. +107 −0 Maze/the-boaster/the-boaster.js
  38. +11 −0 Maze/the-bot/node_modules/xmldom/.project
  39. +4 −0 Maze/the-bot/node_modules/xmldom/__package__.js
  40. +5 −0 Maze/the-bot/node_modules/xmldom/changelog
  41. +253 −0 Maze/the-bot/node_modules/xmldom/dom-parser.js
  42. +1,135 −0 Maze/the-bot/node_modules/xmldom/dom.js
  43. +73 −0 Maze/the-bot/node_modules/xmldom/package.json
  44. +213 −0 Maze/the-bot/node_modules/xmldom/readme.md
  45. +551 −0 Maze/the-bot/node_modules/xmldom/sax.js
  46. +1 −0 Maze/the-bot/node_modules/xmldom/test/3rd-cases/index.js
  47. +1 −0 Maze/the-bot/node_modules/xmldom/test/3rd-cases/mock.js
  48. +21 −0 Maze/the-bot/node_modules/xmldom/test/3rd-cases/o3xml.js
  49. +152 −0 Maze/the-bot/node_modules/xmldom/test/big-file-performance.js
  50. +64 −0 Maze/the-bot/node_modules/xmldom/test/dom/attr.js
  51. +22 −0 Maze/the-bot/node_modules/xmldom/test/dom/clone.js
  52. +139 −0 Maze/the-bot/node_modules/xmldom/test/dom/element.js
  53. +5 −0 Maze/the-bot/node_modules/xmldom/test/dom/index.js
  54. +8 −0 Maze/the-bot/node_modules/xmldom/test/dom/level3.js
  55. +14 −0 Maze/the-bot/node_modules/xmldom/test/dom/serializer.js
  56. +71 −0 Maze/the-bot/node_modules/xmldom/test/error.js
  57. +89 −0 Maze/the-bot/node_modules/xmldom/test/html/normalize.js
  58. +63 −0 Maze/the-bot/node_modules/xmldom/test/index.js
  59. +50 −0 Maze/the-bot/node_modules/xmldom/test/locator.js
  60. +32 −0 Maze/the-bot/node_modules/xmldom/test/namespace.js
  61. +102 −0 Maze/the-bot/node_modules/xmldom/test/node.js
  62. +31 −0 Maze/the-bot/node_modules/xmldom/test/parse-element.js
  63. +11 −0 Maze/the-bot/node_modules/xmldom/test/simple.js
  64. +24 −0 Maze/the-bot/node_modules/xmldom/test/test.js
  65. +19,719 −0 Maze/the-bot/node_modules/xmldom/test/test.xml
  66. +11 −0 Maze/the-bot/package.json
  67. +153 −0 Maze/the-bot/the-bot.js
  68. +46 −0 Maze/the-game/app.js
  69. +30 −0 Maze/the-game/index.css
  70. +51 −0 Maze/the-game/index.html
  71. +378 −0 Maze/the-game/index.js
  72. +53 −0 Maze/the-game/mozxpath.js
  73. +19 −0 Maze/the-game/node_modules/mime/LICENSE
  74. +63 −0 Maze/the-game/node_modules/mime/README.md
  75. +104 −0 Maze/the-game/node_modules/mime/mime.js
  76. +31 −0 Maze/the-game/node_modules/mime/package.json
  77. +55 −0 Maze/the-game/node_modules/mime/test.js
  78. +1,588 −0 Maze/the-game/node_modules/mime/types/mime.types
  79. +59 −0 Maze/the-game/node_modules/mime/types/node.types
  80. +11 −0 Maze/the-game/package.json
  81. +11 −0 Maze/the-mapmaker/node_modules/xmldom/.project
  82. +4 −0 Maze/the-mapmaker/node_modules/xmldom/__package__.js
  83. +5 −0 Maze/the-mapmaker/node_modules/xmldom/changelog
  84. +253 −0 Maze/the-mapmaker/node_modules/xmldom/dom-parser.js
  85. +1,135 −0 Maze/the-mapmaker/node_modules/xmldom/dom.js
  86. +73 −0 Maze/the-mapmaker/node_modules/xmldom/package.json
  87. +213 −0 Maze/the-mapmaker/node_modules/xmldom/readme.md
  88. +551 −0 Maze/the-mapmaker/node_modules/xmldom/sax.js
  89. +1 −0 Maze/the-mapmaker/node_modules/xmldom/test/3rd-cases/index.js
  90. +1 −0 Maze/the-mapmaker/node_modules/xmldom/test/3rd-cases/mock.js
  91. +21 −0 Maze/the-mapmaker/node_modules/xmldom/test/3rd-cases/o3xml.js
  92. +152 −0 Maze/the-mapmaker/node_modules/xmldom/test/big-file-performance.js
  93. +64 −0 Maze/the-mapmaker/node_modules/xmldom/test/dom/attr.js
  94. +22 −0 Maze/the-mapmaker/node_modules/xmldom/test/dom/clone.js
  95. +139 −0 Maze/the-mapmaker/node_modules/xmldom/test/dom/element.js
  96. +5 −0 Maze/the-mapmaker/node_modules/xmldom/test/dom/index.js
  97. +8 −0 Maze/the-mapmaker/node_modules/xmldom/test/dom/level3.js
  98. +14 −0 Maze/the-mapmaker/node_modules/xmldom/test/dom/serializer.js
  99. +71 −0 Maze/the-mapmaker/node_modules/xmldom/test/error.js
  100. +89 −0 Maze/the-mapmaker/node_modules/xmldom/test/html/normalize.js
  101. +63 −0 Maze/the-mapmaker/node_modules/xmldom/test/index.js
  102. +50 −0 Maze/the-mapmaker/node_modules/xmldom/test/locator.js
  103. +32 −0 Maze/the-mapmaker/node_modules/xmldom/test/namespace.js
  104. +102 −0 Maze/the-mapmaker/node_modules/xmldom/test/node.js
  105. +31 −0 Maze/the-mapmaker/node_modules/xmldom/test/parse-element.js
  106. +11 −0 Maze/the-mapmaker/node_modules/xmldom/test/simple.js
  107. +24 −0 Maze/the-mapmaker/node_modules/xmldom/test/test.js
  108. +19,719 −0 Maze/the-mapmaker/node_modules/xmldom/test/test.xml
  109. +11 −0 Maze/the-mapmaker/package.json
  110. +340 −0 Maze/the-mapmaker/the-mapmaker.js
  111. +53 −2 README.md
  112. +1 −0 YouTypeIt/server/Procfile
  113. +442 −0 YouTypeIt/server/app.js
  114. +1 −0 YouTypeIt/server/data/613856331910938
  115. +103 −0 YouTypeIt/server/messages.js
  116. +8 −0 YouTypeIt/server/package.json
  117. +21 −0 YouTypeIt/server/templates.js
  118. +22 −0 YouTypeIt/server/templates/about.html
  119. +17 −0 YouTypeIt/server/templates/collection.js
  120. +23 −0 YouTypeIt/server/templates/home.html
  121. +24 −0 YouTypeIt/server/templates/item.html
  122. +38 −0 YouTypeIt/server/templates/list.html
  123. +39 −0 YouTypeIt/server/templates/script.js
  124. +7 −0 YouTypeIt/test/README.md
  125. +32 −0 YouTypeIt/test/item-response.js
  126. +28 −0 YouTypeIt/test/item-response2.js
  127. +9 −0 YouTypeIt/test/post.js
  128. +7 −0 YouTypeIt/test/put.js
View
101 Maze/server/100-rooms.txt
@@ -0,0 +1,101 @@
+Living Room
+Family Room
+Formal Living Room
+Kitchen
+Pantry
+Nook
+Dining Room
+Formal Dining
+Master Bedroom
+Closet
+Walk-In Closet
+Dressing Room
+Bedroom
+Nursery
+Guest Bedroom
+Guest Suite
+Mother-In-Law Quarters
+Master Bath Room
+Bath Room
+Walk-In Shower
+Sauna
+Three-Quarter Bath
+Half-Bath
+Powder Room
+Entry
+Mud Room
+Sitting Room
+Coat Closet
+Utility Room
+Laundry Room
+Sewing Room
+Storage Room
+Mechanical Room
+Garage
+RV Garage
+Work Shop
+Home Gym
+Home Office
+Study
+Library
+Drawing Room
+Reading Room
+Retreat
+Den
+Parlor
+Game Room
+Play Room
+Media Room
+Wet Bar
+Butler's Quarters
+Maid's Quarters
+Butler's Kitchen
+Butler's Pantry
+Wine Room
+Atrium
+Lounge
+Gallery
+Kitchenette
+Indoor Pool
+Indoor Spa
+Prayer Room
+Gun Room
+Sword Room
+Archery Room
+Nunchuck Room
+Chamber of Stars
+Chamber of Planets
+Chamber of Pets
+Chamber of Enemies
+Hall of Mirrors
+Hall of Windows
+Hall of Plates
+Hall of Silverware
+Hall of Sculpture
+Hall of Fiber Art
+Hall of Prints
+Hall of Easels
+Hall of Monty
+Hall of Oats
+Computer Room
+Laptop Room
+Phone Room
+Dog Room
+Cat Room
+Bird Room
+Lizard Room
+Insect Room
+Tape Room
+Dance Room
+Fight Room
+Television Room
+Theater
+Concert Hall
+Indoor Tennis Court
+Bowling Alley
+Card Room
+Climbing Gym
+Woodshop
+Metalshop
+Panic Room
+
View
1 Maze/server/Procfile
@@ -0,0 +1 @@
+web: node app.js
View
199 Maze/server/app.js
@@ -0,0 +1,199 @@
+/* RESTful Web APIs - 2013 */
+/* Maze+XML server implementation */
+
+var http = require('http');
+var mazes = require('./mazes.js');
+
+var port = (process.env.PORT||1337);
+var root = '';
+
+// add support for CORS
+var headers = {
+ 'Content-Type' : 'application/xml',
+ 'Access-Control-Allow-Origin' : '*',
+ 'Access-Control-Allow-Methods' : '*',
+ 'Access-Control-Allow-Headers' : '*'
+};
+
+// document model for responses
+var template = {};
+template.mazeStart = '<maze version="1.0">';
+template.mazeEnd = '</maze>';
+template.collectionStart = '<collection href="{l}/">';
+template.collectionEnd = '</collection>';
+template.itemStart = '<item href="{l}" title="{t}">';
+template.itemEnd = '</item>';
+template.cellStart = '<cell href="{l}" rel="current" title="{t}">';
+template.cellEnd = '</cell>';
+template.link = '<link href="{l}" rel="{d}"/>';
+template.titleLink = '<link href="{l}" rel="{d}" title="{t}" />';
+template.error = '<error><title>{t}</title></error>';
+
+// handle request
+function handler(req, res) {
+ var segments, i, x, parts;
+
+ // set global var
+ root = 'http://'+req.headers.host;
+
+ // simple routing
+ parts = [];
+ segments = req.url.split('/');
+ for(i=0,x=segments.length;i<x;i++) {
+ if(segments[i]!=='') {
+ parts.push(segments[i]);
+ }
+ }
+
+ // ignore thes requests
+ if(req.url==='/favicon.ico') {
+ return;
+ }
+
+ // handle CORS OPTIONS call
+ if(req.method==='OPTIONS') {
+ var body = JSON.stringify(headers);
+ showResponse(req, res, body, 200);
+ }
+
+ // only accept GETs
+ if(req.method!=='GET') {
+ showError(req, res, 'Method Not Allowed', 405);
+ }
+ else {
+ // route to handle requests
+ switch(parts.length) {
+ case 0:
+ showCollection(req, res);
+ break;
+ case 1:
+ showMaze(req, res, parts[0]);
+ break;
+ case 2:
+ showCell(req, res, parts[0], parts[1]);
+ break;
+ default:
+ showError(req, res, 'Not Found', 404);
+ break;
+ }
+ }
+}
+
+// show list of available mazes
+function showCollection(req, res) {
+ var body, list, i, x;
+
+ body = '';
+ body += template.mazeStart;
+ body += template.collectionStart.replace('{l}',root);
+
+ list = mazes('list');
+ if(list!==undefined) {
+ for(i=0,x=list.length;i<x;i++) {
+ body += template.titleLink.replace('{l}',root+'/'+list[i].link).replace('{d}','maze').replace('{t}',list[i].title);
+ }
+ }
+
+ body += template.collectionEnd;
+ body += template.mazeEnd;
+
+ showResponse(req, res, body, 200);
+}
+
+// response for a single maze
+function showMaze(req, res, maze) {
+ var body, data;
+
+ // make sure it exists before crafting response
+ data = mazes('maze',maze);
+ if(data!==undefined) {
+ body = '';
+ body += template.mazeStart;
+ body += template.itemStart.replace('{l}',root+'/'+maze).replace('{t}',data.title);
+ body += template.link.replace('{l}',root+'/'+maze+'/0').replace('{d}','start');
+ body += template.itemEnd;
+ body += template.mazeEnd;
+
+ showResponse(req, res, body, 200);
+ }
+ else {
+ showError(req, res, 'Maze Not Found', 404);
+ }
+}
+
+// response for a cell within the maze
+function showCell(req, res, maze, cell) {
+ var body, data, rel, mov, mz, sq, ex, z, t;
+
+ // validate the maze
+ mz = mazes('maze',maze);
+ if(mz===undefined) {
+ showError(req, res, 'Maze Not Found', 404);
+ return;
+ }
+
+ // compute state and set up possible moves
+ z = parseInt(cell, 10);
+ t = Object.keys(mz.cells).length;
+ sq = Math.sqrt(t);
+ ex = t-1;
+
+ rel = ['north', 'west', 'south', 'east'];
+ mov = [z-1, z+(sq*-1), z+1, z+sq]
+
+ // get cell details
+ if(z===999) {
+ data = {"title":"The Exit",doors:[1,1,1,1]};
+ }
+ else {
+ data = mazes('cell', maze, cell);
+ }
+
+ // if we have details, craft representation
+ if(data!==undefined) {
+ body = '';
+ body += template.mazeStart;
+ body += template.cellStart.replace('{l}',root+'/'+maze+'/'+cell).replace('{t}',data.title);
+
+ // add doors
+ for(i=0,x=data.doors.length;i<x;i++) {
+ if(data.doors[i]===0) {
+ body += template.link.replace('{l}',root+'/'+maze+'/'+mov[i]).replace('{d}',rel[i]);
+ }
+ }
+
+ // if there is an exit, add it
+ if(z===ex) {
+ body += template.link.replace('{l}',root+'/'+maze+'/999').replace('{d}','exit').replace('{t}',data.title);
+ }
+
+ // add link to start of the maze and the entire collection
+ body += template.titleLink.replace('{l}',root+'/'+maze).replace('{d}','maze').replace('{t}',mz.title);
+ body += template.link.replace('{l}',root).replace('{d}', 'collection');
+
+ body += template.cellEnd;
+ body += template.mazeEnd;
+
+ showResponse(req, res, body, 200);
+ }
+ else {
+ showError(req, res, 'Cell Not Found', 404);
+ }
+}
+
+// unexpected request
+function showError(req, res, title, code) {
+ var body = template.mazeStart
+ + template.error.replace('{t}',title)
+ + template.mazeEnd;
+ showResponse(req, res, body, code);
+}
+
+// return response to caller
+function showResponse(req, res, body, code) {
+ res.writeHead(code,headers);
+ res.end(body);
+}
+
+// wait for someone to call
+http.createServer(handler).listen(port);
View
31 Maze/server/data/01-a-beginner-maze.js
@@ -0,0 +1,31 @@
+{
+ "_id" : "five-by-five",
+ "title" : "A Beginner's Maze",
+ "cells" : {
+ "cell0":{"title":"Entrance", "doors":[1,1,1,0]},
+ "cell1":{"title":"Hall of Knives", "doors":[1,1,1,0]},
+ "cell2":{"title":"Library", "doors":[1,1,0,0]},
+ "cell3":{"title":"Trophy Room", "doors":[0,1,0,1]},
+ "cell4":{"title":"Pantry", "doors":[0,1,1,0]},
+ "cell5":{"title":"Kitchen", "doors":[1,0,1,0]},
+ "cell6":{"title":"Cloak Room", "doors":[1,0,0,1]},
+ "cell7":{"title":"Master Bedroom", "doors":[0,0,1,0]},
+ "cell8":{"title":"Fruit Closet", "doors":[1,1,0,0]},
+ "cell9":{"title":"Den of Forks", "doors":[0,0,1,1]},
+ "cell10":{"title":"Nursery", "doors":[1,0,0,1]},
+ "cell11":{"title":"Laundry Room", "doors":[0,1,1,0]},
+ "cell12":{"title":"Smoking Room", "doors":[1,0,1,1]},
+ "cell13":{"title":"Dining Room", "doors":[1,0,0,1]},
+ "cell14":{"title":"Sitting Room", "doors":[0,1,1,0]},
+ "cell15":{"title":"Standing Room", "doors":[1,1,1,0]},
+ "cell16":{"title":"Hobby Room", "doors":[1,0,1,0]},
+ "cell17":{"title":"Observatory", "doors":[1,1,0,0]},
+ "cell18":{"title":"Hot House", "doors":[0,1,0,1]},
+ "cell19":{"title":"Guest Room", "doors":[0,0,1,0]},
+ "cell20":{"title":"Servant's Quarters", "doors":[1,0,0,1]},
+ "cell21":{"title":"Garage", "doors":[0,0,0,1]},
+ "cell22":{"title":"Tool Room", "doors":[0,0,1,1]},
+ "cell23":{"title":"Banquet Hall", "doors":[1,1,0,1]},
+ "cell24":{"title":"Spoon Storage", "doors":[0,0,1,1]}
+ }
+}
View
107 Maze/server/data/02-for-experts-only.js
@@ -0,0 +1,107 @@
+{
+ "_id" : "ten-by-ten",
+ "title" : "For Experts Only",
+ "cells" : {
+ "cell0":{"title":"Entry", "doors":[1,1,1,0]},
+ "cell1":{"title":"Living Room", "doors":[1,1,0,0]},
+ "cell2":{"title":"Dressing Room", "doors":[0,1,0,1]},
+ "cell3":{"title":"Family Room", "doors":[0,1,0,1]},
+ "cell4":{"title":"Kitchen", "doors":[0,1,0,1]},
+ "cell5":{"title":"Formal Living Room", "doors":[0,1,1,0]},
+ "cell6":{"title":"Pantry", "doors":[1,1,1,0]},
+ "cell7":{"title":"Nook", "doors":[1,1,0,0]},
+ "cell8":{"title":"Dining Room", "doors":[0,1,0,0]},
+ "cell9":{"title":"Master Bedroom", "doors":[0,1,1,0]},
+ "cell10":{"title":"Formal Dining", "doors":[1,0,0,1]},
+ "cell11":{"title":"Closet", "doors":[0,0,1,1]},
+ "cell12":{"title":"Dressing Room", "doors":[1,1,0,0]},
+ "cell13":{"title":"Nursery", "doors":[0,1,1,1]},
+ "cell14":{"title":"Walk-In Closet", "doors":[1,1,0,0]},
+ "cell15":{"title":"Bedroom", "doors":[0,0,1,1]},
+ "cell16":{"title":"Guest Bedroom", "doors":[1,0,1,0]},
+ "cell17":{"title":"Master Bath Room", "doors":[1,0,1,0]},
+ "cell18":{"title":"Guest Suite", "doors":[1,0,1,0]},
+ "cell19":{"title":"Bath Room", "doors":[1,0,1,0]},
+ "cell20":{"title":"Mother-In-Law Quarters", "doors":[1,1,1,0]},
+ "cell21":{"title":"Walk-In Shower", "doors":[1,1,0,0]},
+ "cell22":{"title":"Sauna", "doors":[0,0,0,1]},
+ "cell23":{"title":"Mud Room", "doors":[0,1,0,1]},
+ "cell24":{"title":"Three-Quarter Bath", "doors":[0,0,1,1]},
+ "cell25":{"title":"Sitting Room", "doors":[1,1,0,0]},
+ "cell26":{"title":"Half-Bath", "doors":[0,0,1,0]},
+ "cell27":{"title":"Coat Closet", "doors":[1,0,1,0]},
+ "cell28":{"title":"Powder Room", "doors":[1,0,1,0]},
+ "cell29":{"title":"Utility Room", "doors":[1,0,1,1]},
+ "cell30":{"title":"Metalshop", "doors":[1,0,0,0]},
+ "cell31":{"title":"Laundry Room", "doors":[0,0,1,1]},
+ "cell32":{"title":"Woodshop", "doors":[1,1,0,1]},
+ "cell33":{"title":"Sewing Room", "doors":[0,1,0,1]},
+ "cell34":{"title":"Climbing Gym", "doors":[0,1,0,0]},
+ "cell35":{"title":"Storage Room", "doors":[0,0,1,1]},
+ "cell36":{"title":"Card Room", "doors":[1,0,0,1]},
+ "cell37":{"title":"Mechanical Room", "doors":[0,0,1,1]},
+ "cell38":{"title":"Bowling Alley", "doors":[1,0,0,1]},
+ "cell39":{"title":"Garage", "doors":[0,1,1,0]},
+ "cell40":{"title":"Indoor Tennis Court", "doors":[1,0,0,1]},
+ "cell41":{"title":"RV Garage", "doors":[0,1,0,1]},
+ "cell42":{"title":"Concert Hall", "doors":[0,1,0,1]},
+ "cell43":{"title":"Work Shop", "doors":[0,1,1,0]},
+ "cell44":{"title":"Theater", "doors":[1,0,0,1]},
+ "cell45":{"title":"Home Gym", "doors":[0,1,1,1]},
+ "cell46":{"title":"Television Room", "doors":[1,1,0,0]},
+ "cell47":{"title":"Home Office", "doors":[0,1,0,1]},
+ "cell48":{"title":"Fight Room", "doors":[0,1,1,0]},
+ "cell49":{"title":"Study", "doors":[1,0,1,0]},
+ "cell50":{"title":"Dance Room", "doors":[1,1,0,0]},
+ "cell51":{"title":"Library", "doors":[0,1,0,1]},
+ "cell52":{"title":"Tape Room", "doors":[0,1,1,0]},
+ "cell53":{"title":"Drawing Room", "doors":[1,0,0,1]},
+ "cell54":{"title":"Insect Room", "doors":[0,1,1,0]},
+ "cell55":{"title":"Reading Room", "doors":[1,1,0,0]},
+ "cell56":{"title":"Lizard Room", "doors":[0,0,1,1]},
+ "cell57":{"title":"Retreat", "doors":[1,1,1,0]},
+ "cell58":{"title":"Bird Room", "doors":[1,0,0,1]},
+ "cell59":{"title":"Den", "doors":[0,0,1,0]},
+ "cell60":{"title":"Cat Room", "doors":[1,0,1,1]},
+ "cell61":{"title":"Parlor", "doors":[1,1,0,0]},
+ "cell62":{"title":"Dog Room", "doors":[0,0,1,0]},
+ "cell63":{"title":"Game Room", "doors":[1,1,0,0]},
+ "cell64":{"title":"Phone Room", "doors":[0,0,1,1]},
+ "cell65":{"title":"Play Room", "doors":[1,0,0,1]},
+ "cell66":{"title":"Laptop Room", "doors":[0,1,1,0]},
+ "cell67":{"title":"Media Room", "doors":[1,0,0,0]},
+ "cell68":{"title":"Panic Room", "doors":[0,1,1,0]},
+ "cell69":{"title":"Wet Bar", "doors":[1,0,1,0]},
+ "cell70":{"title":"Computer Room", "doors":[1,1,0,0]},
+ "cell71":{"title":"Butler's Quarters", "doors":[0,0,1,0]},
+ "cell72":{"title":"Hall of Oats", "doors":[1,0,1,1]},
+ "cell73":{"title":"Maid's Quarters", "doors":[1,0,0,1]},
+ "cell74":{"title":"Hall of Monty", "doors":[0,1,0,1]},
+ "cell75":{"title":"Butler's Kitchen", "doors":[0,1,0,1]},
+ "cell76":{"title":"Hall of Easels", "doors":[0,0,1,1]},
+ "cell77":{"title":"Butler's Pantry", "doors":[1,0,1,0]},
+ "cell78":{"title":"Hall of Prints", "doors":[1,0,1,1]},
+ "cell79":{"title":"Wine Room", "doors":[1,0,1,0]},
+ "cell80":{"title":"Hall of Fiber Art", "doors":[1,0,1,0]},
+ "cell81":{"title":"Atrium", "doors":[1,0,1,1]},
+ "cell82":{"title":"Hall of Sculpture", "doors":[1,1,0,0]},
+ "cell83":{"title":"Lounge", "doors":[0,1,0,1]},
+ "cell84":{"title":"Hall of Silverware", "doors":[0,1,1,0]},
+ "cell85":{"title":"Gallery", "doors":[1,1,0,0]},
+ "cell86":{"title":"Hall of Plates", "doors":[0,1,1,0]},
+ "cell87":{"title":"Kitchenette", "doors":[1,0,0,0]},
+ "cell88":{"title":"Hall of Windows", "doors":[0,1,0,1]},
+ "cell89":{"title":"Indoor Pool", "doors":[0,0,1,1]},
+ "cell90":{"title":"Hall of Mirrors", "doors":[1,0,0,1]},
+ "cell91":{"title":"Indoor Spa", "doors":[0,1,0,1]},
+ "cell92":{"title":"Chamber of Enemies", "doors":[0,0,0,1]},
+ "cell93":{"title":"Gun Room", "doors":[0,1,1,1]},
+ "cell94":{"title":"Chamber of Pets", "doors":[1,0,0,1]},
+ "cell95":{"title":"Sword Room", "doors":[0,0,1,1]},
+ "cell96":{"title":"Chamber of Planets", "doors":[1,0,0,1]},
+ "cell97":{"title":"Archery Room", "doors":[0,0,0,1]},
+ "cell98":{"title":"Chamber of Stars", "doors":[0,1,0,1]},
+ "cell99":{"title":"Nunchuck Room", "doors":[0,1,1,1]}
+ }
+}
+
View
64 Maze/server/mazes.js
@@ -0,0 +1,64 @@
+/*
+ * maze file handler
+ * 2012-10 (mca)
+ */
+
+var fs = require('fs');
+var folder = process.cwd()+'/data/';
+
+module.exports = main;
+
+// hande all requests for maze data
+function main(cmd, maze, cell) {
+ var rtn;
+
+ switch(cmd)
+ {
+ case 'list':
+ rtn = getList();
+ break;
+ case 'maze':
+ rtn = getMaze(maze);
+ break;
+ case 'cell':
+ rtn = getCell(maze, cell);
+ break;
+ default:
+ break;
+ }
+ return rtn;
+}
+
+// read a list of maze files off the disk
+function getList() {
+ var coll, maze, list, i, x;
+
+ coll = [];
+ list = fs.readdirSync(folder);
+ for(i=0,x=list.length;i<x;i++) {
+ maze = getMaze(list[i].replace('.js',''));
+ coll.push({"title":maze.title,"link":list[i].replace('.js','')});
+ }
+ return coll;
+}
+
+// return the contents of a single maze file
+function getMaze(m) {
+ try {
+ return JSON.parse(fs.readFileSync(folder+m+'.js'));
+ }
+ catch(ex) {
+ return undefined;
+ }
+}
+
+// return a single cell from the specified maze file
+function getCell(m, c) {
+ try {
+ var maze = getMaze(m);
+ return maze.cells['cell'+c];
+ }
+ catch(ex) {
+ return undefined;
+ }
+}
View
8 Maze/server/package.json
@@ -0,0 +1,8 @@
+{
+ "name": "maze-xml-server",
+ "version": "0.0.1",
+ "engines": {
+ "node": "0.8.x",
+ "npm": "1.1.x"
+ }
+}
View
11 Maze/the-boaster/node_modules/xmldom/.project
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>xmldom</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ </buildSpec>
+ <natures>
+ </natures>
+</projectDescription>
View
4 Maze/the-boaster/node_modules/xmldom/__package__.js
@@ -0,0 +1,4 @@
+this.addScript('dom.js',['DOMImplementation','XMLSerializer']);
+this.addScript('dom-parser.js',['DOMHandler','DOMParser'],
+ ['DOMImplementation','XMLReader']);
+this.addScript('sax.js','XMLReader');
View
5 Maze/the-boaster/node_modules/xmldom/changelog
@@ -0,0 +1,5 @@
+0.1.8
+ * Add: some test case from node-o3-xml(excludes xpath support)
+ * Fix: remove existed attribute before setting (bug introduced in v0.1.5)
+ * Fix: index direct access for childNodes and any NodeList collection(not w3c standard)
+ * Fix: remove last child bug
View
253 Maze/the-boaster/node_modules/xmldom/dom-parser.js
@@ -0,0 +1,253 @@
+function DOMParser(options){
+ this.options =
+ options != true && //To the version (0.1.12) compatible
+ options ||{locator:{}};
+
+}
+DOMParser.prototype.parseFromString = function(source,mimeType){
+ var sax = new XMLReader();
+ var options = this.options;
+ var domBuilder = options.domBuilder || new DOMHandler();//contentHandler and LexicalHandler
+ var errorHandler = options.errorHandler;
+ var locator = options.locator;
+ var defaultNSMap = {};
+ var entityMap = {'lt':'<','gt':'>','amp':'&','quot':'"','apos':"'"}
+ if(locator){
+ domBuilder.setDocumentLocator(locator)
+ }
+
+ sax.errorHandler = buildErrorHandler(errorHandler,domBuilder,locator);
+ sax.domBuilder = options.domBuilder || domBuilder;
+ if(/\/x?html?$/.test(mimeType)){
+ entityMap.nbsp = '\xa0';
+ entityMap.copy = '\xa9';
+ defaultNSMap['']= 'http://www.w3.org/1999/xhtml';
+ }
+ sax.parse(source,defaultNSMap,entityMap);
+ return domBuilder.document;
+}
+function buildErrorHandler(errorImpl,domBuilder,locator){
+ if(!errorImpl){
+ if(domBuilder instanceof DOMHandler){
+ return domBuilder;
+ }
+ errorImpl = domBuilder ;
+ }
+ var errorHandler = {}
+ var isCallback = errorImpl instanceof Function;
+ locator = locator||{}
+ function build(key){
+ var fn = errorImpl[key];
+ if(!fn){
+ if(isCallback){
+ fn = errorImpl.length == 2?function(msg){errorImpl(key,msg)}:errorImpl;
+ }else{
+ var i=arguments.length;
+ while(--i){
+ if(fn = errorImpl[arguments[i]]){
+ break;
+ }
+ }
+ }
+ }
+ errorHandler[key] = fn && function(msg){
+ fn(msg+_locator(locator));
+ }||function(){};
+ }
+ build('warning','warn');
+ build('error','warn','warning');
+ build('fatalError','warn','warning','error');
+ return errorHandler;
+}
+/**
+ * +ContentHandler+ErrorHandler
+ * +LexicalHandler+EntityResolver2
+ * -DeclHandler-DTDHandler
+ *
+ * DefaultHandler:EntityResolver, DTDHandler, ContentHandler, ErrorHandler
+ * DefaultHandler2:DefaultHandler,LexicalHandler, DeclHandler, EntityResolver2
+ * @link http://www.saxproject.org/apidoc/org/xml/sax/helpers/DefaultHandler.html
+ */
+function DOMHandler() {
+ this.cdata = false;
+}
+function position(locator,node){
+ node.lineNumber = locator.lineNumber;
+ node.columnNumber = locator.columnNumber;
+}
+/**
+ * @see org.xml.sax.ContentHandler#startDocument
+ * @link http://www.saxproject.org/apidoc/org/xml/sax/ContentHandler.html
+ */
+DOMHandler.prototype = {
+ startDocument : function() {
+ this.document = new DOMImplementation().createDocument(null, null, null);
+ if (this.locator) {
+ this.document.documentURI = this.locator.systemId;
+ }
+ },
+ startElement:function(namespaceURI, localName, qName, attrs) {
+ var doc = this.document;
+ var el = doc.createElementNS(namespaceURI, qName||localName);
+ var len = attrs.length;
+ appendElement(this, el);
+ this.currentElement = el;
+
+ this.locator && position(this.locator,el)
+ for (var i = 0 ; i < len; i++) {
+ var namespaceURI = attrs.getURI(i);
+ var value = attrs.getValue(i);
+ var qName = attrs.getQName(i);
+ var attr = doc.createAttributeNS(namespaceURI, qName);
+ if( attr.getOffset){
+ position(attr.getOffset(1),attr)
+ }
+ attr.value = attr.nodeValue = value;
+ el.setAttributeNode(attr)
+ }
+ },
+ endElement:function(namespaceURI, localName, qName) {
+ var current = this.currentElement
+ var tagName = current.tagName;
+ this.currentElement = current.parentNode;
+ },
+ startPrefixMapping:function(prefix, uri) {
+ },
+ endPrefixMapping:function(prefix) {
+ },
+ processingInstruction:function(target, data) {
+ var ins = this.document.createProcessingInstruction(target, data);
+ this.locator && position(this.locator,ins)
+ appendElement(this, ins);
+ },
+ ignorableWhitespace:function(ch, start, length) {
+ },
+ characters:function(chars, start, length) {
+ chars = _toString.apply(this,arguments)
+ //console.log(chars)
+ if(this.currentElement && chars){
+ if (this.cdata) {
+ var charNode = this.document.createCDATASection(chars);
+ this.currentElement.appendChild(charNode);
+ } else {
+ var charNode = this.document.createTextNode(chars);
+ this.currentElement.appendChild(charNode);
+ }
+ this.locator && position(this.locator,charNode)
+ }
+ },
+ skippedEntity:function(name) {
+ },
+ endDocument:function() {
+ this.document.normalize();
+ },
+ setDocumentLocator:function (locator) {
+ if(this.locator = locator){// && !('lineNumber' in locator)){
+ locator.lineNumber = 0;
+ }
+ },
+ //LexicalHandler
+ comment:function(chars, start, length) {
+ chars = _toString.apply(this,arguments)
+ var comm = this.document.createComment(chars);
+ this.locator && position(this.locator,comm)
+ appendElement(this, comm);
+ },
+
+ startCDATA:function() {
+ //used in characters() methods
+ this.cdata = true;
+ },
+ endCDATA:function() {
+ this.cdata = false;
+ },
+
+ startDTD:function(name, publicId, systemId) {
+ var impl = this.document.implementation;
+ if (impl && impl.createDocumentType) {
+ var dt = impl.createDocumentType(name, publicId, systemId);
+ this.locator && position(this.locator,dt)
+ appendElement(this, dt);
+ }
+ },
+ /**
+ * @see org.xml.sax.ErrorHandler
+ * @link http://www.saxproject.org/apidoc/org/xml/sax/ErrorHandler.html
+ */
+ warning:function(error) {
+ console.warn(error,_locator(this.locator));
+ },
+ error:function(error) {
+ console.error(error,_locator(this.locator));
+ },
+ fatalError:function(error) {
+ console.error(error,_locator(this.locator));
+ throw error;
+ }
+}
+function _locator(l){
+ if(l){
+ return '\n@'+(l.systemId ||'')+'#[line:'+l.lineNumber+',col:'+l.columnNumber+']'
+ }
+}
+function _toString(chars,start,length){
+ if(typeof chars == 'string'){
+ return chars.substr(start,length)
+ }else{//java sax connect width xmldom on rhino(what about: "? && !(chars instanceof String)")
+ if(chars.length >= start+length || start){
+ return new java.lang.String(chars,start,length)+'';
+ }
+ return chars;
+ }
+}
+
+/*
+ * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/LexicalHandler.html
+ * used method of org.xml.sax.ext.LexicalHandler:
+ * #comment(chars, start, length)
+ * #startCDATA()
+ * #endCDATA()
+ * #startDTD(name, publicId, systemId)
+ *
+ *
+ * IGNORED method of org.xml.sax.ext.LexicalHandler:
+ * #endDTD()
+ * #startEntity(name)
+ * #endEntity(name)
+ *
+ *
+ * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/DeclHandler.html
+ * IGNORED method of org.xml.sax.ext.DeclHandler
+ * #attributeDecl(eName, aName, type, mode, value)
+ * #elementDecl(name, model)
+ * #externalEntityDecl(name, publicId, systemId)
+ * #internalEntityDecl(name, value)
+ * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/EntityResolver2.html
+ * IGNORED method of org.xml.sax.EntityResolver2
+ * #resolveEntity(String name,String publicId,String baseURI,String systemId)
+ * #resolveEntity(publicId, systemId)
+ * #getExternalSubset(name, baseURI)
+ * @link http://www.saxproject.org/apidoc/org/xml/sax/DTDHandler.html
+ * IGNORED method of org.xml.sax.DTDHandler
+ * #notationDecl(name, publicId, systemId) {};
+ * #unparsedEntityDecl(name, publicId, systemId, notationName) {};
+ */
+"endDTD,startEntity,endEntity,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,resolveEntity,getExternalSubset,notationDecl,unparsedEntityDecl".replace(/\w+/g,function(key){
+ DOMHandler.prototype[key] = function(){return null}
+})
+
+/* Private static helpers treated below as private instance methods, so don't need to add these to the public API; we might use a Relator to also get rid of non-standard public properties */
+function appendElement (hander,node) {
+ if (!hander.currentElement) {
+ hander.document.appendChild(node);
+ } else {
+ hander.currentElement.appendChild(node);
+ }
+}//appendChild and setAttributeNS are preformance key
+
+if(typeof require == 'function'){
+ var XMLReader = require('./sax').XMLReader;
+ var DOMImplementation = require('./dom').DOMImplementation;
+ exports.XMLSerializer = require('./dom').XMLSerializer ;
+ exports.DOMParser = DOMParser;
+}
View
1,135 Maze/the-boaster/node_modules/xmldom/dom.js
@@ -0,0 +1,1135 @@
+/*
+ * DOM Level 2
+ * Object DOMException
+ * @see http://www.w3.org/TR/REC-DOM-Level-1/ecma-script-language-binding.html
+ * @see http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/ecma-script-binding.html
+ */
+
+function copy(src,dest){
+ for(var p in src){
+ dest[p] = src[p];
+ }
+}
+/**
+^\w+\.prototype\.([_\w]+)\s*=\s*((?:.*\{\s*?[\r\n][\s\S]*?^})|\S.*?(?=[;\r\n]));?
+^\w+\.prototype\.([_\w]+)\s*=\s*(\S.*?(?=[;\r\n]));?
+ */
+function _extends(Class,Super){
+ var pt = Class.prototype;
+ if(Object.create){
+ var ppt = Object.create(Super.prototype)
+ pt.__proto__ = ppt;
+ }
+ if(!(pt instanceof Super)){
+ function t(){};
+ t.prototype = Super.prototype;
+ t = new t();
+ copy(pt,t);
+ Class.prototype = pt = t;
+ }
+ if(pt.constructor != Class){
+ if(typeof Class != 'function'){
+ console.error("unknow Class:"+Class)
+ }
+ pt.constructor = Class
+ }
+}
+var htmlns = 'http://www.w3.org/1999/xhtml' ;
+// Node Types
+var NodeType = {}
+var ELEMENT_NODE = NodeType.ELEMENT_NODE = 1;
+var ATTRIBUTE_NODE = NodeType.ATTRIBUTE_NODE = 2;
+var TEXT_NODE = NodeType.TEXT_NODE = 3;
+var CDATA_SECTION_NODE = NodeType.CDATA_SECTION_NODE = 4;
+var ENTITY_REFERENCE_NODE = NodeType.ENTITY_REFERENCE_NODE = 5;
+var ENTITY_NODE = NodeType.ENTITY_NODE = 6;
+var PROCESSING_INSTRUCTION_NODE = NodeType.PROCESSING_INSTRUCTION_NODE = 7;
+var COMMENT_NODE = NodeType.COMMENT_NODE = 8;
+var DOCUMENT_NODE = NodeType.DOCUMENT_NODE = 9;
+var DOCUMENT_TYPE_NODE = NodeType.DOCUMENT_TYPE_NODE = 10;
+var DOCUMENT_FRAGMENT_NODE = NodeType.DOCUMENT_FRAGMENT_NODE = 11;
+var NOTATION_NODE = NodeType.NOTATION_NODE = 12;
+
+// ExceptionCode
+var ExceptionCode = {}
+var ExceptionMessage = {};
+var INDEX_SIZE_ERR = ExceptionCode.INDEX_SIZE_ERR = ((ExceptionMessage[1]="Index size error"),1);
+var DOMSTRING_SIZE_ERR = ExceptionCode.DOMSTRING_SIZE_ERR = ((ExceptionMessage[2]="DOMString size error"),2);
+var HIERARCHY_REQUEST_ERR = ExceptionCode.HIERARCHY_REQUEST_ERR = ((ExceptionMessage[3]="Hierarchy request error"),3);
+var WRONG_DOCUMENT_ERR = ExceptionCode.WRONG_DOCUMENT_ERR = ((ExceptionMessage[4]="Wrong document"),4);
+var INVALID_CHARACTER_ERR = ExceptionCode.INVALID_CHARACTER_ERR = ((ExceptionMessage[5]="Invalid character"),5);
+var NO_DATA_ALLOWED_ERR = ExceptionCode.NO_DATA_ALLOWED_ERR = ((ExceptionMessage[6]="No data allowed"),6);
+var NO_MODIFICATION_ALLOWED_ERR = ExceptionCode.NO_MODIFICATION_ALLOWED_ERR = ((ExceptionMessage[7]="No modification allowed"),7);
+var NOT_FOUND_ERR = ExceptionCode.NOT_FOUND_ERR = ((ExceptionMessage[8]="Not found"),8);
+var NOT_SUPPORTED_ERR = ExceptionCode.NOT_SUPPORTED_ERR = ((ExceptionMessage[9]="Not supported"),9);
+var INUSE_ATTRIBUTE_ERR = ExceptionCode.INUSE_ATTRIBUTE_ERR = ((ExceptionMessage[10]="Attribute in use"),10);
+//level2
+var INVALID_STATE_ERR = ExceptionCode.INVALID_STATE_ERR = ((ExceptionMessage[11]="Invalid state"),11);
+var SYNTAX_ERR = ExceptionCode.SYNTAX_ERR = ((ExceptionMessage[12]="Syntax error"),12);
+var INVALID_MODIFICATION_ERR = ExceptionCode.INVALID_MODIFICATION_ERR = ((ExceptionMessage[13]="Invalid modification"),13);
+var NAMESPACE_ERR = ExceptionCode.NAMESPACE_ERR = ((ExceptionMessage[14]="Invalid namespace"),14);
+var INVALID_ACCESS_ERR = ExceptionCode.INVALID_ACCESS_ERR = ((ExceptionMessage[15]="Invalid access"),15);
+
+
+function DOMException(code, message) {
+ if(message instanceof Error){
+ var error = message;
+ }else{
+ error = this;
+ Error.call(this, ExceptionMessage[code]);
+ this.message = ExceptionMessage[code];
+ if(Error.captureStackTrace) Error.captureStackTrace(this, DOMException);
+ }
+ error.code = code;
+ if(message) this.message = this.message + ": " + message;
+ return error;
+};
+DOMException.prototype = Error.prototype;
+copy(ExceptionCode,DOMException)
+/**
+ * @see http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-536297177
+ * The NodeList interface provides the abstraction of an ordered collection of nodes, without defining or constraining how this collection is implemented. NodeList objects in the DOM are live.
+ * The items in the NodeList are accessible via an integral index, starting from 0.
+ */
+function NodeList() {
+};
+NodeList.prototype = {
+ /**
+ * The number of nodes in the list. The range of valid child node indices is 0 to length-1 inclusive.
+ * @standard level1
+ */
+ length:0,
+ /**
+ * Returns the indexth item in the collection. If index is greater than or equal to the number of nodes in the list, this returns null.
+ * @standard level1
+ * @param index unsigned long
+ * Index into the collection.
+ * @return Node
+ * The node at the indexth position in the NodeList, or null if that is not a valid index.
+ */
+ item: function(index) {
+ return this[index] || null;
+ }
+};
+function LiveNodeList(node,refresh){
+ this._node = node;
+ this._refresh = refresh
+ _updateLiveList(this);
+}
+function _updateLiveList(list){
+ var inc = list._node._inc || list._node.ownerDocument._inc;
+ if(list._inc != inc){
+ var ls = list._refresh(list._node);
+ //console.log(ls.length)
+ __set__(list,'length',ls.length);
+ copy(ls,list);
+ list._inc = inc;
+ }
+}
+LiveNodeList.prototype.item = function(i){
+ _updateLiveList(this);
+ return this[i];
+}
+
+_extends(LiveNodeList,NodeList);
+/**
+ *
+ * Objects implementing the NamedNodeMap interface are used to represent collections of nodes that can be accessed by name. Note that NamedNodeMap does not inherit from NodeList; NamedNodeMaps are not maintained in any particular order. Objects contained in an object implementing NamedNodeMap may also be accessed by an ordinal index, but this is simply to allow convenient enumeration of the contents of a NamedNodeMap, and does not imply that the DOM specifies an order to these Nodes.
+ * NamedNodeMap objects in the DOM are live.
+ * used for attributes or DocumentType entities
+ */
+function NamedNodeMap() {
+};
+
+function _findNodeIndex(list,node){
+ var i = list.length;
+ while(i--){
+ if(list[i] === node){return i}
+ }
+}
+
+function _addNamedNode(el,list,newAttr,oldAttr){
+ if(oldAttr){
+ list[_findNodeIndex(list,oldAttr)] = newAttr;
+ }else{
+ list[list.length++] = newAttr;
+ }
+ if(el){
+ newAttr.ownerElement = el;
+ var doc = el.ownerDocument;
+ if(doc){
+ oldAttr && _onRemoveAttribute(doc,el,oldAttr);
+ _onAddAttribute(doc,el,newAttr);
+ }
+ }
+}
+function _removeNamedNode(el,list,attr){
+ var i = _findNodeIndex(list,attr);
+ if(i>=0){
+ var lastIndex = list.length-1
+ while(i<lastIndex){
+ list[i] = list[++i]
+ }
+ list.length = lastIndex;
+ if(el){
+ var doc = el.ownerDocument;
+ if(doc){
+ _onRemoveAttribute(doc,el,attr);
+ attr.ownerElement = null;
+ }
+ }
+ }else{
+ throw DOMException(NOT_FOUND_ERR,new Error())
+ }
+}
+NamedNodeMap.prototype = {
+ length:0,
+ item:NodeList.prototype.item,
+ getNamedItem: function(key) {
+// if(key.indexOf(':')>0 || key == 'xmlns'){
+// return null;
+// }
+ var i = this.length;
+ while(i--){
+ var attr = this[i];
+ if(attr.nodeName == key){
+ return attr;
+ }
+ }
+ },
+ setNamedItem: function(attr) {
+ var el = attr.ownerElement;
+ if(el && el!=this._ownerElement){
+ throw new DOMException(INUSE_ATTRIBUTE_ERR);
+ }
+ var oldAttr = this.getNamedItem(attr.nodeName);
+ _addNamedNode(this._ownerElement,this,attr,oldAttr);
+ return oldAttr;
+ },
+ /* returns Node */
+ setNamedItemNS: function(attr) {// raises: WRONG_DOCUMENT_ERR,NO_MODIFICATION_ALLOWED_ERR,INUSE_ATTRIBUTE_ERR
+ var el = attr.ownerElement, oldAttr;
+ if(el && el!=this._ownerElement){
+ throw new DOMException(INUSE_ATTRIBUTE_ERR);
+ }
+ oldAttr = this.getNamedItemNS(attr.namespaceURI,attr.localName);
+ _addNamedNode(this._ownerElement,this,attr,oldAttr);
+ return oldAttr;
+ },
+
+ /* returns Node */
+ removeNamedItem: function(key) {
+ var attr = this.getNamedItem(key);
+ _removeNamedNode(this._ownerElement,this,attr);
+ return attr;
+
+
+ },// raises: NOT_FOUND_ERR,NO_MODIFICATION_ALLOWED_ERR
+
+ //for level2
+ removeNamedItemNS:function(namespaceURI,localName){
+ var attr = this.getNamedItemNS(namespaceURI,localName);
+ _removeNamedNode(this._ownerElement,this,attr);
+ return attr;
+ },
+ getNamedItemNS: function(namespaceURI, localName) {
+ var i = this.length;
+ while(i--){
+ var node = this[i];
+ if(node.localName == localName && node.namespaceURI == namespaceURI){
+ return node;
+ }
+ }
+ return null;
+ }
+};
+/**
+ * @see http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-102161490
+ */
+function DOMImplementation(/* Object */ features) {
+ this._features = {};
+ if (features) {
+ for (var feature in features) {
+ this._features = features[feature];
+ }
+ }
+};
+
+DOMImplementation.prototype = {
+ hasFeature: function(/* string */ feature, /* string */ version) {
+ var versions = this._features[feature.toLowerCase()];
+ if (versions && (!version || version in versions)) {
+ return true;
+ } else {
+ return false;
+ }
+ },
+ // Introduced in DOM Level 2:
+ createDocument:function(namespaceURI, qualifiedName, doctype){// raises:INVALID_CHARACTER_ERR,NAMESPACE_ERR,WRONG_DOCUMENT_ERR
+ var doc = new Document();
+ doc.doctype = doctype;
+ if(doctype){
+ doc.appendChild(doctype);
+ }
+ doc.implementation = this;
+ doc.childNodes = new NodeList();
+ if(qualifiedName){
+ var root = doc.createElementNS(namespaceURI,qualifiedName);
+ doc.appendChild(root);
+ }
+ return doc;
+ },
+ // Introduced in DOM Level 2:
+ createDocumentType:function(qualifiedName, publicId, systemId){// raises:INVALID_CHARACTER_ERR,NAMESPACE_ERR
+ var node = new DocumentType();
+ node.name = qualifiedName;
+ node.nodeName = qualifiedName;
+ node.publicId = publicId;
+ node.systemId = systemId;
+ // Introduced in DOM Level 2:
+ //readonly attribute DOMString internalSubset;
+
+ //TODO:..
+ // readonly attribute NamedNodeMap entities;
+ // readonly attribute NamedNodeMap notations;
+ return node;
+ }
+};
+
+
+/**
+ * @see http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1950641247
+ */
+
+function Node() {
+};
+
+Node.prototype = {
+ firstChild : null,
+ lastChild : null,
+ previousSibling : null,
+ nextSibling : null,
+ attributes : null,
+ parentNode : null,
+ childNodes : null,
+ ownerDocument : null,
+ nodeValue : null,
+ namespaceURI : null,
+ prefix : null,
+ localName : null,
+ // Modified in DOM Level 2:
+ insertBefore:function(newChild, refChild){//raises
+ return _insertBefore(this,newChild,refChild);
+ },
+ replaceChild:function(newChild, oldChild){//raises
+ this.insertBefore(newChild,oldChild);
+ if(oldChild){
+ this.removeChild(oldChild);
+ }
+ },
+ removeChild:function(oldChild){
+ return _removeChild(this,oldChild);
+ },
+ appendChild:function(newChild){
+ return this.insertBefore(newChild,null);
+ },
+ hasChildNodes:function(){
+ return this.firstChild != null;
+ },
+ cloneNode:function(deep){
+ return cloneNode(this.ownerDocument||this,this,deep);
+ },
+ // Modified in DOM Level 2:
+ normalize:function(){
+ var child = this.firstChild;
+ while(child){
+ var next = child.nextSibling;
+ if(next && next.nodeType == TEXT_NODE && child.nodeType == TEXT_NODE){
+ this.removeChild(next);
+ child.appendData(next.data);
+ }else{
+ child.normalize();
+ child = next;
+ }
+ }
+ },
+ // Introduced in DOM Level 2:
+ isSupported:function(feature, version){
+ return this.ownerDocument.implementation.hasFeature(feature,version);
+ },
+ // Introduced in DOM Level 2:
+ hasAttributes:function(){
+ return this.attributes.length>0;
+ },
+ lookupPrefix:function(namespaceURI){
+ var el = this;
+ while(el){
+ var map = el._nsMap;
+ //console.dir(map)
+ if(map){
+ for(var n in map){
+ if(map[n] == namespaceURI){
+ return n;
+ }
+ }
+ }
+ el = el.nodeType == 2?el.ownerDocument : el.parentNode;
+ }
+ return null;
+ },
+ // Introduced in DOM Level 3:
+ lookupNamespaceURI:function(prefix){
+ var el = this;
+ while(el){
+ var map = el._nsMap;
+ //console.dir(map)
+ if(map){
+ if(prefix in map){
+ return map[prefix] ;
+ }
+ }
+ el = el.nodeType == 2?el.ownerDocument : el.parentNode;
+ }
+ return null;
+ },
+ // Introduced in DOM Level 3:
+ isDefaultNamespace:function(namespaceURI){
+ var prefix = this.lookupPrefix(namespaceURI);
+ return prefix == null;
+ }
+};
+
+
+function _xmlEncoder(c){
+ return c == '<' && '&lt;' ||
+ c == '>' && '&gt;' ||
+ c == '&' && '&amp;' ||
+ c == '"' && '&quot;' ||
+ '&#'+c.charCodeAt()+';'
+}
+
+
+copy(NodeType,Node);
+copy(NodeType,Node.prototype);
+
+/**
+ * @param callback return true for continue,false for break
+ * @return boolean true: break visit;
+ */
+function _visitNode(node,callback){
+ if(callback(node)){
+ return true;
+ }
+ if(node = node.firstChild){
+ do{
+ if(_visitNode(node,callback)){return true}
+ }while(node=node.nextSibling)
+ }
+}
+
+
+
+function Document(){
+}
+function _onAddAttribute(doc,el,newAttr){
+ doc && doc._inc++;
+ var ns = newAttr.namespaceURI ;
+ if(ns == 'http://www.w3.org/2000/xmlns/'){
+ //update namespace
+ el._nsMap[newAttr.prefix?newAttr.localName:''] = newAttr.value
+ }
+}
+function _onRemoveAttribute(doc,el,newAttr,remove){
+ doc && doc._inc++;
+ var ns = newAttr.namespaceURI ;
+ if(ns == 'http://www.w3.org/2000/xmlns/'){
+ //update namespace
+ delete el._nsMap[newAttr.prefix?newAttr.localName:'']
+ }
+}
+function _onUpdateChild(doc,el,newChild){
+ if(doc && doc._inc){
+ doc._inc++;
+ //update childNodes
+ var cs = el.childNodes;
+ if(newChild){
+ cs[cs.length++] = newChild;
+ }else{
+ //console.log(1)
+ var child = el.firstChild;
+ var i = 0;
+ while(child){
+ cs[i++] = child;
+ child =child.nextSibling;
+ }
+ cs.length = i;
+ }
+ }
+}
+
+/**
+ * attributes;
+ * children;
+ *
+ * writeable properties:
+ * nodeValue,Attr:value,CharacterData:data
+ * prefix
+ */
+function _removeChild(parentNode,child){
+ var previous = child.previousSibling;
+ var next = child.nextSibling;
+ if(previous){
+ previous.nextSibling = next;
+ }else{
+ parentNode.firstChild = next
+ }
+ if(next){
+ next.previousSibling = previous;
+ }else{
+ parentNode.lastChild = previous;
+ }
+ _onUpdateChild(parentNode.ownerDocument,parentNode);
+ return child;
+}
+/**
+ * preformance key(refChild == null)
+ */
+function _insertBefore(parentNode,newChild,nextChild){
+ var cp = newChild.parentNode;
+ if(cp){
+ cp.removeChild(newChild);//remove and update
+ }
+ if(newChild.nodeType === DOCUMENT_FRAGMENT_NODE){
+ var newFirst = newChild.firstChild;
+ var newLast = newChild.lastChild;
+ }else{
+ newFirst = newLast = newChild;
+ }
+ var pre = nextChild ? nextChild.previousSibling : parentNode.lastChild;
+
+ newFirst.previousSibling = pre;
+ newLast.nextSibling = nextChild;
+
+
+ if(pre){
+ pre.nextSibling = newFirst;
+ }else{
+ parentNode.firstChild = newFirst;
+ }
+ if(nextChild == null){
+ parentNode.lastChild = newLast;
+ }else{
+ nextChild.previousSibling = newLast;
+ }
+ do{
+ newFirst.parentNode = parentNode;
+ }while(newFirst !== newLast && (newFirst= newFirst.nextSibling))
+ _onUpdateChild(parentNode.ownerDocument||parentNode,parentNode);
+ //console.log(parentNode.lastChild.nextSibling == null)
+ if (newChild.nodeType == DOCUMENT_FRAGMENT_NODE) {
+ newChild.firstChild = newChild.lastChild = null;
+ }
+ return newChild;
+}
+function _appendSingleChild(parentNode,newChild){
+ var cp = newChild.parentNode;
+ if(cp){
+ var pre = parentNode.lastChild;
+ cp.removeChild(newChild);//remove and update
+ var pre = parentNode.lastChild;
+ }
+ var pre = parentNode.lastChild;
+ newChild.parentNode = parentNode;
+ newChild.previousSibling = pre;
+ newChild.nextSibling = null;
+ if(pre){
+ pre.nextSibling = newChild;
+ }else{
+ parentNode.firstChild = newChild;
+ }
+ parentNode.lastChild = newChild;
+ _onUpdateChild(parentNode.ownerDocument,parentNode,newChild);
+ return newChild;
+ //console.log("__aa",parentNode.lastChild.nextSibling == null)
+}
+Document.prototype = {
+ //implementation : null,
+ nodeName : '#document',
+ nodeType : DOCUMENT_NODE,
+ doctype : null,
+ documentElement : null,
+ _inc : 1,
+
+ insertBefore : function(newChild, refChild){//raises
+ if(newChild.nodeType == DOCUMENT_FRAGMENT_NODE){
+ var child = newChild.firstChild;
+ while(child){
+ var next = child.nextSibling;
+ this.insertBefore(child,refChild);
+ child = next;
+ }
+ return newChild;
+ }
+ if(this.documentElement == null && newChild.nodeType == 1){
+ this.documentElement = newChild;
+ }
+
+ return _insertBefore(this,newChild,refChild),(newChild.ownerDocument = this),newChild;
+ },
+ removeChild : function(oldChild){
+ if(this.documentElement == oldChild){
+ this.documentElement = null;
+ }
+ return _removeChild(this,oldChild);
+ },
+ // Introduced in DOM Level 2:
+ importNode : function(importedNode,deep){
+ return importNode(this,importedNode,deep);
+ },
+ // Introduced in DOM Level 2:
+ getElementById : function(id){
+ var rtv = null;
+ _visitNode(this.documentElement,function(node){
+ if(node.nodeType == 1){
+ if(node.getAttribute('id') == id){
+ rtv = node;
+ return true;
+ }
+ }
+ })
+ return rtv;
+ },
+
+ //document factory method:
+ createElement : function(tagName){
+ var node = new Element();
+ node.ownerDocument = this;
+ node.nodeName = tagName;
+ node.tagName = tagName;
+ node.childNodes = new NodeList();
+ var attrs = node.attributes = new NamedNodeMap();
+ attrs._ownerElement = node;
+ return node;
+ },
+ createDocumentFragment : function(){
+ var node = new DocumentFragment();
+ node.ownerDocument = this;
+ node.childNodes = new NodeList();
+ return node;
+ },
+ createTextNode : function(data){
+ var node = new Text();
+ node.ownerDocument = this;
+ node.appendData(data)
+ return node;
+ },
+ createComment : function(data){
+ var node = new Comment();
+ node.ownerDocument = this;
+ node.appendData(data)
+ return node;
+ },
+ createCDATASection : function(data){
+ var node = new CDATASection();
+ node.ownerDocument = this;
+ node.appendData(data)
+ return node;
+ },
+ createProcessingInstruction : function(target,data){
+ var node = new ProcessingInstruction();
+ node.ownerDocument = this;
+ node.tagName = node.target = target;
+ node.nodeValue= node.data = data;
+ return node;
+ },
+ createAttribute : function(name){
+ var node = new Attr();
+ node.ownerDocument = this;
+ node.name = name;
+ node.nodeName = name;
+ node.localName = name;
+ node.specified = true;
+ return node;
+ },
+ createEntityReference : function(name){
+ var node = new EntityReference();
+ node.ownerDocument = this;
+ node.nodeName = name;
+ return node;
+ },
+ // Introduced in DOM Level 2:
+ createElementNS : function(namespaceURI,qualifiedName){
+ var node = new Element();
+ var pl = qualifiedName.split(':');
+ var attrs = node.attributes = new NamedNodeMap();
+ node.childNodes = new NodeList();
+ node.ownerDocument = this;
+ node.nodeName = qualifiedName;
+ node.tagName = qualifiedName;
+ node.namespaceURI = namespaceURI;
+ if(pl.length == 2){
+ node.prefix = pl[0];
+ node.localName = pl[1];
+ }else{
+ //el.prefix = null;
+ node.localName = qualifiedName;
+ }
+ attrs._ownerElement = node;
+ return node;
+ },
+ // Introduced in DOM Level 2:
+ createAttributeNS : function(namespaceURI,qualifiedName){
+ var node = new Attr();
+ var pl = qualifiedName.split(':');
+ node.ownerDocument = this;
+ node.nodeName = qualifiedName;
+ node.name = qualifiedName;
+ node.namespaceURI = namespaceURI;
+ node.specified = true;
+ if(pl.length == 2){
+ node.prefix = pl[0];
+ node.localName = pl[1];
+ }else{
+ //el.prefix = null;
+ node.localName = qualifiedName;
+ }
+ return node;
+ }
+};
+_extends(Document,Node);
+
+
+function Element() {
+ this._nsMap = {};
+};
+Element.prototype = {
+ nodeType : ELEMENT_NODE,
+ hasAttribute : function(name){
+ return this.getAttributeNode(name)!=null;
+ },
+ getAttribute : function(name){
+ var attr = this.getAttributeNode(name);
+ return attr && attr.value || '';
+ },
+ getAttributeNode : function(name){
+ return this.attributes.getNamedItem(name);
+ },
+ setAttribute : function(name, value){
+ var attr = this.ownerDocument.createAttribute(name);
+ attr.value = attr.nodeValue = "" + value;
+ this.setAttributeNode(attr)
+ },
+ removeAttribute : function(name){
+ var attr = this.getAttributeNode(name)
+ attr && this.removeAttributeNode(attr);
+ },
+
+ //four real opeartion method
+ appendChild:function(newChild){
+ if(newChild.nodeType === DOCUMENT_FRAGMENT_NODE){
+ return this.insertBefore(newChild,null);
+ }else{
+ return _appendSingleChild(this,newChild);
+ }
+ },
+ setAttributeNode : function(newAttr){
+ return this.attributes.setNamedItem(newAttr);
+ },
+ setAttributeNodeNS : function(newAttr){
+ return this.attributes.setNamedItemNS(newAttr);
+ },
+ removeAttributeNode : function(oldAttr){
+ return this.attributes.removeNamedItem(oldAttr.nodeName);
+ },
+ //get real attribute name,and remove it by removeAttributeNode
+ removeAttributeNS : function(namespaceURI, localName){
+ var old = this.getAttributeNodeNS(namespaceURI, localName);
+ old && this.removeAttributeNode(old);
+ },
+
+ hasAttributeNS : function(namespaceURI, localName){
+ return this.getAttributeNodeNS(namespaceURI, localName)!=null;
+ },
+ getAttributeNS : function(namespaceURI, localName){
+ var attr = this.getAttributeNodeNS(namespaceURI, localName);
+ return attr && attr.value || '';
+ },
+ setAttributeNS : function(namespaceURI, qualifiedName, value){
+ var attr = this.ownerDocument.createAttributeNS(namespaceURI, qualifiedName);
+ attr.value = attr.nodeValue = value;
+ this.setAttributeNode(attr)
+ },
+ getAttributeNodeNS : function(namespaceURI, localName){
+ return this.attributes.getNamedItemNS(namespaceURI, localName);
+ },
+
+ getElementsByTagName : function(tagName){
+ return new LiveNodeList(this,function(base){
+ var ls = [];
+ _visitNode(base,function(node){
+ if(node !== base && node.nodeType == ELEMENT_NODE && (tagName === '*' || node.tagName == tagName)){
+ ls.push(node);
+ }
+ });
+ return ls;
+ });
+ },
+ getElementsByTagNameNS : function(namespaceURI, localName){
+ return new LiveNodeList(this,function(base){
+ var ls = [];
+ _visitNode(base,function(node){
+ if(node !== base && node.nodeType === ELEMENT_NODE && node.namespaceURI === namespaceURI && (localName === '*' || node.localName == localName)){
+ ls.push(node);
+ }
+ });
+ return ls;
+ });
+ }
+};
+Document.prototype.getElementsByTagName = Element.prototype.getElementsByTagName;
+Document.prototype.getElementsByTagNameNS = Element.prototype.getElementsByTagNameNS;
+
+
+_extends(Element,Node);
+function Attr() {
+};
+Attr.prototype.nodeType = ATTRIBUTE_NODE;
+_extends(Attr,Node);
+
+
+function CharacterData() {
+};
+CharacterData.prototype = {
+ data : '',
+ substringData : function(offset, count) {
+ return this.data.substring(offset, offset+count);
+ },
+ appendData: function(text) {
+ text = this.data+text;
+ this.nodeValue = this.data = text;
+ this.length = text.length;
+ },
+ insertData: function(offset,text) {
+ this.replaceData(offset,0,text);
+
+ },
+ appendChild:function(newChild){
+ //if(!(newChild instanceof CharacterData)){
+ throw new Error(ExceptionMessage[3])
+ //}
+ return Node.prototype.appendChild.apply(this,arguments)
+ },
+ deleteData: function(offset, count) {
+ this.replaceData(offset,count,"");
+ },
+ replaceData: function(offset, count, text) {
+ var start = this.data.substring(0,offset);
+ var end = this.data.substring(offset+count);
+ text = start + text + end;
+ this.nodeValue = this.data = text;
+ this.length = text.length;
+ }
+}
+_extends(CharacterData,Node);
+function Text() {
+};
+Text.prototype = {
+ nodeName : "#text",
+ nodeType : TEXT_NODE,
+ splitText : function(offset) {
+ var text = this.data;
+ var newText = text.substring(offset);
+ text = text.substring(0, offset);
+ this.data = this.nodeValue = text;
+ this.length = text.length;
+ var newNode = this.ownerDocument.createTextNode(newText);
+ if(this.parentNode){
+ this.parentNode.insertBefore(newNode, this.nextSibling);
+ }
+ return newNode;
+ }
+}
+_extends(Text,CharacterData);
+function Comment() {
+};
+Comment.prototype = {
+ nodeName : "#comment",
+ nodeType : COMMENT_NODE
+}
+_extends(Comment,CharacterData);
+
+function CDATASection() {
+};
+CDATASection.prototype = {
+ nodeName : "#cdata-section",
+ nodeType : CDATA_SECTION_NODE
+}
+_extends(CDATASection,CharacterData);
+
+
+function DocumentType() {
+};
+DocumentType.prototype.nodeType = DOCUMENT_TYPE_NODE;
+_extends(DocumentType,Node);
+
+function Notation() {
+};
+Notation.prototype.nodeType = NOTATION_NODE;
+_extends(Notation,Node);
+
+function Entity() {
+};
+Entity.prototype.nodeType = ENTITY_NODE;
+_extends(Entity,Node);
+
+function EntityReference() {
+};
+EntityReference.prototype.nodeType = ENTITY_REFERENCE_NODE;
+_extends(EntityReference,Node);
+
+function DocumentFragment() {
+};
+DocumentFragment.prototype.nodeName = "#document-fragment";
+DocumentFragment.prototype.nodeType = DOCUMENT_FRAGMENT_NODE;
+_extends(DocumentFragment,Node);
+
+
+function ProcessingInstruction() {
+}
+ProcessingInstruction.prototype.nodeType = PROCESSING_INSTRUCTION_NODE;
+_extends(ProcessingInstruction,Node);
+function XMLSerializer(){}
+XMLSerializer.prototype.serializeToString = function(node){
+ var buf = [];
+ serializeToString(node,buf);
+ return buf.join('');
+}
+Node.prototype.toString =function(){
+ return XMLSerializer.prototype.serializeToString(this);
+}
+function serializeToString(node,buf){
+ switch(node.nodeType){
+ case ELEMENT_NODE:
+ var attrs = node.attributes;
+ var len = attrs.length;
+ var child = node.firstChild;
+ var nodeName = node.tagName;
+ var isHTML = htmlns === node.namespaceURI
+ buf.push('<',nodeName);
+ for(var i=0;i<len;i++){
+ serializeToString(attrs.item(i),buf,isHTML);
+ }
+ if(child || isHTML && !/^(?:meta|link|img|br|hr|input)$/i.test(nodeName)){
+ buf.push('>');
+ //if is cdata child node
+ if(isHTML && /^script$/i.test(nodeName)){
+ if(child){
+ buf.push(child.data);
+ }
+ }else{
+ while(child){
+ serializeToString(child,buf);
+ child = child.nextSibling;
+ }
+ }
+ buf.push('</',nodeName,'>');
+ }else{
+ buf.push('/>');
+ }
+ return;
+ case DOCUMENT_NODE:
+ case DOCUMENT_FRAGMENT_NODE:
+ var child = node.firstChild;
+ while(child){
+ serializeToString(child,buf);
+ child = child.nextSibling;
+ }
+ return;
+ case ATTRIBUTE_NODE:
+ return buf.push(' ',node.name,'="',node.value.replace(/[<&"]/g,_xmlEncoder),'"');
+ case TEXT_NODE:
+ return buf.push(node.data.replace(/[<&]/g,_xmlEncoder));
+ case CDATA_SECTION_NODE:
+ return buf.push( '<![CDATA[',node.data,']]>');
+ case COMMENT_NODE:
+ return buf.push( "<!--",node.data,"-->");
+ case DOCUMENT_TYPE_NODE:
+ var pubid = node.publicId;
+ var sysid = node.systemId;
+ buf.push('<!DOCTYPE ',node.name);
+ if(pubid){
+ buf.push(' PUBLIC "',pubid);
+ if (sysid && sysid!='.') {
+ buf.push( '" "',sysid);
+ }
+ buf.push('">');
+ }else if(sysid && sysid!='.'){
+ buf.push(' SYSTEM "',sysid,'">');
+ }else{
+ var sub = node.internalSubset;
+ if(sub){
+ buf.push(" [",sub,"]");
+ }
+ buf.push(">");
+ }
+ return;
+ case PROCESSING_INSTRUCTION_NODE:
+ return buf.push( "<?",node.target," ",node.data,"?>");
+ case ENTITY_REFERENCE_NODE:
+ return buf.push( '&',node.nodeName,';');
+ //case ENTITY_NODE:
+ //case NOTATION_NODE:
+ default:
+ buf.push('??',node.nodeName);
+ }
+}
+function importNode(doc,node,deep){
+ var node2;
+ switch (node.nodeType) {
+ case ELEMENT_NODE:
+ node2 = node.cloneNode(false);
+ node2.ownerDocument = doc;
+ var attrs = node2.attributes;
+ var len = attrs.length;
+ for(var i=0;i<len;i++){
+ node2.setAttributeNodeNS(importNode(doc,attrs.item(i),deep));
+ }
+ case DOCUMENT_FRAGMENT_NODE:
+ break;
+ case ATTRIBUTE_NODE:
+ deep = true;
+ break;
+ //case ENTITY_REFERENCE_NODE:
+ //case PROCESSING_INSTRUCTION_NODE:
+ ////case TEXT_NODE:
+ //case CDATA_SECTION_NODE:
+ //case COMMENT_NODE:
+ // deep = false;
+ // break;
+ //case DOCUMENT_NODE:
+ //case DOCUMENT_TYPE_NODE:
+ //cannot be imported.
+ //case ENTITY_NODE:
+ //case NOTATION_NODE:
+ //can not hit in level3
+ //default:throw e;
+ }
+ if(!node2){
+ node2 = node.cloneNode(false);//false
+ }
+ node2.ownerDocument = doc;
+ node2.parentNode = null;
+ if(deep){
+ var child = node.firstChild;
+ while(child){
+ node2.appendChild(importNode(doc,child,deep));
+ child = child.nextSibling;
+ }
+ }
+ return node2;
+}
+//
+//var _relationMap = {firstChild:1,lastChild:1,previousSibling:1,nextSibling:1,
+// attributes:1,childNodes:1,parentNode:1,documentElement:1,doctype,};
+function cloneNode(doc,node,deep){
+ var node2 = new node.constructor();
+ for(var n in node){
+ var v = node[n];
+ if(typeof v != 'object' ){
+ if(v != node2[n]){
+ node2[n] = v;
+ }
+ }
+ }
+ if(node.childNodes){
+ node2.childNodes = new NodeList();
+ }
+ node2.ownerDocument = doc;
+ switch (node2.nodeType) {
+ case ELEMENT_NODE:
+ var attrs = node.attributes;
+ var attrs2 = node2.attributes = new NamedNodeMap();
+ var len = attrs.length
+ attrs2._ownerElement = node2;
+ for(var i=0;i<len;i++){
+ node2.setAttributeNode(cloneNode(doc,attrs.item(i),true));
+ }
+ break;;
+ case ATTRIBUTE_NODE:
+ deep = true;
+ }
+ if(deep){
+ var child = node.firstChild;
+ while(child){
+ node2.appendChild(cloneNode(doc,child,deep));
+ child = child.nextSibling;
+ }
+ }
+ return node2;
+}
+
+function __set__(object,key,value){
+ object[key] = value
+}
+//do dynamic
+try{
+ if(Object.defineProperty){
+ Object.defineProperty(LiveNodeList.prototype,'length',{
+ get:function(){
+ _updateLiveList(this);
+ return this.$$length;
+ }
+ });
+ Object.defineProperty(Node.prototype,'textContent',{
+ get:function(){
+ return getTextContent(this);
+ },
+ set:function(data){
+ switch(this.nodeType){
+ case 1:
+ case 11:
+ while(this.firstChild){
+ this.removeChild(this.firstChild);
+ }
+ if(data || String(data)){
+ this.appendChild(this.ownerDocument.createTextNode(data));
+ }
+ break;
+ default:
+ //TODO:
+ this.data = data;
+ this.value = value;
+ this.nodeValue = data;
+ }
+ }
+ })
+
+ function getTextContent(node){
+ switch(node.nodeType){
+ case 1:
+ case 11:
+ var buf = [];
+ node = node.firstChild;
+ while(node){
+ if(node.nodeType!==7 && node.nodeType !==8){
+ buf.push(getTextContent(node));
+ }
+ node = node.nextSibling;
+ }
+ return buf.join('');
+ default:
+ return node.nodeValue;
+ }
+ }
+ __set__ = function(object,key,value){
+ //console.log(value)
+ object['$$'+key] = value
+ }
+ }
+}catch(e){//ie8
+}
+
+if(typeof require == 'function'){
+ exports.DOMImplementation = DOMImplementation;
+ exports.XMLSerializer = XMLSerializer;
+}
View
70 Maze/the-boaster/node_modules/xmldom/package.json
@@ -0,0 +1,70 @@
+{