opal 0.2.2 → 0.3.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.
- data/.gitignore +5 -10
- data/LICENSE +75 -0
- data/README.md +55 -3
- data/Rakefile +62 -139
- data/bin/opal +7 -10
- data/gems/core/README.md +5 -0
- data/gems/core/Rakefile +7 -0
- data/gems/core/core.gemspec +13 -0
- data/gems/core/lib/core.rb +33 -0
- data/gems/core/lib/core/array.rb +1470 -0
- data/gems/core/lib/core/basic_object.rb +15 -0
- data/gems/core/lib/core/class.rb +31 -0
- data/gems/core/lib/core/dir.rb +26 -0
- data/gems/core/lib/core/error.rb +43 -0
- data/gems/core/lib/core/false_class.rb +21 -0
- data/gems/core/lib/core/file.rb +54 -0
- data/gems/core/lib/core/hash.rb +725 -0
- data/gems/core/lib/core/kernel.rb +240 -0
- data/gems/core/lib/core/module.rb +98 -0
- data/gems/core/lib/core/nil_class.rb +41 -0
- data/gems/core/lib/core/numeric.rb +370 -0
- data/gems/core/lib/core/proc.rb +11 -0
- data/gems/core/lib/core/range.rb +17 -0
- data/gems/core/lib/core/regexp.rb +18 -0
- data/gems/core/lib/core/string.rb +328 -0
- data/gems/core/lib/core/symbol.rb +15 -0
- data/gems/core/lib/core/top_self.rb +8 -0
- data/gems/core/lib/core/true_class.rb +20 -0
- data/gems/core/lib/core/vm.rb +16 -0
- data/{opals/opal/opal → gems/core}/spec/core/array/append_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/array/assoc_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/array/at_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/array/clear_spec.rb +1 -1
- data/{opals/opal/opal → gems/core}/spec/core/array/collect_bang_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/array/collect_spec.rb +0 -0
- data/gems/core/spec/core/array/compact_spec.rb +41 -0
- data/{opals/opal/opal → gems/core}/spec/core/array/concat_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/array/constructor_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/array/each_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/array/element_reference_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/array/first_spec.rb +1 -1
- data/{opals/opal/opal → gems/core}/spec/core/array/include_spec.rb +0 -0
- data/gems/core/spec/core/array/join_spec.rb +6 -0
- data/gems/core/spec/core/array/last_spec.rb +51 -0
- data/gems/core/spec/core/array/length_spec.rb +6 -0
- data/{opals/opal/opal → gems/core}/spec/core/array/map_spec.rb +2 -0
- data/gems/core/spec/core/array/reverse_spec.rb +6 -0
- data/{opals/opal/opal → gems/core}/spec/core/builtin_constants/builtin_constants_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/false/and_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/false/inspect_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/false/or_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/false/to_s_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/false/xor_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/file/join_spec.rb +1 -1
- data/gems/core/spec/core/hash/assoc_spec.rb +32 -0
- data/{opals/opal/opal → gems/core}/spec/core/kernel/instance_eval_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/kernel/loop_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/kernel/raise_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/module/attr_accessor_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/number/lt_spec.rb +0 -0
- data/gems/core/spec/core/string/sub_spec.rb +24 -0
- data/{opals/opal/opal → gems/core}/spec/core/true/and_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/true/inspect_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/true/or_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/true/to_s_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/core/true/xor_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/language/and_spec.rb +2 -3
- data/{opals/opal/opal → gems/core}/spec/language/array_spec.rb +21 -5
- data/gems/core/spec/language/block_spec.rb +38 -0
- data/{opals/opal/opal → gems/core}/spec/language/break_spec.rb +0 -0
- data/gems/core/spec/language/case_spec.rb +103 -0
- data/{opals/opal/opal → gems/core}/spec/language/def_spec.rb +11 -1
- data/{opals/opal/opal → gems/core}/spec/language/eigenclass_spec.rb +0 -0
- data/gems/core/spec/language/file_spec.rb +13 -0
- data/gems/core/spec/language/fixtures/block.rb +21 -0
- data/gems/core/spec/language/fixtures/super.rb +293 -0
- data/{opals/opal/opal → gems/core}/spec/language/hash_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/language/if_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/language/loop_spec.rb +0 -0
- data/gems/core/spec/language/metaclass_spec.rb +21 -0
- data/{opals/opal/opal → gems/core}/spec/language/method_spec.rb +60 -0
- data/{opals/opal/opal → gems/core}/spec/language/next_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/language/or_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/language/redo_spec.rb +0 -0
- data/gems/core/spec/language/regexp_spec.rb +26 -0
- data/{opals/opal/opal → gems/core}/spec/language/rescue_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/language/return_spec.rb +0 -0
- data/{opals/opal/opal → gems/core}/spec/language/string_spec.rb +0 -0
- data/gems/core/spec/language/super_spec.rb +32 -0
- data/{opals/opal/opal → gems/core}/spec/language/until_spec.rb +47 -47
- data/gems/core/spec/language/variables_spec.rb +155 -0
- data/{opals/opal/opal → gems/core}/spec/language/while_spec.rb +47 -47
- data/{opals/opal/opal → gems/core}/spec/spec_helper.rb +1 -1
- data/gems/core_fs/README.md +19 -0
- data/gems/dev/Rakefile +5 -0
- data/gems/dev/lib/dev.js +99 -0
- data/gems/dev/lib/dev/generator.js +1264 -0
- data/gems/dev/lib/dev/parser.js +979 -0
- data/gems/dev/lib/dev/ruby_parser.js +1088 -0
- data/gems/dev/lib/dev/ruby_parser.y +1267 -0
- data/gems/dev/lib/dev/string_scanner.js +38 -0
- data/gems/dev/tools/racc2js/README.md +39 -0
- data/gems/dev/tools/racc2js/math_parser.js +222 -0
- data/gems/dev/tools/racc2js/math_parser.rb +133 -0
- data/gems/dev/tools/racc2js/math_parser.y +28 -0
- data/gems/dev/tools/racc2js/parser.js +218 -0
- data/gems/dev/tools/racc2js/racc2js.rb +153 -0
- data/gems/json/README.md +4 -0
- data/gems/json/json.gemspec +14 -0
- data/gems/json/lib/json.rb +64 -0
- data/gems/json/lib/json/ext.rb +51 -0
- data/{opals/opal/browser/lib/browser/json_parse.js → gems/json/lib/json/json2.js} +197 -37
- data/gems/ospec/README.md +0 -0
- data/gems/ospec/lib/ospec.rb +6 -0
- data/gems/ospec/lib/ospec/autorun.rb +3 -0
- data/gems/ospec/lib/ospec/dsl.rb +15 -0
- data/gems/ospec/lib/ospec/example.rb +11 -0
- data/gems/ospec/lib/ospec/example/before_and_after_hooks.rb +56 -0
- data/gems/ospec/lib/ospec/example/errors.rb +17 -0
- data/gems/ospec/lib/ospec/example/example_group.rb +12 -0
- data/gems/ospec/lib/ospec/example/example_group_factory.rb +21 -0
- data/gems/ospec/lib/ospec/example/example_group_hierarchy.rb +20 -0
- data/{opals/opal/spec/lib/spec → gems/ospec/lib/ospec}/example/example_group_methods.rb +26 -68
- data/gems/ospec/lib/ospec/example/example_group_proxy.rb +14 -0
- data/gems/ospec/lib/ospec/example/example_methods.rb +46 -0
- data/gems/ospec/lib/ospec/example/example_proxy.rb +18 -0
- data/gems/ospec/lib/ospec/expectations.rb +19 -0
- data/gems/ospec/lib/ospec/expectations/errors.rb +8 -0
- data/gems/ospec/lib/ospec/expectations/fail_with.rb +8 -0
- data/gems/ospec/lib/ospec/expectations/handler.rb +27 -0
- data/gems/ospec/lib/ospec/matchers.rb +24 -0
- data/{opals/opal/Rakefile → gems/ospec/lib/ospec/matchers/be.rb} +0 -0
- data/gems/ospec/lib/ospec/matchers/generated_descriptions.rb +20 -0
- data/gems/ospec/lib/ospec/matchers/operator_matcher.rb +52 -0
- data/gems/ospec/lib/ospec/runner.rb +40 -0
- data/gems/ospec/lib/ospec/runner/example_group_runner.rb +44 -0
- data/{opals/opal/spec/lib/spec → gems/ospec/lib/ospec}/runner/formatter/html_formatter.rb +31 -40
- data/gems/ospec/lib/ospec/runner/formatter/terminal_formatter.rb +48 -0
- data/gems/ospec/lib/ospec/runner/options.rb +36 -0
- data/{opals/opal/spec/lib/spec → gems/ospec/lib/ospec}/runner/reporter.rb +23 -55
- data/gems/ospec/ospec.gemspec +0 -0
- data/gems/rquery/README.md +9 -0
- data/gems/rquery/lib/rquery.rb +10 -0
- data/gems/rquery/lib/rquery/ajax.rb +4 -0
- data/gems/rquery/lib/rquery/css.rb +96 -0
- data/gems/rquery/lib/rquery/document.rb +25 -0
- data/gems/rquery/lib/rquery/element.rb +292 -0
- data/gems/rquery/lib/rquery/event.rb +108 -0
- data/gems/rquery/lib/rquery/jquery.js +8177 -0
- data/gems/rquery/lib/rquery/request.rb +138 -0
- data/gems/rquery/lib/rquery/response.rb +49 -0
- data/gems/rquery/rquery.gemspec +16 -0
- data/lib/opal.js +1597 -0
- data/lib/opal.rb +6 -69
- data/lib/opal/builder.rb +115 -0
- data/lib/opal/bundle.rb +131 -0
- data/lib/opal/command.rb +11 -0
- data/lib/opal/context.rb +69 -0
- data/lib/opal/context/console.rb +12 -0
- data/lib/opal/context/file_system.rb +19 -0
- data/lib/opal/context/loader.rb +117 -0
- data/lib/opal/gem.rb +153 -0
- data/lib/opal/ruby/nodes.rb +1302 -0
- data/lib/opal/ruby/parser.rb +780 -0
- data/lib/opal/ruby/ruby_parser.rb +5170 -0
- data/lib/opal/ruby/ruby_parser.y +1298 -0
- data/opal.gemspec +11 -256
- metadata +179 -240
- data/.gitmodules +0 -6
- data/Opalfile +0 -384
- data/VERSION +0 -1
- data/demos/apps/browser_demo/index.html +0 -11
- data/demos/apps/browser_demo/lib/browser_demo.rb +0 -31
- data/demos/apps/simple_opal/Opalfile +0 -13
- data/demos/apps/simple_opal/index.html +0 -11
- data/demos/apps/simple_opal/lib/app_controller.rb +0 -62
- data/demos/apps/simple_opal/lib/main_window.rb +0 -146
- data/demos/browser/request/index.html +0 -52
- data/demos/browser/request/request.rb +0 -48
- data/gen/browser/__PROJECT_NAME__/Rakefile +0 -12
- data/gen/browser/__PROJECT_NAME__/index.html +0 -11
- data/gen/browser/__PROJECT_NAME__/javascripts/opal.debug.js +0 -4687
- data/gen/browser/__PROJECT_NAME__/javascripts/opal.min.js +0 -175
- data/gen/browser/__PROJECT_NAME__/lib/__PROJECT_NAME__.rb +0 -1
- data/lib/opal/builders/base.rb +0 -50
- data/lib/opal/builders/css.rb +0 -46
- data/lib/opal/builders/javascript.rb +0 -44
- data/lib/opal/builders/opal.rb +0 -79
- data/lib/opal/builders/ruby.rb +0 -50
- data/lib/opal/builders/ruby/generate.rb +0 -1851
- data/lib/opal/builders/ruby/nodes.rb +0 -210
- data/lib/opal/builders/ruby/ruby.rb +0 -916
- data/lib/opal/builders/ruby/ruby_parser.rb +0 -6008
- data/lib/opal/builders/ruby/ruby_parser.rb.y +0 -1451
- data/lib/opal/models/build_item.rb +0 -104
- data/lib/opal/models/hash_struct.rb +0 -40
- data/lib/opal/models/project.rb +0 -252
- data/lib/opal/models/struct_accessors.rb +0 -58
- data/lib/opal/models/target.rb +0 -176
- data/lib/opal/opal/build.rb +0 -169
- data/lib/opal/opal/env/console.rb +0 -66
- data/lib/opal/opal/env/fs.rb +0 -98
- data/lib/opal/opal/env/object.rb +0 -48
- data/lib/opal/opal/environment.rb +0 -139
- data/lib/opal/opal/gen.rb +0 -62
- data/lib/opal/opal/opal.rb +0 -75
- data/lib/opal/opal/repl.rb +0 -38
- data/lib/opal/opalfile/dsl.rb +0 -62
- data/lib/opal/opalfile/opalfile.rb +0 -133
- data/lib/opal/opalfile/task.rb +0 -96
- data/lib/opal/opalfile/task_manager.rb +0 -63
- data/lib/opal/opalfile/task_scope.rb +0 -52
- data/lib/opal/rack/app_server.rb +0 -119
- data/lib/opal/rake/opal_task.rb +0 -34
- data/opals/opal/README.md +0 -37
- data/opals/opal/browser/Opalfile +0 -11
- data/opals/opal/browser/README.md +0 -146
- data/opals/opal/browser/SIZZLE_LICESNSE.txt +0 -148
- data/opals/opal/browser/lib/browser.rb +0 -118
- data/opals/opal/browser/lib/browser/builder.rb +0 -41
- data/opals/opal/browser/lib/browser/canvas_context.rb +0 -115
- data/opals/opal/browser/lib/browser/dimensions.rb +0 -50
- data/opals/opal/browser/lib/browser/document.rb +0 -146
- data/opals/opal/browser/lib/browser/element.rb +0 -487
- data/opals/opal/browser/lib/browser/element/attributes.rb +0 -88
- data/opals/opal/browser/lib/browser/element/css.rb +0 -290
- data/opals/opal/browser/lib/browser/element/form.rb +0 -146
- data/opals/opal/browser/lib/browser/event/dom_events.rb +0 -81
- data/opals/opal/browser/lib/browser/event/event.rb +0 -177
- data/opals/opal/browser/lib/browser/event/trigger_events.rb +0 -53
- data/opals/opal/browser/lib/browser/geometry.rb +0 -97
- data/opals/opal/browser/lib/browser/json.rb +0 -32
- data/opals/opal/browser/lib/browser/request/request.rb +0 -201
- data/opals/opal/browser/lib/browser/sizzle.js +0 -1068
- data/opals/opal/browser/lib/browser/string.rb +0 -42
- data/opals/opal/browser/lib/browser/touch.rb +0 -37
- data/opals/opal/browser/lib/browser/vml_context.js +0 -33
- data/opals/opal/browser/lib/browser/window.rb +0 -36
- data/opals/opal/browser/spec/browser/browser_detection_spec.rb +0 -7
- data/opals/opal/browser/spec/document/aref_spec.rb +0 -110
- data/opals/opal/browser/spec/document/ready_spec.rb +0 -16
- data/opals/opal/browser/spec/element/body_spec.rb +0 -11
- data/opals/opal/browser/spec/element/clear_spec.rb +0 -26
- data/opals/opal/browser/spec/element/empty_spec.rb +0 -29
- data/opals/opal/browser/spec/element/has_class_spec.rb +0 -40
- data/opals/opal/browser/spec/element/hidden_spec.rb +0 -23
- data/opals/opal/browser/spec/element/hide_spec.rb +0 -31
- data/opals/opal/browser/spec/element/remove_spec.rb +0 -25
- data/opals/opal/browser/spec/element/show_spec.rb +0 -31
- data/opals/opal/browser/spec/element/style_spec.rb +0 -69
- data/opals/opal/browser/spec/element/toggle_spec.rb +0 -31
- data/opals/opal/browser/spec/element/visible_spec.rb +0 -23
- data/opals/opal/browser/spec/spec_helper.rb +0 -1
- data/opals/opal/opal/Opalfile +0 -14
- data/opals/opal/opal/spec/core/array/compact_spec.rb +0 -15
- data/opals/opal/opal/spec/fixtures/super.rb +0 -70
- data/opals/opal/opal/spec/language/____temp_remove_this.rb +0 -12
- data/opals/opal/opal/spec/language/block_spec.rb +0 -18
- data/opals/opal/opal/spec/language/case_spec.rb +0 -103
- data/opals/opal/opal/spec/language/metaclass_spec.rb +0 -21
- data/opals/opal/opal/spec/language/super_spec.rb +0 -26
- data/opals/opal/runtime/Opalfile +0 -78
- data/opals/opal/runtime/README.md +0 -12
- data/opals/opal/runtime/docs/debugging.md +0 -51
- data/opals/opal/runtime/lib/array.rb +0 -1516
- data/opals/opal/runtime/lib/basic_object.rb +0 -49
- data/opals/opal/runtime/lib/class.rb +0 -54
- data/opals/opal/runtime/lib/dir.rb +0 -36
- data/opals/opal/runtime/lib/error.rb +0 -49
- data/opals/opal/runtime/lib/false_class.rb +0 -52
- data/opals/opal/runtime/lib/file.rb +0 -79
- data/opals/opal/runtime/lib/hash.rb +0 -791
- data/opals/opal/runtime/lib/io.rb +0 -39
- data/opals/opal/runtime/lib/kernel.rb +0 -288
- data/opals/opal/runtime/lib/match_data.rb +0 -36
- data/opals/opal/runtime/lib/module.rb +0 -109
- data/opals/opal/runtime/lib/nil_class.rb +0 -69
- data/opals/opal/runtime/lib/number.rb +0 -398
- data/opals/opal/runtime/lib/proc.rb +0 -77
- data/opals/opal/runtime/lib/range.rb +0 -63
- data/opals/opal/runtime/lib/regexp.rb +0 -111
- data/opals/opal/runtime/lib/ruby.rb +0 -30
- data/opals/opal/runtime/lib/string.rb +0 -328
- data/opals/opal/runtime/lib/symbol.rb +0 -40
- data/opals/opal/runtime/lib/top_self.rb +0 -33
- data/opals/opal/runtime/lib/true_class.rb +0 -45
- data/opals/opal/runtime/runtime/browser.js +0 -287
- data/opals/opal/runtime/runtime/debug.js +0 -180
- data/opals/opal/runtime/runtime/opal.js +0 -1008
- data/opals/opal/runtime/runtime/post_opal.js +0 -1
- data/opals/opal/runtime/runtime/pre_opal.js +0 -2
- data/opals/opal/runtime/runtime/server_side.js +0 -50
- data/opals/opal/spec/LICENSE.txt +0 -26
- data/opals/opal/spec/Opalfile +0 -5
- data/opals/opal/spec/bin/spec.rb +0 -43
- data/opals/opal/spec/lib/spec.rb +0 -33
- data/opals/opal/spec/lib/spec/dsl.rb +0 -41
- data/opals/opal/spec/lib/spec/example.rb +0 -35
- data/opals/opal/spec/lib/spec/example/before_and_after_hooks.rb +0 -81
- data/opals/opal/spec/lib/spec/example/errors.rb +0 -42
- data/opals/opal/spec/lib/spec/example/example_group.rb +0 -37
- data/opals/opal/spec/lib/spec/example/example_group_factory.rb +0 -43
- data/opals/opal/spec/lib/spec/example/example_group_hierarchy.rb +0 -45
- data/opals/opal/spec/lib/spec/example/example_group_proxy.rb +0 -41
- data/opals/opal/spec/lib/spec/example/example_methods.rb +0 -73
- data/opals/opal/spec/lib/spec/example/example_proxy.rb +0 -48
- data/opals/opal/spec/lib/spec/expectations.rb +0 -46
- data/opals/opal/spec/lib/spec/expectations/errors.rb +0 -35
- data/opals/opal/spec/lib/spec/expectations/fail_with.rb +0 -37
- data/opals/opal/spec/lib/spec/expectations/handler.rb +0 -48
- data/opals/opal/spec/lib/spec/matchers.rb +0 -50
- data/opals/opal/spec/lib/spec/matchers/be.rb +0 -26
- data/opals/opal/spec/lib/spec/matchers/generated_descriptions.rb +0 -47
- data/opals/opal/spec/lib/spec/matchers/operator_matcher.rb +0 -66
- data/opals/opal/spec/lib/spec/runner.rb +0 -48
- data/opals/opal/spec/lib/spec/runner/example_group_runner.rb +0 -71
- data/opals/opal/spec/lib/spec/runner/formatter/terminal_formatter.rb +0 -82
- data/opals/opal/spec/lib/spec/runner/options.rb +0 -63
- data/opals/opal/spec/resources/index.html +0 -25
- data/opals/opal/spec/resources/spec.css +0 -132
- data/spec/cherry_kit/iseq_spec.rb +0 -38
- data/spec/spec_helper.rb +0 -16
- data/spec/vienna_spec.rb +0 -7
- data/yard/index.html +0 -43
- data/yard/style.css +0 -765
|
@@ -1,81 +0,0 @@
|
|
|
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
|
|
@@ -1,177 +0,0 @@
|
|
|
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'
|
|
@@ -1,53 +0,0 @@
|
|
|
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
|
|
@@ -1,97 +0,0 @@
|
|
|
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
|
|
@@ -1,32 +0,0 @@
|
|
|
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
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
#
|
|
2
|
-
# request.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
|
-
require 'browser/event/trigger_events'
|
|
28
|
-
|
|
29
|
-
# Request class
|
|
30
|
-
#
|
|
31
|
-
# ## Events
|
|
32
|
-
#
|
|
33
|
-
# ### request
|
|
34
|
-
#
|
|
35
|
-
# Triggered when request is initially sent.
|
|
36
|
-
#
|
|
37
|
-
# ### complete
|
|
38
|
-
#
|
|
39
|
-
# Triggered when the request completes. Last callback to be triggered (it is
|
|
40
|
-
# fired after :success/:failure)
|
|
41
|
-
#
|
|
42
|
-
# ### cancel
|
|
43
|
-
#
|
|
44
|
-
# Triggered if request cancels
|
|
45
|
-
#
|
|
46
|
-
# ### success
|
|
47
|
-
#
|
|
48
|
-
# Triggered if the event completes successfully
|
|
49
|
-
#
|
|
50
|
-
# ### failure
|
|
51
|
-
#
|
|
52
|
-
# Triggered if the request failed (got a response, but it was an error code)
|
|
53
|
-
#
|
|
54
|
-
class Request
|
|
55
|
-
|
|
56
|
-
include Event::TriggerEvents
|
|
57
|
-
|
|
58
|
-
OPTIONS = {
|
|
59
|
-
:url => '',
|
|
60
|
-
:data => {},
|
|
61
|
-
# :headers => {
|
|
62
|
-
# 'X-Requested-With' => 'XMLHttpRequest',
|
|
63
|
-
# 'Accept' =>' text/javascript, text/html, application/xml, text/xml, */*'
|
|
64
|
-
# },
|
|
65
|
-
:async => true,
|
|
66
|
-
:format => nil,
|
|
67
|
-
:method => 'POST',
|
|
68
|
-
:link => 'ignore',
|
|
69
|
-
:is_success => nil,
|
|
70
|
-
:emulation => true,
|
|
71
|
-
:url_encoded => true,
|
|
72
|
-
:encoding => 'utf-8',
|
|
73
|
-
:eval_scripts => false,
|
|
74
|
-
:eval_response => false,
|
|
75
|
-
:timeout => 0,
|
|
76
|
-
:no_cache => false
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
# Get the current status of the request
|
|
80
|
-
attr_reader :status
|
|
81
|
-
|
|
82
|
-
attr_reader :text
|
|
83
|
-
|
|
84
|
-
def initialize(options = {})
|
|
85
|
-
`#{self}.__xhr__ = opal.request();`
|
|
86
|
-
@options = OPTIONS.merge options
|
|
87
|
-
@headers = @options[:headers]
|
|
88
|
-
@running = false
|
|
89
|
-
@status = 0
|
|
90
|
-
@text = ""
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
# FIXME: Do we want lowercase? good practice to use uppercase?
|
|
94
|
-
%W{get post put delete GET POST PUT DELETE}.each do |method|
|
|
95
|
-
define_method(method) do |data|
|
|
96
|
-
send :data => data, :method => method
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
# Sends the request with the given data and options. Can also take a block
|
|
101
|
-
# that acts as the on :complete proc callback handler.
|
|
102
|
-
#
|
|
103
|
-
# @example
|
|
104
|
-
# request = Request.new :url => 'clients.html, :method => 'get'
|
|
105
|
-
#
|
|
106
|
-
# @param [Hash] options to set on receiver before sending
|
|
107
|
-
# @return [Request] returns receiver
|
|
108
|
-
def send(options = {}, &block)
|
|
109
|
-
@running = true
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
method = :post
|
|
113
|
-
|
|
114
|
-
url = options[:url] || ""
|
|
115
|
-
|
|
116
|
-
request = self
|
|
117
|
-
`#{self}.__xhr__.onreadystatechange = function() {
|
|
118
|
-
#{request}.$state_change();
|
|
119
|
-
};`
|
|
120
|
-
|
|
121
|
-
`#{self}.__xhr__.open(#{method.to_s}.toUpperCase(), #{url}, true);`
|
|
122
|
-
|
|
123
|
-
trigger :request, self
|
|
124
|
-
|
|
125
|
-
`#{self}.__xhr__.send(null);`
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
# Returns +true+ if the +Request+ is running, +false+ otherwise
|
|
129
|
-
#
|
|
130
|
-
# @example
|
|
131
|
-
# req = Request.new
|
|
132
|
-
# req.running? # => false
|
|
133
|
-
# req.send
|
|
134
|
-
# req.running? # => true
|
|
135
|
-
#
|
|
136
|
-
# @return [true, false]
|
|
137
|
-
def running?
|
|
138
|
-
@running
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
# Returns +true+ if the request succeeded, +false+ otherwise
|
|
142
|
-
#
|
|
143
|
-
# @return [true, false]
|
|
144
|
-
def success?
|
|
145
|
-
`return (#{@status} >= 200 && #{@status} < 300) ? #{true} : #{false};`
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
# Returns +true+ if the request failed, +false+ otherwise
|
|
149
|
-
#
|
|
150
|
-
# @return [true, false]
|
|
151
|
-
def failed?
|
|
152
|
-
!success?
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
def state_change
|
|
156
|
-
# only handle state change when request is done (state 4)
|
|
157
|
-
`if (#{self}.__xhr__.readyState !== 4 || !#{@running}.r) return;`
|
|
158
|
-
|
|
159
|
-
`#{self}.__xhr__.onreadystatechange = function() { };`
|
|
160
|
-
|
|
161
|
-
@running = false
|
|
162
|
-
@status = 0
|
|
163
|
-
|
|
164
|
-
begin
|
|
165
|
-
@status = `#{self}.__xhr__.status`
|
|
166
|
-
rescue Exception => e
|
|
167
|
-
# warning?
|
|
168
|
-
puts "warning"
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
puts "our status is now #{@status}"
|
|
172
|
-
|
|
173
|
-
# should be:
|
|
174
|
-
# @status = `#{@xhr}.status` rescue nil
|
|
175
|
-
|
|
176
|
-
if success?
|
|
177
|
-
# puts "success #{@status}"
|
|
178
|
-
@text = `#{self}.__xhr__.responseText || ''`
|
|
179
|
-
|
|
180
|
-
trigger :success, self
|
|
181
|
-
trigger :complete, self
|
|
182
|
-
else
|
|
183
|
-
`console.log(#{@status});`
|
|
184
|
-
puts "aww :( #{@status}"
|
|
185
|
-
|
|
186
|
-
trigger :failure, self
|
|
187
|
-
trigger :complete, self
|
|
188
|
-
end
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
def cancel
|
|
192
|
-
return self unless @running
|
|
193
|
-
@running = false
|
|
194
|
-
`#{self}.__xhr__.abort();`
|
|
195
|
-
`#{self}.__xhr__.onreadystatechange = function() {};`
|
|
196
|
-
`#{self}.__xhr__ = opal.request();`
|
|
197
|
-
trigger :cancel
|
|
198
|
-
self
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
end
|