opal-jquery 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -4,5 +4,5 @@ gemspec
4
4
  gem 'rake'
5
5
  gem 'sprockets'
6
6
 
7
- gem 'opal'
8
- gem 'opal-spec'
7
+ gem 'opal', '~> 0.3.36'
8
+ gem 'opal-spec', '~> 0.2.8'
data/Rakefile CHANGED
@@ -1,28 +1,5 @@
1
1
  require 'bundler'
2
2
  Bundler.require
3
3
 
4
- desc "Build opal-jquery into build"
5
- task :build => [:dir] do
6
- File.open('build/opal-jquery.js', 'w+') do |out|
7
- out.puts Opal.process('opal-jquery')
8
- end
9
- end
10
-
11
- desc "Build example specs ready to run"
12
- task :build_specs => [:dir] do
13
- Opal.append_path File.join(File.dirname(__FILE__), 'spec')
14
-
15
- File.open('build/specs.js', 'w+') do |out|
16
- out.puts Opal.process('spec_helper')
17
- end
18
- end
19
-
20
- task :dir do
21
- FileUtils.mkdir_p 'build'
22
- end
23
-
24
- task :test do
25
- OpalSpec.runner
26
- end
27
-
28
- task :default => [:build_specs, :test]
4
+ require 'opal/spec/rake_task'
5
+ Opal::Spec::RakeTask.new(:default)
@@ -0,0 +1,31 @@
1
+ require 'bundler'
2
+ Bundler.require
3
+
4
+ html = <<-HTML
5
+ <!DOCTYPE html>
6
+ <html>
7
+ <head>
8
+ <title>opal-jquery specs</title>
9
+ </head>
10
+ <body>
11
+ <script src="/assets/autorun.js"></script>
12
+ </body>
13
+ </html>
14
+ HTML
15
+
16
+ map '/assets' do
17
+ env = Opal::Environment.new
18
+ env.append_path 'vendor' # for jquery
19
+ env.append_path 'spec'
20
+ run env
21
+ end
22
+
23
+ map '/' do
24
+ run lambda { |env|
25
+ if env['PATH_INFO'] == '/'
26
+ [200, {'Content-Type' => 'text/html'}, [html]]
27
+ else
28
+ Rack::Directory.new('spec').call(env)
29
+ end
30
+ }
31
+ end
@@ -0,0 +1,3 @@
1
+ //= require opal/jquery
2
+
3
+ Opal.jquery_version = <%= Opal::JQuery::VERSION.inspect %>;
@@ -0,0 +1,6 @@
1
+ require 'opal/jquery/document'
2
+ require 'opal/jquery/element'
3
+ require 'opal/jquery/event'
4
+ require 'opal/jquery/http'
5
+ require 'opal/jquery/kernel'
6
+ require 'opal/jquery/local_storage'
@@ -226,6 +226,12 @@ class Element < `jQuery`
226
226
  }
227
227
  end
228
228
 
229
+ alias_native :blur, :blur
230
+
231
+ alias_native :closest, :closest
232
+
233
+ alias_native :data, :data
234
+
229
235
  # Yields each element in #{self} collection in turn. The yielded element
230
236
  # is wrapped as a `DOM` instance.
231
237
  #
@@ -342,45 +348,38 @@ class Element < `jQuery`
342
348
 
343
349
  alias_native :siblings, :siblings
344
350
 
