opal-jquery 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +7 -0
- data/Gemfile +2 -5
- data/lib/assets/javascripts/opal/jquery/document.rb +0 -24
- data/lib/assets/javascripts/opal/jquery/element.rb +54 -164
- data/lib/opal/jquery/version.rb +1 -1
- data/opal-jquery.gemspec +2 -0
- data/spec/document_spec.rb +0 -73
- data/spec/element/after_spec.rb +5 -5
- data/spec/element/animations_spec.rb +3 -3
- data/spec/element/append_spec.rb +5 -5
- data/spec/element/append_to_spec.rb +5 -5
- data/spec/element/at_spec.rb +3 -3
- data/spec/element/attributes_spec.rb +26 -26
- data/spec/element/before_spec.rb +5 -5
- data/spec/element/class_name_spec.rb +13 -13
- data/spec/element/css_spec.rb +6 -6
- data/spec/element/display_spec.rb +4 -4
- data/spec/element/inspect_spec.rb +3 -3
- data/spec/element/iterable_spec.rb +7 -8
- data/spec/element/method_missing_spec.rb +28 -0
- data/spec/element/traversing_spec.rb +28 -28
- data/spec/element_spec.rb +85 -10
- data/spec/event_spec.rb +5 -5
- data/spec/spec_helper.rb +4 -4
- metadata +22 -3
@@ -0,0 +1,28 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
# Add our jquery extension
|
4
|
+
%x{
|
5
|
+
$.fn.opal_specs_extension = function() {
|
6
|
+
return "foo_bar_baz";
|
7
|
+
};
|
8
|
+
|
9
|
+
$.fn.opal_specs_args = function() {
|
10
|
+
return Array.prototype.slice.call(arguments);
|
11
|
+
};
|
12
|
+
}
|
13
|
+
|
14
|
+
describe "Element#method_missing" do
|
15
|
+
it "calls jquery plugins by given name" do
|
16
|
+
Element.new.opal_specs_extension.should eq("foo_bar_baz")
|
17
|
+
end
|
18
|
+
|
19
|
+
it "forwards any args onto native function" do
|
20
|
+
Element.new.opal_specs_args(:foo, 42, false).should eq([:foo, 42, false])
|
21
|
+
end
|
22
|
+
|
23
|
+
it "only forwards calls when a native method exists" do
|
24
|
+
lambda {
|
25
|
+
Element.new.some_unknown_plugin
|
26
|
+
}.should raise_error(NoMethodError)
|
27
|
+
end
|
28
|
+
end
|
@@ -2,7 +2,7 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Element do
|
4
4
|
before do
|
5
|
-
@div =
|
5
|
+
@div = Element.parse <<-HTML
|
6
6
|
<div id="traversing-spec">
|
7
7
|
<div id="foo" class="traversing-class"></div>
|
8
8
|
<div id="bar" class="traversing-class">
|
@@ -24,12 +24,12 @@ describe Element do
|
|
24
24
|
|
25
25
|
describe '#children' do
|
26
26
|
it "should return a new collection of all direct children of element" do
|
27
|
-
|
28
|
-
|
27
|
+
Element.find('#foo').children.size.should == 0
|
28
|
+
Element.find('#bar').children.size.should == 2
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should only return direct children" do
|
32
|
-
c =
|
32
|
+
c = Element.find('#baz').children
|
33
33
|
c.size.should == 1
|
34
34
|
end
|
35
35
|
end
|
@@ -37,7 +37,7 @@ describe Element do
|
|
37
37
|
describe '#each' do
|
38
38
|
it "should loop over each element passing element to block" do
|
39
39
|
result = []
|
40
|
-
|
40
|
+
Element.find('.traversing-class').each do |e|
|
41
41
|
result << e.id
|
42
42
|
end
|
43
43
|
|
@@ -45,7 +45,7 @@ describe Element do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should not call the block with an empty element set" do
|
48
|
-
|
48
|
+
Element.find('.bad-each-class').each do
|
49
49
|
raise "shouldn't get here"
|
50
50
|
end
|
51
51
|
end
|
@@ -53,32 +53,32 @@ describe Element do
|
|
53
53
|
|
54
54
|
describe '#find' do
|
55
55
|
it "should match all elements within scope of receiver" do
|
56
|
-
foo =
|
56
|
+
foo = Element.find('#traversing-spec')
|
57
57
|
foo.find('.traversing-class').size.should == 2
|
58
58
|
foo.find('.main-content-wrapper').size.should == 1
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should return an empty collection if there are no matching elements" do
|
62
|
-
bar =
|
62
|
+
bar = Element.find('#bar')
|
63
63
|
bar.find('.some-non-existant-class').size.should == 0
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
67
|
describe '#first' do
|
68
68
|
it "should return the first element in the receiver" do
|
69
|
-
|
70
|
-
|
69
|
+
Element.find('.traversing-class').first.id.should == 'foo'
|
70
|
+
Element.find('#baz').first.id.should == 'baz'
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should return nil when receiver has no elements" do
|
74
|
-
|
74
|
+
Element.find('.some-random-class').first.should == nil
|
75
75
|
end
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
79
|
describe "Element#next" do
|
80
80
|
before do
|
81
|
-
@div =
|
81
|
+
@div = Element.parse <<-HTML
|
82
82
|
<div id="next-spec">
|
83
83
|
<div id="foo"></div>
|
84
84
|
<div id="bar"></div>
|
@@ -93,17 +93,17 @@ describe "Element#next" do
|
|
93
93
|
end
|
94
94
|
|
95
95
|
it "should return the next sibling" do
|
96
|
-
|
96
|
+
Element.find('#foo').next.id.should == "bar"
|
97
97
|
end
|
98
98
|
|
99
99
|
it "should return an empty instance when no next element" do
|
100
|
-
|
100
|
+
Element.find('#bar').next.size.should == 0
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
104
|
describe "Element#parent" do
|
105
105
|
before do
|
106
|
-
@div =
|
106
|
+
@div = Element.parse <<-HTML
|
107
107
|
<div id="foo">
|
108
108
|
<div id="bar">
|
109
109
|
<div id="baz"></div>
|
@@ -120,15 +120,15 @@ describe "Element#parent" do
|
|
120
120
|
end
|
121
121
|
|
122
122
|
it "should return the parent of the element" do
|
123
|
-
|
124
|
-
|
125
|
-
|
123
|
+
Element.find('#bar').parent.id.should == "foo"
|
124
|
+
Element.find('#baz').parent.id.should == "bar"
|
125
|
+
Element.find('#buz').parent.id.should == "bar"
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
129
|
describe "Element#succ" do
|
130
130
|
before do
|
131
|
-
@div =
|
131
|
+
@div = Element.parse <<-HTML
|
132
132
|
<div id="succ-spec">
|
133
133
|
<div id="foo"></div>
|
134
134
|
<div id="bar"></div>
|
@@ -143,17 +143,17 @@ describe "Element#succ" do
|
|
143
143
|
end
|
144
144
|
|
145
145
|
it "should return the next sibling" do
|
146
|
-
|
146
|
+
Element.find('#foo').succ.id.should == "bar"
|
147
147
|
end
|
148
148
|
|
149
149
|
it "should return an empty instance when no next element" do
|
150
|
-
|
150
|
+
Element.find('#bar').succ.size.should == 0
|
151
151
|
end
|
152
152
|
end
|
153
153
|
|
154
154
|
describe "Element#siblings" do
|
155
155
|
before do
|
156
|
-
@div =
|
156
|
+
@div = Element.parse <<-HTML
|
157
157
|
<div id="siblings-spec">
|
158
158
|
<div>
|
159
159
|
<div id="foo"></div>
|
@@ -174,17 +174,17 @@ describe "Element#siblings" do
|
|
174
174
|
end
|
175
175
|
|
176
176
|
it "should return all siblings" do
|
177
|
-
|
178
|
-
|
179
|
-
|
177
|
+
Element.find('#bar').siblings.size.should == 2
|
178
|
+
Element.find('#bar').siblings.at(0).id.should == "foo"
|
179
|
+
Element.find('#bar').siblings.at(1).id.should == "baz"
|
180
180
|
end
|
181
181
|
|
182
182
|
it "should return all siblings that match the selector" do
|
183
|
-
|
184
|
-
|
183
|
+
Element.find('#bar').siblings('.special').size.should == 1
|
184
|
+
Element.find('#bar').siblings('.special').at(0).id.should == "baz"
|
185
185
|
end
|
186
186
|
|
187
187
|
it "should return an empty instance when there are no siblings" do
|
188
|
-
|
188
|
+
Element.find('#uno').siblings.size.should == 0
|
189
189
|
end
|
190
190
|
end
|
data/spec/element_spec.rb
CHANGED
@@ -11,7 +11,7 @@ describe Element do
|
|
11
11
|
describe '#on' do
|
12
12
|
it 'adds an event listener onto the elements' do
|
13
13
|
count = 0
|
14
|
-
foo =
|
14
|
+
foo = Element['#foo']
|
15
15
|
|
16
16
|
foo.on(:click) { count += 1 }
|
17
17
|
count.should == 0
|
@@ -25,8 +25,8 @@ describe Element do
|
|
25
25
|
|
26
26
|
it 'takes an optional second parameter to delegate events' do
|
27
27
|
count = 0
|
28
|
-
foo =
|
29
|
-
bar =
|
28
|
+
foo = Element['#foo']
|
29
|
+
bar = Element['#bar']
|
30
30
|
|
31
31
|
foo.on(:click, '#bar') { count += 1 }
|
32
32
|
count.should == 0
|
@@ -42,7 +42,7 @@ describe Element do
|
|
42
42
|
|
43
43
|
it 'can listen for non-browser events' do
|
44
44
|
count = 0
|
45
|
-
foo =
|
45
|
+
foo = Element['#foo']
|
46
46
|
|
47
47
|
foo.on('opal-is-mega-lolz') { count += 1 }
|
48
48
|
count.should == 0
|
@@ -54,11 +54,11 @@ describe Element do
|
|
54
54
|
|
55
55
|
it 'returns the given handler' do
|
56
56
|
handler = proc {}
|
57
|
-
|
57
|
+
Element['#foo'].on(:click, &handler).should == handler
|
58
58
|
end
|
59
59
|
|
60
60
|
it 'has an Event instance passed to the handler' do
|
61
|
-
foo =
|
61
|
+
foo = Element['#foo']
|
62
62
|
foo.on :click do |event|
|
63
63
|
event.should be_kind_of(Event)
|
64
64
|
end
|
@@ -66,7 +66,7 @@ describe Element do
|
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'has an Event instance, plus any additional parameters passed to the handler' do
|
69
|
-
foo =
|
69
|
+
foo = Element['#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'
|
@@ -81,7 +81,7 @@ describe Element do
|
|
81
81
|
describe '#off' do
|
82
82
|
it 'removes event handlers that were added using #on' do
|
83
83
|
count = 0
|
84
|
-
foo =
|
84
|
+
foo = Element['#foo']
|
85
85
|
|
86
86
|
handler = foo.on(:click) { count += 1 }
|
87
87
|
count.should == 0
|
@@ -95,8 +95,8 @@ describe Element do
|
|
95
95
|
|
96
96
|
it 'removes event handlers added with a selector' do
|
97
97
|
count = 0
|
98
|
-
foo =
|
99
|
-
bar =
|
98
|
+
foo = Element['#foo']
|
99
|
+
bar = Element['#bar']
|
100
100
|
|
101
101
|
handler = foo.on(:click, '#bar') { count += 1 }
|
102
102
|
count.should == 0
|
@@ -109,3 +109,78 @@ describe Element do
|
|
109
109
|
end
|
110
110
|
end
|
111
111
|
end
|
112
|
+
|
113
|
+
describe Element do
|
114
|
+
html <<-HTML
|
115
|
+
<div id="foo" class="bar"></div>
|
116
|
+
<div class="woosh"></div>
|
117
|
+
<div class="woosh"></div>
|
118
|
+
<div class="find-foo"></div>
|
119
|
+
<div class="find-bar"></div>
|
120
|
+
<div class="find-foo"></div>
|
121
|
+
HTML
|
122
|
+
|
123
|
+
describe ".[]" do
|
124
|
+
it "should be able to find elements with given id" do
|
125
|
+
Element['#foo'].class_name.should == "bar"
|
126
|
+
Element['#foo'].size.should == 1
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should be able to match any valid CSS selector" do
|
130
|
+
Element['.woosh'].should be_kind_of(Element)
|
131
|
+
Element['.woosh'].size.should == 2
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should return an empty Elements instance when not matching any elements" do
|
135
|
+
dom = Element['.some-non-existing-class']
|
136
|
+
|
137
|
+
dom.should be_kind_of(Element)
|
138
|
+
dom.size.should == 0
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should accept an HTML string and parse it into a Elements instance" do
|
142
|
+
el = Element['<div id="foo-bar-baz"></div>']
|
143
|
+
|
144
|
+
el.should be_kind_of(Element)
|
145
|
+
el.id.should == "foo-bar-baz"
|
146
|
+
el.size.should == 1
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe ".find" do
|
151
|
+
it "should find all elements matching CSS selector" do
|
152
|
+
foo = Element.find '.find-foo'
|
153
|
+
foo.should be_kind_of(Element)
|
154
|
+
foo.length.should == 2
|
155
|
+
|
156
|
+
bar = Element.find '.find-bar'
|
157
|
+
bar.should be_kind_of(Element)
|
158
|
+
bar.length.should == 1
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should return an empty Element instance with length 0 when no matching" do
|
162
|
+
baz = Element.find '.find-baz'
|
163
|
+
baz.should be_kind_of(Element)
|
164
|
+
baz.length.should == 0
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe '.id' do
|
169
|
+
it "should return a new instance with the element with given id" do
|
170
|
+
Element.id('foo').should be_kind_of(Element)
|
171
|
+
Element.id('foo').id.should == 'foo'
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should return nil if no element could be found" do
|
175
|
+
Element.id('bad-element-id').should be_nil
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
describe '.parse' do
|
180
|
+
it "should return a new instance with parsed element as single element" do
|
181
|
+
foo = Element.parse '<div id="foo" class="bar"></div>'
|
182
|
+
foo.id.should == 'foo'
|
183
|
+
foo.class_name.should == 'bar'
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
data/spec/event_spec.rb
CHANGED
@@ -11,8 +11,8 @@ describe Event do
|
|
11
11
|
HTML
|
12
12
|
|
13
13
|
it '#current_target returns the current element in the bubbling' do
|
14
|
-
foo =
|
15
|
-
bar =
|
14
|
+
foo = Element['#foo']
|
15
|
+
bar = Element['#bar']
|
16
16
|
result = []
|
17
17
|
|
18
18
|
foo.on(:click) { |e| result << e.current_target.id }
|
@@ -28,7 +28,7 @@ describe Event do
|
|
28
28
|
|
29
29
|
it '#type returns the type of event' do
|
30
30
|
type = nil
|
31
|
-
foo =
|
31
|
+
foo = Element['#foo']
|
32
32
|
|
33
33
|
foo.on(:click) { |e| type = e.type }
|
34
34
|
foo.on(:mousedown) { |e| type = e.type }
|
@@ -45,8 +45,8 @@ describe Event do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
it '#target returns a JQuery wrapper around the element that triggered the event' do
|
48
|
-
foo =
|
49
|
-
bar =
|
48
|
+
foo = Element['#foo']
|
49
|
+
bar = Element['#bar']
|
50
50
|
target = nil
|
51
51
|
|
52
52
|
foo.on(:click) { |e| target = e.target.id }
|
data/spec/spec_helper.rb
CHANGED
@@ -2,8 +2,8 @@ require 'jquery'
|
|
2
2
|
require 'opal-spec'
|
3
3
|
require 'opal-jquery'
|
4
4
|
|
5
|
-
module
|
6
|
-
class
|
5
|
+
module OpalTest
|
6
|
+
class TestCase
|
7
7
|
|
8
8
|
# Add some html code to the body tag ready for testing. This will
|
9
9
|
# be added before each test, then removed after each test. It is
|
@@ -21,10 +21,10 @@ module Spec
|
|
21
21
|
# end
|
22
22
|
#
|
23
23
|
# @param [String] html_string html content to add
|
24
|
-
def html(html_string='')
|
24
|
+
def self.html(html_string='')
|
25
25
|
html = '<div id="opal-jquery-test-div">' + html_string + '</div>'
|
26
26
|
before do
|
27
|
-
@_spec_html =
|
27
|
+
@_spec_html = Element.parse(html)
|
28
28
|
@_spec_html.append_to_body
|
29
29
|
end
|
30
30
|
|
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
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
13
|
-
dependencies:
|
12
|
+
date: 2013-02-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: opal
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.3.39
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.3.39
|
14
30
|
description: Opal DOM library for jquery
|
15
31
|
email: adam.beynon@gmail.com
|
16
32
|
executables: []
|
@@ -19,6 +35,7 @@ extra_rdoc_files: []
|
|
19
35
|
files:
|
20
36
|
- .gitignore
|
21
37
|
- .travis.yml
|
38
|
+
- CHANGELOG.md
|
22
39
|
- Gemfile
|
23
40
|
- LICENSE
|
24
41
|
- README.md
|
@@ -52,6 +69,7 @@ files:
|
|
52
69
|
- spec/element/inspect_spec.rb
|
53
70
|
- spec/element/iterable_spec.rb
|
54
71
|
- spec/element/length_spec.rb
|
72
|
+
- spec/element/method_missing_spec.rb
|
55
73
|
- spec/element/traversing_spec.rb
|
56
74
|
- spec/element_spec.rb
|
57
75
|
- spec/event_spec.rb
|
@@ -100,6 +118,7 @@ test_files:
|
|
100
118
|
- spec/element/inspect_spec.rb
|
101
119
|
- spec/element/iterable_spec.rb
|
102
120
|
- spec/element/length_spec.rb
|
121
|
+
- spec/element/method_missing_spec.rb
|
103
122
|
- spec/element/traversing_spec.rb
|
104
123
|
- spec/element_spec.rb
|
105
124
|
- spec/event_spec.rb
|