johnson 1.2.0 → 2.0.0.pre0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (782) hide show
  1. data/CHANGELOG.rdoc +8 -0
  2. data/Manifest.txt +762 -48
  3. data/README.rdoc +2 -1
  4. data/Rakefile +90 -18
  5. data/ext/spidermonkey/conversions.c +9 -2
  6. data/ext/spidermonkey/ruby_land_proxy.c +1 -1
  7. data/ext/spidermonkey/runtime.h +1 -1
  8. data/ext/tracemonkey/context.cc +125 -0
  9. data/ext/tracemonkey/context.h +19 -0
  10. data/ext/tracemonkey/conversions.cc +365 -0
  11. data/ext/tracemonkey/conversions.h +32 -0
  12. data/ext/tracemonkey/debugger.cc +234 -0
  13. data/ext/tracemonkey/debugger.h +10 -0
  14. data/ext/tracemonkey/extconf.rb +37 -0
  15. data/ext/tracemonkey/extensions.cc +37 -0
  16. data/ext/tracemonkey/extensions.h +12 -0
  17. data/ext/tracemonkey/global.cc +40 -0
  18. data/ext/tracemonkey/global.h +11 -0
  19. data/ext/tracemonkey/idhash.cc +16 -0
  20. data/ext/tracemonkey/idhash.h +8 -0
  21. data/ext/tracemonkey/immutable_node.cc +1199 -0
  22. data/ext/tracemonkey/immutable_node.cc.erb +559 -0
  23. data/ext/tracemonkey/immutable_node.h +22 -0
  24. data/ext/tracemonkey/jroot.h +215 -0
  25. data/ext/tracemonkey/js_land_proxy.cc +620 -0
  26. data/ext/tracemonkey/js_land_proxy.h +20 -0
  27. data/ext/tracemonkey/ruby_land_proxy.cc +618 -0
  28. data/ext/tracemonkey/ruby_land_proxy.h +38 -0
  29. data/ext/tracemonkey/runtime.cc +454 -0
  30. data/ext/tracemonkey/runtime.h +27 -0
  31. data/ext/tracemonkey/split_global.cc +392 -0
  32. data/ext/tracemonkey/split_global.h +11 -0
  33. data/ext/tracemonkey/tracemonkey.cc +23 -0
  34. data/ext/tracemonkey/tracemonkey.h +32 -0
  35. data/lib/johnson.rb +12 -4
  36. data/lib/johnson/error.rb +5 -0
  37. data/lib/johnson/js/prelude.js +16 -1
  38. data/lib/johnson/parser.rb +2 -1
  39. data/lib/johnson/runtime.rb +87 -26
  40. data/lib/johnson/spidermonkey/runtime.rb +7 -16
  41. data/lib/johnson/tracemonkey.rb +13 -0
  42. data/lib/johnson/tracemonkey/context.rb +10 -0
  43. data/lib/johnson/tracemonkey/debugger.rb +67 -0
  44. data/lib/johnson/tracemonkey/immutable_node.rb +282 -0
  45. data/lib/johnson/tracemonkey/js_land_proxy.rb +64 -0
  46. data/lib/johnson/tracemonkey/mutable_tree_visitor.rb +242 -0
  47. data/lib/johnson/tracemonkey/ruby_land_proxy.rb +17 -0
  48. data/lib/johnson/tracemonkey/runtime.rb +80 -0
  49. data/test/{johnson_test.rb → generic/johnson_test.rb} +1 -1
  50. data/test/{parser_test.rb → generic/parser_test.rb} +1 -1
  51. data/test/helper.rb +23 -4
  52. data/test/johnson/{browser_test.rb → generic/browser_test.rb} +1 -1
  53. data/test/johnson/{conversions → generic/conversions}/array_test.rb +1 -1
  54. data/test/johnson/{conversions → generic/conversions}/boolean_test.rb +1 -1
  55. data/test/johnson/{conversions → generic/conversions}/callable_test.rb +1 -1
  56. data/test/johnson/{conversions → generic/conversions}/file_test.rb +1 -1
  57. data/test/johnson/generic/conversions/helper.rb +1 -0
  58. data/test/johnson/{conversions → generic/conversions}/nil_test.rb +1 -1
  59. data/test/johnson/{conversions → generic/conversions}/number_test.rb +1 -1
  60. data/test/johnson/{conversions → generic/conversions}/regexp_test.rb +1 -1
  61. data/test/johnson/{conversions → generic/conversions}/string_test.rb +1 -1
  62. data/test/johnson/{conversions → generic/conversions}/struct_test.rb +1 -1
  63. data/test/johnson/{conversions → generic/conversions}/symbol_test.rb +1 -1
  64. data/test/johnson/{conversions → generic/conversions}/thread_test.rb +1 -1
  65. data/test/johnson/{custom_conversions_test.rb → generic/custom_conversions_test.rb} +1 -1
  66. data/test/johnson/generic/default_test.rb +12 -0
  67. data/test/johnson/{error_test.rb → generic/error_test.rb} +1 -1
  68. data/test/johnson/{extensions_test.rb → generic/extensions_test.rb} +1 -1
  69. data/test/johnson/generic/helper.rb +1 -0
  70. data/test/johnson/{nodes → generic/nodes}/array_literal_test.rb +1 -1
  71. data/test/johnson/{nodes → generic/nodes}/array_node_test.rb +1 -1
  72. data/test/johnson/{nodes → generic/nodes}/binary_node_test.rb +1 -1
  73. data/test/johnson/{nodes → generic/nodes}/bracket_access_test.rb +1 -1
  74. data/test/johnson/{nodes → generic/nodes}/delete_test.rb +1 -1
  75. data/test/johnson/{nodes → generic/nodes}/do_while_test.rb +1 -1
  76. data/test/johnson/{nodes → generic/nodes}/dot_accessor_test.rb +1 -1
  77. data/test/johnson/generic/nodes/export_test.rb +11 -0
  78. data/test/johnson/{nodes → generic/nodes}/for_test.rb +1 -1
  79. data/test/johnson/{nodes → generic/nodes}/function_test.rb +1 -1
  80. data/test/johnson/generic/nodes/helper.rb +1 -0
  81. data/test/johnson/{nodes → generic/nodes}/if_test.rb +16 -6
  82. data/test/johnson/generic/nodes/import_test.rb +15 -0
  83. data/test/johnson/{nodes → generic/nodes}/label_test.rb +1 -1
  84. data/test/johnson/{nodes → generic/nodes}/let_test.rb +1 -1
  85. data/test/johnson/{nodes → generic/nodes}/object_literal_test.rb +1 -1
  86. data/test/johnson/{nodes → generic/nodes}/return_test.rb +1 -1
  87. data/test/johnson/{nodes → generic/nodes}/semi_test.rb +1 -1
  88. data/test/johnson/{nodes → generic/nodes}/switch_test.rb +1 -1
  89. data/test/johnson/{nodes → generic/nodes}/ternary_test.rb +1 -1
  90. data/test/johnson/{nodes → generic/nodes}/throw_test.rb +1 -1
  91. data/test/johnson/{nodes → generic/nodes}/try_node_test.rb +36 -6
  92. data/test/johnson/{nodes → generic/nodes}/typeof_test.rb +1 -1
  93. data/test/johnson/{nodes → generic/nodes}/unary_node_test.rb +1 -1
  94. data/test/johnson/{nodes → generic/nodes}/void_test.rb +1 -1
  95. data/test/johnson/{nodes → generic/nodes}/while_test.rb +1 -1
  96. data/test/johnson/{nodes → generic/nodes}/with_test.rb +1 -1
  97. data/test/johnson/{prelude_test.rb → generic/prelude_test.rb} +1 -1
  98. data/test/johnson/{runtime_test.rb → generic/runtime_test.rb} +3 -6
  99. data/test/johnson/generic/version_test.rb +13 -0
  100. data/test/johnson/{visitors → generic/visitors}/dot_visitor_test.rb +1 -1
  101. data/test/johnson/{visitors → generic/visitors}/enumerating_visitor_test.rb +1 -1
  102. data/test/johnson/generic/visitors/helper.rb +1 -0
  103. data/test/johnson/spidermonkey/js_land_proxy_test.rb +1 -5
  104. data/test/johnson/spidermonkey/ruby_land_proxy_test.rb +11 -7
  105. data/test/johnson/tracemonkey/context_test.rb +21 -0
  106. data/test/johnson/tracemonkey/immutable_node_test.rb +34 -0
  107. data/test/johnson/tracemonkey/js_land_proxy_test.rb +273 -0
  108. data/test/johnson/tracemonkey/ruby_land_proxy_test.rb +274 -0
  109. data/test/johnson/tracemonkey/runtime_test.rb +41 -0
  110. data/test/johnson/tracemonkey/split_global_test.rb +32 -0
  111. data/vendor/spidermonkey/js.pkg +2 -0
  112. data/vendor/tracemonkey/Makefile.in +668 -0
  113. data/vendor/tracemonkey/Makefile.ref +483 -0
  114. data/vendor/tracemonkey/README.html +54 -0
  115. data/vendor/tracemonkey/SpiderMonkey.rsp +11 -0
  116. data/vendor/tracemonkey/Y.js +19 -0
  117. data/vendor/tracemonkey/aclocal.m4 +9 -0
  118. data/vendor/tracemonkey/bench.sh +5 -0
  119. data/vendor/tracemonkey/build/autoconf/acoutput-fast.pl +202 -0
  120. data/vendor/tracemonkey/build/autoconf/altoptions.m4 +154 -0
  121. data/vendor/tracemonkey/build/autoconf/config.guess +1537 -0
  122. data/vendor/tracemonkey/build/autoconf/config.sub +1595 -0
  123. data/vendor/tracemonkey/build/autoconf/install-sh +119 -0
  124. data/vendor/tracemonkey/build/autoconf/make-makefile +315 -0
  125. data/vendor/tracemonkey/build/autoconf/match-dir.sh +101 -0
  126. data/vendor/tracemonkey/build/autoconf/moznbytetype.m4 +136 -0
  127. data/vendor/tracemonkey/build/autoconf/nspr.m4 +82 -0
  128. data/vendor/tracemonkey/build/autoconf/pkg.m4 +59 -0
  129. data/vendor/tracemonkey/build/autoconf/update-makefile.sh +118 -0
  130. data/vendor/tracemonkey/build/cygwin-wrapper +75 -0
  131. data/vendor/tracemonkey/build/hcc +111 -0
  132. data/vendor/tracemonkey/build/hcpp +155 -0
  133. data/vendor/tracemonkey/build/unix/mddepend.pl +165 -0
  134. data/vendor/tracemonkey/build/unix/uniq.pl +63 -0
  135. data/vendor/tracemonkey/build/win32/pgomerge.py +40 -0
  136. data/vendor/tracemonkey/builtins.tbl +91 -0
  137. data/vendor/tracemonkey/call.js +13 -0
  138. data/vendor/tracemonkey/config.mk +206 -0
  139. data/vendor/tracemonkey/config/Makefile.in +106 -0
  140. data/vendor/tracemonkey/config/Moz/Milestone.pm +232 -0
  141. data/vendor/tracemonkey/config/autoconf.mk.in +362 -0
  142. data/vendor/tracemonkey/config/check-sync-dirs.py +103 -0
  143. data/vendor/tracemonkey/config/check-sync-exceptions +7 -0
  144. data/vendor/tracemonkey/config/config.mk +881 -0
  145. data/vendor/tracemonkey/config/fastcwd.pl +66 -0
  146. data/vendor/tracemonkey/config/gcc_hidden.h +2 -0
  147. data/vendor/tracemonkey/config/insure.mk +53 -0
  148. data/vendor/tracemonkey/config/make-system-wrappers.pl +59 -0
  149. data/vendor/tracemonkey/config/milestone.pl +112 -0
  150. data/vendor/tracemonkey/config/milestone.txt +13 -0
  151. data/vendor/tracemonkey/config/mkdepend/Makefile.in +84 -0
  152. data/vendor/tracemonkey/config/mkdepend/cppsetup.c +233 -0
  153. data/vendor/tracemonkey/config/mkdepend/def.h +184 -0
  154. data/vendor/tracemonkey/config/mkdepend/ifparser.c +551 -0
  155. data/vendor/tracemonkey/config/mkdepend/ifparser.h +83 -0
  156. data/vendor/tracemonkey/config/mkdepend/imakemdep.h +733 -0
  157. data/vendor/tracemonkey/config/mkdepend/include.c +337 -0
  158. data/vendor/tracemonkey/config/mkdepend/main.c +860 -0
  159. data/vendor/tracemonkey/config/mkdepend/mkdepend.man +382 -0
  160. data/vendor/tracemonkey/config/mkdepend/parse.c +686 -0
  161. data/vendor/tracemonkey/config/mkdepend/pr.c +124 -0
  162. data/vendor/tracemonkey/config/nfspwd.pl +50 -0
  163. data/vendor/tracemonkey/config/nsinstall.c +481 -0
  164. data/vendor/tracemonkey/config/nsinstall.py +155 -0
  165. data/vendor/tracemonkey/config/pathsub.c +247 -0
  166. data/vendor/tracemonkey/config/pathsub.h +74 -0
  167. data/vendor/tracemonkey/config/preprocessor.pl +671 -0
  168. data/vendor/tracemonkey/config/revdepth-nt.pl +48 -0
  169. data/vendor/tracemonkey/config/revdepth.pl +51 -0
  170. data/vendor/tracemonkey/config/rules.mk +2310 -0
  171. data/vendor/tracemonkey/config/static-checking-config.mk +21 -0
  172. data/vendor/tracemonkey/config/static-checking.js +92 -0
  173. data/vendor/tracemonkey/config/string-format.js +61 -0
  174. data/vendor/tracemonkey/config/system-headers +1035 -0
  175. data/vendor/tracemonkey/config/version.mk +85 -0
  176. data/vendor/tracemonkey/config/version_win.pl +442 -0
  177. data/vendor/tracemonkey/configure +14183 -0
  178. data/vendor/tracemonkey/configure.in +5363 -0
  179. data/vendor/tracemonkey/correct.sh +23 -0
  180. data/vendor/tracemonkey/correct/check-3d-morph.js +55 -0
  181. data/vendor/tracemonkey/correct/check-3d-raytrace.js +445 -0
  182. data/vendor/tracemonkey/correct/check-access-binary-trees.js +52 -0
  183. data/vendor/tracemonkey/correct/check-access-fannkuch.js +66 -0
  184. data/vendor/tracemonkey/correct/check-access-nbody.js +171 -0
  185. data/vendor/tracemonkey/correct/check-access-nsieve.js +40 -0
  186. data/vendor/tracemonkey/correct/check-bitops-3bit-bits-in-byte.js +35 -0
  187. data/vendor/tracemonkey/correct/check-bitops-bits-in-byte.js +24 -0
  188. data/vendor/tracemonkey/correct/check-bitops-bitwise-and.js +29 -0
  189. data/vendor/tracemonkey/correct/check-bitops-nsieve-bits.js +40 -0
  190. data/vendor/tracemonkey/correct/check-controlflow-recursive.js +27 -0
  191. data/vendor/tracemonkey/correct/check-date-format-tofte.js +302 -0
  192. data/vendor/tracemonkey/correct/check-date-format-xparb.js +421 -0
  193. data/vendor/tracemonkey/correct/check-mont.js +119 -0
  194. data/vendor/tracemonkey/dtoa.c +3335 -0
  195. data/vendor/tracemonkey/editline/Makefile.in +55 -0
  196. data/vendor/tracemonkey/editline/Makefile.ref +143 -0
  197. data/vendor/tracemonkey/editline/README +83 -0
  198. data/vendor/tracemonkey/editline/editline.3 +175 -0
  199. data/vendor/tracemonkey/editline/editline.c +1371 -0
  200. data/vendor/tracemonkey/editline/editline.h +135 -0
  201. data/vendor/tracemonkey/editline/sysunix.c +182 -0
  202. data/vendor/tracemonkey/editline/unix.h +82 -0
  203. data/vendor/tracemonkey/if.js +13 -0
  204. data/vendor/tracemonkey/imacro_asm.js.in +396 -0
  205. data/vendor/tracemonkey/imacros.c.out +1034 -0
  206. data/vendor/tracemonkey/imacros.jsasm +770 -0
  207. data/vendor/tracemonkey/javascript-trace.d +73 -0
  208. data/vendor/tracemonkey/jitstats.tbl +55 -0
  209. data/vendor/tracemonkey/js-config.h.in +82 -0
  210. data/vendor/tracemonkey/js-config.in +111 -0
  211. data/vendor/tracemonkey/js.mdp +0 -0
  212. data/vendor/tracemonkey/js.msg +312 -0
  213. data/vendor/tracemonkey/js3240.rc +79 -0
  214. data/vendor/tracemonkey/jsOS240.def +654 -0
  215. data/vendor/tracemonkey/jsapi.cpp +6005 -0
  216. data/vendor/tracemonkey/jsapi.h +2727 -0
  217. data/vendor/tracemonkey/jsarena.cpp +450 -0
  218. data/vendor/tracemonkey/jsarena.h +318 -0
  219. data/vendor/tracemonkey/jsarray.cpp +3664 -0
  220. data/vendor/tracemonkey/jsarray.h +238 -0
  221. data/vendor/tracemonkey/jsatom.cpp +1244 -0
  222. data/vendor/tracemonkey/jsatom.h +493 -0
  223. data/vendor/tracemonkey/jsbit.h +249 -0
  224. data/vendor/tracemonkey/jsbool.cpp +184 -0
  225. data/vendor/tracemonkey/jsbool.h +88 -0
  226. data/vendor/tracemonkey/jsbuiltins.cpp +415 -0
  227. data/vendor/tracemonkey/jsbuiltins.h +456 -0
  228. data/vendor/tracemonkey/jsclist.h +139 -0
  229. data/vendor/tracemonkey/jscntxt.cpp +1816 -0
  230. data/vendor/tracemonkey/jscntxt.h +1541 -0
  231. data/vendor/tracemonkey/jscompat.h +57 -0
  232. data/vendor/tracemonkey/jsconfig.mk +181 -0
  233. data/vendor/tracemonkey/jscpucfg.cpp +194 -0
  234. data/vendor/tracemonkey/jscpucfg.h +91 -0
  235. data/vendor/tracemonkey/jsdate.cpp +2465 -0
  236. data/vendor/tracemonkey/jsdate.h +129 -0
  237. data/vendor/tracemonkey/jsdbgapi.cpp +2017 -0
  238. data/vendor/tracemonkey/jsdbgapi.h +500 -0
  239. data/vendor/tracemonkey/jsdhash.cpp +876 -0
  240. data/vendor/tracemonkey/jsdhash.h +588 -0
  241. data/vendor/tracemonkey/jsdtoa.cpp +572 -0
  242. data/vendor/tracemonkey/jsdtoa.h +131 -0
  243. data/vendor/tracemonkey/jsdtracef.c +318 -0
  244. data/vendor/tracemonkey/jsdtracef.h +81 -0
  245. data/vendor/tracemonkey/jsemit.cpp +7292 -0
  246. data/vendor/tracemonkey/jsemit.h +802 -0
  247. data/vendor/tracemonkey/jsexn.cpp +1337 -0
  248. data/vendor/tracemonkey/jsexn.h +96 -0
  249. data/vendor/tracemonkey/jsfile.cpp +2747 -0
  250. data/vendor/tracemonkey/jsfile.h +56 -0
  251. data/vendor/tracemonkey/jsfile.msg +90 -0
  252. data/vendor/tracemonkey/jsfun.cpp +3089 -0
  253. data/vendor/tracemonkey/jsfun.h +366 -0
  254. data/vendor/tracemonkey/jsgc.cpp +3816 -0
  255. data/vendor/tracemonkey/jsgc.h +429 -0
  256. data/vendor/tracemonkey/jshash.cpp +477 -0
  257. data/vendor/tracemonkey/jshash.h +151 -0
  258. data/vendor/tracemonkey/jsify.pl +483 -0
  259. data/vendor/tracemonkey/jsinterp.cpp +7441 -0
  260. data/vendor/tracemonkey/jsinterp.h +666 -0
  261. data/vendor/tracemonkey/jsinvoke.cpp +42 -0
  262. data/vendor/tracemonkey/jsiter.cpp +1040 -0
  263. data/vendor/tracemonkey/jsiter.h +140 -0
  264. data/vendor/tracemonkey/jskeyword.tbl +124 -0
  265. data/vendor/tracemonkey/jskwgen.cpp +460 -0
  266. data/vendor/tracemonkey/jslibmath.h +69 -0
  267. data/vendor/tracemonkey/jslock.cpp +1512 -0
  268. data/vendor/tracemonkey/jslock.h +325 -0
  269. data/vendor/tracemonkey/jslocko.asm +60 -0
  270. data/vendor/tracemonkey/jslog2.cpp +111 -0
  271. data/vendor/tracemonkey/jslong.h +167 -0
  272. data/vendor/tracemonkey/jsmath.cpp +806 -0
  273. data/vendor/tracemonkey/jsmath.h +63 -0
  274. data/vendor/tracemonkey/jsnum.cpp +1374 -0
  275. data/vendor/tracemonkey/jsnum.h +280 -0
  276. data/vendor/tracemonkey/jsobj.cpp +6165 -0
  277. data/vendor/tracemonkey/jsobj.h +870 -0
  278. data/vendor/tracemonkey/json.cpp +1338 -0
  279. data/vendor/tracemonkey/json.h +108 -0
  280. data/vendor/tracemonkey/jsopcode.cpp +5484 -0
  281. data/vendor/tracemonkey/jsopcode.h +434 -0
  282. data/vendor/tracemonkey/jsopcode.tbl +591 -0
  283. data/vendor/tracemonkey/jsoplengen.cpp +121 -0
  284. data/vendor/tracemonkey/jsotypes.h +202 -0
  285. data/vendor/tracemonkey/jsparse.cpp +9257 -0
  286. data/vendor/tracemonkey/jsparse.h +900 -0
  287. data/vendor/tracemonkey/jsprf.cpp +1262 -0
  288. data/vendor/tracemonkey/jsprf.h +150 -0
  289. data/vendor/tracemonkey/jsproto.tbl +117 -0
  290. data/vendor/tracemonkey/jsprvtd.h +366 -0
  291. data/vendor/tracemonkey/jspubtd.h +585 -0
  292. data/vendor/tracemonkey/jsregexp.cpp +5051 -0
  293. data/vendor/tracemonkey/jsregexp.h +199 -0
  294. data/vendor/tracemonkey/jsreops.tbl +145 -0
  295. data/vendor/tracemonkey/jsscan.cpp +2040 -0
  296. data/vendor/tracemonkey/jsscan.h +467 -0
  297. data/vendor/tracemonkey/jsscope.cpp +1966 -0
  298. data/vendor/tracemonkey/jsscope.h +487 -0
  299. data/vendor/tracemonkey/jsscript.cpp +1932 -0
  300. data/vendor/tracemonkey/jsscript.h +345 -0
  301. data/vendor/tracemonkey/jsshell.msg +54 -0
  302. data/vendor/tracemonkey/jsstack.js +167 -0
  303. data/vendor/tracemonkey/jsstaticcheck.h +69 -0
  304. data/vendor/tracemonkey/jsstddef.h +87 -0
  305. data/vendor/tracemonkey/jsstdint.h +96 -0
  306. data/vendor/tracemonkey/jsstr.cpp +5277 -0
  307. data/vendor/tracemonkey/jsstr.h +702 -0
  308. data/vendor/tracemonkey/jstracer.cpp +10991 -0
  309. data/vendor/tracemonkey/jstracer.h +794 -0
  310. data/vendor/tracemonkey/jstypes.h +481 -0
  311. data/vendor/tracemonkey/jsutil.cpp +361 -0
  312. data/vendor/tracemonkey/jsutil.h +178 -0
  313. data/vendor/tracemonkey/jsversion.h +243 -0
  314. data/vendor/tracemonkey/jswince.asm +44 -0
  315. data/vendor/tracemonkey/jsxdrapi.cpp +800 -0
  316. data/vendor/tracemonkey/jsxdrapi.h +220 -0
  317. data/vendor/tracemonkey/jsxml.cpp +8327 -0
  318. data/vendor/tracemonkey/jsxml.h +305 -0
  319. data/vendor/tracemonkey/liveconnect/LiveConnect.dsp +157 -0
  320. data/vendor/tracemonkey/liveconnect/LiveConnectShell.dsp +120 -0
  321. data/vendor/tracemonkey/liveconnect/LiveConnectShell.dsw +44 -0
  322. data/vendor/tracemonkey/liveconnect/Makefile.in +105 -0
  323. data/vendor/tracemonkey/liveconnect/Makefile.ref +169 -0
  324. data/vendor/tracemonkey/liveconnect/README.html +712 -0
  325. data/vendor/tracemonkey/liveconnect/_jni/netscape_javascript_JSException.h +14 -0
  326. data/vendor/tracemonkey/liveconnect/_jni/netscape_javascript_JSObject.h +155 -0
  327. data/vendor/tracemonkey/liveconnect/classes/Makefile.in +89 -0
  328. data/vendor/tracemonkey/liveconnect/classes/Makefile.ref +57 -0
  329. data/vendor/tracemonkey/liveconnect/classes/netscape/Makefile.ref +47 -0
  330. data/vendor/tracemonkey/liveconnect/classes/netscape/javascript/JSException.java +140 -0
  331. data/vendor/tracemonkey/liveconnect/classes/netscape/javascript/JSObject.java +183 -0
  332. data/vendor/tracemonkey/liveconnect/classes/netscape/javascript/JSProxy.java +58 -0
  333. data/vendor/tracemonkey/liveconnect/classes/netscape/javascript/JSRunnable.java +70 -0
  334. data/vendor/tracemonkey/liveconnect/classes/netscape/javascript/JSUtil.java +59 -0
  335. data/vendor/tracemonkey/liveconnect/classes/netscape/javascript/Makefile.ref +53 -0
  336. data/vendor/tracemonkey/liveconnect/config/AIX4.1.mk +45 -0
  337. data/vendor/tracemonkey/liveconnect/config/AIX4.2.mk +45 -0
  338. data/vendor/tracemonkey/liveconnect/config/AIX4.3.mk +50 -0
  339. data/vendor/tracemonkey/liveconnect/config/HP-UXB.10.10.mk +43 -0
  340. data/vendor/tracemonkey/liveconnect/config/HP-UXB.10.20.mk +43 -0
  341. data/vendor/tracemonkey/liveconnect/config/HP-UXB.11.00.mk +43 -0
  342. data/vendor/tracemonkey/liveconnect/config/IRIX6.2.mk +43 -0
  343. data/vendor/tracemonkey/liveconnect/config/IRIX6.3.mk +43 -0
  344. data/vendor/tracemonkey/liveconnect/config/IRIX6.5.mk +43 -0
  345. data/vendor/tracemonkey/liveconnect/config/Linux_All.mk +73 -0
  346. data/vendor/tracemonkey/liveconnect/config/OSF1V4.0.mk +65 -0
  347. data/vendor/tracemonkey/liveconnect/config/OSF1V5.0.mk +62 -0
  348. data/vendor/tracemonkey/liveconnect/config/SunOS5.5.1.mk +55 -0
  349. data/vendor/tracemonkey/liveconnect/config/SunOS5.6.mk +39 -0
  350. data/vendor/tracemonkey/liveconnect/config/SunOS5.7.mk +39 -0
  351. data/vendor/tracemonkey/liveconnect/config/SunOS5.8.mk +39 -0
  352. data/vendor/tracemonkey/liveconnect/config/WINNT4.0.mk +53 -0
  353. data/vendor/tracemonkey/liveconnect/jsj.c +886 -0
  354. data/vendor/tracemonkey/liveconnect/jsj.msg +98 -0
  355. data/vendor/tracemonkey/liveconnect/jsj_JSObject.c +1377 -0
  356. data/vendor/tracemonkey/liveconnect/jsj_JavaArray.c +474 -0
  357. data/vendor/tracemonkey/liveconnect/jsj_JavaClass.c +737 -0
  358. data/vendor/tracemonkey/liveconnect/jsj_JavaMember.c +191 -0
  359. data/vendor/tracemonkey/liveconnect/jsj_JavaObject.c +1079 -0
  360. data/vendor/tracemonkey/liveconnect/jsj_JavaPackage.c +569 -0
  361. data/vendor/tracemonkey/liveconnect/jsj_array.c +207 -0
  362. data/vendor/tracemonkey/liveconnect/jsj_class.c +770 -0
  363. data/vendor/tracemonkey/liveconnect/jsj_convert.c +902 -0
  364. data/vendor/tracemonkey/liveconnect/jsj_field.c +421 -0
  365. data/vendor/tracemonkey/liveconnect/jsj_hash.c +488 -0
  366. data/vendor/tracemonkey/liveconnect/jsj_hash.h +161 -0
  367. data/vendor/tracemonkey/liveconnect/jsj_method.c +1825 -0
  368. data/vendor/tracemonkey/liveconnect/jsj_nodl.c +1 -0
  369. data/vendor/tracemonkey/liveconnect/jsj_private.h +677 -0
  370. data/vendor/tracemonkey/liveconnect/jsj_simpleapi.c +219 -0
  371. data/vendor/tracemonkey/liveconnect/jsj_utils.c +513 -0
  372. data/vendor/tracemonkey/liveconnect/jsjava.h +316 -0
  373. data/vendor/tracemonkey/liveconnect/netscape_javascript_JSObject.h +155 -0
  374. data/vendor/tracemonkey/liveconnect/nsCLiveconnect.cpp +785 -0
  375. data/vendor/tracemonkey/liveconnect/nsCLiveconnect.h +197 -0
  376. data/vendor/tracemonkey/liveconnect/nsCLiveconnectFactory.cpp +118 -0
  377. data/vendor/tracemonkey/liveconnect/nsCLiveconnectFactory.h +76 -0
  378. data/vendor/tracemonkey/liveconnect/nsILiveconnect.h +197 -0
  379. data/vendor/tracemonkey/liveconnect/nsISecureLiveconnect.h +94 -0
  380. data/vendor/tracemonkey/liveconnect/nsISecurityContext.h +136 -0
  381. data/vendor/tracemonkey/lock_SunOS.s +119 -0
  382. data/vendor/tracemonkey/mandelbrot-results.js +3 -0
  383. data/vendor/tracemonkey/math-partial-sums.js +32 -0
  384. data/vendor/tracemonkey/math-trace-tests.js +507 -0
  385. data/vendor/tracemonkey/md5.js +289 -0
  386. data/vendor/tracemonkey/nanojit/Assembler.cpp +1984 -0
  387. data/vendor/tracemonkey/nanojit/Assembler.h +375 -0
  388. data/vendor/tracemonkey/nanojit/Fragmento.cpp +651 -0
  389. data/vendor/tracemonkey/nanojit/Fragmento.h +237 -0
  390. data/vendor/tracemonkey/nanojit/LIR.cpp +2314 -0
  391. data/vendor/tracemonkey/nanojit/LIR.h +879 -0
  392. data/vendor/tracemonkey/nanojit/LIRopcode.tbl +252 -0
  393. data/vendor/tracemonkey/nanojit/Native.h +127 -0
  394. data/vendor/tracemonkey/nanojit/NativeARM.cpp +1742 -0
  395. data/vendor/tracemonkey/nanojit/NativeARM.h +844 -0
  396. data/vendor/tracemonkey/nanojit/NativeSparc.cpp +1130 -0
  397. data/vendor/tracemonkey/nanojit/NativeSparc.h +948 -0
  398. data/vendor/tracemonkey/nanojit/NativeThumb.cpp +1322 -0
  399. data/vendor/tracemonkey/nanojit/NativeThumb.h +525 -0
  400. data/vendor/tracemonkey/nanojit/Nativei386.cpp +1748 -0
  401. data/vendor/tracemonkey/nanojit/Nativei386.h +857 -0
  402. data/vendor/tracemonkey/nanojit/RegAlloc.cpp +183 -0
  403. data/vendor/tracemonkey/nanojit/RegAlloc.h +95 -0
  404. data/vendor/tracemonkey/nanojit/TraceTreeDrawer.cpp +306 -0
  405. data/vendor/tracemonkey/nanojit/TraceTreeDrawer.h +88 -0
  406. data/vendor/tracemonkey/nanojit/avmplus.cpp +56 -0
  407. data/vendor/tracemonkey/nanojit/avmplus.h +1016 -0
  408. data/vendor/tracemonkey/nanojit/nanojit.h +253 -0
  409. data/vendor/tracemonkey/perfect.js +39 -0
  410. data/vendor/tracemonkey/plify_jsdhash.sed +35 -0
  411. data/vendor/tracemonkey/prmjtime.cpp +869 -0
  412. data/vendor/tracemonkey/prmjtime.h +103 -0
  413. data/vendor/tracemonkey/ref-config/AIX4.1.mk +65 -0
  414. data/vendor/tracemonkey/ref-config/AIX4.2.mk +64 -0
  415. data/vendor/tracemonkey/ref-config/AIX4.3.mk +65 -0
  416. data/vendor/tracemonkey/ref-config/Darwin.mk +85 -0
  417. data/vendor/tracemonkey/ref-config/Darwin1.3.mk +81 -0
  418. data/vendor/tracemonkey/ref-config/Darwin1.4.mk +41 -0
  419. data/vendor/tracemonkey/ref-config/Darwin5.2.mk +81 -0
  420. data/vendor/tracemonkey/ref-config/Darwin5.3.mk +81 -0
  421. data/vendor/tracemonkey/ref-config/Darwin64.mk +72 -0
  422. data/vendor/tracemonkey/ref-config/HP-UXB.10.10.mk +77 -0
  423. data/vendor/tracemonkey/ref-config/HP-UXB.10.20.mk +77 -0
  424. data/vendor/tracemonkey/ref-config/HP-UXB.11.00.mk +80 -0
  425. data/vendor/tracemonkey/ref-config/IRIX.mk +87 -0
  426. data/vendor/tracemonkey/ref-config/IRIX5.3.mk +44 -0
  427. data/vendor/tracemonkey/ref-config/IRIX6.1.mk +44 -0
  428. data/vendor/tracemonkey/ref-config/IRIX6.2.mk +44 -0
  429. data/vendor/tracemonkey/ref-config/IRIX6.3.mk +44 -0
  430. data/vendor/tracemonkey/ref-config/IRIX6.5.mk +44 -0
  431. data/vendor/tracemonkey/ref-config/Linux_All.mk +105 -0
  432. data/vendor/tracemonkey/ref-config/Mac_OS10.0.mk +82 -0
  433. data/vendor/tracemonkey/ref-config/OSF1V4.0.mk +72 -0
  434. data/vendor/tracemonkey/ref-config/OSF1V5.0.mk +69 -0
  435. data/vendor/tracemonkey/ref-config/SunOS4.1.4.mk +101 -0
  436. data/vendor/tracemonkey/ref-config/SunOS5.10.mk +50 -0
  437. data/vendor/tracemonkey/ref-config/SunOS5.3.mk +91 -0
  438. data/vendor/tracemonkey/ref-config/SunOS5.4.mk +92 -0
  439. data/vendor/tracemonkey/ref-config/SunOS5.5.1.mk +44 -0
  440. data/vendor/tracemonkey/ref-config/SunOS5.5.mk +87 -0
  441. data/vendor/tracemonkey/ref-config/SunOS5.6.mk +89 -0
  442. data/vendor/tracemonkey/ref-config/SunOS5.7.mk +44 -0
  443. data/vendor/tracemonkey/ref-config/SunOS5.8.mk +44 -0
  444. data/vendor/tracemonkey/ref-config/SunOS5.9.mk +44 -0
  445. data/vendor/tracemonkey/ref-config/WINNT4.0.mk +118 -0
  446. data/vendor/tracemonkey/ref-config/WINNT5.0.mk +118 -0
  447. data/vendor/tracemonkey/ref-config/WINNT5.1.mk +118 -0
  448. data/vendor/tracemonkey/ref-config/WINNT5.2.mk +118 -0
  449. data/vendor/tracemonkey/ref-config/WINNT6.0.mk +118 -0
  450. data/vendor/tracemonkey/ref-config/dgux.mk +64 -0
  451. data/vendor/tracemonkey/resource.h +15 -0
  452. data/vendor/tracemonkey/rules.mk +206 -0
  453. data/vendor/tracemonkey/shell/Makefile.in +72 -0
  454. data/vendor/tracemonkey/shell/js.cpp +4719 -0
  455. data/vendor/tracemonkey/t/3d-cube.js +337 -0
  456. data/vendor/tracemonkey/t/3d-morph.js +54 -0
  457. data/vendor/tracemonkey/t/3d-raytrace.js +441 -0
  458. data/vendor/tracemonkey/t/access-binary-trees.js +50 -0
  459. data/vendor/tracemonkey/t/access-fannkuch.js +66 -0
  460. data/vendor/tracemonkey/t/access-nbody.js +169 -0
  461. data/vendor/tracemonkey/t/access-nsieve.js +38 -0
  462. data/vendor/tracemonkey/t/bitops-3bit-bits-in-byte.js +32 -0
  463. data/vendor/tracemonkey/t/bitops-bits-in-byte.js +21 -0
  464. data/vendor/tracemonkey/t/bitops-bitwise-and.js +28 -0
  465. data/vendor/tracemonkey/t/bitops-nsieve-bits.js +32 -0
  466. data/vendor/tracemonkey/t/controlflow-recursive.js +25 -0
  467. data/vendor/tracemonkey/t/crypto-aes.js +422 -0
  468. data/vendor/tracemonkey/t/crypto-md5.js +286 -0
  469. data/vendor/tracemonkey/t/crypto-sha1.js +224 -0
  470. data/vendor/tracemonkey/t/date-format-tofte.js +299 -0
  471. data/vendor/tracemonkey/t/date-format-xparb.js +417 -0
  472. data/vendor/tracemonkey/t/math-cordic.js +95 -0
  473. data/vendor/tracemonkey/t/math-partial-sums.js +33 -0
  474. data/vendor/tracemonkey/t/math-spectral-norm.js +51 -0
  475. data/vendor/tracemonkey/t/regexp-dna.js +1712 -0
  476. data/vendor/tracemonkey/t/string-base64.js +135 -0
  477. data/vendor/tracemonkey/t/string-fasta.js +85 -0
  478. data/vendor/tracemonkey/t/string-tagcloud.js +265 -0
  479. data/vendor/tracemonkey/t/string-unpack-code.js +68 -0
  480. data/vendor/tracemonkey/t/string-validate-input.js +89 -0
  481. data/vendor/tracemonkey/time.sh +13 -0
  482. data/vendor/tracemonkey/trace-test.js +5564 -0
  483. data/vendor/tracemonkey/v8/base.js +187 -0
  484. data/vendor/tracemonkey/v8/crypto.js +1689 -0
  485. data/vendor/tracemonkey/v8/deltablue.js +880 -0
  486. data/vendor/tracemonkey/v8/earley-boyer.js +4682 -0
  487. data/vendor/tracemonkey/v8/raytrace.js +3418 -0
  488. data/vendor/tracemonkey/v8/richards.js +539 -0
  489. data/vendor/tracemonkey/v8/run-crypto.js +44 -0
  490. data/vendor/tracemonkey/v8/run-deltablue.js +44 -0
  491. data/vendor/tracemonkey/v8/run-earley-boyer.js +44 -0
  492. data/vendor/tracemonkey/v8/run-raytrace.js +44 -0
  493. data/vendor/tracemonkey/v8/run-richards.js +44 -0
  494. data/vendor/tracemonkey/v8/run.js +49 -0
  495. data/vendor/tracemonkey/vprof/readme.txt +93 -0
  496. data/vendor/tracemonkey/vprof/vprof.cpp +360 -0
  497. data/vendor/tracemonkey/vprof/vprof.h +245 -0
  498. data/vendor/tracemonkey/xpconnect/Makefile.in +67 -0
  499. data/vendor/tracemonkey/xpconnect/crashtests/117307-1.html +20 -0
  500. data/vendor/tracemonkey/xpconnect/crashtests/193710.html +11 -0
  501. data/vendor/tracemonkey/xpconnect/crashtests/290162-1.html +5 -0
  502. data/vendor/tracemonkey/xpconnect/crashtests/326615-1.html +16 -0
  503. data/vendor/tracemonkey/xpconnect/crashtests/328553-1.html +13 -0
  504. data/vendor/tracemonkey/xpconnect/crashtests/346258-1.html +12 -0
  505. data/vendor/tracemonkey/xpconnect/crashtests/346512-1-frame1.xhtml +16 -0
  506. data/vendor/tracemonkey/xpconnect/crashtests/346512-1-frame2.xhtml +15 -0
  507. data/vendor/tracemonkey/xpconnect/crashtests/346512-1.xhtml +30 -0
  508. data/vendor/tracemonkey/xpconnect/crashtests/382133-1.html +3 -0
  509. data/vendor/tracemonkey/xpconnect/crashtests/386680-1.html +22 -0
  510. data/vendor/tracemonkey/xpconnect/crashtests/394810-1.html +4 -0
  511. data/vendor/tracemonkey/xpconnect/crashtests/400349-1.html +20 -0
  512. data/vendor/tracemonkey/xpconnect/crashtests/403356-1.html +13 -0
  513. data/vendor/tracemonkey/xpconnect/crashtests/418139-1.svg +22 -0
  514. data/vendor/tracemonkey/xpconnect/crashtests/420513-1.html +11 -0
  515. data/vendor/tracemonkey/xpconnect/crashtests/453935-1.html +37 -0
  516. data/vendor/tracemonkey/xpconnect/crashtests/462926.html +12 -0
  517. data/vendor/tracemonkey/xpconnect/crashtests/468552-1.html +18 -0
  518. data/vendor/tracemonkey/xpconnect/crashtests/471366-1.html +12 -0
  519. data/vendor/tracemonkey/xpconnect/crashtests/475185-1.html +13 -0
  520. data/vendor/tracemonkey/xpconnect/crashtests/475291-1.html +14 -0
  521. data/vendor/tracemonkey/xpconnect/crashtests/503286-1.html +23 -0
  522. data/vendor/tracemonkey/xpconnect/crashtests/crashtests.list +21 -0
  523. data/vendor/tracemonkey/xpconnect/idl/Makefile.in +78 -0
  524. data/vendor/tracemonkey/xpconnect/idl/XPCIDispatch.idl +51 -0
  525. data/vendor/tracemonkey/xpconnect/idl/mozIJSSubScriptLoader.idl +64 -0
  526. data/vendor/tracemonkey/xpconnect/idl/nsIActiveXSecurityPolicy.idl +67 -0
  527. data/vendor/tracemonkey/xpconnect/idl/nsIDispatchSupport.idl +119 -0
  528. data/vendor/tracemonkey/xpconnect/idl/nsIJSContextStack.idl +85 -0
  529. data/vendor/tracemonkey/xpconnect/idl/nsIJSRuntimeService.idl +51 -0
  530. data/vendor/tracemonkey/xpconnect/idl/nsIScriptError.idl +102 -0
  531. data/vendor/tracemonkey/xpconnect/idl/nsIScriptableInterfaces.idl +67 -0
  532. data/vendor/tracemonkey/xpconnect/idl/nsIXPCScriptNotify.idl +66 -0
  533. data/vendor/tracemonkey/xpconnect/idl/nsIXPCScriptable.idl +183 -0
  534. data/vendor/tracemonkey/xpconnect/idl/nsIXPCSecurityManager.idl +114 -0
  535. data/vendor/tracemonkey/xpconnect/idl/nsIXPConnect.idl +819 -0
  536. data/vendor/tracemonkey/xpconnect/idl/xpcIJSModuleLoader.idl +95 -0
  537. data/vendor/tracemonkey/xpconnect/idl/xpcIJSWeakReference.idl +49 -0
  538. data/vendor/tracemonkey/xpconnect/idl/xpccomponents.idl +254 -0
  539. data/vendor/tracemonkey/xpconnect/idl/xpcexception.idl +66 -0
  540. data/vendor/tracemonkey/xpconnect/idl/xpcjsid.idl +83 -0
  541. data/vendor/tracemonkey/xpconnect/loader/ISO8601DateUtils.jsm +176 -0
  542. data/vendor/tracemonkey/xpconnect/loader/Makefile.in +63 -0
  543. data/vendor/tracemonkey/xpconnect/loader/XPCOMUtils.jsm +267 -0
  544. data/vendor/tracemonkey/xpconnect/loader/mozJSComponentLoader.cpp +1717 -0
  545. data/vendor/tracemonkey/xpconnect/loader/mozJSComponentLoader.h +172 -0
  546. data/vendor/tracemonkey/xpconnect/loader/mozJSLoaderConstructors.h +101 -0
  547. data/vendor/tracemonkey/xpconnect/loader/mozJSSubScriptLoader.cpp +360 -0
  548. data/vendor/tracemonkey/xpconnect/loader/mozJSSubScriptLoader.h +66 -0
  549. data/vendor/tracemonkey/xpconnect/public/Makefile.in +54 -0
  550. data/vendor/tracemonkey/xpconnect/public/nsAXPCNativeCallContext.h +89 -0
  551. data/vendor/tracemonkey/xpconnect/public/nsAutoJSValHolder.h +168 -0
  552. data/vendor/tracemonkey/xpconnect/public/xpc_map_end.h +327 -0
  553. data/vendor/tracemonkey/xpconnect/sample/Makefile.in +71 -0
  554. data/vendor/tracemonkey/xpconnect/sample/README +39 -0
  555. data/vendor/tracemonkey/xpconnect/sample/xpcsample1.cpp +337 -0
  556. data/vendor/tracemonkey/xpconnect/sample/xpcsample1.idl +82 -0
  557. data/vendor/tracemonkey/xpconnect/sample/xpcsample1.js +21 -0
  558. data/vendor/tracemonkey/xpconnect/shell/Makefile.in +106 -0
  559. data/vendor/tracemonkey/xpconnect/shell/jsshell.msg +50 -0
  560. data/vendor/tracemonkey/xpconnect/shell/xpcshell.cpp +1817 -0
  561. data/vendor/tracemonkey/xpconnect/shell/xpcshellMacUtils.h +43 -0
  562. data/vendor/tracemonkey/xpconnect/shell/xpcshellMacUtils.mm +54 -0
  563. data/vendor/tracemonkey/xpconnect/src/Makefile.in +228 -0
  564. data/vendor/tracemonkey/xpconnect/src/README +3 -0
  565. data/vendor/tracemonkey/xpconnect/src/XPCCrossOriginWrapper.cpp +1186 -0
  566. data/vendor/tracemonkey/xpconnect/src/XPCDispConvert.cpp +593 -0
  567. data/vendor/tracemonkey/xpconnect/src/XPCDispInlines.h +667 -0
  568. data/vendor/tracemonkey/xpconnect/src/XPCDispInterface.cpp +383 -0
  569. data/vendor/tracemonkey/xpconnect/src/XPCDispObject.cpp +516 -0
  570. data/vendor/tracemonkey/xpconnect/src/XPCDispParamPropJSClass.cpp +223 -0
  571. data/vendor/tracemonkey/xpconnect/src/XPCDispParams.cpp +103 -0
  572. data/vendor/tracemonkey/xpconnect/src/XPCDispPrivate.h +1401 -0
  573. data/vendor/tracemonkey/xpconnect/src/XPCDispTearOff.cpp +547 -0
  574. data/vendor/tracemonkey/xpconnect/src/XPCDispTypeInfo.cpp +471 -0
  575. data/vendor/tracemonkey/xpconnect/src/XPCIDispatchClassInfo.cpp +139 -0
  576. data/vendor/tracemonkey/xpconnect/src/XPCIDispatchExtension.cpp +362 -0
  577. data/vendor/tracemonkey/xpconnect/src/XPCNativeWrapper.cpp +1350 -0
  578. data/vendor/tracemonkey/xpconnect/src/XPCNativeWrapper.h +88 -0
  579. data/vendor/tracemonkey/xpconnect/src/XPCSafeJSObjectWrapper.cpp +1148 -0
  580. data/vendor/tracemonkey/xpconnect/src/XPCSystemOnlyWrapper.cpp +718 -0
  581. data/vendor/tracemonkey/xpconnect/src/XPCWrapper.cpp +850 -0
  582. data/vendor/tracemonkey/xpconnect/src/XPCWrapper.h +394 -0
  583. data/vendor/tracemonkey/xpconnect/src/dom_quickstubs.qsconf +568 -0
  584. data/vendor/tracemonkey/xpconnect/src/nsDispatchSupport.cpp +348 -0
  585. data/vendor/tracemonkey/xpconnect/src/nsScriptError.cpp +201 -0
  586. data/vendor/tracemonkey/xpconnect/src/nsXPConnect.cpp +2609 -0
  587. data/vendor/tracemonkey/xpconnect/src/qsgen.py +1487 -0
  588. data/vendor/tracemonkey/xpconnect/src/xpc.msg +217 -0
  589. data/vendor/tracemonkey/xpconnect/src/xpcJSWeakReference.cpp +148 -0
  590. data/vendor/tracemonkey/xpconnect/src/xpcJSWeakReference.h +56 -0
  591. data/vendor/tracemonkey/xpconnect/src/xpccallcontext.cpp +579 -0
  592. data/vendor/tracemonkey/xpconnect/src/xpccomponents.cpp +4144 -0
  593. data/vendor/tracemonkey/xpconnect/src/xpccontext.cpp +115 -0
  594. data/vendor/tracemonkey/xpconnect/src/xpcconvert.cpp +2298 -0
  595. data/vendor/tracemonkey/xpconnect/src/xpcdebug.cpp +481 -0
  596. data/vendor/tracemonkey/xpconnect/src/xpcexception.cpp +502 -0
  597. data/vendor/tracemonkey/xpconnect/src/xpcforwards.h +114 -0
  598. data/vendor/tracemonkey/xpconnect/src/xpcinlines.h +772 -0
  599. data/vendor/tracemonkey/xpconnect/src/xpcjsid.cpp +1025 -0
  600. data/vendor/tracemonkey/xpconnect/src/xpcjsruntime.cpp +1342 -0
  601. data/vendor/tracemonkey/xpconnect/src/xpclog.cpp +128 -0
  602. data/vendor/tracemonkey/xpconnect/src/xpclog.h +101 -0
  603. data/vendor/tracemonkey/xpconnect/src/xpcmaps.cpp +761 -0
  604. data/vendor/tracemonkey/xpconnect/src/xpcmaps.h +713 -0
  605. data/vendor/tracemonkey/xpconnect/src/xpcmodule.cpp +136 -0
  606. data/vendor/tracemonkey/xpconnect/src/xpcprivate.h +4138 -0
  607. data/vendor/tracemonkey/xpconnect/src/xpcquickstubs.cpp +1128 -0
  608. data/vendor/tracemonkey/xpconnect/src/xpcquickstubs.h +480 -0
  609. data/vendor/tracemonkey/xpconnect/src/xpcruntimesvc.cpp +179 -0
  610. data/vendor/tracemonkey/xpconnect/src/xpcstack.cpp +342 -0
  611. data/vendor/tracemonkey/xpconnect/src/xpcstring.cpp +139 -0
  612. data/vendor/tracemonkey/xpconnect/src/xpcthreadcontext.cpp +599 -0
  613. data/vendor/tracemonkey/xpconnect/src/xpcthrower.cpp +399 -0
  614. data/vendor/tracemonkey/xpconnect/src/xpcvariant.cpp +850 -0
  615. data/vendor/tracemonkey/xpconnect/src/xpcwrappedjs.cpp +670 -0
  616. data/vendor/tracemonkey/xpconnect/src/xpcwrappedjsclass.cpp +2015 -0
  617. data/vendor/tracemonkey/xpconnect/src/xpcwrappednative.cpp +3482 -0
  618. data/vendor/tracemonkey/xpconnect/src/xpcwrappednativeinfo.cpp +945 -0
  619. data/vendor/tracemonkey/xpconnect/src/xpcwrappednativejsops.cpp +2003 -0
  620. data/vendor/tracemonkey/xpconnect/src/xpcwrappednativeproto.cpp +302 -0
  621. data/vendor/tracemonkey/xpconnect/src/xpcwrappednativescope.cpp +991 -0
  622. data/vendor/tracemonkey/xpconnect/tests/Makefile.in +75 -0
  623. data/vendor/tracemonkey/xpconnect/tests/TestXPC.cpp +785 -0
  624. data/vendor/tracemonkey/xpconnect/tests/chrome/Makefile.in +51 -0
  625. data/vendor/tracemonkey/xpconnect/tests/chrome/test_bug500931.xul +43 -0
  626. data/vendor/tracemonkey/xpconnect/tests/components/Makefile.in +85 -0
  627. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_array.cpp +388 -0
  628. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_attributes.cpp +305 -0
  629. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_calljs.cpp +135 -0
  630. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_child.cpp +225 -0
  631. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_const.cpp +76 -0
  632. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_domstring.cpp +118 -0
  633. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_echo.cpp +616 -0
  634. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_in.cpp +204 -0
  635. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_inout.cpp +171 -0
  636. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_module.cpp +77 -0
  637. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_multiple.cpp +554 -0
  638. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_noisy.cpp +154 -0
  639. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_out.cpp +335 -0
  640. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_overloaded.cpp +250 -0
  641. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_private.h +192 -0
  642. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_string.cpp +185 -0
  643. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_variant.cpp +355 -0
  644. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/StdAfx.cpp +12 -0
  645. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/StdAfx.h +28 -0
  646. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/XPCDispUtilities.h +28 -0
  647. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/XPCIDispatchTest.cpp +86 -0
  648. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/XPCIDispatchTest.def +9 -0
  649. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/XPCIDispatchTest.dsp +318 -0
  650. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/XPCIDispatchTest.dsw +29 -0
  651. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/XPCIDispatchTest.idl +454 -0
  652. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/XPCIDispatchTest.rc +145 -0
  653. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispSimple.cpp +44 -0
  654. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispSimple.h +56 -0
  655. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispSimple.rgs +23 -0
  656. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestArrays.cpp +221 -0
  657. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestArrays.h +53 -0
  658. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestArrays.rgs +23 -0
  659. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestMethods.cpp +699 -0
  660. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestMethods.h +138 -0
  661. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestMethods.rgs +23 -0
  662. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestNoIDispatch.cpp +23 -0
  663. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestNoIDispatch.h +41 -0
  664. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestNoIDispatch.rgs +23 -0
  665. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestProperties.cpp +256 -0
  666. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestProperties.h +88 -0
  667. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestProperties.rgs +23 -0
  668. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestScriptOff.cpp +23 -0
  669. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestScriptOff.h +43 -0
  670. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestScriptOff.rgs +23 -0
  671. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestScriptOn.cpp +29 -0
  672. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestScriptOn.h +45 -0
  673. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestScriptOn.rgs +23 -0
  674. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestWrappedJS.cpp +177 -0
  675. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestWrappedJS.h +50 -0
  676. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestWrappedJS.rgs +23 -0
  677. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/resource.h +36 -0
  678. data/vendor/tracemonkey/xpconnect/tests/idispatch/Tests/WrappedCOM/Arrays/XPCIDispatchArrayTests.js +54 -0
  679. data/vendor/tracemonkey/xpconnect/tests/idispatch/Tests/WrappedCOM/Attributes/XPCIDispatchAttributeTests.js +150 -0
  680. data/vendor/tracemonkey/xpconnect/tests/idispatch/Tests/WrappedCOM/General/XPCIDispatchInstantiations.js +122 -0
  681. data/vendor/tracemonkey/xpconnect/tests/idispatch/Tests/WrappedCOM/General/XPCStress.js +58 -0
  682. data/vendor/tracemonkey/xpconnect/tests/idispatch/Tests/WrappedCOM/Methods/XPCIDispatchMethodTests.js +376 -0
  683. data/vendor/tracemonkey/xpconnect/tests/idispatch/Tests/WrappedCOM/shell.js +377 -0
  684. data/vendor/tracemonkey/xpconnect/tests/idispatch/Tests/WrappedJS/General/XPCIDispatchTestWrappedJS.js +76 -0
  685. data/vendor/tracemonkey/xpconnect/tests/idispatch/Tests/WrappedJS/shell.js +377 -0
  686. data/vendor/tracemonkey/xpconnect/tests/idispatch/Tests/exectests.cmd +1 -0
  687. data/vendor/tracemonkey/xpconnect/tests/idispatch/Tests/jsDriver.pl +1288 -0
  688. data/vendor/tracemonkey/xpconnect/tests/idl/Makefile.in +61 -0
  689. data/vendor/tracemonkey/xpconnect/tests/idl/xpctest.idl +312 -0
  690. data/vendor/tracemonkey/xpconnect/tests/idl/xpctest2.idl +51 -0
  691. data/vendor/tracemonkey/xpconnect/tests/idl/xpctest_attributes.idl +67 -0
  692. data/vendor/tracemonkey/xpconnect/tests/idl/xpctest_calljs.idl +59 -0
  693. data/vendor/tracemonkey/xpconnect/tests/idl/xpctest_const.idl +61 -0
  694. data/vendor/tracemonkey/xpconnect/tests/idl/xpctest_domstring.idl +59 -0
  695. data/vendor/tracemonkey/xpconnect/tests/idl/xpctest_in.idl +88 -0
  696. data/vendor/tracemonkey/xpconnect/tests/idl/xpctest_inout.idl +86 -0
  697. data/vendor/tracemonkey/xpconnect/tests/idl/xpctest_multiple.idl +77 -0
  698. data/vendor/tracemonkey/xpconnect/tests/idl/xpctest_out.idl +142 -0
  699. data/vendor/tracemonkey/xpconnect/tests/js/checkid.js +82 -0
  700. data/vendor/tracemonkey/xpconnect/tests/js/evaluate.js +311 -0
  701. data/vendor/tracemonkey/xpconnect/tests/js/exceptions-2.js +153 -0
  702. data/vendor/tracemonkey/xpconnect/tests/js/exceptions-3.js +194 -0
  703. data/vendor/tracemonkey/xpconnect/tests/js/exceptions-4.js +297 -0
  704. data/vendor/tracemonkey/xpconnect/tests/js/exceptions-5.js +343 -0
  705. data/vendor/tracemonkey/xpconnect/tests/js/exceptions.js +230 -0
  706. data/vendor/tracemonkey/xpconnect/tests/js/javascript.js +96 -0
  707. data/vendor/tracemonkey/xpconnect/tests/js/multiple-2.js +151 -0
  708. data/vendor/tracemonkey/xpconnect/tests/js/multiple-3.js +148 -0
  709. data/vendor/tracemonkey/xpconnect/tests/js/multiple-4.js +152 -0
  710. data/vendor/tracemonkey/xpconnect/tests/js/multiple.js +137 -0
  711. data/vendor/tracemonkey/xpconnect/tests/js/notscriptable.js +104 -0
  712. data/vendor/tracemonkey/xpconnect/tests/js/old/simpletest.js +36 -0
  713. data/vendor/tracemonkey/xpconnect/tests/js/old/speed.js +60 -0
  714. data/vendor/tracemonkey/xpconnect/tests/js/old/testxpc.js +464 -0
  715. data/vendor/tracemonkey/xpconnect/tests/js/old/threads.js +74 -0
  716. data/vendor/tracemonkey/xpconnect/tests/js/old/try.js +27 -0
  717. data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_array.js +308 -0
  718. data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_callcontext.js +68 -0
  719. data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_echo.js +636 -0
  720. data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_enum_and_sort.js +28 -0
  721. data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_enum_constants.js +15 -0
  722. data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_enum_create.js +200 -0
  723. data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_exceptions.js +167 -0
  724. data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_ids.js +135 -0
  725. data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_observer.js +36 -0
  726. data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_overloaded.js +14 -0
  727. data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_primitives.js +141 -0
  728. data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_propertybag.js +36 -0
  729. data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_variant.js +339 -0
  730. data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_variant_array.js +30 -0
  731. data/vendor/tracemonkey/xpconnect/tests/js/readonlyattributes.js +74 -0
  732. data/vendor/tracemonkey/xpconnect/tests/js/readwriteattributes.js +101 -0
  733. data/vendor/tracemonkey/xpconnect/tests/js/scriptable.js +120 -0
  734. data/vendor/tracemonkey/xpconnect/tests/js/testin.js +203 -0
  735. data/vendor/tracemonkey/xpconnect/tests/js/xpcfun.js +234 -0
  736. data/vendor/tracemonkey/xpconnect/tests/js/xpctest_primitives.js +200 -0
  737. data/vendor/tracemonkey/xpconnect/tests/mochitest/Makefile.in +66 -0
  738. data/vendor/tracemonkey/xpconnect/tests/mochitest/bug500931_helper.html +7 -0
  739. data/vendor/tracemonkey/xpconnect/tests/mochitest/inner.html +7 -0
  740. data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug361111.xul +29 -0
  741. data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug384632.html +32 -0
  742. data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug390488.html +65 -0
  743. data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug393269.html +46 -0
  744. data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug396851.html +43 -0
  745. data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug428021.html +41 -0
  746. data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug446584.html +49 -0
  747. data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug448587.html +31 -0
  748. data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug462428.html +42 -0
  749. data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug478438.html +66 -0
  750. data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug484107.html +100 -0
  751. data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug484459.html +36 -0
  752. data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug500691.html +28 -0
  753. data/vendor/tracemonkey/xpconnect/tests/mochitest/test_wrappers.html +116 -0
  754. data/vendor/tracemonkey/xpconnect/tests/unit/bogus_element_type.jsm +1 -0
  755. data/vendor/tracemonkey/xpconnect/tests/unit/bogus_exports_type.jsm +1 -0
  756. data/vendor/tracemonkey/xpconnect/tests/unit/bug451678_subscript.js +2 -0
  757. data/vendor/tracemonkey/xpconnect/tests/unit/component_import.js +144 -0
  758. data/vendor/tracemonkey/xpconnect/tests/unit/recursive_importA.jsm +44 -0
  759. data/vendor/tracemonkey/xpconnect/tests/unit/recursive_importB.jsm +45 -0
  760. data/vendor/tracemonkey/xpconnect/tests/unit/syntax_error.jsm +1 -0
  761. data/vendor/tracemonkey/xpconnect/tests/unit/test_bogus_files.js +88 -0
  762. data/vendor/tracemonkey/xpconnect/tests/unit/test_bug408412.js +51 -0
  763. data/vendor/tracemonkey/xpconnect/tests/unit/test_bug451678.js +52 -0
  764. data/vendor/tracemonkey/xpconnect/tests/unit/test_bug_442086.js +68 -0
  765. data/vendor/tracemonkey/xpconnect/tests/unit/test_import.js +127 -0
  766. data/vendor/tracemonkey/xpconnect/tests/unit/test_js_weak_references.js +63 -0
  767. data/vendor/tracemonkey/xpconnect/tests/unit/test_recursive_import.js +62 -0
  768. data/vendor/tracemonkey/xpconnect/tools/Makefile.in +49 -0
  769. data/vendor/tracemonkey/xpconnect/tools/idl/Makefile.in +53 -0
  770. data/vendor/tracemonkey/xpconnect/tools/idl/nsIXPCToolsCompiler.idl +60 -0
  771. data/vendor/tracemonkey/xpconnect/tools/idl/nsIXPCToolsProfiler.idl +57 -0
  772. data/vendor/tracemonkey/xpconnect/tools/js/CompileJSFiles.js +28 -0
  773. data/vendor/tracemonkey/xpconnect/tools/js/ListJSFiles.js +18 -0
  774. data/vendor/tracemonkey/xpconnect/tools/src/Makefile.in +76 -0
  775. data/vendor/tracemonkey/xpconnect/tools/src/nsXPCToolsCompiler.cpp +161 -0
  776. data/vendor/tracemonkey/xpconnect/tools/src/nsXPCToolsModule.cpp +65 -0
  777. data/vendor/tracemonkey/xpconnect/tools/src/nsXPCToolsProfiler.cpp +370 -0
  778. data/vendor/tracemonkey/xpconnect/tools/src/xpctools_private.h +236 -0
  779. metadata +782 -107
  780. data/test/johnson/nodes/export_test.rb +0 -9
  781. data/test/johnson/nodes/import_test.rb +0 -13
  782. data/test/johnson/version_test.rb +0 -13