345
- def off(event_name, selector, handler=nil)
351
+ def on(name, selector = nil, &handler)
346
352
  %x{
347
- if (handler === nil) {
348
- handler = selector;
349
- #{self}.off(event_name, handler._jq);
353
+ if (selector === nil) {
354
+ #{self}.on(name, handler);
350
355
  }
351
356
  else {
352
- #{self}.off(event_name, selector, handler._jq);
357
+ #{self}.on(name, selector, handler);
353
358
  }
359
+
360
+ return handler;
354
361
  }
355
-
356
- handler
357
362
  end
358
363
 
359
- def on(event_name, selector=nil, &block)
360
- return unless block_given?
361
-
362
- # The choice of allowing a maximum of four parameters is arbitrary. arg1 is typically the
363
- # event object and the rest are parameters passed by trigger(). For example, Rails 3 AJAX
364
- # event handlers get passed up to three additional parameters in addition to the event object.
364
+ def off(name, selector = nil, &handler)
365
365
  %x{
366
- var handler = function(arg1, arg2, arg3, arg4) {
367
- return #{ block.call `arg1, arg2, arg3, arg4` }
368
- };
369
- block._jq = handler;
370
-
371
366
  if (selector === nil) {
372
- #{self}.on(event_name, handler);
367
+ return #{self}.off(name, handler);
373
368
  }
374
369
  else {
375
- #{self}.on(event_name, selector, handler);
370
+ return #{self}.off(name, selector, handler);
376
371
  }
377
372
  }
378
-
379
- block
380
373
  end
381
374
 
375
+ alias_native :remove_attr, :removeAttr
376
+
382
377
  alias_native :parent, :parent
383
378
 
379
+ alias_native :parents, :parents
380
+
381
+ alias_native :prepend, :prepend
382
+
384
383
  alias_native :prev, :prev
385
384
 
386
385
  alias_native :remove, :remove
@@ -10,6 +10,11 @@ class Event < `$.Event`
10
10
 
11
11
  alias_native :default_prevented?, :isDefaultPrevented
12
12
 
13
+ def kill
14
+ stop_propagation
15
+ prevent_default
16
+ end
17
+
13
18
  alias_native :prevent_default, :preventDefault
14
19
 
15
20
  def page_x
@@ -30,6 +35,14 @@ class Event < `$.Event`
30
35
  `$(#{self}.target)`
31
36
  end
32
37
 
38
+ def touch_x
39
+ `#{self}.originalEvent.touches[0].pageX`
40
+ end
41
+
42
+ def touch_y
43
+ `#{self}.originalEvent.touches[0].pageY`
44
+ end
45
+
33
46
  def type
34
47
  `#{self}.type`
35
48
  end
@@ -19,11 +19,16 @@ class HTTP
19
19
  self.new(url, :POST, opts, block).send!
20
20
  end
21
21
 
22
+ def self.put(url, opts={}, &block)
23
+ self.new(url, :PUT, opts, block).send!
24
+ end
25
+
22
26
  def initialize(url, method, options, handler=nil)
23
27
  @url = url
24
28
  @method = method
25
29
  @ok = true
26
30
  http = self
31
+ payload = options.delete :payload
27
32
  settings = options.to_native
28
33
 
29
34
  if handler
@@ -31,7 +36,14 @@ class HTTP
31
36
  end
32
37
 
33
38
  %x{
34
- settings.data = settings.payload;
39
+ if (typeof(payload) === 'string') {
40
+ settings.data = payload;
41
+ }
42
+ else if (payload !== nil) {
43
+ settings.data = payload.$to_json();
44
+ settings.contentType = 'application/json';
45
+ }
46
+
35
47
  settings.url = url;
36
48
  settings.type = method;
37
49
 
@@ -1,5 +1,5 @@
1
1
  module Opal
2
2
  module JQuery
3
- VERSION = '0.0.4'
3
+ VERSION = '0.0.5'
4
4
  end
5
5
  end
@@ -0,0 +1,3 @@
1
+ #= require opal
2
+ #= require opal-spec
3
+ #= require_tree .
@@ -65,14 +65,14 @@ describe Element do
65
65
  foo.trigger(:click)
66
66
  end
67
67
 
68
- it 'has an Event instance, plus up to three additional parameters passed to the handler' do
68
+ it 'has an Event instance, plus any additional parameters passed to the handler' do
69
69
  foo = Document['#foo']
70
70
  foo.on :bozo do |event, foo, bar, baz, buz|
71
71
  event.should be_kind_of(Event)
72
72
  foo.should == 'foo'
73
73
  bar.should == 'bar'
74
74
  baz.should == 'baz'
75
- buz.should be_nil
75
+ buz.should == 'buz'
76
76
  end
77
77
  foo.trigger(:bozo, ['foo', 'bar', 'baz', 'buz'])
78
78
  end
@@ -41,7 +41,7 @@ describe HTTP do
41
41
  run_async { response.ok?.should be_true }
42
42
  end
43
43
  end
44
-
44
+
45
45
  async 'returns false when the request failed' do
46
46
  HTTP.get('data/non_existant.txt') do |response|
47
47
  run_async { response.ok?.should be_false }
@@ -1,4 +1,4 @@
1
- describe "spec_helper"
1
+ require "spec_helper"
2
2
 
3
3
  describe LocalStorage do
4
4
  before do
@@ -1,7 +1,6 @@
1
- #= require opal-spec
2
- #= require opal-jquery
3
- #= require_self
4
- #= require_tree .
1
+ require 'jquery'
2
+ require 'opal-spec'
3
+ require 'opal-jquery'
5
4
 
6
5
  module OpalSpec
7
6
  class ExampleGroup
@@ -34,4 +33,4 @@ module OpalSpec
34
33
  end
35
34
  end
36
35
 
37
- OpalSpec::Runner.autorun
36
+ Opal::Spec::Runner.autorun
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal-jquery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-05 00:00:00.000000000Z
12
+ date: 2013-02-08 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Opal DOM library for jquery
15
15
  email: adam.beynon@gmail.com
@@ -23,8 +23,9 @@ files:
23
23
  - LICENSE
24
24
  - README.md
25
25
  - Rakefile
26
- - lib/assets/javascripts/opal-jquery.js
27
- - lib/assets/javascripts/opal/jquery.js
26
+ - config.ru
27
+ - lib/assets/javascripts/opal-jquery.js.erb
28
+ - lib/assets/javascripts/opal/jquery.rb
28
29
  - lib/assets/javascripts/opal/jquery/document.rb
29
30
  - lib/assets/javascripts/opal/jquery/element.rb
30
31
  - lib/assets/javascripts/opal/jquery/event.rb
@@ -35,6 +36,7 @@ files:
35
36
  - lib/opal/jquery.rb
36
37
  - lib/opal/jquery/version.rb
37
38
  - opal-jquery.gemspec
39
+ - spec/autorun.rb
38
40
  - spec/data/simple.txt
39
41
  - spec/data/user.json
40
42
  - spec/document_spec.rb
@@ -55,7 +57,6 @@ files:
55
57
  - spec/element_spec.rb
56
58
  - spec/event_spec.rb
57
59
  - spec/http_spec.rb
58
- - spec/index.html
59
60
  - spec/local_storage_spec.rb
60
61
  - spec/spec_helper.rb
61
62
  - vendor/jquery.js
@@ -79,11 +80,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
80
  version: '0'
80
81
  requirements: []
81
82
  rubyforge_project:
82
- rubygems_version: 1.8.11
83
+ rubygems_version: 1.8.23
83
84
  signing_key:
84
85
  specification_version: 3
85
86
  summary: Opal access to jquery
86
87
  test_files:
88
+ - spec/autorun.rb
87
89
  - spec/data/simple.txt
88
90
  - spec/data/user.json
89
91
  - spec/document_spec.rb
@@ -104,6 +106,5 @@ test_files:
104
106
  - spec/element_spec.rb
105
107
  - spec/event_spec.rb
106
108
  - spec/http_spec.rb
107
- - spec/index.html
108
109
  - spec/local_storage_spec.rb
109
110
  - spec/spec_helper.rb
@@ -1 +0,0 @@
1
- //= require opal/jquery
@@ -1,6 +0,0 @@
1
- //= require opal/jquery/document
2
- //= require opal/jquery/element
3
- //= require opal/jquery/event
4
- //= require opal/jquery/http
5
- //= require opal/jquery/kernel
6
- //= require opal/jquery/local_storage
@@ -1,10 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>opal-jquery Specs (jquery)</title>
5
- </head>
6
- <body>
7
- <script src="../vendor/jquery.js"></script>
8
- <script src="../build/specs.js"></script>
9
- </body>
10
- </html>