opal 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (306) hide show
  1. data/.gitignore +10 -1
  2. data/.gitmodules +0 -0
  3. data/Opalfile +371 -0
  4. data/README.md +45 -0
  5. data/Rakefile +237 -34
  6. data/VERSION +1 -1
  7. data/bin/opal +13 -0
  8. data/demos/apps/browser_demo/index.html +11 -0
  9. data/demos/apps/browser_demo/lib/browser_demo.rb +31 -0
  10. data/demos/apps/simple_opal/Opalfile +13 -0
  11. data/demos/apps/simple_opal/index.html +11 -0
  12. data/demos/apps/simple_opal/lib/app_controller.rb +62 -0
  13. data/demos/apps/simple_opal/lib/main_window.rb +146 -0
  14. data/demos/browser/request/index.html +52 -0
  15. data/demos/browser/request/request.rb +48 -0
  16. data/gen/browser/__PROJECT_NAME__/index.html +10 -0
  17. data/gen/browser/__PROJECT_NAME__/lib/__PROJECT_NAME__.rb +1 -0
  18. data/lib/opal.rb +48 -3
  19. data/lib/opal/builders/base.rb +50 -0
  20. data/lib/opal/builders/css.rb +46 -0
  21. data/lib/opal/builders/javascript.rb +44 -0
  22. data/lib/opal/builders/opal.rb +79 -0
  23. data/lib/opal/builders/ruby.rb +50 -0
  24. data/lib/opal/builders/ruby/generate.rb +1851 -0
  25. data/lib/opal/builders/ruby/nodes.rb +210 -0
  26. data/lib/opal/builders/ruby/ruby.rb +916 -0
  27. data/lib/opal/builders/ruby/ruby_parser.rb +6008 -0
  28. data/lib/opal/builders/ruby/ruby_parser.rb.y +1451 -0
  29. data/lib/opal/models/build_item.rb +104 -0
  30. data/lib/opal/models/hash_struct.rb +40 -0
  31. data/lib/opal/models/project.rb +215 -0
  32. data/lib/opal/models/struct_accessors.rb +58 -0
  33. data/lib/opal/models/target.rb +176 -0
  34. data/lib/opal/opal/env/console.rb +66 -0
  35. data/lib/opal/opal/env/fs.rb +98 -0
  36. data/lib/opal/opal/env/object.rb +48 -0
  37. data/lib/opal/opal/environment.rb +139 -0
  38. data/lib/opal/opal/gen.rb +62 -0
  39. data/lib/opal/opal/opal.rb +68 -0
  40. data/lib/opal/opal/repl.rb +38 -0
  41. data/lib/opal/opalfile/dsl.rb +62 -0
  42. data/lib/opal/opalfile/opalfile.rb +133 -0
  43. data/lib/opal/opalfile/task.rb +96 -0
  44. data/lib/opal/opalfile/task_manager.rb +63 -0
  45. data/lib/opal/opalfile/task_scope.rb +52 -0
  46. data/lib/opal/rack/app_server.rb +119 -0
  47. data/opals/aristo/README.md +16 -0
  48. data/opals/browser/Opalfile +11 -0
  49. data/opals/browser/README.md +146 -0
  50. data/opals/browser/SIZZLE_LICESNSE.txt +148 -0
  51. data/opals/browser/lib/browser.rb +118 -0
  52. data/opals/browser/lib/browser/builder.rb +41 -0
  53. data/opals/browser/lib/browser/canvas_context.rb +115 -0
  54. data/opals/browser/lib/browser/dimensions.rb +50 -0
  55. data/opals/browser/lib/browser/document.rb +146 -0
  56. data/opals/browser/lib/browser/element.rb +487 -0
  57. data/opals/browser/lib/browser/element/attributes.rb +88 -0
  58. data/opals/browser/lib/browser/element/css.rb +290 -0
  59. data/opals/browser/lib/browser/element/form.rb +146 -0
  60. data/opals/browser/lib/browser/event/dom_events.rb +81 -0
  61. data/opals/browser/lib/browser/event/event.rb +177 -0
  62. data/opals/browser/lib/browser/event/trigger_events.rb +53 -0
  63. data/opals/browser/lib/browser/geometry.rb +97 -0
  64. data/opals/browser/lib/browser/json.rb +32 -0
  65. data/opals/browser/lib/browser/json_parse.js +321 -0
  66. data/opals/browser/lib/browser/request/request.rb +201 -0
  67. data/opals/browser/lib/browser/sizzle.js +1068 -0
  68. data/opals/browser/lib/browser/string.rb +42 -0
  69. data/opals/browser/lib/browser/touch.rb +37 -0
  70. data/{runtime/yaml.js → opals/browser/lib/browser/vml_context.js} +8 -8
  71. data/opals/browser/lib/browser/window.rb +36 -0
  72. data/opals/browser/spec/browser/browser_detection_spec.rb +7 -0
  73. data/opals/browser/spec/document/aref_spec.rb +110 -0
  74. data/opals/browser/spec/document/ready_spec.rb +16 -0
  75. data/opals/browser/spec/element/body_spec.rb +11 -0
  76. data/opals/browser/spec/element/clear_spec.rb +26 -0
  77. data/opals/browser/spec/element/empty_spec.rb +29 -0
  78. data/opals/browser/spec/element/has_class_spec.rb +40 -0
  79. data/opals/browser/spec/element/hidden_spec.rb +23 -0
  80. data/opals/browser/spec/element/hide_spec.rb +31 -0
  81. data/opals/browser/spec/element/remove_spec.rb +25 -0
  82. data/opals/browser/spec/element/show_spec.rb +31 -0
  83. data/opals/browser/spec/element/style_spec.rb +69 -0
  84. data/opals/browser/spec/element/toggle_spec.rb +31 -0
  85. data/opals/browser/spec/element/visible_spec.rb +23 -0
  86. data/opals/browser/spec/spec_helper.rb +1 -0
  87. data/opals/cherry_kit/Opalfile +6 -0
  88. data/opals/cherry_kit/bin/cherry_kit.rb +11 -0
  89. data/opals/cherry_kit/lib/cherry_kit.rb +29 -0
  90. data/opals/foundation/Opalfile +11 -0
  91. data/opals/foundation/bin/foundation.rb +12 -0
  92. data/opals/foundation/lib/foundation.rb +32 -0
  93. data/opals/foundation/lib/foundation/__table_view_desktop/outline_view.rb +57 -0
  94. data/opals/foundation/lib/foundation/__table_view_desktop/table_column.rb +59 -0
  95. data/opals/foundation/lib/foundation/__table_view_desktop/table_header_view.rb +34 -0
  96. data/opals/foundation/lib/foundation/__table_view_desktop/table_view.rb +304 -0
  97. data/opals/foundation/lib/foundation/controllers/array_controller.rb +54 -0
  98. data/opals/foundation/lib/foundation/controllers/controller.rb +74 -0
  99. data/opals/foundation/lib/foundation/controllers/controller_selection_proxy.rb +67 -0
  100. data/opals/foundation/lib/foundation/controllers/object_controller.rb +145 -0
  101. data/opals/foundation/lib/foundation/controllers/view.rb +40 -0
  102. data/opals/foundation/lib/foundation/core/application.rb +476 -0
  103. data/opals/foundation/lib/foundation/core/attributes.rb +146 -0
  104. data/opals/foundation/lib/foundation/core/bindings.rb +125 -0
  105. data/opals/foundation/lib/foundation/core/builder.rb +101 -0
  106. data/opals/foundation/lib/foundation/core/event.rb +112 -0
  107. data/opals/foundation/lib/foundation/core/index_path.rb +49 -0
  108. data/opals/foundation/lib/foundation/core/index_set.rb +97 -0
  109. data/opals/foundation/lib/foundation/core/notification.rb +113 -0
  110. data/opals/foundation/lib/foundation/core/observable.rb +275 -0
  111. data/opals/foundation/lib/foundation/core/observable_array.rb +30 -0
  112. data/opals/foundation/lib/foundation/core/responder.rb +85 -0
  113. data/opals/foundation/lib/foundation/core/run_loop.rb +89 -0
  114. data/opals/foundation/lib/foundation/core/touch.rb +95 -0
  115. data/opals/foundation/lib/foundation/gestures/gesture_recognizer.rb +35 -0
  116. data/opals/foundation/lib/foundation/rendering/render_context.rb +100 -0
  117. data/opals/foundation/lib/foundation/rendering/renderer.rb +137 -0
  118. data/opals/foundation/lib/foundation/rendering/root_theme.rb +77 -0
  119. data/opals/foundation/lib/foundation/rendering/root_theme/button.rb +62 -0
  120. data/opals/foundation/lib/foundation/rendering/root_theme/control.rb +72 -0
  121. data/opals/foundation/lib/foundation/rendering/root_theme/label.rb +54 -0
  122. data/opals/foundation/lib/foundation/rendering/root_theme/scroller.rb +58 -0
  123. data/opals/foundation/lib/foundation/rendering/root_theme/slider.rb +72 -0
  124. data/opals/foundation/lib/foundation/rendering/root_theme/table_view.rb +97 -0
  125. data/opals/foundation/lib/foundation/rendering/root_theme/text_field.rb +55 -0
  126. data/opals/foundation/lib/foundation/rendering/root_theme/view.rb +81 -0
  127. data/opals/foundation/lib/foundation/rendering/theme.rb +38 -0
  128. data/opals/foundation/lib/foundation/table_view/cell.rb +39 -0
  129. data/opals/foundation/lib/foundation/table_view/table.rb +171 -0
  130. data/opals/foundation/lib/foundation/views/button.rb +63 -0
  131. data/opals/foundation/lib/foundation/views/checkbox.rb +28 -0
  132. data/opals/foundation/lib/foundation/views/clip.rb +47 -0
  133. data/opals/foundation/lib/foundation/views/control.rb +199 -0
  134. data/opals/foundation/lib/foundation/views/label.rb +54 -0
  135. data/opals/foundation/lib/foundation/views/scroll.rb +294 -0
  136. data/opals/foundation/lib/foundation/views/scroll_view_desktop.rb +152 -0
  137. data/opals/foundation/lib/foundation/views/scroller.rb +54 -0
  138. data/opals/foundation/lib/foundation/views/slider.rb +93 -0
  139. data/opals/foundation/lib/foundation/views/text_field.rb +83 -0
  140. data/opals/foundation/lib/foundation/views/view.rb +426 -0
  141. data/opals/foundation/lib/foundation/windows/window.rb +191 -0
  142. data/opals/foundation/resources/button/button.css +23 -0
  143. data/{runtime/init.js → opals/foundation/resources/foundation.css} +27 -33
  144. data/opals/foundation/resources/scroll/scroll.css +22 -0
  145. data/opals/foundation/resources/scroll_view/scroll_view.css +3 -0
  146. data/opals/foundation/resources/scroll_view/scroller.css +3 -0
  147. data/opals/foundation/resources/slider/regular/slider.css +3 -0
  148. data/opals/foundation/resources/slider/slider.css +27 -0
  149. data/opals/foundation/resources/table_view/outline_view.css +3 -0
  150. data/opals/foundation/resources/table_view/table_view.css +15 -0
  151. data/opals/foundation/resources/text_field/text_field.css +71 -0
  152. data/opals/foundation/spec/spec_helper.rb +1 -0
  153. data/opals/foundation/spec/system/attributes/get_attribute_spec.rb +69 -0
  154. data/opals/foundation/spec/system/attributes/get_path_spec.rb +44 -0
  155. data/opals/foundation/spec/system/attributes/set_path_spec.rb +24 -0
  156. data/opals/foundation/spec/system/attributes/set_spec.rb +58 -0
  157. data/opals/foundation/spec/system/bindings/bindings.rb +85 -0
  158. data/opals/foundation/spec/system/key_value_binding/bind_spec.rb +43 -0
  159. data/opals/foundation/spec/system/observable/dependant_keys_spec.rb +74 -0
  160. data/opals/foundation/spec/system/observable/observe_spec.rb +292 -0
  161. data/opals/foundation/spec/system/observable/remove_observer_spec.rb +60 -0
  162. data/opals/opal/Opalfile +14 -0
  163. data/opals/opal/spec/core/array/append_spec.rb +30 -0
  164. data/opals/opal/spec/core/array/assoc_spec.rb +29 -0
  165. data/opals/opal/spec/core/array/at_spec.rb +37 -0
  166. data/opals/opal/spec/core/array/clear_spec.rb +22 -0
  167. data/opals/opal/spec/core/array/collect_bang_spec.rb +27 -0
  168. data/opals/opal/spec/core/array/collect_spec.rb +27 -0
  169. data/opals/opal/spec/core/array/compact_spec.rb +15 -0
  170. data/opals/opal/spec/core/array/concat_spec.rb +15 -0
  171. data/opals/opal/spec/core/array/constructor_spec.rb +14 -0
  172. data/opals/opal/spec/core/array/each_spec.rb +9 -0
  173. data/opals/opal/spec/core/array/element_reference_spec.rb +4 -0
  174. data/opals/opal/spec/core/array/first_spec.rb +35 -0
  175. data/opals/opal/spec/core/array/include_spec.rb +9 -0
  176. data/opals/opal/spec/core/array/map_spec.rb +31 -0
  177. data/opals/opal/spec/core/builtin_constants/builtin_constants_spec.rb +7 -0
  178. data/opals/opal/spec/core/false/and_spec.rb +10 -0
  179. data/opals/opal/spec/core/false/inspect_spec.rb +6 -0
  180. data/opals/opal/spec/core/false/or_spec.rb +10 -0
  181. data/opals/opal/spec/core/false/to_s_spec.rb +6 -0
  182. data/opals/opal/spec/core/false/xor_spec.rb +10 -0
  183. data/opals/opal/spec/core/file/join_spec.rb +19 -0
  184. data/opals/opal/spec/core/kernel/instance_eval_spec.rb +0 -0
  185. data/opals/opal/spec/core/kernel/loop_spec.rb +24 -0
  186. data/opals/opal/spec/core/kernel/raise_spec.rb +0 -0
  187. data/opals/opal/spec/core/module/attr_accessor_spec.rb +28 -0
  188. data/opals/opal/spec/core/number/lt_spec.rb +12 -0
  189. data/opals/opal/spec/core/true/and_spec.rb +10 -0
  190. data/opals/opal/spec/core/true/inspect_spec.rb +6 -0
  191. data/opals/opal/spec/core/true/or_spec.rb +10 -0
  192. data/opals/opal/spec/core/true/to_s_spec.rb +6 -0
  193. data/opals/opal/spec/core/true/xor_spec.rb +10 -0
  194. data/opals/opal/spec/fixtures/super.rb +70 -0
  195. data/opals/opal/spec/language/____temp_remove_this.rb +12 -0
  196. data/opals/opal/spec/language/and_spec.rb +62 -0
  197. data/opals/opal/spec/language/array_spec.rb +52 -0
  198. data/opals/opal/spec/language/block_spec.rb +18 -0
  199. data/opals/opal/spec/language/break_spec.rb +36 -0
  200. data/opals/opal/spec/language/case_spec.rb +103 -0
  201. data/opals/opal/spec/language/def_spec.rb +11 -0
  202. data/opals/opal/spec/language/eigenclass_spec.rb +60 -0
  203. data/opals/opal/spec/language/hash_spec.rb +29 -0
  204. data/opals/opal/spec/language/if_spec.rb +54 -0
  205. data/opals/opal/spec/language/loop_spec.rb +11 -0
  206. data/opals/opal/spec/language/metaclass_spec.rb +21 -0
  207. data/opals/opal/spec/language/method_spec.rb +64 -0
  208. data/opals/opal/spec/language/next_spec.rb +25 -0
  209. data/opals/opal/spec/language/or_spec.rb +34 -0
  210. data/opals/opal/spec/language/redo_spec.rb +24 -0
  211. data/opals/opal/spec/language/rescue_spec.rb +20 -0
  212. data/opals/opal/spec/language/return_spec.rb +47 -0
  213. data/opals/opal/spec/language/string_spec.rb +25 -0
  214. data/opals/opal/spec/language/super_spec.rb +26 -0
  215. data/opals/opal/spec/language/until_spec.rb +157 -0
  216. data/opals/opal/spec/language/while_spec.rb +163 -0
  217. data/opals/opal/spec/spec_helper.rb +5 -0
  218. data/opals/runtime/Opalfile +68 -0
  219. data/opals/runtime/README.md +12 -0
  220. data/opals/runtime/docs/debugging.md +51 -0
  221. data/opals/runtime/lib/array.rb +1516 -0
  222. data/opals/runtime/lib/basic_object.rb +49 -0
  223. data/opals/runtime/lib/class.rb +54 -0
  224. data/opals/runtime/lib/dir.rb +36 -0
  225. data/opals/runtime/lib/error.rb +49 -0
  226. data/opals/runtime/lib/false_class.rb +52 -0
  227. data/opals/runtime/lib/file.rb +79 -0
  228. data/opals/runtime/lib/hash.rb +791 -0
  229. data/opals/runtime/lib/io.rb +39 -0
  230. data/opals/runtime/lib/kernel.rb +288 -0
  231. data/opals/runtime/lib/match_data.rb +36 -0
  232. data/opals/runtime/lib/module.rb +109 -0
  233. data/opals/runtime/lib/nil_class.rb +69 -0
  234. data/opals/runtime/lib/number.rb +398 -0
  235. data/opals/runtime/lib/proc.rb +77 -0
  236. data/opals/runtime/lib/range.rb +63 -0
  237. data/opals/runtime/lib/regexp.rb +111 -0
  238. data/opals/runtime/lib/ruby.rb +30 -0
  239. data/opals/runtime/lib/string.rb +328 -0
  240. data/opals/runtime/lib/symbol.rb +40 -0
  241. data/opals/runtime/lib/top_self.rb +33 -0
  242. data/opals/runtime/lib/true_class.rb +45 -0
  243. data/opals/runtime/runtime/browser.js +287 -0
  244. data/opals/runtime/runtime/debug.js +182 -0
  245. data/opals/runtime/runtime/opal.js +1010 -0
  246. data/opals/runtime/runtime/post_opal.js +1 -0
  247. data/opals/runtime/runtime/pre_opal.js +2 -0
  248. data/opals/runtime/runtime/server_side.js +50 -0
  249. data/opals/spec/LICENSE.txt +26 -0
  250. data/opals/spec/Opalfile +5 -0
  251. data/opals/spec/bin/spec.rb +43 -0
  252. data/opals/spec/lib/spec.rb +33 -0
  253. data/opals/spec/lib/spec/dsl.rb +41 -0
  254. data/opals/spec/lib/spec/example.rb +35 -0
  255. data/opals/spec/lib/spec/example/before_and_after_hooks.rb +81 -0
  256. data/opals/spec/lib/spec/example/errors.rb +42 -0
  257. data/opals/spec/lib/spec/example/example_group.rb +37 -0
  258. data/opals/spec/lib/spec/example/example_group_factory.rb +43 -0
  259. data/opals/spec/lib/spec/example/example_group_hierarchy.rb +45 -0
  260. data/opals/spec/lib/spec/example/example_group_methods.rb +142 -0
  261. data/opals/spec/lib/spec/example/example_group_proxy.rb +41 -0
  262. data/opals/spec/lib/spec/example/example_methods.rb +73 -0
  263. data/opals/spec/lib/spec/example/example_proxy.rb +48 -0
  264. data/opals/spec/lib/spec/expectations.rb +46 -0
  265. data/opals/spec/lib/spec/expectations/errors.rb +35 -0
  266. data/opals/spec/lib/spec/expectations/fail_with.rb +37 -0
  267. data/opals/spec/lib/spec/expectations/handler.rb +48 -0
  268. data/opals/spec/lib/spec/matchers.rb +50 -0
  269. data/opals/spec/lib/spec/matchers/be.rb +26 -0
  270. data/opals/spec/lib/spec/matchers/generated_descriptions.rb +47 -0
  271. data/opals/spec/lib/spec/matchers/operator_matcher.rb +66 -0
  272. data/opals/spec/lib/spec/runner.rb +48 -0
  273. data/opals/spec/lib/spec/runner/example_group_runner.rb +71 -0
  274. data/opals/spec/lib/spec/runner/formatter/html_formatter.rb +100 -0
  275. data/opals/spec/lib/spec/runner/formatter/terminal_formatter.rb +82 -0
  276. data/opals/spec/lib/spec/runner/options.rb +63 -0
  277. data/opals/spec/lib/spec/runner/reporter.rb +123 -0
  278. data/opals/spec/resources/index.html +25 -0
  279. data/opals/spec/resources/spec.css +132 -0
  280. data/spec/cherry_kit/iseq_spec.rb +38 -0
  281. data/spec/spec_helper.rb +16 -0
  282. data/spec/vienna_spec.rb +7 -0
  283. data/yard/index.html +43 -0
  284. data/yard/style.css +765 -0
  285. metadata +312 -49
  286. data/docs/jarv.rdoc +0 -27
  287. data/runtime/array.js +0 -153
  288. data/runtime/class.js +0 -469
  289. data/runtime/compar.js +0 -73
  290. data/runtime/dir.js +0 -115
  291. data/runtime/enum.js +0 -74
  292. data/runtime/file.js +0 -165
  293. data/runtime/gem.js +0 -241
  294. data/runtime/hash.js +0 -181
  295. data/runtime/load.js +0 -251
  296. data/runtime/module.js +0 -98
  297. data/runtime/number.js +0 -148
  298. data/runtime/object.js +0 -522
  299. data/runtime/opal.js +0 -200
  300. data/runtime/parse.js +0 -2218
  301. data/runtime/range.js +0 -56
  302. data/runtime/re.js +0 -91
  303. data/runtime/string.js +0 -199
  304. data/runtime/variable.js +0 -184
  305. data/runtime/vm.js +0 -1150
  306. data/tasks/build.rb +0 -16