@@ -0,0 +1,3418 @@
1
+ // The ray tracer code in this file is written by Adam Burmister. It
2
+ // is available in its original form from:
3
+ //
4
+ // http://labs.flog.nz.co/raytracer/
5
+ //
6
+ // It has been modified slightly by Google to work as a standalone
7
+ // benchmark, but the all the computational code remains
8
+ // untouched. This file also contains a copy of the Prototype
9
+ // JavaScript framework which is used by the ray tracer.
10
+
11
+ var RayTrace = new BenchmarkSuite('RayTrace', 932666, [
12
+ new Benchmark('RayTrace', renderScene)
13
+ ]);
14
+
15
+
16
+ // Create dummy objects if we're not running in a browser.
17
+ if (typeof document == 'undefined') {
18
+ document = { };
19
+ window = { opera: null };
20
+ navigator = { userAgent: null, appVersion: "" };
21
+ }
22
+
23
+
24
+ // ------------------------------------------------------------------------
25
+ // ------------------------------------------------------------------------
26
+
27
+
28
+ /* Prototype JavaScript framework, version 1.5.0
29
+ * (c) 2005-2007 Sam Stephenson
30
+ *
31
+ * Prototype is freely distributable under the terms of an MIT-style license.
32
+ * For details, see the Prototype web site: http://prototype.conio.net/
33
+ *
34
+ /*--------------------------------------------------------------------------*/
35
+
36
+ //--------------------
37
+ var Prototype = {
38
+ Version: '1.5.0',
39
+ BrowserFeatures: {
40
+ XPath: !!document.evaluate
41
+ },
42
+
43
+ ScriptFragment: '(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)',
44
+ emptyFunction: function() {},
45
+ K: function(x) { return x }
46
+ }
47
+
48
+ var Class = {
49
+ create: function() {
50
+ return function() {
51
+ this.initialize.apply(this, arguments);
52
+ }
53
+ }
54
+ }
55
+
56
+ var Abstract = new Object();
57
+
58
+ Object.extend = function(destination, source) {
59
+ for (var property in source) {
60
+ destination[property] = source[property];
61
+ }
62
+ return destination;
63
+ }
64
+
65
+ Object.extend(Object, {
66
+ inspect: function(object) {
67
+ try {
68
+ if (object === undefined) return 'undefined';
69
+ if (object === null) return 'null';
70
+ return object.inspect ? object.inspect() : object.toString();
71
+ } catch (e) {
72
+ if (e instanceof RangeError) return '...';
73
+ throw e;
74
+ }
75
+ },
76
+
77
+ keys: function(object) {
78
+ var keys = [];
79
+ for (var property in object)
80
+ keys.push(property);
81
+ return keys;
82
+ },
83
+
84
+ values: function(object) {
85
+ var values = [];
86
+ for (var property in object)
87
+ values.push(object[property]);
88
+ return values;
89
+ },
90
+
91
+ clone: function(object) {
92
+ return Object.extend({}, object);
93
+ }
94
+ });
95
+
96
+ Function.prototype.bind = function() {
97
+ var __method = this, args = $A(arguments), object = args.shift();
98
+ return function() {
99
+ return __method.apply(object, args.concat($A(arguments)));
100
+ }
101
+ }
102
+
103
+ Function.prototype.bindAsEventListener = function(object) {
104
+ var __method = this, args = $A(arguments), object = args.shift();
105
+ return function(event) {
106
+ return __method.apply(object, [( event || window.event)].concat(args).concat($A(arguments)));
107
+ }
108
+ }
109
+
110
+ Object.extend(Number.prototype, {
111
+ toColorPart: function() {
112
+ var digits = this.toString(16);
113
+ if (this < 16) return '0' + digits;
114
+ return digits;
115
+ },
116
+
117
+ succ: function() {
118
+ return this + 1;
119
+ },
120
+
121
+ times: function(iterator) {
122
+ $R(0, this, true).each(iterator);
123
+ return this;
124
+ }
125
+ });
126
+
127
+ var Try = {
128
+ these: function() {
129
+ var returnValue;
130
+
131
+ for (var i = 0, length = arguments.length; i < length; i++) {
132
+ var lambda = arguments[i];
133
+ try {
134
+ returnValue = lambda();
135
+ break;
136
+ } catch (e) {}
137
+ }
138
+
139
+ return returnValue;
140
+ }
141
+ }
142
+
143
+ /*--------------------------------------------------------------------------*/
144
+
145
+ var PeriodicalExecuter = Class.create();
146
+ PeriodicalExecuter.prototype = {
147
+ initialize: function(callback, frequency) {
148
+ this.callback = callback;
149
+ this.frequency = frequency;
150
+ this.currentlyExecuting = false;
151
+
152
+ this.registerCallback();
153
+ },
154
+
155
+ registerCallback: function() {
156
+ this.timer = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
157
+ },
158
+
159
+ stop: function() {
160
+ if (!this.timer) return;
161
+ clearInterval(this.timer);
162
+ this.timer = null;
163
+ },
164
+
165
+ onTimerEvent: function() {
166
+ if (!this.currentlyExecuting) {
167
+ try {
168
+ this.currentlyExecuting = true;
169
+ this.callback(this);
170
+ } finally {
171
+ this.currentlyExecuting = false;
172
+ }
173
+ }
174
+ }
175
+ }
176
+ String.interpret = function(value){
177
+ return value == null ? '' : String(value);
178
+ }
179
+
180
+ Object.extend(String.prototype, {
181
+ gsub: function(pattern, replacement) {
182
+ var result = '', source = this, match;
183
+ replacement = arguments.callee.prepareReplacement(replacement);
184
+
185
+ while (source.length > 0) {
186
+ if (match = source.match(pattern)) {
187
+ result += source.slice(0, match.index);
188
+ result += String.interpret(replacement(match));
189
+ source = source.slice(match.index + match[0].length);
190
+ } else {
191
+ result += source, source = '';
192
+ }
193
+ }
194
+ return result;
195
+ },
196
+
197
+ sub: function(pattern, replacement, count) {
198
+ replacement = this.gsub.prepareReplacement(replacement);
199
+ count = count === undefined ? 1 : count;
200
+
201
+ return this.gsub(pattern, function(match) {
202
+ if (--count < 0) return match[0];
203
+ return replacement(match);
204
+ });
205
+ },
206
+
207
+ scan: function(pattern, iterator) {
208
+ this.gsub(pattern, iterator);
209
+ return this;
210
+ },
211
+
212
+ truncate: function(length, truncation) {
213
+ length = length || 30;
214
+ truncation = truncation === undefined ? '...' : truncation;
215
+ return this.length > length ?
216
+ this.slice(0, length - truncation.length) + truncation : this;
217
+ },
218
+
219
+ strip: function() {
220
+ return this.replace(/^\s+/, '').replace(/\s+$/, '');
221
+ },
222
+
223
+ stripTags: function() {
224
+ return this.replace(/<\/?[^>]+>/gi, '');
225
+ },
226
+
227
+ stripScripts: function() {
228
+ return this.replace(new RegExp(Prototype.ScriptFragment, 'img'), '');
229
+ },
230
+
231
+ extractScripts: function() {
232
+ var matchAll = new RegExp(Prototype.ScriptFragment, 'img');
233
+ var matchOne = new RegExp(Prototype.ScriptFragment, 'im');
234
+ return (this.match(matchAll) || []).map(function(scriptTag) {
235
+ return (scriptTag.match(matchOne) || ['', ''])[1];
236
+ });
237
+ },
238
+
239
+ evalScripts: function() {
240
+ return this.extractScripts().map(function(script) { return eval(script) });
241
+ },
242
+
243
+ escapeHTML: function() {
244
+ var div = document.createElement('div');
245
+ var text = document.createTextNode(this);
246
+ div.appendChild(text);
247
+ return div.innerHTML;
248
+ },
249
+
250
+ unescapeHTML: function() {
251
+ var div = document.createElement('div');
252
+ div.innerHTML = this.stripTags();
253
+ return div.childNodes[0] ? (div.childNodes.length > 1 ?
254
+ $A(div.childNodes).inject('',function(memo,node){ return memo+node.nodeValue }) :
255
+ div.childNodes[0].nodeValue) : '';
256
+ },
257
+
258
+ toQueryParams: function(separator) {
259
+ var match = this.strip().match(/([^?#]*)(#.*)?$/);
260
+ if (!match) return {};
261
+
262
+ return match[1].split(separator || '&').inject({}, function(hash, pair) {
263
+ if ((pair = pair.split('='))[0]) {
264
+ var name = decodeURIComponent(pair[0]);
265
+ var value = pair[1] ? decodeURIComponent(pair[1]) : undefined;
266
+
267
+ if (hash[name] !== undefined) {
268
+ if (hash[name].constructor != Array)
269
+ hash[name] = [hash[name]];
270
+ if (value) hash[name].push(value);
271
+ }
272
+ else hash[name] = value;
273
+ }
274
+ return hash;
275
+ });
276
+ },
277
+
278
+ toArray: function() {
279
+ return this.split('');
280
+ },
281
+
282
+ succ: function() {
283
+ return this.slice(0, this.length - 1) +
284
+ String.fromCharCode(this.charCodeAt(this.length - 1) + 1);
285
+ },
286
+
287
+ camelize: function() {
288
+ var parts = this.split('-'), len = parts.length;
289
+ if (len == 1) return parts[0];
290
+
291
+ var camelized = this.charAt(0) == '-'
292
+ ? parts[0].charAt(0).toUpperCase() + parts[0].substring(1)
293
+ : parts[0];
294
+
295
+ for (var i = 1; i < len; i++)
296
+ camelized += parts[i].charAt(0).toUpperCase() + parts[i].substring(1);
297
+
298
+ return camelized;
299
+ },
300
+
301
+ capitalize: function(){
302
+ return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase();
303
+ },
304
+
305
+ underscore: function() {
306
+ return this.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'#{1}_#{2}').gsub(/([a-z\d])([A-Z])/,'#{1}_#{2}').gsub(/-/,'_').toLowerCase();
307
+ },
308
+
309
+ dasherize: function() {
310
+ return this.gsub(/_/,'-');
311
+ },
312
+
313
+ inspect: function(useDoubleQuotes) {
314
+ var escapedString = this.replace(/\\/g, '\\\\');
315
+ if (useDoubleQuotes)
316
+ return '"' + escapedString.replace(/"/g, '\\"') + '"';
317
+ else
318
+ return "'" + escapedString.replace(/'/g, '\\\'') + "'";
319
+ }
320
+ });
321
+
322
+ String.prototype.gsub.prepareReplacement = function(replacement) {
323
+ if (typeof replacement == 'function') return replacement;
324
+ var template = new Template(replacement);
325
+ return function(match) { return template.evaluate(match) };
326
+ }
327
+
328
+ String.prototype.parseQuery = String.prototype.toQueryParams;
329
+
330
+ var Template = Class.create();
331
+ Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/;
332
+ Template.prototype = {
333
+ initialize: function(template, pattern) {
334
+ this.template = template.toString();
335
+ this.pattern = pattern || Template.Pattern;
336
+ },
337
+
338
+ evaluate: function(object) {
339
+ return this.template.gsub(this.pattern, function(match) {
340
+ var before = match[1];
341
+ if (before == '\\') return match[2];
342
+ return before + String.interpret(object[match[3]]);
343
+ });
344
+ }
345
+ }
346
+
347
+ var $break = new Object();
348
+ var $continue = new Object();
349
+
350
+ var Enumerable = {
351
+ each: function(iterator) {
352
+ var index = 0;
353
+ try {
354
+ this._each(function(value) {
355
+ try {
356
+ iterator(value, index++);
357
+ } catch (e) {
358
+ if (e != $continue) throw e;
359
+ }
360
+ });
361
+ } catch (e) {
362
+ if (e != $break) throw e;
363
+ }
364
+ return this;
365
+ },
366
+
367
+ eachSlice: function(number, iterator) {
368
+ var index = -number, slices = [], array = this.toArray();
369
+ while ((index += number) < array.length)
370
+ slices.push(array.slice(index, index+number));
371
+ return slices.map(iterator);
372
+ },
373
+
374
+ all: function(iterator) {
375
+ var result = true;
376
+ this.each(function(value, index) {
377
+ result = result && !!(iterator || Prototype.K)(value, index);
378
+ if (!result) throw $break;
379
+ });
380
+ return result;
381
+ },
382
+
383
+ any: function(iterator) {
384
+ var result = false;
385
+ this.each(function(value, index) {
386
+ if (result = !!(iterator || Prototype.K)(value, index))
387
+ throw $break;
388
+ });
389
+ return result;
390
+ },
391
+
392
+ collect: function(iterator) {
393
+ var results = [];
394
+ this.each(function(value, index) {
395
+ results.push((iterator || Prototype.K)(value, index));
396
+ });
397
+ return results;
398
+ },
399
+
400
+ detect: function(iterator) {
401
+ var result;
402
+ this.each(function(value, index) {
403
+ if (iterator(value, index)) {
404
+ result = value;
405
+ throw $break;
406
+ }
407
+ });
408
+ return result;
409
+ },
410
+
411
+ findAll: function(iterator) {
412
+ var results = [];
413
+ this.each(function(value, index) {
414
+ if (iterator(value, index))
415
+ results.push(value);
416
+ });
417
+ return results;
418
+ },
419
+
420
+ grep: function(pattern, iterator) {
421
+ var results = [];
422
+ this.each(function(value, index) {
423
+ var stringValue = value.toString();
424
+ if (stringValue.match(pattern))
425
+ results.push((iterator || Prototype.K)(value, index));
426
+ })
427
+ return results;
428
+ },
429
+
430
+ include: function(object) {
431
+ var found = false;
432
+ this.each(function(value) {
433
+ if (value == object) {
434
+ found = true;
435
+ throw $break;
436
+ }
437
+ });
438
+ return found;
439
+ },
440
+
441
+ inGroupsOf: function(number, fillWith) {
442
+ fillWith = fillWith === undefined ? null : fillWith;
443
+ return this.eachSlice(number, function(slice) {
444
+ while(slice.length < number) slice.push(fillWith);
445
+ return slice;
446
+ });
447
+ },
448
+
449
+ inject: function(memo, iterator) {
450
+ this.each(function(value, index) {
451
+ memo = iterator(memo, value, index);
452
+ });
453
+ return memo;
454
+ },
455
+
456
+ invoke: function(method) {
457
+ var args = $A(arguments).slice(1);
458
+ return this.map(function(value) {
459
+ return value[method].apply(value, args);
460
+ });
461
+ },
462
+
463
+ max: function(iterator) {
464
+ var result;
465
+ this.each(function(value, index) {
466
+ value = (iterator || Prototype.K)(value, index);
467
+ if (result == undefined || value >= result)
468
+ result = value;
469
+ });
470
+ return result;
471
+ },
472
+
473
+ min: function(iterator) {
474
+ var result;
475
+ this.each(function(value, index) {
476
+ value = (iterator || Prototype.K)(value, index);
477
+ if (result == undefined || value < result)
478
+ result = value;
479
+ });
480
+ return result;
481
+ },
482
+
483
+ partition: function(iterator) {
484
+ var trues = [], falses = [];
485
+ this.each(function(value, index) {
486
+ ((iterator || Prototype.K)(value, index) ?
487
+ trues : falses).push(value);
488
+ });
489
+ return [trues, falses];
490
+ },
491
+
492
+ pluck: function(property) {
493
+ var results = [];
494
+ this.each(function(value, index) {
495
+ results.push(value[property]);
496
+ });
497
+ return results;
498
+ },
499
+
500
+ reject: function(iterator) {
501
+ var results = [];
502
+ this.each(function(value, index) {
503
+ if (!iterator(value, index))
504
+ results.push(value);
505
+ });
506
+ return results;
507
+ },
508
+
509
+ sortBy: function(iterator) {
510
+ return this.map(function(value, index) {
511
+ return {value: value, criteria: iterator(value, index)};
512
+ }).sort(function(left, right) {
513
+ var a = left.criteria, b = right.criteria;
514
+ return a < b ? -1 : a > b ? 1 : 0;
515
+ }).pluck('value');
516
+ },
517
+
518
+ toArray: function() {
519
+ return this.map();
520
+ },
521
+
522
+ zip: function() {
523
+ var iterator = Prototype.K, args = $A(arguments);
524
+ if (typeof args.last() == 'function')
525
+ iterator = args.pop();
526
+
527
+ var collections = [this].concat(args).map($A);
528
+ return this.map(function(value, index) {
529
+ return iterator(collections.pluck(index));
530
+ });
531
+ },
532
+
533
+ size: function() {
534
+ return this.toArray().length;
535
+ },
536
+
537
+ inspect: function() {
538
+ return '#<Enumerable:' + this.toArray().inspect() + '>';
539
+ }
540
+ }
541
+
542
+ Object.extend(Enumerable, {
543
+ map: Enumerable.collect,
544
+ find: Enumerable.detect,
545
+ select: Enumerable.findAll,
546
+ member: Enumerable.include,
547
+ entries: Enumerable.toArray
548
+ });
549
+ var $A = Array.from = function(iterable) {
550
+ if (!iterable) return [];
551
+ if (iterable.toArray) {
552
+ return iterable.toArray();
553
+ } else {
554
+ var results = [];
555
+ for (var i = 0, length = iterable.length; i < length; i++)
556
+ results.push(iterable[i]);
557
+ return results;
558
+ }
559
+ }
560
+
561
+ Object.extend(Array.prototype, Enumerable);
562
+
563
+ if (!Array.prototype._reverse)
564
+ Array.prototype._reverse = Array.prototype.reverse;
565
+
566
+ Object.extend(Array.prototype, {
567
+ _each: function(iterator) {
568
+ for (var i = 0, length = this.length; i < length; i++)
569
+ iterator(this[i]);
570
+ },
571
+
572
+ clear: function() {
573
+ this.length = 0;
574
+ return this;
575
+ },
576
+
577
+ first: function() {
578
+ return this[0];
579
+ },
580
+
581
+ last: function() {
582
+ return this[this.length - 1];
583
+ },
584
+
585
+ compact: function() {
586
+ return this.select(function(value) {
587
+ return value != null;
588
+ });
589
+ },
590
+
591
+ flatten: function() {
592
+ return this.inject([], function(array, value) {
593
+ return array.concat(value && value.constructor == Array ?
594
+ value.flatten() : [value]);
595
+ });
596
+ },
597
+
598
+ without: function() {
599
+ var values = $A(arguments);
600
+ return this.select(function(value) {
601
+ return !values.include(value);
602
+ });
603
+ },
604
+
605
+ indexOf: function(object) {
606
+ for (var i = 0, length = this.length; i < length; i++)
607
+ if (this[i] == object) return i;
608
+ return -1;
609
+ },
610
+
611
+ reverse: function(inline) {
612
+ return (inline !== false ? this : this.toArray())._reverse();
613
+ },
614
+
615
+ reduce: function() {
616
+ return this.length > 1 ? this : this[0];
617
+ },
618
+
619
+ uniq: function() {
620
+ return this.inject([], function(array, value) {
621
+ return array.include(value) ? array : array.concat([value]);
622
+ });
623
+ },
624
+
625
+ clone: function() {
626
+ return [].concat(this);
627
+ },
628
+
629
+ size: function() {
630
+ return this.length;
631
+ },
632
+
633
+ inspect: function() {
634
+ return '[' + this.map(Object.inspect).join(', ') + ']';
635
+ }
636
+ });
637
+
638
+ Array.prototype.toArray = Array.prototype.clone;
639
+
640
+ function $w(string){
641
+ string = string.strip();
642
+ return string ? string.split(/\s+/) : [];
643
+ }
644
+
645
+ if(window.opera){
646
+ Array.prototype.concat = function(){
647
+ var array = [];
648
+ for(var i = 0, length = this.length; i < length; i++) array.push(this[i]);
649
+ for(var i = 0, length = arguments.length; i < length; i++) {
650
+ if(arguments[i].constructor == Array) {
651
+ for(var j = 0, arrayLength = arguments[i].length; j < arrayLength; j++)
652
+ array.push(arguments[i][j]);
653
+ } else {
654
+ array.push(arguments[i]);
655
+ }
656
+ }
657
+ return array;
658
+ }
659
+ }
660
+ var Hash = function(obj) {
661
+ Object.extend(this, obj || {});
662
+ };
663
+
664
+ Object.extend(Hash, {
665
+ toQueryString: function(obj) {
666
+ var parts = [];
667
+
668
+ this.prototype._each.call(obj, function(pair) {
669
+ if (!pair.key) return;
670
+
671
+ if (pair.value && pair.value.constructor == Array) {
672
+ var values = pair.value.compact();
673
+ if (values.length < 2) pair.value = values.reduce();
674
+ else {
675
+ key = encodeURIComponent(pair.key);
676
+ values.each(function(value) {
677
+ value = value != undefined ? encodeURIComponent(value) : '';
678
+ parts.push(key + '=' + encodeURIComponent(value));
679
+ });
680
+ return;
681
+ }
682
+ }
683
+ if (pair.value == undefined) pair[1] = '';
684
+ parts.push(pair.map(encodeURIComponent).join('='));
685
+ });
686
+
687
+ return parts.join('&');
688
+ }
689
+ });
690
+
691
+ Object.extend(Hash.prototype, Enumerable);
692
+ Object.extend(Hash.prototype, {
693
+ _each: function(iterator) {
694
+ for (var key in this) {
695
+ var value = this[key];
696
+ if (value && value == Hash.prototype[key]) continue;
697
+
698
+ var pair = [key, value];
699
+ pair.key = key;
700
+ pair.value = value;
701
+ iterator(pair);
702
+ }
703
+ },
704
+
705
+ keys: function() {
706
+ return this.pluck('key');
707
+ },
708
+
709
+ values: function() {
710
+ return this.pluck('value');
711
+ },
712
+
713
+ merge: function(hash) {
714
+ return $H(hash).inject(this, function(mergedHash, pair) {
715
+ mergedHash[pair.key] = pair.value;
716
+ return mergedHash;
717
+ });
718
+ },
719
+
720
+ remove: function() {
721
+ var result;
722
+ for(var i = 0, length = arguments.length; i < length; i++) {
723
+ var value = this[arguments[i]];
724
+ if (value !== undefined){
725
+ if (result === undefined) result = value;
726
+ else {
727
+ if (result.constructor != Array) result = [result];
728
+ result.push(value)
729
+ }
730
+ }
731
+ delete this[arguments[i]];
732
+ }
733
+ return result;
734
+ },
735
+
736
+ toQueryString: function() {
737
+ return Hash.toQueryString(this);
738
+ },
739
+
740
+ inspect: function() {
741
+ return '#<Hash:{' + this.map(function(pair) {
742
+ return pair.map(Object.inspect).join(': ');
743
+ }).join(', ') + '}>';
744
+ }
745
+ });
746
+
747
+ function $H(object) {
748
+ if (object && object.constructor == Hash) return object;
749
+ return new Hash(object);
750
+ };
751
+ ObjectRange = Class.create();
752
+ Object.extend(ObjectRange.prototype, Enumerable);
753
+ Object.extend(ObjectRange.prototype, {
754
+ initialize: function(start, end, exclusive) {
755
+ this.start = start;
756
+ this.end = end;
757
+ this.exclusive = exclusive;
758
+ },
759
+
760
+ _each: function(iterator) {
761
+ var value = this.start;
762
+ while (this.include(value)) {
763
+ iterator(value);
764
+ value = value.succ();
765
+ }
766
+ },
767
+
768
+ include: function(value) {
769
+ if (value < this.start)
770
+ return false;
771
+ if (this.exclusive)
772
+ return value < this.end;
773
+ return value <= this.end;
774
+ }
775
+ });
776
+
777
+ var $R = function(start, end, exclusive) {
778
+ return new ObjectRange(start, end, exclusive);
779
+ }
780
+
781
+ var Ajax = {
782
+ getTransport: function() {
783
+ return Try.these(
784
+ function() {return new XMLHttpRequest()},
785
+ function() {return new ActiveXObject('Msxml2.XMLHTTP')},
786
+ function() {return new ActiveXObject('Microsoft.XMLHTTP')}
787
+ ) || false;
788
+ },
789
+
790
+ activeRequestCount: 0
791
+ }
792
+
793
+ Ajax.Responders = {
794
+ responders: [],
795
+
796
+ _each: function(iterator) {
797
+ this.responders._each(iterator);
798
+ },
799
+
800
+ register: function(responder) {
801
+ if (!this.include(responder))
802
+ this.responders.push(responder);
803
+ },
804
+
805
+ unregister: function(responder) {
806
+ this.responders = this.responders.without(responder);
807
+ },
808
+
809
+ dispatch: function(callback, request, transport, json) {
810
+ this.each(function(responder) {
811
+ if (typeof responder[callback] == 'function') {
812
+ try {
813
+ responder[callback].apply(responder, [request, transport, json]);
814
+ } catch (e) {}
815
+ }
816
+ });
817
+ }
818
+ };
819
+
820
+ Object.extend(Ajax.Responders, Enumerable);
821
+
822
+ Ajax.Responders.register({
823
+ onCreate: function() {
824
+ Ajax.activeRequestCount++;
825
+ },
826
+ onComplete: function() {
827
+ Ajax.activeRequestCount--;
828
+ }
829
+ });
830
+
831
+ Ajax.Base = function() {};
832
+ Ajax.Base.prototype = {
833
+ setOptions: function(options) {
834
+ this.options = {
835
+ method: 'post',
836
+ asynchronous: true,
837
+ contentType: 'application/x-www-form-urlencoded',
838
+ encoding: 'UTF-8',
839
+ parameters: ''
840
+ }
841
+ Object.extend(this.options, options || {});
842
+
843
+ this.options.method = this.options.method.toLowerCase();
844
+ if (typeof this.options.parameters == 'string')
845
+ this.options.parameters = this.options.parameters.toQueryParams();
846
+ }
847
+ }
848
+
849
+ Ajax.Request = Class.create();
850
+ Ajax.Request.Events =
851
+ ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'];
852
+
853
+ Ajax.Request.prototype = Object.extend(new Ajax.Base(), {
854
+ _complete: false,
855
+
856
+ initialize: function(url, options) {
857
+ this.transport = Ajax.getTransport();
858
+ this.setOptions(options);
859
+ this.request(url);
860
+ },
861
+
862
+ request: function(url) {
863
+ this.url = url;
864
+ this.method = this.options.method;
865
+ var params = this.options.parameters;
866
+
867
+ if (!['get', 'post'].include(this.method)) {
868
+ // simulate other verbs over post
869
+ params['_method'] = this.method;
870
+ this.method = 'post';
871
+ }
872
+
873
+ params = Hash.toQueryString(params);
874
+ if (params && /Konqueror|Safari|KHTML/.test(navigator.userAgent)) params += '&_='
875
+
876
+ // when GET, append parameters to URL
877
+ if (this.method == 'get' && params)
878
+ this.url += (this.url.indexOf('?') > -1 ? '&' : '?') + params;
879
+
880
+ try {
881
+ Ajax.Responders.dispatch('onCreate', this, this.transport);
882
+
883
+ this.transport.open(this.method.toUpperCase(), this.url,
884
+ this.options.asynchronous);
885
+
886
+ if (this.options.asynchronous)
887
+ setTimeout(function() { this.respondToReadyState(1) }.bind(this), 10);
888
+
889
+ this.transport.onreadystatechange = this.onStateChange.bind(this);
890
+ this.setRequestHeaders();
891
+
892
+ var body = this.method == 'post' ? (this.options.postBody || params) : null;
893
+
894
+ this.transport.send(body);
895
+
896
+ /* Force Firefox to handle ready state 4 for synchronous requests */
897
+ if (!this.options.asynchronous && this.transport.overrideMimeType)
898
+ this.onStateChange();
899
+
900
+ }
901
+ catch (e) {
902
+ this.dispatchException(e);
903
+ }
904
+ },
905
+
906
+ onStateChange: function() {
907
+ var readyState = this.transport.readyState;
908
+ if (readyState > 1 && !((readyState == 4) && this._complete))
909
+ this.respondToReadyState(this.transport.readyState);
910
+ },
911
+
912
+ setRequestHeaders: function() {
913
+ var headers = {
914
+ 'X-Requested-With': 'XMLHttpRequest',
915
+ 'X-Prototype-Version': Prototype.Version,
916
+ 'Accept': 'text/javascript, text/html, application/xml, text/xml, */*'
917
+ };
918
+
919
+ if (this.method == 'post') {
920
+ headers['Content-type'] = this.options.contentType +
921
+ (this.options.encoding ? '; charset=' + this.options.encoding : '');
922
+
923
+ /* Force "Connection: close" for older Mozilla browsers to work
924
+ * around a bug where XMLHttpRequest sends an incorrect
925
+ * Content-length header. See Mozilla Bugzilla #246651.
926
+ */
927
+ if (this.transport.overrideMimeType &&
928
+ (navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005)
929
+ headers['Connection'] = 'close';
930
+ }
931
+
932
+ // user-defined headers
933
+ if (typeof this.options.requestHeaders == 'object') {
934
+ var extras = this.options.requestHeaders;
935
+
936
+ if (typeof extras.push == 'function')
937
+ for (var i = 0, length = extras.length; i < length; i += 2)
938
+ headers[extras[i]] = extras[i+1];
939
+ else
940
+ $H(extras).each(function(pair) { headers[pair.key] = pair.value });
941
+ }
942
+
943
+ for (var name in headers)
944
+ this.transport.setRequestHeader(name, headers[name]);
945
+ },
946
+
947
+ success: function() {
948
+ return !this.transport.status
949
+ || (this.transport.status >= 200 && this.transport.status < 300);
950
+ },
951
+
952
+ respondToReadyState: function(readyState) {
953
+ var state = Ajax.Request.Events[readyState];
954
+ var transport = this.transport, json = this.evalJSON();
955
+
956
+ if (state == 'Complete') {
957
+ try {
958
+ this._complete = true;
959
+ (this.options['on' + this.transport.status]
960
+ || this.options['on' + (this.success() ? 'Success' : 'Failure')]
961
+ || Prototype.emptyFunction)(transport, json);
962
+ } catch (e) {
963
+ this.dispatchException(e);
964
+ }
965
+
966
+ if ((this.getHeader('Content-type') || 'text/javascript').strip().
967
+ match(/^(text|application)\/(x-)?(java|ecma)script(;.*)?$/i))
968
+ this.evalResponse();
969
+ }
970
+
971
+ try {
972
+ (this.options['on' + state] || Prototype.emptyFunction)(transport, json);
973
+ Ajax.Responders.dispatch('on' + state, this, transport, json);
974
+ } catch (e) {
975
+ this.dispatchException(e);
976
+ }
977
+
978
+ if (state == 'Complete') {
979
+ // avoid memory leak in MSIE: clean up
980
+ this.transport.onreadystatechange = Prototype.emptyFunction;
981
+ }
982
+ },
983
+
984
+ getHeader: function(name) {
985
+ try {
986
+ return this.transport.getResponseHeader(name);
987
+ } catch (e) { return null }
988
+ },
989
+
990
+ evalJSON: function() {
991
+ try {
992
+ var json = this.getHeader('X-JSON');
993
+ return json ? eval('(' + json + ')') : null;
994
+ } catch (e) { return null }
995
+ },
996
+
997
+ evalResponse: function() {
998
+ try {
999
+ return eval(this.transport.responseText);
1000
+ } catch (e) {
1001
+ this.dispatchException(e);
1002
+ }
1003
+ },
1004
+
1005
+ dispatchException: function(exception) {
1006
+ (this.options.onException || Prototype.emptyFunction)(this, exception);
1007
+ Ajax.Responders.dispatch('onException', this, exception);
1008
+ }
1009
+ });
1010
+
1011
+ Ajax.Updater = Class.create();
1012
+
1013
+ Object.extend(Object.extend(Ajax.Updater.prototype, Ajax.Request.prototype), {
1014
+ initialize: function(container, url, options) {
1015
+ this.container = {
1016
+ success: (container.success || container),
1017
+ failure: (container.failure || (container.success ? null : container))
1018
+ }
1019
+
1020
+ this.transport = Ajax.getTransport();
1021
+ this.setOptions(options);
1022
+
1023
+ var onComplete = this.options.onComplete || Prototype.emptyFunction;
1024
+ this.options.onComplete = (function(transport, param) {
1025
+ this.updateContent();
1026
+ onComplete(transport, param);
1027
+ }).bind(this);
1028
+
1029
+ this.request(url);
1030
+ },
1031
+
1032
+ updateContent: function() {
1033
+ var receiver = this.container[this.success() ? 'success' : 'failure'];
1034
+ var response = this.transport.responseText;
1035
+
1036
+ if (!this.options.evalScripts) response = response.stripScripts();
1037
+
1038
+ if (receiver = $(receiver)) {
1039
+ if (this.options.insertion)
1040
+ new this.options.insertion(receiver, response);
1041
+ else
1042
+ receiver.update(response);
1043
+ }
1044
+
1045
+ if (this.success()) {
1046
+ if (this.onComplete)
1047
+ setTimeout(this.onComplete.bind(this), 10);
1048
+ }
1049
+ }
1050
+ });
1051
+
1052
+ Ajax.PeriodicalUpdater = Class.create();
1053
+ Ajax.PeriodicalUpdater.prototype = Object.extend(new Ajax.Base(), {
1054
+ initialize: function(container, url, options) {
1055
+ this.setOptions(options);
1056
+ this.onComplete = this.options.onComplete;
1057
+
1058
+ this.frequency = (this.options.frequency || 2);
1059
+ this.decay = (this.options.decay || 1);
1060
+
1061
+ this.updater = {};
1062
+ this.container = container;
1063
+ this.url = url;
1064
+
1065
+ this.start();
1066
+ },
1067
+
1068
+ start: function() {
1069
+ this.options.onComplete = this.updateComplete.bind(this);
1070
+ this.onTimerEvent();
1071
+ },
1072
+
1073
+ stop: function() {
1074
+ this.updater.options.onComplete = undefined;
1075
+ clearTimeout(this.timer);
1076
+ (this.onComplete || Prototype.emptyFunction).apply(this, arguments);
1077
+ },
1078
+
1079
+ updateComplete: function(request) {
1080
+ if (this.options.decay) {
1081
+ this.decay = (request.responseText == this.lastText ?
1082
+ this.decay * this.options.decay : 1);
1083
+
1084
+ this.lastText = request.responseText;
1085
+ }
1086
+ this.timer = setTimeout(this.onTimerEvent.bind(this),
1087
+ this.decay * this.frequency * 1000);
1088
+ },
1089
+
1090
+ onTimerEvent: function() {
1091
+ this.updater = new Ajax.Updater(this.container, this.url, this.options);
1092
+ }
1093
+ });
1094
+ function $(element) {
1095
+ if (arguments.length > 1) {
1096
+ for (var i = 0, elements = [], length = arguments.length; i < length; i++)
1097
+ elements.push($(arguments[i]));
1098
+ return elements;
1099
+ }
1100
+ if (typeof element == 'string')
1101
+ element = document.getElementById(element);
1102
+ return Element.extend(element);
1103
+ }
1104
+
1105
+ if (Prototype.BrowserFeatures.XPath) {
1106
+ document._getElementsByXPath = function(expression, parentElement) {
1107
+ var results = [];
1108
+ var query = document.evaluate(expression, $(parentElement) || document,
1109
+ null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
1110
+ for (var i = 0, length = query.snapshotLength; i < length; i++)
1111
+ results.push(query.snapshotItem(i));
1112
+ return results;
1113
+ };
1114
+ }
1115
+
1116
+ document.getElementsByClassName = function(className, parentElement) {
1117
+ if (Prototype.BrowserFeatures.XPath) {
1118
+ var q = ".//*[contains(concat(' ', @class, ' '), ' " + className + " ')]";
1119
+ return document._getElementsByXPath(q, parentElement);
1120
+ } else {
1121
+ var children = ($(parentElement) || document.body).getElementsByTagName('*');
1122
+ var elements = [], child;
1123
+ for (var i = 0, length = children.length; i < length; i++) {
1124
+ child = children[i];
1125
+ if (Element.hasClassName(child, className))
1126
+ elements.push(Element.extend(child));
1127
+ }
1128
+ return elements;
1129
+ }
1130
+ };
1131
+
1132
+ /*--------------------------------------------------------------------------*/
1133
+
1134
+ if (!window.Element)
1135
+ var Element = new Object();
1136
+
1137
+ Element.extend = function(element) {
1138
+ if (!element || _nativeExtensions || element.nodeType == 3) return element;
1139
+
1140
+ if (!element._extended && element.tagName && element != window) {
1141
+ var methods = Object.clone(Element.Methods), cache = Element.extend.cache;
1142
+
1143
+ if (element.tagName == 'FORM')
1144
+ Object.extend(methods, Form.Methods);
1145
+ if (['INPUT', 'TEXTAREA', 'SELECT'].include(element.tagName))
1146
+ Object.extend(methods, Form.Element.Methods);
1147
+
1148
+ Object.extend(methods, Element.Methods.Simulated);
1149
+
1150
+ for (var property in methods) {
1151
+ var value = methods[property];
1152
+ if (typeof value == 'function' && !(property in element))
1153
+ element[property] = cache.findOrStore(value);
1154
+ }
1155
+ }
1156
+
1157
+ element._extended = true;
1158
+ return element;
1159
+ };
1160
+
1161
+ Element.extend.cache = {
1162
+ findOrStore: function(value) {
1163
+ return this[value] = this[value] || function() {
1164
+ return value.apply(null, [this].concat($A(arguments)));
1165
+ }
1166
+ }
1167
+ };
1168
+
1169
+ Element.Methods = {
1170
+ visible: function(element) {
1171
+ return $(element).style.display != 'none';
1172
+ },
1173
+
1174
+ toggle: function(element) {
1175
+ element = $(element);
1176
+ Element[Element.visible(element) ? 'hide' : 'show'](element);
1177
+ return element;
1178
+ },
1179
+
1180
+ hide: function(element) {
1181
+ $(element).style.display = 'none';
1182
+ return element;
1183
+ },
1184
+
1185
+ show: function(element) {
1186
+ $(element).style.display = '';
1187
+ return element;
1188
+ },
1189
+
1190
+ remove: function(element) {
1191
+ element = $(element);
1192
+ element.parentNode.removeChild(element);
1193
+ return element;
1194
+ },
1195
+
1196
+ update: function(element, html) {
1197
+ html = typeof html == 'undefined' ? '' : html.toString();
1198
+ $(element).innerHTML = html.stripScripts();
1199
+ setTimeout(function() {html.evalScripts()}, 10);
1200
+ return element;
1201
+ },
1202
+
1203
+ replace: function(element, html) {
1204
+ element = $(element);
1205
+ html = typeof html == 'undefined' ? '' : html.toString();
1206
+ if (element.outerHTML) {
1207
+ element.outerHTML = html.stripScripts();
1208
+ } else {
1209
+ var range = element.ownerDocument.createRange();
1210
+ range.selectNodeContents(element);
1211
+ element.parentNode.replaceChild(
1212
+ range.createContextualFragment(html.stripScripts()), element);
1213
+ }
1214
+ setTimeout(function() {html.evalScripts()}, 10);
1215
+ return element;
1216
+ },
1217
+
1218
+ inspect: function(element) {
1219
+ element = $(element);
1220
+ var result = '<' + element.tagName.toLowerCase();
1221
+ $H({'id': 'id', 'className': 'class'}).each(function(pair) {
1222
+ var property = pair.first(), attribute = pair.last();
1223
+ var value = (element[property] || '').toString();
1224
+ if (value) result += ' ' + attribute + '=' + value.inspect(true);
1225
+ });
1226
+ return result + '>';
1227
+ },
1228
+
1229
+ recursivelyCollect: function(element, property) {
1230
+ element = $(element);
1231
+ var elements = [];
1232
+ while (element = element[property])
1233
+ if (element.nodeType == 1)
1234
+ elements.push(Element.extend(element));
1235
+ return elements;
1236
+ },
1237
+
1238
+ ancestors: function(element) {
1239
+ return $(element).recursivelyCollect('parentNode');
1240
+ },
1241
+
1242
+ descendants: function(element) {
1243
+ return $A($(element).getElementsByTagName('*'));
1244
+ },
1245
+
1246
+ immediateDescendants: function(element) {
1247
+ if (!(element = $(element).firstChild)) return [];
1248
+ while (element && element.nodeType != 1) element = element.nextSibling;
1249
+ if (element) return [element].concat($(element).nextSiblings());
1250
+ return [];
1251
+ },
1252
+
1253
+ previousSiblings: function(element) {
1254
+ return $(element).recursivelyCollect('previousSibling');
1255
+ },
1256
+
1257
+ nextSiblings: function(element) {
1258
+ return $(element).recursivelyCollect('nextSibling');
1259
+ },
1260
+
1261
+ siblings: function(element) {
1262
+ element = $(element);
1263
+ return element.previousSiblings().reverse().concat(element.nextSiblings());
1264
+ },
1265
+
1266
+ match: function(element, selector) {
1267
+ if (typeof selector == 'string')
1268
+ selector = new Selector(selector);
1269
+ return selector.match($(element));
1270
+ },
1271
+
1272
+ up: function(element, expression, index) {
1273
+ return Selector.findElement($(element).ancestors(), expression, index);
1274
+ },
1275
+
1276
+ down: function(element, expression, index) {
1277
+ return Selector.findElement($(element).descendants(), expression, index);
1278
+ },
1279
+
1280
+ previous: function(element, expression, index) {
1281
+ return Selector.findElement($(element).previousSiblings(), expression, index);
1282
+ },
1283
+
1284
+ next: function(element, expression, index) {
1285
+ return Selector.findElement($(element).nextSiblings(), expression, index);
1286
+ },
1287
+
1288
+ getElementsBySelector: function() {
1289
+ var args = $A(arguments), element = $(args.shift());
1290
+ return Selector.findChildElements(element, args);
1291
+ },
1292
+
1293
+ getElementsByClassName: function(element, className) {
1294
+ return document.getElementsByClassName(className, element);
1295
+ },
1296
+
1297
+ readAttribute: function(element, name) {
1298
+ element = $(element);
1299
+ if (document.all && !window.opera) {
1300
+ var t = Element._attributeTranslations;
1301
+ if (t.values[name]) return t.values[name](element, name);
1302
+ if (t.names[name]) name = t.names[name];
1303
+ var attribute = element.attributes[name];
1304
+ if(attribute) return attribute.nodeValue;
1305
+ }
1306
+ return element.getAttribute(name);
1307
+ },
1308
+
1309
+ getHeight: function(element) {
1310
+ return $(element).getDimensions().height;
1311
+ },
1312
+
1313
+ getWidth: function(element) {
1314
+ return $(element).getDimensions().width;
1315
+ },
1316
+
1317
+ classNames: function(element) {
1318
+ return new Element.ClassNames(element);
1319
+ },
1320
+
1321
+ hasClassName: function(element, className) {
1322
+ if (!(element = $(element))) return;
1323
+ var elementClassName = element.className;
1324
+ if (elementClassName.length == 0) return false;
1325
+ if (elementClassName == className ||
1326
+ elementClassName.match(new RegExp("(^|\\s)" + className + "(\\s|$)")))
1327
+ return true;
1328
+ return false;
1329
+ },
1330
+
1331
+ addClassName: function(element, className) {
1332
+ if (!(element = $(element))) return;
1333
+ Element.classNames(element).add(className);
1334
+ return element;
1335
+ },
1336
+
1337
+ removeClassName: function(element, className) {
1338
+ if (!(element = $(element))) return;
1339
+ Element.classNames(element).remove(className);
1340
+ return element;
1341
+ },
1342
+
1343
+ toggleClassName: function(element, className) {
1344
+ if (!(element = $(element))) return;
1345
+ Element.classNames(element)[element.hasClassName(className) ? 'remove' : 'add'](className);
1346
+ return element;
1347
+ },
1348
+
1349
+ observe: function() {
1350
+ Event.observe.apply(Event, arguments);
1351
+ return $A(arguments).first();
1352
+ },
1353
+
1354
+ stopObserving: function() {
1355
+ Event.stopObserving.apply(Event, arguments);
1356
+ return $A(arguments).first();
1357
+ },
1358
+
1359
+ // removes whitespace-only text node children
1360
+ cleanWhitespace: function(element) {
1361
+ element = $(element);
1362
+ var node = element.firstChild;
1363
+ while (node) {
1364
+ var nextNode = node.nextSibling;
1365
+ if (node.nodeType == 3 && !/\S/.test(node.nodeValue))
1366
+ element.removeChild(node);
1367
+ node = nextNode;
1368
+ }
1369
+ return element;
1370
+ },
1371
+
1372
+ empty: function(element) {
1373
+ return $(element).innerHTML.match(/^\s*$/);
1374
+ },
1375
+
1376
+ descendantOf: function(element, ancestor) {
1377
+ element = $(element), ancestor = $(ancestor);
1378
+ while (element = element.parentNode)
1379
+ if (element == ancestor) return true;
1380
+ return false;
1381
+ },
1382
+
1383
+ scrollTo: function(element) {
1384
+ element = $(element);
1385
+ var pos = Position.cumulativeOffset(element);
1386
+ window.scrollTo(pos[0], pos[1]);
1387
+ return element;
1388
+ },
1389
+
1390
+ getStyle: function(element, style) {
1391
+ element = $(element);
1392
+ if (['float','cssFloat'].include(style))
1393
+ style = (typeof element.style.styleFloat != 'undefined' ? 'styleFloat' : 'cssFloat');
1394
+ style = style.camelize();
1395
+ var value = element.style[style];
1396
+ if (!value) {
1397
+ if (document.defaultView && document.defaultView.getComputedStyle) {
1398
+ var css = document.defaultView.getComputedStyle(element, null);
1399
+ value = css ? css[style] : null;
1400
+ } else if (element.currentStyle) {
1401
+ value = element.currentStyle[style];
1402
+ }
1403
+ }
1404
+
1405
+ if((value == 'auto') && ['width','height'].include(style) && (element.getStyle('display') != 'none'))
1406
+ value = element['offset'+style.capitalize()] + 'px';
1407
+
1408
+ if (window.opera && ['left', 'top', 'right', 'bottom'].include(style))
1409
+ if (Element.getStyle(element, 'position') == 'static') value = 'auto';
1410
+ if(style == 'opacity') {
1411
+ if(value) return parseFloat(value);
1412
+ if(value = (element.getStyle('filter') || '').match(/alpha\(opacity=(.*)\)/))
1413
+ if(value[1]) return parseFloat(value[1]) / 100;
1414
+ return 1.0;
1415
+ }
1416
+ return value == 'auto' ? null : value;
1417
+ },
1418
+
1419
+ setStyle: function(element, style) {
1420
+ element = $(element);
1421
+ for (var name in style) {
1422
+ var value = style[name];
1423
+ if(name == 'opacity') {
1424
+ if (value == 1) {
1425
+ value = (/Gecko/.test(navigator.userAgent) &&
1426
+ !/Konqueror|Safari|KHTML/.test(navigator.userAgent)) ? 0.999999 : 1.0;
1427
+ if(/MSIE/.test(navigator.userAgent) && !window.opera)
1428
+ element.style.filter = element.getStyle('filter').replace(/alpha\([^\)]*\)/gi,'');
1429
+ } else if(value == '') {
1430
+ if(/MSIE/.test(navigator.userAgent) && !window.opera)
1431
+ element.style.filter = element.getStyle('filter').replace(/alpha\([^\)]*\)/gi,'');
1432
+ } else {
1433
+ if(value < 0.00001) value = 0;
1434
+ if(/MSIE/.test(navigator.userAgent) && !window.opera)
1435
+ element.style.filter = element.getStyle('filter').replace(/alpha\([^\)]*\)/gi,'') +
1436
+ 'alpha(opacity='+value*100+')';
1437
+ }
1438
+ } else if(['float','cssFloat'].include(name)) name = (typeof element.style.styleFloat != 'undefined') ? 'styleFloat' : 'cssFloat';
1439
+ element.style[name.camelize()] = value;
1440
+ }
1441
+ return element;
1442
+ },
1443
+
1444
+ getDimensions: function(element) {
1445
+ element = $(element);
1446
+ var display = $(element).getStyle('display');
1447
+ if (display != 'none' && display != null) // Safari bug
1448
+ return {width: element.offsetWidth, height: element.offsetHeight};
1449
+
1450
+ // All *Width and *Height properties give 0 on elements with display none,
1451
+ // so enable the element temporarily
1452
+ var els = element.style;
1453
+ var originalVisibility = els.visibility;
1454
+ var originalPosition = els.position;
1455
+ var originalDisplay = els.display;
1456
+ els.visibility = 'hidden';
1457
+ els.position = 'absolute';
1458
+ els.display = 'block';
1459
+ var originalWidth = element.clientWidth;
1460
+ var originalHeight = element.clientHeight;
1461
+ els.display = originalDisplay;
1462
+ els.position = originalPosition;
1463
+ els.visibility = originalVisibility;
1464
+ return {width: originalWidth, height: originalHeight};
1465
+ },
1466
+
1467
+ makePositioned: function(element) {
1468
+ element = $(element);
1469
+ var pos = Element.getStyle(element, 'position');
1470
+ if (pos == 'static' || !pos) {
1471
+ element._madePositioned = true;
1472
+ element.style.position = 'relative';
1473
+ // Opera returns the offset relative to the positioning context, when an
1474
+ // element is position relative but top and left have not been defined
1475
+ if (window.opera) {
1476
+ element.style.top = 0;
1477
+ element.style.left = 0;
1478
+ }
1479
+ }
1480
+ return element;
1481
+ },
1482
+
1483
+ undoPositioned: function(element) {
1484
+ element = $(element);
1485
+ if (element._madePositioned) {
1486
+ element._madePositioned = undefined;
1487
+ element.style.position =
1488
+ element.style.top =
1489
+ element.style.left =
1490
+ element.style.bottom =
1491
+ element.style.right = '';
1492
+ }
1493
+ return element;
1494
+ },
1495
+
1496
+ makeClipping: function(element) {
1497
+ element = $(element);
1498
+ if (element._overflow) return element;
1499
+ element._overflow = element.style.overflow || 'auto';
1500
+ if ((Element.getStyle(element, 'overflow') || 'visible') != 'hidden')
1501
+ element.style.overflow = 'hidden';
1502
+ return element;
1503
+ },
1504
+
1505
+ undoClipping: function(element) {
1506
+ element = $(element);
1507
+ if (!element._overflow) return element;
1508
+ element.style.overflow = element._overflow == 'auto' ? '' : element._overflow;
1509
+ element._overflow = null;
1510
+ return element;
1511
+ }
1512
+ };
1513
+
1514
+ Object.extend(Element.Methods, {childOf: Element.Methods.descendantOf});
1515
+
1516
+ Element._attributeTranslations = {};
1517
+
1518
+ Element._attributeTranslations.names = {
1519
+ colspan: "colSpan",
1520
+ rowspan: "rowSpan",
1521
+ valign: "vAlign",
1522
+ datetime: "dateTime",
1523
+ accesskey: "accessKey",
1524
+ tabindex: "tabIndex",
1525
+ enctype: "encType",
1526
+ maxlength: "maxLength",
1527
+ readonly: "readOnly",
1528
+ longdesc: "longDesc"
1529
+ };
1530
+
1531
+ Element._attributeTranslations.values = {
1532
+ _getAttr: function(element, attribute) {
1533
+ return element.getAttribute(attribute, 2);
1534
+ },
1535
+
1536
+ _flag: function(element, attribute) {
1537
+ return $(element).hasAttribute(attribute) ? attribute : null;
1538
+ },
1539
+
1540
+ style: function(element) {
1541
+ return element.style.cssText.toLowerCase();
1542
+ },
1543
+
1544
+ title: function(element) {
1545
+ var node = element.getAttributeNode('title');
1546
+ return node.specified ? node.nodeValue : null;
1547
+ }
1548
+ };
1549
+
1550
+ Object.extend(Element._attributeTranslations.values, {
1551
+ href: Element._attributeTranslations.values._getAttr,
1552
+ src: Element._attributeTranslations.values._getAttr,
1553
+ disabled: Element._attributeTranslations.values._flag,
1554
+ checked: Element._attributeTranslations.values._flag,
1555
+ readonly: Element._attributeTranslations.values._flag,
1556
+ multiple: Element._attributeTranslations.values._flag
1557
+ });
1558
+
1559
+ Element.Methods.Simulated = {
1560
+ hasAttribute: function(element, attribute) {
1561
+ var t = Element._attributeTranslations;
1562
+ attribute = t.names[attribute] || attribute;
1563
+ return $(element).getAttributeNode(attribute).specified;
1564
+ }
1565
+ };
1566
+
1567
+ // IE is missing .innerHTML support for TABLE-related elements
1568
+ if (document.all && !window.opera){
1569
+ Element.Methods.update = function(element, html) {
1570
+ element = $(element);
1571
+ html = typeof html == 'undefined' ? '' : html.toString();
1572
+ var tagName = element.tagName.toUpperCase();
1573
+ if (['THEAD','TBODY','TR','TD'].include(tagName)) {
1574
+ var div = document.createElement('div');
1575
+ switch (tagName) {
1576
+ case 'THEAD':
1577
+ case 'TBODY':
1578
+ div.innerHTML = '<table><tbody>' + html.stripScripts() + '</tbody></table>';
1579
+ depth = 2;
1580
+ break;
1581
+ case 'TR':
1582
+ div.innerHTML = '<table><tbody><tr>' + html.stripScripts() + '</tr></tbody></table>';
1583
+ depth = 3;
1584
+ break;
1585
+ case 'TD':
1586
+ div.innerHTML = '<table><tbody><tr><td>' + html.stripScripts() + '</td></tr></tbody></table>';
1587
+ depth = 4;
1588
+ }
1589
+ $A(element.childNodes).each(function(node){
1590
+ element.removeChild(node)
1591
+ });
1592
+ depth.times(function(){ div = div.firstChild });
1593
+
1594
+ $A(div.childNodes).each(
1595
+ function(node){ element.appendChild(node) });
1596
+ } else {
1597
+ element.innerHTML = html.stripScripts();
1598
+ }
1599
+ setTimeout(function() {html.evalScripts()}, 10);
1600
+ return element;
1601
+ }
1602
+ };
1603
+
1604
+ Object.extend(Element, Element.Methods);
1605
+
1606
+ var _nativeExtensions = false;
1607
+
1608
+ if(/Konqueror|Safari|KHTML/.test(navigator.userAgent))
1609
+ ['', 'Form', 'Input', 'TextArea', 'Select'].each(function(tag) {
1610
+ var className = 'HTML' + tag + 'Element';
1611
+ if(window[className]) return;
1612
+ var klass = window[className] = {};
1613
+ klass.prototype = document.createElement(tag ? tag.toLowerCase() : 'div').__proto__;
1614
+ });
1615
+
1616
+ Element.addMethods = function(methods) {
1617
+ Object.extend(Element.Methods, methods || {});
1618
+
1619
+ function copy(methods, destination, onlyIfAbsent) {
1620
+ onlyIfAbsent = onlyIfAbsent || false;
1621
+ var cache = Element.extend.cache;
1622
+ for (var property in methods) {
1623
+ var value = methods[property];
1624
+ if (!onlyIfAbsent || !(property in destination))
1625
+ destination[property] = cache.findOrStore(value);
1626
+ }
1627
+ }
1628
+
1629
+ if (typeof HTMLElement != 'undefined') {
1630
+ copy(Element.Methods, HTMLElement.prototype);
1631
+ copy(Element.Methods.Simulated, HTMLElement.prototype, true);
1632
+ copy(Form.Methods, HTMLFormElement.prototype);
1633
+ [HTMLInputElement, HTMLTextAreaElement, HTMLSelectElement].each(function(klass) {
1634
+ copy(Form.Element.Methods, klass.prototype);
1635
+ });
1636
+ _nativeExtensions = true;
1637
+ }
1638
+ }
1639
+
1640
+ var Toggle = new Object();
1641
+ Toggle.display = Element.toggle;
1642
+
1643
+ /*--------------------------------------------------------------------------*/
1644
+
1645
+ Abstract.Insertion = function(adjacency) {
1646
+ this.adjacency = adjacency;
1647
+ }
1648
+
1649
+ Abstract.Insertion.prototype = {
1650
+ initialize: function(element, content) {
1651
+ this.element = $(element);
1652
+ this.content = content.stripScripts();
1653
+
1654
+ if (this.adjacency && this.element.insertAdjacentHTML) {
1655
+ try {
1656
+ this.element.insertAdjacentHTML(this.adjacency, this.content);
1657
+ } catch (e) {
1658
+ var tagName = this.element.tagName.toUpperCase();
1659
+ if (['TBODY', 'TR'].include(tagName)) {
1660
+ this.insertContent(this.contentFromAnonymousTable());
1661
+ } else {
1662
+ throw e;
1663
+ }
1664
+ }
1665
+ } else {
1666
+ this.range = this.element.ownerDocument.createRange();
1667
+ if (this.initializeRange) this.initializeRange();
1668
+ this.insertContent([this.range.createContextualFragment(this.content)]);
1669
+ }
1670
+
1671
+ setTimeout(function() {content.evalScripts()}, 10);
1672
+ },
1673
+
1674
+ contentFromAnonymousTable: function() {
1675
+ var div = document.createElement('div');
1676
+ div.innerHTML = '<table><tbody>' + this.content + '</tbody></table>';
1677
+ return $A(div.childNodes[0].childNodes[0].childNodes);
1678
+ }
1679
+ }
1680
+
1681
+ var Insertion = new Object();
1682
+
1683
+ Insertion.Before = Class.create();
1684
+ Insertion.Before.prototype = Object.extend(new Abstract.Insertion('beforeBegin'), {
1685
+ initializeRange: function() {
1686
+ this.range.setStartBefore(this.element);
1687
+ },
1688
+
1689
+ insertContent: function(fragments) {
1690
+ fragments.each((function(fragment) {
1691
+ this.element.parentNode.insertBefore(fragment, this.element);
1692
+ }).bind(this));
1693
+ }
1694
+ });
1695
+
1696
+ Insertion.Top = Class.create();
1697
+ Insertion.Top.prototype = Object.extend(new Abstract.Insertion('afterBegin'), {
1698
+ initializeRange: function() {
1699
+ this.range.selectNodeContents(this.element);
1700
+ this.range.collapse(true);
1701
+ },
1702
+
1703
+ insertContent: function(fragments) {
1704
+ fragments.reverse(false).each((function(fragment) {
1705
+ this.element.insertBefore(fragment, this.element.firstChild);
1706
+ }).bind(this));
1707
+ }
1708
+ });
1709
+
1710
+ Insertion.Bottom = Class.create();
1711
+ Insertion.Bottom.prototype = Object.extend(new Abstract.Insertion('beforeEnd'), {
1712
+ initializeRange: function() {
1713
+ this.range.selectNodeContents(this.element);
1714
+ this.range.collapse(this.element);
1715
+ },
1716
+
1717
+ insertContent: function(fragments) {
1718
+ fragments.each((function(fragment) {
1719
+ this.element.appendChild(fragment);
1720
+ }).bind(this));
1721
+ }
1722
+ });
1723
+
1724
+ Insertion.After = Class.create();
1725
+ Insertion.After.prototype = Object.extend(new Abstract.Insertion('afterEnd'), {
1726
+ initializeRange: function() {
1727
+ this.range.setStartAfter(this.element);
1728
+ },
1729
+
1730
+ insertContent: function(fragments) {
1731
+ fragments.each((function(fragment) {
1732
+ this.element.parentNode.insertBefore(fragment,
1733
+ this.element.nextSibling);
1734
+ }).bind(this));
1735
+ }
1736
+ });
1737
+
1738
+ /*--------------------------------------------------------------------------*/
1739
+
1740
+ Element.ClassNames = Class.create();
1741
+ Element.ClassNames.prototype = {
1742
+ initialize: function(element) {
1743
+ this.element = $(element);
1744
+ },
1745
+
1746
+ _each: function(iterator) {
1747
+ this.element.className.split(/\s+/).select(function(name) {
1748
+ return name.length > 0;
1749
+ })._each(iterator);
1750
+ },
1751
+
1752
+ set: function(className) {
1753
+ this.element.className = className;
1754
+ },
1755
+
1756
+ add: function(classNameToAdd) {
1757
+ if (this.include(classNameToAdd)) return;
1758
+ this.set($A(this).concat(classNameToAdd).join(' '));
1759
+ },
1760
+
1761
+ remove: function(classNameToRemove) {
1762
+ if (!this.include(classNameToRemove)) return;
1763
+ this.set($A(this).without(classNameToRemove).join(' '));
1764
+ },
1765
+
1766
+ toString: function() {
1767
+ return $A(this).join(' ');
1768
+ }
1769
+ };
1770
+
1771
+ Object.extend(Element.ClassNames.prototype, Enumerable);
1772
+ var Selector = Class.create();
1773
+ Selector.prototype = {
1774
+ initialize: function(expression) {
1775
+ this.params = {classNames: []};
1776
+ this.expression = expression.toString().strip();
1777
+ this.parseExpression();
1778
+ this.compileMatcher();
1779
+ },
1780
+
1781
+ parseExpression: function() {
1782
+ function abort(message) { throw 'Parse error in selector: ' + message; }
1783
+
1784
+ if (this.expression == '') abort('empty expression');
1785
+
1786
+ var params = this.params, expr = this.expression, match, modifier, clause, rest;
1787
+ while (match = expr.match(/^(.*)\[([a-z0-9_:-]+?)(?:([~\|!]?=)(?:"([^"]*)"|([^\]\s]*)))?\]$/i)) {
1788
+ params.attributes = params.attributes || [];
1789
+ params.attributes.push({name: match[2], operator: match[3], value: match[4] || match[5] || ''});
1790
+ expr = match[1];
1791
+ }
1792
+
1793
+ if (expr == '*') return this.params.wildcard = true;
1794
+
1795
+ while (match = expr.match(/^([^a-z0-9_-])?([a-z0-9_-]+)(.*)/i)) {
1796
+ modifier = match[1], clause = match[2], rest = match[3];
1797
+ switch (modifier) {
1798
+ case '#': params.id = clause; break;
1799
+ case '.': params.classNames.push(clause); break;
1800
+ case '':
1801
+ case undefined: params.tagName = clause.toUpperCase(); break;
1802
+ default: abort(expr.inspect());
1803
+ }
1804
+ expr = rest;
1805
+ }
1806
+
1807
+ if (expr.length > 0) abort(expr.inspect());
1808
+ },
1809
+
1810
+ buildMatchExpression: function() {
1811
+ var params = this.params, conditions = [], clause;
1812
+
1813
+ if (params.wildcard)
1814
+ conditions.push('true');
1815
+ if (clause = params.id)
1816
+ conditions.push('element.readAttribute("id") == ' + clause.inspect());
1817
+ if (clause = params.tagName)
1818
+ conditions.push('element.tagName.toUpperCase() == ' + clause.inspect());
1819
+ if ((clause = params.classNames).length > 0)
1820
+ for (var i = 0, length = clause.length; i < length; i++)
1821
+ conditions.push('element.hasClassName(' + clause[i].inspect() + ')');
1822
+ if (clause = params.attributes) {
1823
+ clause.each(function(attribute) {
1824
+ var value = 'element.readAttribute(' + attribute.name.inspect() + ')';
1825
+ var splitValueBy = function(delimiter) {
1826
+ return value + ' && ' + value + '.split(' + delimiter.inspect() + ')';
1827
+ }
1828
+
1829
+ switch (attribute.operator) {
1830
+ case '=': conditions.push(value + ' == ' + attribute.value.inspect()); break;
1831
+ case '~=': conditions.push(splitValueBy(' ') + '.include(' + attribute.value.inspect() + ')'); break;
1832
+ case '|=': conditions.push(
1833
+ splitValueBy('-') + '.first().toUpperCase() == ' + attribute.value.toUpperCase().inspect()
1834
+ ); break;
1835
+ case '!=': conditions.push(value + ' != ' + attribute.value.inspect()); break;
1836
+ case '':
1837
+ case undefined: conditions.push('element.hasAttribute(' + attribute.name.inspect() + ')'); break;
1838
+ default: throw 'Unknown operator ' + attribute.operator + ' in selector';
1839
+ }
1840
+ });
1841
+ }
1842
+
1843
+ return conditions.join(' && ');
1844
+ },
1845
+
1846
+ compileMatcher: function() {
1847
+ this.match = new Function('element', 'if (!element.tagName) return false; \
1848
+ element = $(element); \
1849
+ return ' + this.buildMatchExpression());
1850
+ },
1851
+
1852
+ findElements: function(scope) {
1853
+ var element;
1854
+
1855
+ if (element = $(this.params.id))
1856
+ if (this.match(element))
1857
+ if (!scope || Element.childOf(element, scope))
1858
+ return [element];
1859
+
1860
+ scope = (scope || document).getElementsByTagName(this.params.tagName || '*');
1861
+
1862
+ var results = [];
1863
+ for (var i = 0, length = scope.length; i < length; i++)
1864
+ if (this.match(element = scope[i]))
1865
+ results.push(Element.extend(element));
1866
+
1867
+ return results;
1868
+ },
1869
+
1870
+ toString: function() {
1871
+ return this.expression;
1872
+ }
1873
+ }
1874
+
1875
+ Object.extend(Selector, {
1876
+ matchElements: function(elements, expression) {
1877
+ var selector = new Selector(expression);
1878
+ return elements.select(selector.match.bind(selector)).map(Element.extend);
1879
+ },
1880
+
1881
+ findElement: function(elements, expression, index) {
1882
+ if (typeof expression == 'number') index = expression, expression = false;
1883
+ return Selector.matchElements(elements, expression || '*')[index || 0];
1884
+ },
1885
+
1886
+ findChildElements: function(element, expressions) {
1887
+ return expressions.map(function(expression) {
1888
+ return expression.match(/[^\s"]+(?:"[^"]*"[^\s"]+)*/g).inject([null], function(results, expr) {
1889
+ var selector = new Selector(expr);
1890
+ return results.inject([], function(elements, result) {
1891
+ return elements.concat(selector.findElements(result || element));
1892
+ });
1893
+ });
1894
+ }).flatten();
1895
+ }
1896
+ });
1897
+
1898
+ function $$() {
1899
+ return Selector.findChildElements(document, $A(arguments));
1900
+ }
1901
+ var Form = {
1902
+ reset: function(form) {
1903
+ $(form).reset();
1904
+ return form;
1905
+ },
1906
+
1907
+ serializeElements: function(elements, getHash) {
1908
+ var data = elements.inject({}, function(result, element) {
1909
+ if (!element.disabled && element.name) {
1910
+ var key = element.name, value = $(element).getValue();
1911
+ if (value != undefined) {
1912
+ if (result[key]) {
1913
+ if (result[key].constructor != Array) result[key] = [result[key]];
1914
+ result[key].push(value);
1915
+ }
1916
+ else result[key] = value;
1917
+ }
1918
+ }
1919
+ return result;
1920
+ });
1921
+
1922
+ return getHash ? data : Hash.toQueryString(data);
1923
+ }
1924
+ };
1925
+
1926
+ Form.Methods = {
1927
+ serialize: function(form, getHash) {
1928
+ return Form.serializeElements(Form.getElements(form), getHash);
1929
+ },
1930
+
1931
+ getElements: function(form) {
1932
+ return $A($(form).getElementsByTagName('*')).inject([],
1933
+ function(elements, child) {
1934
+ if (Form.Element.Serializers[child.tagName.toLowerCase()])
1935
+ elements.push(Element.extend(child));
1936
+ return elements;
1937
+ }
1938
+ );
1939
+ },
1940
+
1941
+ getInputs: function(form, typeName, name) {
1942
+ form = $(form);
1943
+ var inputs = form.getElementsByTagName('input');
1944
+
1945
+ if (!typeName && !name) return $A(inputs).map(Element.extend);
1946
+
1947
+ for (var i = 0, matchingInputs = [], length = inputs.length; i < length; i++) {
1948
+ var input = inputs[i];
1949
+ if ((typeName && input.type != typeName) || (name && input.name != name))
1950
+ continue;
1951
+ matchingInputs.push(Element.extend(input));
1952
+ }
1953
+
1954
+ return matchingInputs;
1955
+ },
1956
+
1957
+ disable: function(form) {
1958
+ form = $(form);
1959
+ form.getElements().each(function(element) {
1960
+ element.blur();
1961
+ element.disabled = 'true';
1962
+ });
1963
+ return form;
1964
+ },
1965
+
1966
+ enable: function(form) {
1967
+ form = $(form);
1968
+ form.getElements().each(function(element) {
1969
+ element.disabled = '';
1970
+ });
1971
+ return form;
1972
+ },
1973
+
1974
+ findFirstElement: function(form) {
1975
+ return $(form).getElements().find(function(element) {
1976
+ return element.type != 'hidden' && !element.disabled &&
1977
+ ['input', 'select', 'textarea'].include(element.tagName.toLowerCase());
1978
+ });
1979
+ },
1980
+
1981
+ focusFirstElement: function(form) {
1982
+ form = $(form);
1983
+ form.findFirstElement().activate();
1984
+ return form;
1985
+ }
1986
+ }
1987
+
1988
+ Object.extend(Form, Form.Methods);
1989
+
1990
+ /*--------------------------------------------------------------------------*/
1991
+
1992
+ Form.Element = {
1993
+ focus: function(element) {
1994
+ $(element).focus();
1995
+ return element;
1996
+ },
1997
+
1998
+ select: function(element) {
1999
+ $(element).select();
2000
+ return element;
2001
+ }
2002
+ }
2003
+
2004
+ Form.Element.Methods = {
2005
+ serialize: function(element) {
2006
+ element = $(element);
2007
+ if (!element.disabled && element.name) {
2008
+ var value = element.getValue();
2009
+ if (value != undefined) {
2010
+ var pair = {};
2011
+ pair[element.name] = value;
2012
+ return Hash.toQueryString(pair);
2013
+ }
2014
+ }
2015
+ return '';
2016
+ },
2017
+
2018
+ getValue: function(element) {
2019
+ element = $(element);
2020
+ var method = element.tagName.toLowerCase();
2021
+ return Form.Element.Serializers[method](element);
2022
+ },
2023
+
2024
+ clear: function(element) {
2025
+ $(element).value = '';
2026
+ return element;
2027
+ },
2028
+
2029
+ present: function(element) {
2030
+ return $(element).value != '';
2031
+ },
2032
+
2033
+ activate: function(element) {
2034
+ element = $(element);
2035
+ element.focus();
2036
+ if (element.select && ( element.tagName.toLowerCase() != 'input' ||
2037
+ !['button', 'reset', 'submit'].include(element.type) ) )
2038
+ element.select();
2039
+ return element;
2040
+ },
2041
+
2042
+ disable: function(element) {
2043
+ element = $(element);
2044
+ element.disabled = true;
2045
+ return element;
2046
+ },
2047
+
2048
+ enable: function(element) {
2049
+ element = $(element);
2050
+ element.blur();
2051
+ element.disabled = false;
2052
+ return element;
2053
+ }
2054
+ }
2055
+
2056
+ Object.extend(Form.Element, Form.Element.Methods);
2057
+ var Field = Form.Element;
2058
+ var $F = Form.Element.getValue;
2059
+
2060
+ /*--------------------------------------------------------------------------*/
2061
+
2062
+ Form.Element.Serializers = {
2063
+ input: function(element) {
2064
+ switch (element.type.toLowerCase()) {
2065
+ case 'checkbox':
2066
+ case 'radio':
2067
+ return Form.Element.Serializers.inputSelector(element);
2068
+ default:
2069
+ return Form.Element.Serializers.textarea(element);
2070
+ }
2071
+ },
2072
+
2073
+ inputSelector: function(element) {
2074
+ return element.checked ? element.value : null;
2075
+ },
2076
+
2077
+ textarea: function(element) {
2078
+ return element.value;
2079
+ },
2080
+
2081
+ select: function(element) {
2082
+ return this[element.type == 'select-one' ?
2083
+ 'selectOne' : 'selectMany'](element);
2084
+ },
2085
+
2086
+ selectOne: function(element) {
2087
+ var index = element.selectedIndex;
2088
+ return index >= 0 ? this.optionValue(element.options[index]) : null;
2089
+ },
2090
+
2091
+ selectMany: function(element) {
2092
+ var values, length = element.length;
2093
+ if (!length) return null;
2094
+
2095
+ for (var i = 0, values = []; i < length; i++) {
2096
+ var opt = element.options[i];
2097
+ if (opt.selected) values.push(this.optionValue(opt));
2098
+ }
2099
+ return values;
2100
+ },
2101
+
2102
+ optionValue: function(opt) {
2103
+ // extend element because hasAttribute may not be native
2104
+ return Element.extend(opt).hasAttribute('value') ? opt.value : opt.text;
2105
+ }
2106
+ }
2107
+
2108
+ /*--------------------------------------------------------------------------*/
2109
+
2110
+ Abstract.TimedObserver = function() {}
2111
+ Abstract.TimedObserver.prototype = {
2112
+ initialize: function(element, frequency, callback) {
2113
+ this.frequency = frequency;
2114
+ this.element = $(element);
2115
+ this.callback = callback;
2116
+
2117
+ this.lastValue = this.getValue();
2118
+ this.registerCallback();
2119
+ },
2120
+
2121
+ registerCallback: function() {
2122
+ setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
2123
+ },
2124
+
2125
+ onTimerEvent: function() {
2126
+ var value = this.getValue();
2127
+ var changed = ('string' == typeof this.lastValue && 'string' == typeof value
2128
+ ? this.lastValue != value : String(this.lastValue) != String(value));
2129
+ if (changed) {
2130
+ this.callback(this.element, value);
2131
+ this.lastValue = value;
2132
+ }
2133
+ }
2134
+ }
2135
+
2136
+ Form.Element.Observer = Class.create();
2137
+ Form.Element.Observer.prototype = Object.extend(new Abstract.TimedObserver(), {
2138
+ getValue: function() {
2139
+ return Form.Element.getValue(this.element);
2140
+ }
2141
+ });
2142
+
2143
+ Form.Observer = Class.create();
2144
+ Form.Observer.prototype = Object.extend(new Abstract.TimedObserver(), {
2145
+ getValue: function() {
2146
+ return Form.serialize(this.element);
2147
+ }
2148
+ });
2149
+
2150
+ /*--------------------------------------------------------------------------*/
2151
+
2152
+ Abstract.EventObserver = function() {}
2153
+ Abstract.EventObserver.prototype = {
2154
+ initialize: function(element, callback) {
2155
+ this.element = $(element);
2156
+ this.callback = callback;
2157
+
2158
+ this.lastValue = this.getValue();
2159
+ if (this.element.tagName.toLowerCase() == 'form')
2160
+ this.registerFormCallbacks();
2161
+ else
2162
+ this.registerCallback(this.element);
2163
+ },
2164
+
2165
+ onElementEvent: function() {
2166
+ var value = this.getValue();
2167
+ if (this.lastValue != value) {
2168
+ this.callback(this.element, value);
2169
+ this.lastValue = value;
2170
+ }
2171
+ },
2172
+
2173
+ registerFormCallbacks: function() {
2174
+ Form.getElements(this.element).each(this.registerCallback.bind(this));
2175
+ },
2176
+
2177
+ registerCallback: function(element) {
2178
+ if (element.type) {
2179
+ switch (element.type.toLowerCase()) {
2180
+ case 'checkbox':
2181
+ case 'radio':
2182
+ Event.observe(element, 'click', this.onElementEvent.bind(this));
2183
+ break;
2184
+ default:
2185
+ Event.observe(element, 'change', this.onElementEvent.bind(this));
2186
+ break;
2187
+ }
2188
+ }
2189
+ }
2190
+ }
2191
+
2192
+ Form.Element.EventObserver = Class.create();
2193
+ Form.Element.EventObserver.prototype = Object.extend(new Abstract.EventObserver(), {
2194
+ getValue: function() {
2195
+ return Form.Element.getValue(this.element);
2196
+ }
2197
+ });
2198
+
2199
+ Form.EventObserver = Class.create();
2200
+ Form.EventObserver.prototype = Object.extend(new Abstract.EventObserver(), {
2201
+ getValue: function() {
2202
+ return Form.serialize(this.element);
2203
+ }
2204
+ });
2205
+ if (!window.Event) {
2206
+ var Event = new Object();
2207
+ }
2208
+
2209
+ Object.extend(Event, {
2210
+ KEY_BACKSPACE: 8,
2211
+ KEY_TAB: 9,
2212
+ KEY_RETURN: 13,
2213
+ KEY_ESC: 27,
2214
+ KEY_LEFT: 37,
2215
+ KEY_UP: 38,
2216
+ KEY_RIGHT: 39,
2217
+ KEY_DOWN: 40,
2218
+ KEY_DELETE: 46,
2219
+ KEY_HOME: 36,
2220
+ KEY_END: 35,
2221
+ KEY_PAGEUP: 33,
2222
+ KEY_PAGEDOWN: 34,
2223
+
2224
+ element: function(event) {
2225
+ return event.target || event.srcElement;
2226
+ },
2227
+
2228
+ isLeftClick: function(event) {
2229
+ return (((event.which) && (event.which == 1)) ||
2230
+ ((event.button) && (event.button == 1)));
2231
+ },
2232
+
2233
+ pointerX: function(event) {
2234
+ return event.pageX || (event.clientX +
2235
+ (document.documentElement.scrollLeft || document.body.scrollLeft));
2236
+ },
2237
+
2238
+ pointerY: function(event) {
2239
+ return event.pageY || (event.clientY +
2240
+ (document.documentElement.scrollTop || document.body.scrollTop));
2241
+ },
2242
+
2243
+ stop: function(event) {
2244
+ if (event.preventDefault) {
2245
+ event.preventDefault();
2246
+ event.stopPropagation();
2247
+ } else {
2248
+ event.returnValue = false;
2249
+ event.cancelBubble = true;
2250
+ }
2251
+ },
2252
+
2253
+ // find the first node with the given tagName, starting from the
2254
+ // node the event was triggered on; traverses the DOM upwards
2255
+ findElement: function(event, tagName) {
2256
+ var element = Event.element(event);
2257
+ while (element.parentNode && (!element.tagName ||
2258
+ (element.tagName.toUpperCase() != tagName.toUpperCase())))
2259
+ element = element.parentNode;
2260
+ return element;
2261
+ },
2262
+
2263
+ observers: false,
2264
+
2265
+ _observeAndCache: function(element, name, observer, useCapture) {
2266
+ if (!this.observers) this.observers = [];
2267
+ if (element.addEventListener) {
2268
+ this.observers.push([element, name, observer, useCapture]);
2269
+ element.addEventListener(name, observer, useCapture);
2270
+ } else if (element.attachEvent) {
2271
+ this.observers.push([element, name, observer, useCapture]);
2272
+ element.attachEvent('on' + name, observer);
2273
+ }
2274
+ },
2275
+
2276
+ unloadCache: function() {
2277
+ if (!Event.observers) return;
2278
+ for (var i = 0, length = Event.observers.length; i < length; i++) {
2279
+ Event.stopObserving.apply(this, Event.observers[i]);
2280
+ Event.observers[i][0] = null;
2281
+ }
2282
+ Event.observers = false;
2283
+ },
2284
+
2285
+ observe: function(element, name, observer, useCapture) {
2286
+ element = $(element);
2287
+ useCapture = useCapture || false;
2288
+
2289
+ if (name == 'keypress' &&
2290
+ (navigator.appVersion.match(/Konqueror|Safari|KHTML/)
2291
+ || element.attachEvent))
2292
+ name = 'keydown';
2293
+
2294
+ Event._observeAndCache(element, name, observer, useCapture);
2295
+ },
2296
+
2297
+ stopObserving: function(element, name, observer, useCapture) {
2298
+ element = $(element);
2299
+ useCapture = useCapture || false;
2300
+
2301
+ if (name == 'keypress' &&
2302
+ (navigator.appVersion.match(/Konqueror|Safari|KHTML/)
2303
+ || element.detachEvent))
2304
+ name = 'keydown';
2305
+
2306
+ if (element.removeEventListener) {
2307
+ element.removeEventListener(name, observer, useCapture);
2308
+ } else if (element.detachEvent) {
2309
+ try {
2310
+ element.detachEvent('on' + name, observer);
2311
+ } catch (e) {}
2312
+ }
2313
+ }
2314
+ });
2315
+
2316
+ /* prevent memory leaks in IE */
2317
+ if (navigator.appVersion.match(/\bMSIE\b/))
2318
+ Event.observe(window, 'unload', Event.unloadCache, false);
2319
+ var Position = {
2320
+ // set to true if needed, warning: firefox performance problems
2321
+ // NOT neeeded for page scrolling, only if draggable contained in
2322
+ // scrollable elements
2323
+ includeScrollOffsets: false,
2324
+
2325
+ // must be called before calling withinIncludingScrolloffset, every time the
2326
+ // page is scrolled
2327
+ prepare: function() {
2328
+ this.deltaX = window.pageXOffset
2329
+ || document.documentElement.scrollLeft
2330
+ || document.body.scrollLeft
2331
+ || 0;
2332
+ this.deltaY = window.pageYOffset
2333
+ || document.documentElement.scrollTop
2334
+ || document.body.scrollTop
2335
+ || 0;
2336
+ },
2337
+
2338
+ realOffset: function(element) {
2339
+ var valueT = 0, valueL = 0;
2340
+ do {
2341
+ valueT += element.scrollTop || 0;
2342
+ valueL += element.scrollLeft || 0;
2343
+ element = element.parentNode;
2344
+ } while (element);
2345
+ return [valueL, valueT];
2346
+ },
2347
+
2348
+ cumulativeOffset: function(element) {
2349
+ var valueT = 0, valueL = 0;
2350
+ do {
2351
+ valueT += element.offsetTop || 0;
2352
+ valueL += element.offsetLeft || 0;
2353
+ element = element.offsetParent;
2354
+ } while (element);
2355
+ return [valueL, valueT];
2356
+ },
2357
+
2358
+ positionedOffset: function(element) {
2359
+ var valueT = 0, valueL = 0;
2360
+ do {
2361
+ valueT += element.offsetTop || 0;
2362
+ valueL += element.offsetLeft || 0;
2363
+ element = element.offsetParent;
2364
+ if (element) {
2365
+ if(element.tagName=='BODY') break;
2366
+ var p = Element.getStyle(element, 'position');
2367
+ if (p == 'relative' || p == 'absolute') break;
2368
+ }
2369
+ } while (element);
2370
+ return [valueL, valueT];
2371
+ },
2372
+
2373
+ offsetParent: function(element) {
2374
+ if (element.offsetParent) return element.offsetParent;
2375
+ if (element == document.body) return element;
2376
+
2377
+ while ((element = element.parentNode) && element != document.body)
2378
+ if (Element.getStyle(element, 'position') != 'static')
2379
+ return element;
2380
+
2381
+ return document.body;
2382
+ },
2383
+
2384
+ // caches x/y coordinate pair to use with overlap
2385
+ within: function(element, x, y) {
2386
+ if (this.includeScrollOffsets)
2387
+ return this.withinIncludingScrolloffsets(element, x, y);
2388
+ this.xcomp = x;
2389
+ this.ycomp = y;
2390
+ this.offset = this.cumulativeOffset(element);
2391
+
2392
+ return (y >= this.offset[1] &&
2393
+ y < this.offset[1] + element.offsetHeight &&
2394
+ x >= this.offset[0] &&
2395
+ x < this.offset[0] + element.offsetWidth);
2396
+ },
2397
+
2398
+ withinIncludingScrolloffsets: function(element, x, y) {
2399
+ var offsetcache = this.realOffset(element);
2400
+
2401
+ this.xcomp = x + offsetcache[0] - this.deltaX;
2402
+ this.ycomp = y + offsetcache[1] - this.deltaY;
2403
+ this.offset = this.cumulativeOffset(element);
2404
+
2405
+ return (this.ycomp >= this.offset[1] &&
2406
+ this.ycomp < this.offset[1] + element.offsetHeight &&
2407
+ this.xcomp >= this.offset[0] &&
2408
+ this.xcomp < this.offset[0] + element.offsetWidth);
2409
+ },
2410
+
2411
+ // within must be called directly before
2412
+ overlap: function(mode, element) {
2413
+ if (!mode) return 0;
2414
+ if (mode == 'vertical')
2415
+ return ((this.offset[1] + element.offsetHeight) - this.ycomp) /
2416
+ element.offsetHeight;
2417
+ if (mode == 'horizontal')
2418
+ return ((this.offset[0] + element.offsetWidth) - this.xcomp) /
2419
+ element.offsetWidth;
2420
+ },
2421
+
2422
+ page: function(forElement) {
2423
+ var valueT = 0, valueL = 0;
2424
+
2425
+ var element = forElement;
2426
+ do {
2427
+ valueT += element.offsetTop || 0;
2428
+ valueL += element.offsetLeft || 0;
2429
+
2430
+ // Safari fix
2431
+ if (element.offsetParent==document.body)
2432
+ if (Element.getStyle(element,'position')=='absolute') break;
2433
+
2434
+ } while (element = element.offsetParent);
2435
+
2436
+ element = forElement;
2437
+ do {
2438
+ if (!window.opera || element.tagName=='BODY') {
2439
+ valueT -= element.scrollTop || 0;
2440
+ valueL -= element.scrollLeft || 0;
2441
+ }
2442
+ } while (element = element.parentNode);
2443
+
2444
+ return [valueL, valueT];
2445
+ },
2446
+
2447
+ clone: function(source, target) {
2448
+ var options = Object.extend({
2449
+ setLeft: true,
2450
+ setTop: true,
2451
+ setWidth: true,
2452
+ setHeight: true,
2453
+ offsetTop: 0,
2454
+ offsetLeft: 0
2455
+ }, arguments[2] || {})
2456
+
2457
+ // find page position of source
2458
+ source = $(source);
2459
+ var p = Position.page(source);
2460
+
2461
+ // find coordinate system to use
2462
+ target = $(target);
2463
+ var delta = [0, 0];
2464
+ var parent = null;
2465
+ // delta [0,0] will do fine with position: fixed elements,
2466
+ // position:absolute needs offsetParent deltas
2467
+ if (Element.getStyle(target,'position') == 'absolute') {
2468
+ parent = Position.offsetParent(target);
2469
+ delta = Position.page(parent);
2470
+ }
2471
+
2472
+ // correct by body offsets (fixes Safari)
2473
+ if (parent == document.body) {
2474
+ delta[0] -= document.body.offsetLeft;
2475
+ delta[1] -= document.body.offsetTop;
2476
+ }
2477
+
2478
+ // set position
2479
+ if(options.setLeft) target.style.left = (p[0] - delta[0] + options.offsetLeft) + 'px';
2480
+ if(options.setTop) target.style.top = (p[1] - delta[1] + options.offsetTop) + 'px';
2481
+ if(options.setWidth) target.style.width = source.offsetWidth + 'px';
2482
+ if(options.setHeight) target.style.height = source.offsetHeight + 'px';
2483
+ },
2484
+
2485
+ absolutize: function(element) {
2486
+ element = $(element);
2487
+ if (element.style.position == 'absolute') return;
2488
+ Position.prepare();
2489
+
2490
+ var offsets = Position.positionedOffset(element);
2491
+ var top = offsets[1];
2492
+ var left = offsets[0];
2493
+ var width = element.clientWidth;
2494
+ var height = element.clientHeight;
2495
+
2496
+ element._originalLeft = left - parseFloat(element.style.left || 0);
2497
+ element._originalTop = top - parseFloat(element.style.top || 0);
2498
+ element._originalWidth = element.style.width;
2499
+ element._originalHeight = element.style.height;
2500
+
2501
+ element.style.position = 'absolute';
2502
+ element.style.top = top + 'px';
2503
+ element.style.left = left + 'px';
2504
+ element.style.width = width + 'px';
2505
+ element.style.height = height + 'px';
2506
+ },
2507
+
2508
+ relativize: function(element) {
2509
+ element = $(element);
2510
+ if (element.style.position == 'relative') return;
2511
+ Position.prepare();
2512
+
2513
+ element.style.position = 'relative';
2514
+ var top = parseFloat(element.style.top || 0) - (element._originalTop || 0);
2515
+ var left = parseFloat(element.style.left || 0) - (element._originalLeft || 0);
2516
+
2517
+ element.style.top = top + 'px';
2518
+ element.style.left = left + 'px';
2519
+ element.style.height = element._originalHeight;
2520
+ element.style.width = element._originalWidth;
2521
+ }
2522
+ }
2523
+
2524
+ // Safari returns margins on body which is incorrect if the child is absolutely
2525
+ // positioned. For performance reasons, redefine Position.cumulativeOffset for
2526
+ // KHTML/WebKit only.
2527
+ if (/Konqueror|Safari|KHTML/.test(navigator.userAgent)) {
2528
+ Position.cumulativeOffset = function(element) {
2529
+ var valueT = 0, valueL = 0;
2530
+ do {
2531
+ valueT += element.offsetTop || 0;
2532
+ valueL += element.offsetLeft || 0;
2533
+ if (element.offsetParent == document.body)
2534
+ if (Element.getStyle(element, 'position') == 'absolute') break;
2535
+
2536
+ element = element.offsetParent;
2537
+ } while (element);
2538
+
2539
+ return [valueL, valueT];
2540
+ }
2541
+ }
2542
+
2543
+ Element.addMethods();
2544
+
2545
+
2546
+ // ------------------------------------------------------------------------
2547
+ // ------------------------------------------------------------------------
2548
+
2549
+ // The rest of this file is the actual ray tracer written by Adam
2550
+ // Burmister. It's a concatenation of the following files:
2551
+ //
2552
+ // flog/color.js
2553
+ // flog/light.js
2554
+ // flog/vector.js
2555
+ // flog/ray.js
2556
+ // flog/scene.js
2557
+ // flog/material/basematerial.js
2558
+ // flog/material/solid.js
2559
+ // flog/material/chessboard.js
2560
+ // flog/shape/baseshape.js
2561
+ // flog/shape/sphere.js
2562
+ // flog/shape/plane.js
2563
+ // flog/intersectioninfo.js
2564
+ // flog/camera.js
2565
+ // flog/background.js
2566
+ // flog/engine.js
2567
+
2568
+
2569
+ /* Fake a Flog.* namespace */
2570
+ if(typeof(Flog) == 'undefined') var Flog = {};
2571
+ if(typeof(Flog.RayTracer) == 'undefined') Flog.RayTracer = {};
2572
+
2573
+ Flog.RayTracer.Color = Class.create();
2574
+
2575
+ Flog.RayTracer.Color.prototype = {
2576
+ red : 0.0,
2577
+ green : 0.0,
2578
+ blue : 0.0,
2579
+
2580
+ initialize : function(r, g, b) {
2581
+ if(!r) r = 0.0;
2582
+ if(!g) g = 0.0;
2583
+ if(!b) b = 0.0;
2584
+
2585
+ this.red = r;
2586
+ this.green = g;
2587
+ this.blue = b;
2588
+ },
2589
+
2590
+ add : function(c1, c2){
2591
+ var result = new Flog.RayTracer.Color(0,0,0);
2592
+
2593
+ result.red = c1.red + c2.red;
2594
+ result.green = c1.green + c2.green;
2595
+ result.blue = c1.blue + c2.blue;
2596
+
2597
+ return result;
2598
+ },
2599
+
2600
+ addScalar: function(c1, s){
2601
+ var result = new Flog.RayTracer.Color(0,0,0);
2602
+
2603
+ result.red = c1.red + s;
2604
+ result.green = c1.green + s;
2605
+ result.blue = c1.blue + s;
2606
+
2607
+ result.limit();
2608
+
2609
+ return result;
2610
+ },
2611
+
2612
+ subtract: function(c1, c2){
2613
+ var result = new Flog.RayTracer.Color(0,0,0);
2614
+
2615
+ result.red = c1.red - c2.red;
2616
+ result.green = c1.green - c2.green;
2617
+ result.blue = c1.blue - c2.blue;
2618
+
2619
+ return result;
2620
+ },
2621
+
2622
+ multiply : function(c1, c2) {
2623
+ var result = new Flog.RayTracer.Color(0,0,0);
2624
+
2625
+ result.red = c1.red * c2.red;
2626
+ result.green = c1.green * c2.green;
2627
+ result.blue = c1.blue * c2.blue;
2628
+
2629
+ return result;
2630
+ },
2631
+
2632
+ multiplyScalar : function(c1, f) {
2633
+ var result = new Flog.RayTracer.Color(0,0,0);
2634
+
2635
+ result.red = c1.red * f;
2636
+ result.green = c1.green * f;
2637
+ result.blue = c1.blue * f;
2638
+
2639
+ return result;
2640
+ },
2641
+
2642
+ divideFactor : function(c1, f) {
2643
+ var result = new Flog.RayTracer.Color(0,0,0);
2644
+
2645
+ result.red = c1.red / f;
2646
+ result.green = c1.green / f;
2647
+ result.blue = c1.blue / f;
2648
+
2649
+ return result;
2650
+ },
2651
+
2652
+ limit: function(){
2653
+ this.red = (this.red > 0.0) ? ( (this.red > 1.0) ? 1.0 : this.red ) : 0.0;
2654
+ this.green = (this.green > 0.0) ? ( (this.green > 1.0) ? 1.0 : this.green ) : 0.0;
2655
+ this.blue = (this.blue > 0.0) ? ( (this.blue > 1.0) ? 1.0 : this.blue ) : 0.0;
2656
+ },
2657
+
2658
+ distance : function(color) {
2659
+ var d = Math.abs(this.red - color.red) + Math.abs(this.green - color.green) + Math.abs(this.blue - color.blue);
2660
+ return d;
2661
+ },
2662
+
2663
+ blend: function(c1, c2, w){
2664
+ var result = new Flog.RayTracer.Color(0,0,0);
2665
+ result = Flog.RayTracer.Color.prototype.add(
2666
+ Flog.RayTracer.Color.prototype.multiplyScalar(c1, 1 - w),
2667
+ Flog.RayTracer.Color.prototype.multiplyScalar(c2, w)
2668
+ );
2669
+ return result;
2670
+ },
2671
+
2672
+ toString : function () {
2673
+ var r = Math.floor(this.red*255);
2674
+ var g = Math.floor(this.green*255);
2675
+ var b = Math.floor(this.blue*255);
2676
+
2677
+ return "rgb("+ r +","+ g +","+ b +")";
2678
+ }
2679
+ }
2680
+ /* Fake a Flog.* namespace */
2681
+ if(typeof(Flog) == 'undefined') var Flog = {};
2682
+ if(typeof(Flog.RayTracer) == 'undefined') Flog.RayTracer = {};
2683
+
2684
+ Flog.RayTracer.Light = Class.create();
2685
+
2686
+ Flog.RayTracer.Light.prototype = {
2687
+ position: null,
2688
+ color: null,
2689
+ intensity: 10.0,
2690
+
2691
+ initialize : function(pos, color, intensity) {
2692
+ this.position = pos;
2693
+ this.color = color;
2694
+ this.intensity = (intensity ? intensity : 10.0);
2695
+ },
2696
+
2697
+ getIntensity: function(distance){
2698
+ if(distance >= intensity) return 0;
2699
+
2700
+ return Math.pow((intensity - distance) / strength, 0.2);
2701
+ },
2702
+
2703
+ toString : function () {
2704
+ return 'Light [' + this.position.x + ',' + this.position.y + ',' + this.position.z + ']';
2705
+ }
2706
+ }
2707
+ /* Fake a Flog.* namespace */
2708
+ if(typeof(Flog) == 'undefined') var Flog = {};
2709
+ if(typeof(Flog.RayTracer) == 'undefined') Flog.RayTracer = {};
2710
+
2711
+ Flog.RayTracer.Vector = Class.create();
2712
+
2713
+ Flog.RayTracer.Vector.prototype = {
2714
+ x : 0.0,
2715
+ y : 0.0,
2716
+ z : 0.0,
2717
+
2718
+ initialize : function(x, y, z) {
2719
+ this.x = (x ? x : 0);
2720
+ this.y = (y ? y : 0);
2721
+ this.z = (z ? z : 0);
2722
+ },
2723
+
2724
+ copy: function(vector){
2725
+ this.x = vector.x;
2726
+ this.y = vector.y;
2727
+ this.z = vector.z;
2728
+ },
2729
+
2730
+ normalize : function() {
2731
+ var m = this.magnitude();
2732
+ return new Flog.RayTracer.Vector(this.x / m, this.y / m, this.z / m);
2733
+ },
2734
+
2735
+ magnitude : function() {
2736
+ return Math.sqrt((this.x * this.x) + (this.y * this.y) + (this.z * this.z));
2737
+ },
2738
+
2739
+ cross : function(w) {
2740
+ return new Flog.RayTracer.Vector(
2741
+ -this.z * w.y + this.y * w.z,
2742
+ this.z * w.x - this.x * w.z,
2743
+ -this.y * w.x + this.x * w.y);
2744
+ },
2745
+
2746
+ dot : function(w) {
2747
+ return this.x * w.x + this.y * w.y + this.z * w.z;
2748
+ },
2749
+
2750
+ add : function(v, w) {
2751
+ return new Flog.RayTracer.Vector(w.x + v.x, w.y + v.y, w.z + v.z);
2752
+ },
2753
+
2754
+ subtract : function(v, w) {
2755
+ if(!w || !v) throw 'Vectors must be defined [' + v + ',' + w + ']';
2756
+ return new Flog.RayTracer.Vector(v.x - w.x, v.y - w.y, v.z - w.z);
2757
+ },
2758
+
2759
+ multiplyVector : function(v, w) {
2760
+ return new Flog.RayTracer.Vector(v.x * w.x, v.y * w.y, v.z * w.z);
2761
+ },
2762
+
2763
+ multiplyScalar : function(v, w) {
2764
+ return new Flog.RayTracer.Vector(v.x * w, v.y * w, v.z * w);
2765
+ },
2766
+
2767
+ toString : function () {
2768
+ return 'Vector [' + this.x + ',' + this.y + ',' + this.z + ']';
2769
+ }
2770
+ }
2771
+ /* Fake a Flog.* namespace */
2772
+ if(typeof(Flog) == 'undefined') var Flog = {};
2773
+ if(typeof(Flog.RayTracer) == 'undefined') Flog.RayTracer = {};
2774
+
2775
+ Flog.RayTracer.Ray = Class.create();
2776
+
2777
+ Flog.RayTracer.Ray.prototype = {
2778
+ position : null,
2779
+ direction : null,
2780
+ initialize : function(pos, dir) {
2781
+ this.position = pos;
2782
+ this.direction = dir;
2783
+ },
2784
+
2785
+ toString : function () {
2786
+ return 'Ray [' + this.position + ',' + this.direction + ']';
2787
+ }
2788
+ }
2789
+ /* Fake a Flog.* namespace */
2790
+ if(typeof(Flog) == 'undefined') var Flog = {};
2791
+ if(typeof(Flog.RayTracer) == 'undefined') Flog.RayTracer = {};
2792
+
2793
+ Flog.RayTracer.Scene = Class.create();
2794
+
2795
+ Flog.RayTracer.Scene.prototype = {
2796
+ camera : null,
2797
+ shapes : [],
2798
+ lights : [],
2799
+ background : null,
2800
+
2801
+ initialize : function() {
2802
+ this.camera = new Flog.RayTracer.Camera(
2803
+ new Flog.RayTracer.Vector(0,0,-5),
2804
+ new Flog.RayTracer.Vector(0,0,1),
2805
+ new Flog.RayTracer.Vector(0,1,0)
2806
+ );
2807
+ this.shapes = new Array();
2808
+ this.lights = new Array();
2809
+ this.background = new Flog.RayTracer.Background(new Flog.RayTracer.Color(0,0,0.5), 0.2);
2810
+ }
2811
+ }
2812
+ /* Fake a Flog.* namespace */
2813
+ if(typeof(Flog) == 'undefined') var Flog = {};
2814
+ if(typeof(Flog.RayTracer) == 'undefined') Flog.RayTracer = {};
2815
+ if(typeof(Flog.RayTracer.Material) == 'undefined') Flog.RayTracer.Material = {};
2816
+
2817
+ Flog.RayTracer.Material.BaseMaterial = Class.create();
2818
+
2819
+ Flog.RayTracer.Material.BaseMaterial.prototype = {
2820
+
2821
+ gloss: 2.0, // [0...infinity] 0 = matt
2822
+ transparency: 0.0, // 0=opaque
2823
+ reflection: 0.0, // [0...infinity] 0 = no reflection
2824
+ refraction: 0.50,
2825
+ hasTexture: false,
2826
+
2827
+ initialize : function() {
2828
+
2829
+ },
2830
+
2831
+ getColor: function(u, v){
2832
+
2833
+ },
2834
+
2835
+ wrapUp: function(t){
2836
+ t = t % 2.0;
2837
+ if(t < -1) t += 2.0;
2838
+ if(t >= 1) t -= 2.0;
2839
+ return t;
2840
+ },
2841
+
2842
+ toString : function () {
2843
+ return 'Material [gloss=' + this.gloss + ', transparency=' + this.transparency + ', hasTexture=' + this.hasTexture +']';
2844
+ }
2845
+ }
2846
+ /* Fake a Flog.* namespace */
2847
+ if(typeof(Flog) == 'undefined') var Flog = {};
2848
+ if(typeof(Flog.RayTracer) == 'undefined') Flog.RayTracer = {};
2849
+
2850
+ Flog.RayTracer.Material.Solid = Class.create();
2851
+
2852
+ Flog.RayTracer.Material.Solid.prototype = Object.extend(
2853
+ new Flog.RayTracer.Material.BaseMaterial(), {
2854
+ initialize : function(color, reflection, refraction, transparency, gloss) {
2855
+ this.color = color;
2856
+ this.reflection = reflection;
2857
+ this.transparency = transparency;
2858
+ this.gloss = gloss;
2859
+ this.hasTexture = false;
2860
+ },
2861
+
2862
+ getColor: function(u, v){
2863
+ return this.color;
2864
+ },
2865
+
2866
+ toString : function () {
2867
+ return 'SolidMaterial [gloss=' + this.gloss + ', transparency=' + this.transparency + ', hasTexture=' + this.hasTexture +']';
2868
+ }
2869
+ }
2870
+ );
2871
+ /* Fake a Flog.* namespace */
2872
+ if(typeof(Flog) == 'undefined') var Flog = {};
2873
+ if(typeof(Flog.RayTracer) == 'undefined') Flog.RayTracer = {};
2874
+
2875
+ Flog.RayTracer.Material.Chessboard = Class.create();
2876
+
2877
+ Flog.RayTracer.Material.Chessboard.prototype = Object.extend(
2878
+ new Flog.RayTracer.Material.BaseMaterial(), {
2879
+ colorEven: null,
2880
+ colorOdd: null,
2881
+ density: 0.5,
2882
+
2883
+ initialize : function(colorEven, colorOdd, reflection, transparency, gloss, density) {
2884
+ this.colorEven = colorEven;
2885
+ this.colorOdd = colorOdd;
2886
+ this.reflection = reflection;
2887
+ this.transparency = transparency;
2888
+ this.gloss = gloss;
2889
+ this.density = density;
2890
+ this.hasTexture = true;
2891
+ },
2892
+
2893
+ getColor: function(u, v){
2894
+ var t = this.wrapUp(u * this.density) * this.wrapUp(v * this.density);
2895
+
2896
+ if(t < 0.0)
2897
+ return this.colorEven;
2898
+ else
2899
+ return this.colorOdd;
2900
+ },
2901
+
2902
+ toString : function () {
2903
+ return 'ChessMaterial [gloss=' + this.gloss + ', transparency=' + this.transparency + ', hasTexture=' + this.hasTexture +']';
2904
+ }
2905
+ }
2906
+ );
2907
+ /* Fake a Flog.* namespace */
2908
+ if(typeof(Flog) == 'undefined') var Flog = {};
2909
+ if(typeof(Flog.RayTracer) == 'undefined') Flog.RayTracer = {};
2910
+ if(typeof(Flog.RayTracer.Shape) == 'undefined') Flog.RayTracer.Shape = {};
2911
+
2912
+ Flog.RayTracer.Shape.BaseShape = Class.create();
2913
+
2914
+ Flog.RayTracer.Shape.BaseShape.prototype = {
2915
+ position: null,
2916
+ material: null,
2917
+
2918
+ initialize : function() {
2919
+ this.position = new Vector(0,0,0);
2920
+ this.material = new Flog.RayTracer.Material.SolidMaterial(
2921
+ new Flog.RayTracer.Color(1,0,1),
2922
+ 0,
2923
+ 0,
2924
+ 0
2925
+ );
2926
+ },
2927
+
2928
+ toString : function () {
2929
+ return 'Material [gloss=' + this.gloss + ', transparency=' + this.transparency + ', hasTexture=' + this.hasTexture +']';
2930
+ }
2931
+ }
2932
+ /* Fake a Flog.* namespace */
2933
+ if(typeof(Flog) == 'undefined') var Flog = {};
2934
+ if(typeof(Flog.RayTracer) == 'undefined') Flog.RayTracer = {};
2935
+ if(typeof(Flog.RayTracer.Shape) == 'undefined') Flog.RayTracer.Shape = {};
2936
+
2937
+ Flog.RayTracer.Shape.Sphere = Class.create();
2938
+
2939
+ Flog.RayTracer.Shape.Sphere.prototype = {
2940
+ initialize : function(pos, radius, material) {
2941
+ this.radius = radius;
2942
+ this.position = pos;
2943
+ this.material = material;
2944
+ },
2945
+
2946
+ intersect: function(ray){
2947
+ var info = new Flog.RayTracer.IntersectionInfo();
2948
+ info.shape = this;
2949
+
2950
+ var dst = Flog.RayTracer.Vector.prototype.subtract(ray.position, this.position);
2951
+
2952
+ var B = dst.dot(ray.direction);
2953
+ var C = dst.dot(dst) - (this.radius * this.radius);
2954
+ var D = (B * B) - C;
2955
+
2956
+ if(D > 0){ // intersection!
2957
+ info.isHit = true;
2958
+ info.distance = (-B) - Math.sqrt(D);
2959
+ info.position = Flog.RayTracer.Vector.prototype.add(
2960
+ ray.position,
2961
+ Flog.RayTracer.Vector.prototype.multiplyScalar(
2962
+ ray.direction,
2963
+ info.distance
2964
+ )
2965
+ );
2966
+ info.normal = Flog.RayTracer.Vector.prototype.subtract(
2967
+ info.position,
2968
+ this.position
2969
+ ).normalize();
2970
+
2971
+ info.color = this.material.getColor(0,0);
2972
+ } else {
2973
+ info.isHit = false;
2974
+ }
2975
+ return info;
2976
+ },
2977
+
2978
+ toString : function () {
2979
+ return 'Sphere [position=' + this.position + ', radius=' + this.radius + ']';
2980
+ }
2981
+ }
2982
+ /* Fake a Flog.* namespace */
2983
+ if(typeof(Flog) == 'undefined') var Flog = {};
2984
+ if(typeof(Flog.RayTracer) == 'undefined') Flog.RayTracer = {};
2985
+ if(typeof(Flog.RayTracer.Shape) == 'undefined') Flog.RayTracer.Shape = {};
2986
+
2987
+ Flog.RayTracer.Shape.Plane = Class.create();
2988
+
2989
+ Flog.RayTracer.Shape.Plane.prototype = {
2990
+ d: 0.0,
2991
+
2992
+ initialize : function(pos, d, material) {
2993
+ this.position = pos;
2994
+ this.d = d;
2995
+ this.material = material;
2996
+ },
2997
+
2998
+ intersect: function(ray){
2999
+ var info = new Flog.RayTracer.IntersectionInfo();
3000
+
3001
+ var Vd = this.position.dot(ray.direction);
3002
+ if(Vd == 0) return info; // no intersection
3003
+
3004
+ var t = -(this.position.dot(ray.position) + this.d) / Vd;
3005
+ if(t <= 0) return info;
3006
+
3007
+ info.shape = this;
3008
+ info.isHit = true;
3009
+ info.position = Flog.RayTracer.Vector.prototype.add(
3010
+ ray.position,
3011
+ Flog.RayTracer.Vector.prototype.multiplyScalar(
3012
+ ray.direction,
3013
+ t
3014
+ )
3015
+ );
3016
+ info.normal = this.position;
3017
+ info.distance = t;
3018
+
3019
+ if(this.material.hasTexture){
3020
+ var vU = new Flog.RayTracer.Vector(this.position.y, this.position.z, -this.position.x);
3021
+ var vV = vU.cross(this.position);
3022
+ var u = info.position.dot(vU);
3023
+ var v = info.position.dot(vV);
3024
+ info.color = this.material.getColor(u,v);
3025
+ } else {
3026
+ info.color = this.material.getColor(0,0);
3027
+ }
3028
+
3029
+ return info;
3030
+ },
3031
+
3032
+ toString : function () {
3033
+ return 'Plane [' + this.position + ', d=' + this.d + ']';
3034
+ }
3035
+ }
3036
+ /* Fake a Flog.* namespace */
3037
+ if(typeof(Flog) == 'undefined') var Flog = {};
3038
+ if(typeof(Flog.RayTracer) == 'undefined') Flog.RayTracer = {};
3039
+
3040
+ Flog.RayTracer.IntersectionInfo = Class.create();
3041
+
3042
+ Flog.RayTracer.IntersectionInfo.prototype = {
3043
+ isHit: false,
3044
+ hitCount: 0,
3045
+ shape: null,
3046
+ position: null,
3047
+ normal: null,
3048
+ color: null,
3049
+ distance: null,
3050
+
3051
+ initialize : function() {
3052
+ this.color = new Flog.RayTracer.Color(0,0,0);
3053
+ },
3054
+
3055
+ toString : function () {
3056
+ return 'Intersection [' + this.position + ']';
3057
+ }
3058
+ }
3059
+ /* Fake a Flog.* namespace */
3060
+ if(typeof(Flog) == 'undefined') var Flog = {};
3061
+ if(typeof(Flog.RayTracer) == 'undefined') Flog.RayTracer = {};
3062
+
3063
+ Flog.RayTracer.Camera = Class.create();
3064
+
3065
+ Flog.RayTracer.Camera.prototype = {
3066
+ position: null,
3067
+ lookAt: null,
3068
+ equator: null,
3069
+ up: null,
3070
+ screen: null,
3071
+
3072
+ initialize : function(pos, lookAt, up) {
3073
+ this.position = pos;
3074
+ this.lookAt = lookAt;
3075
+ this.up = up;
3076
+ this.equator = lookAt.normalize().cross(this.up);
3077
+ this.screen = Flog.RayTracer.Vector.prototype.add(this.position, this.lookAt);
3078
+ },
3079
+
3080
+ getRay: function(vx, vy){
3081
+ var pos = Flog.RayTracer.Vector.prototype.subtract(
3082
+ this.screen,
3083
+ Flog.RayTracer.Vector.prototype.subtract(
3084
+ Flog.RayTracer.Vector.prototype.multiplyScalar(this.equator, vx),
3085
+ Flog.RayTracer.Vector.prototype.multiplyScalar(this.up, vy)
3086
+ )
3087
+ );
3088
+ pos.y = pos.y * -1;
3089
+ var dir = Flog.RayTracer.Vector.prototype.subtract(
3090
+ pos,
3091
+ this.position
3092
+ );
3093
+
3094
+ var ray = new Flog.RayTracer.Ray(pos, dir.normalize());
3095
+
3096
+ return ray;
3097
+ },
3098
+
3099
+ toString : function () {
3100
+ return 'Ray []';
3101
+ }
3102
+ }
3103
+ /* Fake a Flog.* namespace */
3104
+ if(typeof(Flog) == 'undefined') var Flog = {};
3105
+ if(typeof(Flog.RayTracer) == 'undefined') Flog.RayTracer = {};
3106
+
3107
+ Flog.RayTracer.Background = Class.create();
3108
+
3109
+ Flog.RayTracer.Background.prototype = {
3110
+ color : null,
3111
+ ambience : 0.0,
3112
+
3113
+ initialize : function(color, ambience) {
3114
+ this.color = color;
3115
+ this.ambience = ambience;
3116
+ }
3117
+ }
3118
+ /* Fake a Flog.* namespace */
3119
+ if(typeof(Flog) == 'undefined') var Flog = {};
3120
+ if(typeof(Flog.RayTracer) == 'undefined') Flog.RayTracer = {};
3121
+
3122
+ Flog.RayTracer.Engine = Class.create();
3123
+
3124
+ Flog.RayTracer.Engine.prototype = {
3125
+ canvas: null, /* 2d context we can render to */
3126
+
3127
+ initialize: function(options){
3128
+ this.options = Object.extend({
3129
+ canvasHeight: 100,
3130
+ canvasWidth: 100,
3131
+ pixelWidth: 2,
3132
+ pixelHeight: 2,
3133
+ renderDiffuse: false,
3134
+ renderShadows: false,
3135
+ renderHighlights: false,
3136
+ renderReflections: false,
3137
+ rayDepth: 2
3138
+ }, options || {});
3139
+
3140
+ this.options.canvasHeight /= this.options.pixelHeight;
3141
+ this.options.canvasWidth /= this.options.pixelWidth;
3142
+
3143
+ /* TODO: dynamically include other scripts */
3144
+ },
3145
+
3146
+ setPixel: function(x, y, color){
3147
+ var pxW, pxH;
3148
+ pxW = this.options.pixelWidth;
3149
+ pxH = this.options.pixelHeight;
3150
+
3151
+ if (this.canvas) {
3152
+ this.canvas.fillStyle = color.toString();
3153
+ this.canvas.fillRect (x * pxW, y * pxH, pxW, pxH);
3154
+ } else {
3155
+ // print(x * pxW, y * pxH, pxW, pxH);
3156
+ }
3157
+ },
3158
+
3159
+ renderScene: function(scene, canvas){
3160
+ /* Get canvas */
3161
+ if (canvas) {
3162
+ this.canvas = canvas.getContext("2d");
3163
+ } else {
3164
+ this.canvas = null;
3165
+ }
3166
+
3167
+ var canvasHeight = this.options.canvasHeight;
3168
+ var canvasWidth = this.options.canvasWidth;
3169
+
3170
+ for(var y=0; y < canvasHeight; y++){
3171
+ for(var x=0; x < canvasWidth; x++){
3172
+ var yp = y * 1.0 / canvasHeight * 2 - 1;
3173
+ var xp = x * 1.0 / canvasWidth * 2 - 1;
3174
+
3175
+ var ray = scene.camera.getRay(xp, yp);
3176
+
3177
+ var color = this.getPixelColor(ray, scene);
3178
+
3179
+ this.setPixel(x, y, color);
3180
+ }
3181
+ }
3182
+ },
3183
+
3184
+ getPixelColor: function(ray, scene){
3185
+ var info = this.testIntersection(ray, scene, null);
3186
+ if(info.isHit){
3187
+ var color = this.rayTrace(info, ray, scene, 0);
3188
+ return color;
3189
+ }
3190
+ return scene.background.color;
3191
+ },
3192
+
3193
+ testIntersection: function(ray, scene, exclude){
3194
+ var hits = 0;
3195
+ var best = new Flog.RayTracer.IntersectionInfo();
3196
+ best.distance = 2000;
3197
+
3198
+ for(var i=0; i<scene.shapes.length; i++){
3199
+ var shape = scene.shapes[i];
3200
+
3201
+ if(shape != exclude){
3202
+ var info = shape.intersect(ray);
3203
+ if(info.isHit && info.distance >= 0 && info.distance < best.distance){
3204
+ best = info;
3205
+ hits++;
3206
+ }
3207
+ }
3208
+ }
3209
+ best.hitCount = hits;
3210
+ return best;
3211
+ },
3212
+
3213
+ getReflectionRay: function(P,N,V){
3214
+ var c1 = -N.dot(V);
3215
+ var R1 = Flog.RayTracer.Vector.prototype.add(
3216
+ Flog.RayTracer.Vector.prototype.multiplyScalar(N, 2*c1),
3217
+ V
3218
+ );
3219
+ return new Flog.RayTracer.Ray(P, R1);
3220
+ },
3221
+
3222
+ rayTrace: function(info, ray, scene, depth){
3223
+ // Calc ambient
3224
+ var color = Flog.RayTracer.Color.prototype.multiplyScalar(info.color, scene.background.ambience);
3225
+ var oldColor = color;
3226
+ var shininess = Math.pow(10, info.shape.material.gloss + 1);
3227
+
3228
+ for(var i=0; i<scene.lights.length; i++){
3229
+ var light = scene.lights[i];
3230
+
3231
+ // Calc diffuse lighting
3232
+ var v = Flog.RayTracer.Vector.prototype.subtract(
3233
+ light.position,
3234
+ info.position
3235
+ ).normalize();
3236
+
3237
+ if(this.options.renderDiffuse){
3238
+ var L = v.dot(info.normal);
3239
+ if(L > 0.0){
3240
+ color = Flog.RayTracer.Color.prototype.add(
3241
+ color,
3242
+ Flog.RayTracer.Color.prototype.multiply(
3243
+ info.color,
3244
+ Flog.RayTracer.Color.prototype.multiplyScalar(
3245
+ light.color,
3246
+ L
3247
+ )
3248
+ )
3249
+ );
3250
+ }
3251
+ }
3252
+
3253
+ // The greater the depth the more accurate the colours, but
3254
+ // this is exponentially (!) expensive
3255
+ if(depth <= this.options.rayDepth){
3256
+ // calculate reflection ray
3257
+ if(this.options.renderReflections && info.shape.material.reflection > 0)
3258
+ {
3259
+ var reflectionRay = this.getReflectionRay(info.position, info.normal, ray.direction);
3260
+ var refl = this.testIntersection(reflectionRay, scene, info.shape);
3261
+
3262
+ if (refl.isHit && refl.distance > 0){
3263
+ refl.color = this.rayTrace(refl, reflectionRay, scene, depth + 1);
3264
+ } else {
3265
+ refl.color = scene.background.color;
3266
+ }
3267
+
3268
+ color = Flog.RayTracer.Color.prototype.blend(
3269
+ color,
3270
+ refl.color,
3271
+ info.shape.material.reflection
3272
+ );
3273
+ }
3274
+
3275
+ // Refraction
3276
+ /* TODO */
3277
+ }
3278
+
3279
+ /* Render shadows and highlights */
3280
+
3281
+ var shadowInfo = new Flog.RayTracer.IntersectionInfo();
3282
+
3283
+ if(this.options.renderShadows){
3284
+ var shadowRay = new Flog.RayTracer.Ray(info.position, v);
3285
+
3286
+ shadowInfo = this.testIntersection(shadowRay, scene, info.shape);
3287
+ if(shadowInfo.isHit && shadowInfo.shape != info.shape /*&& shadowInfo.shape.type != 'PLANE'*/){
3288
+ var vA = Flog.RayTracer.Color.prototype.multiplyScalar(color, 0.5);
3289
+ var dB = (0.5 * Math.pow(shadowInfo.shape.material.transparency, 0.5));
3290
+ color = Flog.RayTracer.Color.prototype.addScalar(vA,dB);
3291
+ }
3292
+ }
3293
+
3294
+ // Phong specular highlights
3295
+ if(this.options.renderHighlights && !shadowInfo.isHit && info.shape.material.gloss > 0){
3296
+ var Lv = Flog.RayTracer.Vector.prototype.subtract(
3297
+ info.shape.position,
3298
+ light.position
3299
+ ).normalize();
3300
+
3301
+ var E = Flog.RayTracer.Vector.prototype.subtract(
3302
+ scene.camera.position,
3303
+ info.shape.position
3304
+ ).normalize();
3305
+
3306
+ var H = Flog.RayTracer.Vector.prototype.subtract(
3307
+ E,
3308
+ Lv
3309
+ ).normalize();
3310
+
3311
+ var glossWeight = Math.pow(Math.max(info.normal.dot(H), 0), shininess);
3312
+ color = Flog.RayTracer.Color.prototype.add(
3313
+ Flog.RayTracer.Color.prototype.multiplyScalar(light.color, glossWeight),
3314
+ color
3315
+ );
3316
+ }
3317
+ }
3318
+ color.limit();
3319
+ return color;
3320
+ }
3321
+ };
3322
+
3323
+
3324
+ function renderScene(){
3325
+ var scene = new Flog.RayTracer.Scene();
3326
+
3327
+ scene.camera = new Flog.RayTracer.Camera(
3328
+ new Flog.RayTracer.Vector(0, 0, -15),
3329
+ new Flog.RayTracer.Vector(-0.2, 0, 5),
3330
+ new Flog.RayTracer.Vector(0, 1, 0)
3331
+ );
3332
+
3333
+ scene.background = new Flog.RayTracer.Background(
3334
+ new Flog.RayTracer.Color(0.5, 0.5, 0.5),
3335
+ 0.4
3336
+ );
3337
+
3338
+ var sphere = new Flog.RayTracer.Shape.Sphere(
3339
+ new Flog.RayTracer.Vector(-1.5, 1.5, 2),
3340
+ 1.5,
3341
+ new Flog.RayTracer.Material.Solid(
3342
+ new Flog.RayTracer.Color(0,0.5,0.5),
3343
+ 0.3,
3344
+ 0.0,
3345
+ 0.0,
3346
+ 2.0
3347
+ )
3348
+ );
3349
+
3350
+ var sphere1 = new Flog.RayTracer.Shape.Sphere(
3351
+ new Flog.RayTracer.Vector(1, 0.25, 1),
3352
+ 0.5,
3353
+ new Flog.RayTracer.Material.Solid(
3354
+ new Flog.RayTracer.Color(0.9,0.9,0.9),
3355
+ 0.1,
3356
+ 0.0,
3357
+ 0.0,
3358
+ 1.5
3359
+ )
3360
+ );
3361
+
3362
+ var plane = new Flog.RayTracer.Shape.Plane(
3363
+ new Flog.RayTracer.Vector(0.1, 0.9, -0.5).normalize(),
3364
+ 1.2,
3365
+ new Flog.RayTracer.Material.Chessboard(
3366
+ new Flog.RayTracer.Color(1,1,1),
3367
+ new Flog.RayTracer.Color(0,0,0),
3368
+ 0.2,
3369
+ 0.0,
3370
+ 1.0,
3371
+ 0.7
3372
+ )
3373
+ );
3374
+
3375
+ scene.shapes.push(plane);
3376
+ scene.shapes.push(sphere);
3377
+ scene.shapes.push(sphere1);
3378
+
3379
+ var light = new Flog.RayTracer.Light(
3380
+ new Flog.RayTracer.Vector(5, 10, -1),
3381
+ new Flog.RayTracer.Color(0.8, 0.8, 0.8)
3382
+ );
3383
+
3384
+ var light1 = new Flog.RayTracer.Light(
3385
+ new Flog.RayTracer.Vector(-3, 5, -15),
3386
+ new Flog.RayTracer.Color(0.8, 0.8, 0.8),
3387
+ 100
3388
+ );
3389
+
3390
+ scene.lights.push(light);
3391
+ scene.lights.push(light1);
3392
+
3393
+ var imageWidth = 100; // $F('imageWidth');
3394
+ var imageHeight = 100; // $F('imageHeight');
3395
+ var pixelSize = "5,5".split(','); // $F('pixelSize').split(',');
3396
+ var renderDiffuse = true; // $F('renderDiffuse');
3397
+ var renderShadows = true; // $F('renderShadows');
3398
+ var renderHighlights = true; // $F('renderHighlights');
3399
+ var renderReflections = true; // $F('renderReflections');
3400
+ var rayDepth = 2;//$F('rayDepth');
3401
+
3402
+ var raytracer = new Flog.RayTracer.Engine(
3403
+ {
3404
+ canvasWidth: imageWidth,
3405
+ canvasHeight: imageHeight,
3406
+ pixelWidth: pixelSize[0],
3407
+ pixelHeight: pixelSize[1],
3408
+ "renderDiffuse": renderDiffuse,
3409
+ "renderHighlights": renderHighlights,
3410
+ "renderShadows": renderShadows,
3411
+ "renderReflections": renderReflections,
3412
+ "rayDepth": rayDepth
3413
+ }
3414
+ );
3415
+
3416
+ raytracer.renderScene(scene, null, 0);
3417
+ }
3418
+