opal-jquery 0.4.1 → 0.4.5
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.
- checksums.yaml +5 -5
- data/.editorconfig +12 -0
- data/.travis.yml +27 -9
- data/CHANGELOG.md +56 -2
- data/Gemfile +15 -0
- data/README.md +5 -3
- data/Rakefile +22 -4
- data/config.ru +4 -6
- data/lib/opal/jquery/element.rb +91 -25
- data/lib/opal/jquery/http.rb +10 -2
- data/lib/opal/jquery/version.rb +1 -1
- data/lib/opal/jquery/window.rb +2 -1
- data/opal-jquery.gemspec +8 -7
- data/{spec → spec-opal}/document_spec.rb +11 -4
- data/{spec → spec-opal}/element/after_spec.rb +1 -1
- data/{spec → spec-opal}/element/animations_spec.rb +5 -5
- data/{spec → spec-opal}/element/append_spec.rb +1 -1
- data/{spec → spec-opal}/element/append_to_spec.rb +1 -1
- data/{spec → spec-opal}/element/at_spec.rb +1 -1
- data/{spec → spec-opal}/element/attributes_spec.rb +1 -1
- data/{spec → spec-opal}/element/before_spec.rb +1 -1
- data/{spec → spec-opal}/element/class_name_spec.rb +2 -2
- data/{spec → spec-opal}/element/css_spec.rb +3 -3
- data/{spec → spec-opal}/element/display_spec.rb +6 -6
- data/spec-opal/element/expose_spec.rb +73 -0
- data/{spec → spec-opal}/element/height_width_spec.rb +1 -1
- data/{spec → spec-opal}/element/inspect_spec.rb +1 -1
- data/{spec → spec-opal}/element/iterable_spec.rb +1 -1
- data/{spec → spec-opal}/element/length_spec.rb +1 -1
- data/spec-opal/element/method_missing_spec.rb +34 -0
- data/{spec → spec-opal}/element/prepend_spec.rb +1 -1
- data/{spec → spec-opal}/element/to_s_spec.rb +1 -1
- data/{spec → spec-opal}/element/traversing_spec.rb +5 -5
- data/spec-opal/element_spec.rb +261 -0
- data/{spec → spec-opal}/event_spec.rb +1 -1
- data/{spec → spec-opal}/fixtures/simple.txt +0 -0
- data/{spec → spec-opal}/fixtures/user.json +0 -0
- data/{spec → spec-opal}/http_spec.rb +15 -1
- data/{spec → spec-opal}/jquery/index.html.erb +2 -1
- data/spec-opal/jquery/index3.html.erb +10 -0
- data/{spec/jquery/jquery.js → spec-opal/jquery/jquery-1.8.3.js} +0 -0
- data/spec-opal/jquery/jquery-3.0.0.js +4 -0
- data/spec-opal/kernel_spec.rb +15 -0
- data/{spec → spec-opal}/local_storage_spec.rb +1 -1
- data/{spec → spec-opal}/spec_helper.rb +10 -0
- data/{spec → spec-opal}/zepto/index.html.erb +1 -0
- data/{spec → spec-opal}/zepto/zepto.js +0 -0
- metadata +81 -83
- data/spec/element/method_missing_spec.rb +0 -32
- data/spec/element_spec.rb +0 -261
- data/spec/kernel_spec.rb +0 -7
data/lib/opal/jquery/http.rb
CHANGED
@@ -165,7 +165,7 @@ class HTTP
|
|
165
165
|
|
166
166
|
%x{
|
167
167
|
if (typeof(#{payload}) === 'string') {
|
168
|
-
|
168
|
+
settings.data = payload;
|
169
169
|
}
|
170
170
|
else if (payload != nil) {
|
171
171
|
settings.data = payload.$to_json();
|
@@ -223,8 +223,16 @@ class HTTP
|
|
223
223
|
#
|
224
224
|
# @param key [String] name of the header to get
|
225
225
|
# @return [String] value of the header
|
226
|
+
# @return [nil] if the header +key+ was not in the response
|
226
227
|
def get_header(key)
|
227
|
-
|
228
|
+
%x{
|
229
|
+
var value = #@xhr.getResponseHeader(#{key});
|
230
|
+
return (value === null) ? nil : value;
|
231
|
+
}
|
232
|
+
end
|
233
|
+
|
234
|
+
def inspect
|
235
|
+
"#<HTTP @url=#{@url} @method=#{@method}>"
|
228
236
|
end
|
229
237
|
|
230
238
|
private
|
data/lib/opal/jquery/version.rb
CHANGED
data/lib/opal/jquery/window.rb
CHANGED
@@ -6,7 +6,8 @@ module Browser
|
|
6
6
|
# Generally, you will want to use the top level {::Window} instance, which
|
7
7
|
# wraps `window` from the main page.
|
8
8
|
class Window
|
9
|
-
|
9
|
+
# In more recent Opal versions Native::Wrapper should be used
|
10
|
+
include defined?(Native::Wrapper) ? Native::Wrapper : Native
|
10
11
|
|
11
12
|
# Returns this {Window} instance wrapped as an {Element}. Useful for
|
12
13
|
# delegating jQuery events, which allows the use of `window` as target.
|
data/opal-jquery.gemspec
CHANGED
@@ -4,19 +4,20 @@ require File.expand_path('../lib/opal/jquery/version', __FILE__)
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = 'opal-jquery'
|
6
6
|
s.version = Opal::JQuery::VERSION
|
7
|
-
s.
|
8
|
-
s.email = '
|
9
|
-
s.homepage = '
|
10
|
-
s.summary = 'Opal access to
|
11
|
-
s.description = 'Opal DOM library for
|
7
|
+
s.authors = ['Adam Beynon', 'Elia Schito']
|
8
|
+
s.email = 'elia@schito.me'
|
9
|
+
s.homepage = 'https://github.com/opal/opal-jquery#readme'
|
10
|
+
s.summary = 'Opal access to jQuery'
|
11
|
+
s.description = 'Opal DOM library for jQuery'
|
12
12
|
|
13
13
|
s.files = `git ls-files`.split("\n")
|
14
14
|
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
15
15
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
16
|
s.require_paths = ['lib']
|
17
17
|
|
18
|
-
s.add_runtime_dependency 'opal', '>= 0.
|
19
|
-
s.add_development_dependency 'opal-rspec', '
|
18
|
+
s.add_runtime_dependency 'opal', ['>= 0.10.0', '< 2.0']
|
19
|
+
s.add_development_dependency 'opal-rspec', ['>= 0.7', '< 2.0']
|
20
|
+
s.add_development_dependency 'opal-sprockets', ['>= 0.4.1', '< 2.0']
|
20
21
|
s.add_development_dependency 'yard'
|
21
22
|
s.add_development_dependency 'rake'
|
22
23
|
end
|
@@ -1,22 +1,29 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Document do
|
3
|
+
RSpec.describe 'Document' do
|
4
4
|
subject { Document }
|
5
5
|
|
6
6
|
describe "ready?" do
|
7
|
+
it "accepts a block" do
|
8
|
+
Document.ready? {
|
9
|
+
puts `$.fn.jquery`
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
7
13
|
it "accepts a block" do
|
8
14
|
Document.ready? { }
|
9
15
|
end
|
10
16
|
end
|
11
|
-
|
17
|
+
|
12
18
|
describe "ready" do
|
19
|
+
p self.ancestors
|
13
20
|
async "resolves when document is ready" do
|
14
|
-
Document.ready.then do
|
21
|
+
Document.ready.then do
|
15
22
|
async { Document.ready.resolved?.should be_truthy }
|
16
23
|
end
|
17
24
|
end
|
18
25
|
end
|
19
|
-
|
26
|
+
|
20
27
|
describe "title" do
|
21
28
|
it "gets the document title" do
|
22
29
|
Document.title.should be_kind_of(String)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe "Element animation methods" do
|
3
|
+
RSpec.describe "Element animation methods" do
|
4
4
|
html <<-HTML
|
5
5
|
<div id="animate-foo"></div>
|
6
6
|
HTML
|
@@ -41,16 +41,16 @@ describe "Element animation methods" do
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
describe "Element effects methods" do
|
44
|
+
RSpec.describe "Element effects methods" do
|
45
45
|
html <<-HTML
|
46
46
|
<div id="effects-foo"></div>
|
47
47
|
HTML
|
48
|
-
|
48
|
+
|
49
49
|
describe "#fadeout / #fadein" do
|
50
50
|
async "should fade the element out first" do
|
51
51
|
foo = Element.find "#effects-foo"
|
52
52
|
foo.effect(:fade_out)
|
53
|
-
|
53
|
+
|
54
54
|
delay 1 do
|
55
55
|
async {
|
56
56
|
foo.css("display").should eq("none")
|
@@ -64,4 +64,4 @@ describe "Element effects methods" do
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
67
|
-
end
|
67
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe "Element#class_name" do
|
3
|
+
RSpec.describe "Element#class_name" do
|
4
4
|
html <<-HTML
|
5
5
|
<div id="foo" class="whiskey"></div>
|
6
6
|
<div id="bar" class="scotch brandy"></div>
|
@@ -30,7 +30,7 @@ describe "Element#class_name" do
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
describe "Element#class_name=" do
|
33
|
+
RSpec.describe "Element#class_name=" do
|
34
34
|
before do
|
35
35
|
@div = Element.parse <<-HTML
|
36
36
|
<div id="class-name-set-spec">
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe "Element#css" do
|
3
|
+
RSpec.describe "Element#css" do
|
4
4
|
html <<-HTML
|
5
5
|
<div id="foo" style="background-color:rgb(15,99,30); color:;"></div>
|
6
6
|
<div id="bar"></div>
|
@@ -32,8 +32,8 @@ describe "Element#css" do
|
|
32
32
|
it "should set the properties" do
|
33
33
|
hash = Element.find("#hash")
|
34
34
|
hash.css(:width => "100px", :height => "200px")
|
35
|
-
hash.css("width").should be_kind_of(String)
|
36
|
-
hash.css("height").should be_kind_of(String)
|
35
|
+
hash.css("width").should be_kind_of(String)
|
36
|
+
hash.css("height").should be_kind_of(String)
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should return self" do
|
@@ -1,34 +1,34 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe "Element display methods" do
|
3
|
+
RSpec.describe "Element display methods" do
|
4
4
|
html <<-HTML
|
5
5
|
<div id="shown"></div>
|
6
6
|
<div id="hidden" style="display: none"></div>
|
7
7
|
HTML
|
8
8
|
|
9
9
|
it "hides an element" do
|
10
|
-
element = Element.find('#shown')
|
10
|
+
element = Element.find('#shown')
|
11
11
|
element.css('display').should == 'block'
|
12
12
|
element.hide
|
13
13
|
element.css('display').should == 'none'
|
14
14
|
end
|
15
15
|
|
16
|
-
it "shows an element" do
|
17
|
-
element = Element.find('#hidden')
|
16
|
+
it "shows an element" do
|
17
|
+
element = Element.find('#hidden')
|
18
18
|
element.css('display').should == 'none'
|
19
19
|
element.show
|
20
20
|
element.css('display').should == 'block'
|
21
21
|
end
|
22
22
|
|
23
23
|
it "toggles on a hidden element" do
|
24
|
-
element = Element.find('#hidden')
|
24
|
+
element = Element.find('#hidden')
|
25
25
|
element.css('display').should == 'none'
|
26
26
|
element.toggle
|
27
27
|
element.css('display').should == 'block'
|
28
28
|
end
|
29
29
|
|
30
30
|
it "toggles off a displayed element" do
|
31
|
-
element = Element.find('#shown')
|
31
|
+
element = Element.find('#shown')
|
32
32
|
element.css('display').should == 'block'
|
33
33
|
element.toggle
|
34
34
|
element.css('display').should == 'none'
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe "Element#expose" do
|
4
|
+
subject(:element) { Element.new }
|
5
|
+
before do
|
6
|
+
`$.fn.exposableMethod = function() {return 123}`
|
7
|
+
`$.fn.exposableMethod2 = function() {return 12}`
|
8
|
+
`$.fn.opal_specs_extension = function() {return "foo_bar_baz";};`
|
9
|
+
`$.fn.opal_specs_args = function() {return Array.prototype.slice.call(arguments);};`
|
10
|
+
Element.expose :opal_specs_extension, :opal_specs_args
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
`delete $.fn.exposableMethod; delete $.fn.$exposableMethod;`
|
15
|
+
`delete $.fn.exposableMethod2; delete $.fn.$exposableMethod2;`
|
16
|
+
`delete $.fn.opal_specs_extension; delete $.fn.$opal_specs_extension;`
|
17
|
+
`delete $.fn.opal_specs_args; delete $.fn.$opal_specs_args;`
|
18
|
+
end
|
19
|
+
|
20
|
+
it "exposes jquery plugins by given name" do
|
21
|
+
Element.new.opal_specs_extension.should eq("foo_bar_baz")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "forwards any args onto native function" do
|
25
|
+
Element.new.opal_specs_args(:foo, 42, false).should eq([:foo, 42, false])
|
26
|
+
end
|
27
|
+
|
28
|
+
it "only forwards calls when a native method exists" do
|
29
|
+
expect {
|
30
|
+
Element.new.some_unknown_plugin
|
31
|
+
}.to raise_error(Exception)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'exposes methods defined on $.fn' do
|
35
|
+
expect(element).to respond_to(:exposableMethod) # via #respond_to_missing?
|
36
|
+
expect(element.methods).not_to include(:exposableMethod)
|
37
|
+
Element.expose :exposableMethod
|
38
|
+
expect(element.methods).to include(:exposableMethod)
|
39
|
+
expect(element).to respond_to(:exposableMethod) # via method missing
|
40
|
+
expect(element.exposableMethod).to eq(123)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'work if exposing the same method multiple times' do
|
44
|
+
Element.expose :exposableMethod
|
45
|
+
Element.expose :exposableMethod
|
46
|
+
expect(element.exposableMethod).to eq(123)
|
47
|
+
|
48
|
+
Element.expose :exposableMethod, :exposableMethod
|
49
|
+
expect(element.exposableMethod).to eq(123)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'work if exposing multiple methods' do
|
53
|
+
Element.expose :exposableMethod, :exposableMethod2
|
54
|
+
expect(element.exposableMethod).to eq(123)
|
55
|
+
expect(element.exposableMethod2).to eq(12)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'does not call method_missing after the method is exposed' do
|
59
|
+
pending "broken on opal < 0.11" if RUBY_ENGINE_VERSION.to_f < 0.11
|
60
|
+
|
61
|
+
expect(element).to receive(:method_missing).once.with(:exposableMethod)
|
62
|
+
def element.method_missing(name)
|
63
|
+
"#{name} (via method_missing)"
|
64
|
+
end
|
65
|
+
|
66
|
+
expect(element.exposableMethod).to eq("exposableMethod (via method_missing)")
|
67
|
+
Element.expose :exposableMethod
|
68
|
+
|
69
|
+
expect(element).not_to receive(:method_missing).once
|
70
|
+
element.exposableMethod
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe "Element#method_missing" do
|
4
|
+
context 'with missing property' do
|
5
|
+
html %{<div id="foo" class="bar"></div>}
|
6
|
+
|
7
|
+
it 'fallsback on method_missing when a method is unknown' do
|
8
|
+
expect(Element['#foo']).to respond_to(:offsetParent)
|
9
|
+
expect(Element['#foo'].offsetParent).to eq(Element['body'])
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'jQuery plugin methods' do
|
14
|
+
subject(:element) { Element.new }
|
15
|
+
|
16
|
+
before do
|
17
|
+
`$.fn.pluginMethod = function() {return 123}`
|
18
|
+
end
|
19
|
+
|
20
|
+
after do
|
21
|
+
`delete $.fn.pluginMethod; delete $.fn.$pluginMethod;`
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'calls method_missing' do
|
25
|
+
expect(element).to receive(:method_missing).once.with(:pluginMethod)
|
26
|
+
element.pluginMethod
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'calls forwards to the plugin', :focus do
|
30
|
+
pending "broken on opal < 0.11" if RUBY_ENGINE_VERSION.to_f < 0.11
|
31
|
+
expect(element.pluginMethod).to eq(123)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe Element do
|
3
|
+
RSpec.describe Element do
|
4
4
|
before do
|
5
5
|
@div = Element.parse <<-HTML
|
6
6
|
<div id="traversing-spec">
|
@@ -76,7 +76,7 @@ describe Element do
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
describe "Element#next" do
|
79
|
+
RSpec.describe "Element#next" do
|
80
80
|
before do
|
81
81
|
@div = Element.parse <<-HTML
|
82
82
|
<div id="next-spec">
|
@@ -101,7 +101,7 @@ describe "Element#next" do
|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
-
describe "Element#parent" do
|
104
|
+
RSpec.describe "Element#parent" do
|
105
105
|
before do
|
106
106
|
@div = Element.parse <<-HTML
|
107
107
|
<div id="foo">
|
@@ -126,7 +126,7 @@ describe "Element#parent" do
|
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
|
-
describe "Element#succ" do
|
129
|
+
RSpec.describe "Element#succ" do
|
130
130
|
before do
|
131
131
|
@div = Element.parse <<-HTML
|
132
132
|
<div id="succ-spec">
|
@@ -151,7 +151,7 @@ describe "Element#succ" do
|
|
151
151
|
end
|
152
152
|
end
|
153
153
|
|
154
|
-
describe "Element#siblings" do
|
154
|
+
RSpec.describe "Element#siblings" do
|
155
155
|
before do
|
156
156
|
@div = Element.parse <<-HTML
|
157
157
|
<div id="siblings-spec">
|