@@ -0,0 +1,81 @@
1
+ #
2
+ # dom_events.rb
3
+ # vienna
4
+ #
5
+ # Created by Adam Beynon.
6
+ # Copyright 2010 Adam Beynon.
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ # of this software and associated documentation files (the "Software"), to deal
10
+ # in the Software without restriction, including without limitation the rights
11
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ # copies of the Software, and to permit persons to whom the Software is
13
+ # furnished to do so, subject to the following conditions:
14
+ #
15
+ # The above copyright notice and this permission notice shall be included in
16
+ # all copies or substantial portions of the Software.
17
+ #
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ # THE SOFTWARE.
25
+ #
26
+
27
+ class Event
28
+
29
+ module DOMEvents
30
+
31
+ # Adds the given +listener+ to the receiver for the given +event_name+.
32
+ # More than one listeners can be added using this method, and they are
33
+ # called in the order that they are added as a listener.
34
+ #
35
+ # @param [String, Symbol] event_name the event type to listen for
36
+ # @param [Proc] listener the proc to deal with the event
37
+ # @return [Element, Document] returns the receiver
38
+ def on(event_name, &listener)
39
+ event_class = Event
40
+ `var func = function(evt) {
41
+ //console.log(#{event_class});
42
+ evt = #{event_class}.$from_native(evt);
43
+ var res = #{listener}.apply(#{listener}.__self__, [evt]);
44
+ return (res !==undefined && res.r);
45
+ };
46
+
47
+ var element = #{self}.__element__;
48
+ if (element.addEventListener) {
49
+ element.addEventListener(#{event_name.to_s}, func, false);
50
+ } else {
51
+ element.attachEvent('on' + #{event_name.to_s}, func);
52
+ }`
53
+ self
54
+ end
55
+
56
+ # Add methods for our core event names
57
+ %W(mousedown mouseup mousemove).each do |event_name|
58
+ define_method(event_name) do |&block|
59
+ # on event_name, &`arguments[0]`
60
+ # this should be:
61
+ #
62
+ # if block_given?
63
+ # self.on event_name, &block
64
+ # else
65
+ # self.fire event_name
66
+ # end
67
+ #
68
+ # to allow us to fire events (pretend they fired for testing???!)
69
+ `if (arguments[0] && arguments[0].info & #{self}.TP) {
70
+ return this.$on(#{event_name}, arguments[0]);
71
+ } else {
72
+ return console.log("need to fire event: " + #{event_name});
73
+ }`
74
+ end
75
+ end
76
+
77
+ end
78
+ end
79
+
80
+ Element.include Event::DOMEvents
81
+ Document.extend Event::DOMEvents
@@ -0,0 +1,177 @@
1
+ #
2
+ # event.rb
3
+ # vienna
4
+ #
5
+ # Created by Adam Beynon.
6
+ # Copyright 2010 Adam Beynon.
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ # of this software and associated documentation files (the "Software"), to deal
10
+ # in the Software without restriction, including without limitation the rights
11
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ # copies of the Software, and to permit persons to whom the Software is
13
+ # furnished to do so, subject to the following conditions:
14
+ #
15
+ # The above copyright notice and this permission notice shall be included in
16
+ # all copies or substantial portions of the Software.
17
+ #
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ # THE SOFTWARE.
25
+ #
26
+
27
+ # Event class
28
+ class Event
29
+
30
+ # Create an Event instance from the given native_event.
31
+ #
32
+ # @param {Native} native_event
33
+ # @return {Event} event
34
+ #
35
+ def self.from_native(event)
36
+ result = allocate
37
+ `#{event} = #{event} || window.event;
38
+
39
+ var type = #{event}.type,
40
+ target = #{event}.target || #{event}.srcElement,
41
+ code = #{event}.which || #{event}.keyCode,
42
+ key = #{Event::KEYS}['$[]'](code);
43
+
44
+ if (!key.r) {
45
+ key = #{self}.Y(String.fromCharCode(code).toLowerCase());
46
+ }
47
+
48
+ while (target && target.nodeType == 3) {
49
+ target = target.parentNode;
50
+ }
51
+
52
+ #{result}.__shift__ = #{event}.shiftKey ? #{true} : #{false};
53
+ #{result}.__alt__ = #{event}.altKey ? #{true} : #{false};
54
+ #{result}.__ctrl__ = #{event}.ctrlKey ? #{true} : #{false};
55
+ #{result}.__meta__ = #{event}.metaKey ? #{true} : #{false};
56
+
57
+ #{result}.__code__ = code;
58
+ #{result}.__key__ = key;
59
+ #{result}.__event__ = #{event};
60
+ #{result}.__type__ = type;`
61
+ result
62
+ end
63
+
64
+ # Stop the receiver from propagating.
65
+ #
66
+ # @return [Event] returns receiver
67
+ def stop_propagation
68
+ `var evt = #{self}.__event__;
69
+ if (evt.stopPropagation) {
70
+ evt.stopPropagation();
71
+ } else {
72
+ evt.cancelBubble = true;
73
+ }`
74
+ self
75
+ end
76
+
77
+ # Stop the default behaviour from the event
78
+ #
79
+ # @return [Event] returns the receiver
80
+ def prevent_default
81
+ `var evt = #{self}.__event__;
82
+ if (evt.preventDefault) {
83
+ evt.preventDefault();
84
+ } else {
85
+ evt.returnValue = false;
86
+ }`
87
+ self
88
+ end
89
+
90
+ # Completely stop the given event.
91
+ #
92
+ # @return [Event] returns the receiver
93
+ def stop!
94
+ stop_propagation
95
+ prevent_default
96
+ end
97
+
98
+ # Type of event, as a symbol. Here we convert the actual event type into a
99
+ # symbol, and also rename some ie only events into more w3c friendly events.
100
+ #
101
+ def type
102
+ if @type
103
+ return @type
104
+ else
105
+ @type = `vnY(#{self}.__event__.type)`
106
+ return @type
107
+ end
108
+ end
109
+
110
+ # Allow event type to be overridden. This only sets the type for our
111
+ # abstraction: the native event type is not altered
112
+ #
113
+ # @param {Symbol} event_type for the event
114
+ #
115
+ def type=(event_type)
116
+ @type = event_type
117
+ end
118
+
119
+ # ==============
120
+ # = Key Events =
121
+ # ==============
122
+
123
+ # Hash of associated key code numbers to their descriptors.
124
+ KEYS = {
125
+ 8 => :backspace,
126
+ 9 => :tab,
127
+ 13 => :enter,
128
+ 27 => :escape,
129
+ 32 => :space,
130
+ 37 => :left,
131
+ 38 => :up,
132
+ 39 => :right,
133
+ 40 => :down,
134
+ 46 => :delete
135
+ }
136
+
137
+ # If the receiver was a key based event, then returns a +Symbol+ for the typed
138
+ # key, otherwise +nil+. Special keys in +KEYS+ are represented as the symbol
139
+ # names as the keys in the hash.
140
+ #
141
+ # @return [Symbol, nil] the typed key
142
+ def key
143
+ `return #{self}.__key__ || #{nil};`
144
+ end
145
+
146
+ # Returns +true+ if the shift key was pressed, +false+ otherwise.
147
+ #
148
+ # @return [true, false] was shift pressed
149
+ def shift?
150
+ `return #{self}.__shift__;`
151
+ end
152
+
153
+ # Returns +true+ if the alt key was pressed, +false+ otherwise.
154
+ #
155
+ # @return [true, false] was alt pressed
156
+ def alt?
157
+ `return #{self}.__alt__;`
158
+ end
159
+
160
+ # Returns +true+ if the ctrl key was pressed, +false+ otherwise.
161
+ #
162
+ # @return [true, false] was ctrl pressed
163
+ def ctrl?
164
+ `return #{self}.__ctrl__;`
165
+ end
166
+
167
+ # Returns +true+ if the meta key was pressed, +false+ otherwise.
168
+ #
169
+ # @return [true, false] was meta pressed
170
+ def meta?
171
+ `return #{self}.__meta__;`
172
+ end
173
+
174
+ end
175
+
176
+ require 'browser/event/trigger_events'
177
+ require 'browser/event/dom_events'
@@ -0,0 +1,53 @@
1
+ #
2
+ # trigger_events.rb
3
+ # vienna
4
+ #
5
+ # Created by Adam Beynon.
6
+ # Copyright 2010 Adam Beynon.
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ # of this software and associated documentation files (the "Software"), to deal
10
+ # in the Software without restriction, including without limitation the rights
11
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ # copies of the Software, and to permit persons to whom the Software is
13
+ # furnished to do so, subject to the following conditions:
14
+ #
15
+ # The above copyright notice and this permission notice shall be included in
16
+ # all copies or substantial portions of the Software.
17
+ #
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ # THE SOFTWARE.
25
+ #
26
+
27
+
28
+ class Event
29
+
30
+ module TriggerEvents
31
+
32
+ def on(name, &block)
33
+ name = name.to_sym
34
+
35
+ @trigger_events = @trigger_events || {}
36
+ @trigger_events[name] || @trigger_events[name] = [block]
37
+ self
38
+ end
39
+
40
+ def trigger(name, *args)
41
+ puts "triggering #{name}"
42
+ name = name.to_sym
43
+
44
+ if @trigger_events && listeners = @trigger_events[name]
45
+ listeners.each do |listener|
46
+ listener.call args[0], args[1], args[2]
47
+ end
48
+ end
49
+
50
+ self
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,97 @@
1
+ #
2
+ # graphics.rb
3
+ # vienna
4
+ #
5
+ # Created by Adam Beynon.
6
+ # Copyright 2010 Adam Beynon.
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ # of this software and associated documentation files (the "Software"), to deal
10
+ # in the Software without restriction, including without limitation the rights
11
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ # copies of the Software, and to permit persons to whom the Software is
13
+ # furnished to do so, subject to the following conditions:
14
+ #
15
+ # The above copyright notice and this permission notice shall be included in
16
+ # all copies or substantial portions of the Software.
17
+ #
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ # THE SOFTWARE.
25
+ #
26
+
27
+ class Point
28
+
29
+ attr_accessor :x, :y
30
+
31
+ def initialize(x, y)
32
+ @x = x
33
+ @y = y
34
+ end
35
+ end
36
+
37
+ class Size
38
+
39
+ attr_accessor :height, :width
40
+
41
+ def initialize(w, h)
42
+ @width = w
43
+ @height = h
44
+ end
45
+
46
+ def inspect
47
+ "#<Size #{@width}, #{@height}>"
48
+ end
49
+ end
50
+
51
+ class Rect
52
+
53
+ attr_accessor :size, :origin
54
+
55
+ def initialize(x, y, w, h)
56
+ @origin = Point.new x, y
57
+ @size = Size.new w, h
58
+ end
59
+
60
+ def x
61
+ origin.x
62
+ end
63
+
64
+ def x=(x)
65
+ origin.x = x
66
+ end
67
+
68
+ def y
69
+ origin.y
70
+ end
71
+
72
+ def y=(y)
73
+ origin.y = y
74
+ end
75
+
76
+ def width
77
+ size.width
78
+ end
79
+
80
+ def width=(width)
81
+ size.width = width
82
+ end
83
+
84
+ def height
85
+ size.height
86
+ end
87
+
88
+ def height=(height)
89
+ size.height = height
90
+ end
91
+
92
+ def contains_point?(point)
93
+ `var res = (#{self.x} < #{point.x}) && (#{self.y} < #{point.y}) && ((#{self.x} + #{self.width}) > #{point.x}) && ((#{self.y} + #{self.height}) > #{point.y});
94
+ return res ? #{true} : #{false};
95
+ `
96
+ end
97
+ end
@@ -0,0 +1,32 @@
1
+ #
2
+ # json.rb
3
+ # vienna
4
+ #
5
+ # Created by Adam Beynon.
6
+ # Copyright 2010 Adam Beynon.
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ # of this software and associated documentation files (the "Software"), to deal
10
+ # in the Software without restriction, including without limitation the rights
11
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ # copies of the Software, and to permit persons to whom the Software is
13
+ # furnished to do so, subject to the following conditions:
14
+ #
15
+ # The above copyright notice and this permission notice shall be included in
16
+ # all copies or substantial portions of the Software.
17
+ #
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ # THE SOFTWARE.
25
+ #
26
+
27
+ module JSON
28
+
29
+ def self.parse(text = "")
30
+ raise "JSON.parse empty string" if text == ""
31
+ end
32
+ end
@@ -0,0 +1,321 @@
1
+ if (!this.JSON) {
2
+ this.JSON = {};
3
+ }
4
+
5
+ (function () {
6
+
7
+ function f(n) {
8
+ // Format integers to have at least two digits.
9
+ return n < 10 ? '0' + n : n;
10
+ }
11
+
12
+ if (typeof Date.prototype.toJSON !== 'function') {
13
+
14
+ Date.prototype.toJSON = function (key) {
15
+
16
+ return isFinite(this.valueOf()) ?
17
+ this.getUTCFullYear() + '-' +
18
+ f(this.getUTCMonth() + 1) + '-' +
19
+ f(this.getUTCDate()) + 'T' +
20
+ f(this.getUTCHours()) + ':' +
21
+ f(this.getUTCMinutes()) + ':' +
22
+ f(this.getUTCSeconds()) + 'Z' : null;
23
+ };
24
+
25
+ String.prototype.toJSON =
26
+ Number.prototype.toJSON =
27
+ Boolean.prototype.toJSON = function (key) {
28
+ return this.valueOf();
29
+ };
30
+ }
31
+
32
+ var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
33
+ escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
34
+ gap,
35
+ indent,
36
+ meta = { // table of character substitutions
37
+ '\b': '\\b',
38
+ '\t': '\\t',
39
+ '\n': '\\n',
40
+ '\f': '\\f',
41
+ '\r': '\\r',
42
+ '"' : '\\"',
43
+ '\\': '\\\\'
44
+ },
45
+ rep;
46
+
47
+
48
+ function quote(string) {
49
+
50
+ // If the string contains no control characters, no quote characters, and no
51
+ // backslash characters, then we can safely slap some quotes around it.
52
+ // Otherwise we must also replace the offending characters with safe escape
53
+ // sequences.
54
+
55
+ escapable.lastIndex = 0;
56
+ return escapable.test(string) ?
57
+ '"' + string.replace(escapable, function (a) {
58
+ var c = meta[a];
59
+ return typeof c === 'string' ? c :
60
+ '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
61
+ }) + '"' :
62
+ '"' + string + '"';
63
+ }
64
+
65
+
66
+ function str(key, holder) {
67
+
68
+ // Produce a string from holder[key].
69
+
70
+ var i, // The loop counter.
71
+ k, // The member key.
72
+ v, // The member value.
73
+ length,
74
+ mind = gap,
75
+ partial,
76
+ value = holder[key];
77
+
78
+ // If the value has a toJSON method, call it to obtain a replacement value.
79
+
80
+ if (value && typeof value === 'object' &&
81
+ typeof value.toJSON === 'function') {
82
+ value = value.toJSON(key);
83
+ }
84
+
85
+ // If we were called with a replacer function, then call the replacer to
86
+ // obtain a replacement value.
87
+
88
+ if (typeof rep === 'function') {
89
+ value = rep.call(holder, key, value);
90
+ }
91
+
92
+ // What happens next depends on the value's type.
93
+
94
+ switch (typeof value) {
95
+ case 'string':
96
+ return quote(value);
97
+
98
+ case 'number':
99
+
100
+ // JSON numbers must be finite. Encode non-finite numbers as null.
101
+
102
+ return isFinite(value) ? String(value) : 'null';
103
+
104
+ case 'boolean':
105
+ case 'null':
106
+
107
+ // If the value is a boolean or null, convert it to a string. Note:
108
+ // typeof null does not produce 'null'. The case is included here in
109
+ // the remote chance that this gets fixed someday.
110
+
111
+ return String(value);
112
+
113
+ // If the type is 'object', we might be dealing with an object or an array or
114
+ // null.
115
+
116
+ case 'object':
117
+
118
+ // Due to a specification blunder in ECMAScript, typeof null is 'object',
119
+ // so watch out for that case.
120
+
121
+ if (!value) {
122
+ return 'null';
123
+ }
124
+
125
+ // Make an array to hold the partial results of stringifying this object value.
126
+
127
+ gap += indent;
128
+ partial = [];
129
+
130
+ // Is the value an array?
131
+
132
+ if (Object.prototype.toString.apply(value) === '[object Array]') {
133
+
134
+ // The value is an array. Stringify every element. Use null as a placeholder
135
+ // for non-JSON values.
136
+
137
+ length = value.length;
138
+ for (i = 0; i < length; i += 1) {
139
+ partial[i] = str(i, value) || 'null';
140
+ }
141
+
142
+ // Join all of the elements together, separated with commas, and wrap them in
143
+ // brackets.
144
+
145
+ v = partial.length === 0 ? '[]' :
146
+ gap ? '[\n' + gap +
147
+ partial.join(',\n' + gap) + '\n' +
148
+ mind + ']' :
149
+ '[' + partial.join(',') + ']';
150
+ gap = mind;
151
+ return v;
152
+ }
153
+
154
+ // If the replacer is an array, use it to select the members to be stringified.
155
+
156
+ if (rep && typeof rep === 'object') {
157
+ length = rep.length;
158
+ for (i = 0; i < length; i += 1) {
159
+ k = rep[i];
160
+ if (typeof k === 'string') {
161
+ v = str(k, value);
162
+ if (v) {
163
+ partial.push(quote(k) + (gap ? ': ' : ':') + v);
164
+ }
165
+ }
166
+ }
167
+ } else {
168
+
169
+ // Otherwise, iterate through all of the keys in the object.
170
+
171
+ for (k in value) {
172
+ if (Object.hasOwnProperty.call(value, k)) {
173
+ v = str(k, value);
174
+ if (v) {
175
+ partial.push(quote(k) + (gap ? ': ' : ':') + v);
176
+ }
177
+ }
178
+ }
179
+ }
180
+
181
+ // Join all of the member texts together, separated with commas,
182
+ // and wrap them in braces.
183
+
184
+ v = partial.length === 0 ? '{}' :
185
+ gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
186
+ mind + '}' : '{' + partial.join(',') + '}';
187
+ gap = mind;
188
+ return v;
189
+ }
190
+ }
191
+
192
+ // If the JSON object does not yet have a stringify method, give it one.
193
+
194
+ if (typeof JSON.stringify !== 'function') {
195
+ JSON.stringify = function (value, replacer, space) {
196
+
197
+ // The stringify method takes a value and an optional replacer, and an optional
198
+ // space parameter, and returns a JSON text. The replacer can be a function
199
+ // that can replace values, or an array of strings that will select the keys.
200
+ // A default replacer method can be provided. Use of the space parameter can
201
+ // produce text that is more easily readable.
202
+
203
+ var i;
204
+ gap = '';
205
+ indent = '';
206
+
207
+ // If the space parameter is a number, make an indent string containing that
208
+ // many spaces.
209
+
210
+ if (typeof space === 'number') {
211
+ for (i = 0; i < space; i += 1) {
212
+ indent += ' ';
213
+ }
214
+
215
+ // If the space parameter is a string, it will be used as the indent string.
216
+
217
+ } else if (typeof space === 'string') {
218
+ indent = space;
219
+ }
220
+
221
+ // If there is a replacer, it must be a function or an array.
222
+ // Otherwise, throw an error.
223
+
224
+ rep = replacer;
225
+ if (replacer && typeof replacer !== 'function' &&
226
+ (typeof replacer !== 'object' ||
227
+ typeof replacer.length !== 'number')) {
228
+ throw new Error('JSON.stringify');
229
+ }
230
+
231
+ // Make a fake root object containing our value under the key of ''.
232
+ // Return the result of stringifying the value.
233
+
234
+ return str('', {'': value});
235
+ };
236
+ }
237
+
238
+
239
+ // If the JSON object does not yet have a parse method, give it one.
240
+
241
+ if (typeof JSON.parse !== 'function') {
242
+ JSON.parse = function (text, reviver) {
243
+
244
+ // The parse method takes a text and an optional reviver function, and returns
245
+ // a JavaScript value if the text is a valid JSON text.
246
+
247
+ var j;
248
+
249
+ function walk(holder, key) {
250
+
251
+ // The walk method is used to recursively walk the resulting structure so
252
+ // that modifications can be made.
253
+
254
+ var k, v, value = holder[key];
255
+ if (value && typeof value === 'object') {
256
+ for (k in value) {
257
+ if (Object.hasOwnProperty.call(value, k)) {
258
+ v = walk(value, k);
259
+ if (v !== undefined) {
260
+ value[k] = v;
261
+ } else {
262
+ delete value[k];
263
+ }
264
+ }
265
+ }
266
+ }
267
+ return reviver.call(holder, key, value);
268
+ }
269
+
270
+
271
+ // Parsing happens in four stages. In the first stage, we replace certain
272
+ // Unicode characters with escape sequences. JavaScript handles many characters
273
+ // incorrectly, either silently deleting them, or treating them as line endings.
274
+
275
+ text = String(text);
276
+ cx.lastIndex = 0;
277
+ if (cx.test(text)) {
278
+ text = text.replace(cx, function (a) {
279
+ return '\\u' +
280
+ ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
281
+ });
282
+ }
283
+
284
+ // In the second stage, we run the text against regular expressions that look
285
+ // for non-JSON patterns. We are especially concerned with '()' and 'new'
286
+ // because they can cause invocation, and '=' because it can cause mutation.
287
+ // But just to be safe, we want to reject all unexpected forms.
288
+
289
+ // We split the second stage into 4 regexp operations in order to work around
290
+ // crippling inefficiencies in IE's and Safari's regexp engines. First we
291
+ // replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
292
+ // replace all simple value tokens with ']' characters. Third, we delete all
293
+ // open brackets that follow a colon or comma or that begin the text. Finally,
294
+ // we look to see that the remaining characters are only whitespace or ']' or
295
+ // ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
296
+
297
+ if (/^[\],:{}\s]*$/
298
+ .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
299
+ .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
300
+ .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
301
+
302
+ // In the third stage we use the eval function to compile the text into a
303
+ // JavaScript structure. The '{' operator is subject to a syntactic ambiguity
304
+ // in JavaScript: it can begin a block or an object literal. We wrap the text
305
+ // in parens to eliminate the ambiguity.
306
+
307
+ j = eval('(' + text + ')');
308
+
309
+ // In the optional fourth stage, we recursively walk the new structure, passing
310
+ // each name/value pair to a reviver function for possible transformation.
311
+
312
+ return typeof reviver === 'function' ?
313
+ walk({'': j}, '') : j;
314
+ }
315
+
316
+ // If the text is not JSON parseable, then a SyntaxError is thrown.
317
+
318
+ throw new SyntaxError('JSON.parse');
319
+ };
320
+ }
321
+ }());