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
@@ -1,32 +0,0 @@
|
|
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
|
-
class Element
|
15
|
-
expose :opal_specs_extension, :opal_specs_args
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "Element#exposes" do
|
19
|
-
it "exposes jquery plugins by given name" do
|
20
|
-
Element.new.opal_specs_extension.should eq("foo_bar_baz")
|
21
|
-
end
|
22
|
-
|
23
|
-
it "forwards any args onto native function" do
|
24
|
-
Element.new.opal_specs_args(:foo, 42, false).should eq([:foo, 42, false])
|
25
|
-
end
|
26
|
-
|
27
|
-
it "only forwards calls when a native method exists" do
|
28
|
-
expect {
|
29
|
-
Element.new.some_unknown_plugin
|
30
|
-
}.to raise_error(Exception)
|
31
|
-
end
|
32
|
-
end
|
data/spec/element_spec.rb
DELETED
@@ -1,261 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Element do
|
4
|
-
html <<-HTML
|
5
|
-
<div id="foo">
|
6
|
-
<div id="bar" class="apples"></div>
|
7
|
-
</div>
|
8
|
-
<div id="baz"></div>
|
9
|
-
HTML
|
10
|
-
|
11
|
-
describe '#on' do
|
12
|
-
it 'adds an event listener onto the elements' do
|
13
|
-
count = 0
|
14
|
-
foo = Element['#foo']
|
15
|
-
|
16
|
-
foo.on(:click) { count += 1 }
|
17
|
-
count.should == 0
|
18
|
-
foo.trigger(:click)
|
19
|
-
count.should == 1
|
20
|
-
foo.trigger(:click)
|
21
|
-
count.should == 2
|
22
|
-
foo.trigger(:mousedown)
|
23
|
-
count.should == 2
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'takes an optional second parameter to delegate events' do
|
27
|
-
count = 0
|
28
|
-
foo = Element['#foo']
|
29
|
-
bar = Element['#bar']
|
30
|
-
|
31
|
-
foo.on(:click, '#bar') { count += 1 }
|
32
|
-
count.should == 0
|
33
|
-
foo.trigger(:click)
|
34
|
-
count.should == 0
|
35
|
-
bar.trigger(:click)
|
36
|
-
count.should == 1
|
37
|
-
bar.trigger(:click)
|
38
|
-
count.should == 2
|
39
|
-
bar.trigger(:mousedown)
|
40
|
-
count.should == 2
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'can listen for non-browser events' do
|
44
|
-
count = 0
|
45
|
-
foo = Element['#foo']
|
46
|
-
|
47
|
-
foo.on('opal-is-mega-lolz') { count += 1 }
|
48
|
-
count.should == 0
|
49
|
-
foo.trigger('opal-is-mega-lolz')
|
50
|
-
count.should == 1
|
51
|
-
foo.trigger('opal-is-mega-lolz')
|
52
|
-
count.should == 2
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'returns the given handler' do
|
56
|
-
handler = proc {}
|
57
|
-
Element['#foo'].on(:click, &handler).should == handler
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'has an Event instance passed to the handler' do
|
61
|
-
foo = Element['#foo']
|
62
|
-
foo.on :click do |event|
|
63
|
-
event.should be_kind_of(Event)
|
64
|
-
end
|
65
|
-
foo.trigger(:click)
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'has an Event instance, plus any additional parameters passed to the handler' do
|
69
|
-
foo = Element['#foo']
|
70
|
-
foo.on :bozo do |event, foo, bar, baz, buz|
|
71
|
-
event.should be_kind_of(Event)
|
72
|
-
foo.should == 'foo'
|
73
|
-
bar.should == 'bar'
|
74
|
-
baz.should == 'baz'
|
75
|
-
buz.should == 'buz'
|
76
|
-
end
|
77
|
-
foo.trigger(:bozo, ['foo', 'bar', 'baz', 'buz'])
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe '#off' do
|
82
|
-
it 'removes event handlers that were added using #on' do
|
83
|
-
count = 0
|
84
|
-
foo = Element['#foo']
|
85
|
-
|
86
|
-
handler = foo.on(:click) { count += 1 }
|
87
|
-
count.should == 0
|
88
|
-
foo.trigger(:click)
|
89
|
-
count.should == 1
|
90
|
-
foo.off(:click, handler)
|
91
|
-
count.should == 1
|
92
|
-
foo.trigger(:click)
|
93
|
-
count.should == 1
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'removes event handlers added with a selector' do
|
97
|
-
count = 0
|
98
|
-
foo = Element['#foo']
|
99
|
-
bar = Element['#bar']
|
100
|
-
|
101
|
-
handler = foo.on(:click, '#bar') { count += 1 }
|
102
|
-
count.should == 0
|
103
|
-
bar.trigger(:click)
|
104
|
-
count.should == 1
|
105
|
-
foo.off(:click, '#bar', handler)
|
106
|
-
count.should == 1
|
107
|
-
bar.trigger(:click)
|
108
|
-
count.should == 1
|
109
|
-
end
|
110
|
-
end
|
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
|
-
|
187
|
-
end
|
188
|
-
|
189
|
-
describe "Element#data" do
|
190
|
-
html <<-HTML
|
191
|
-
<div id="data-foo"></div>
|
192
|
-
<div id="data-ford" data-authur="dent"></div>
|
193
|
-
HTML
|
194
|
-
|
195
|
-
it "sets a data attribute" do
|
196
|
-
foo = Element.id('data-foo')
|
197
|
-
foo.data 'bar', 'baz'
|
198
|
-
expect(foo.data('bar')).to eq('baz')
|
199
|
-
end
|
200
|
-
|
201
|
-
it "can retrieve a data attribute" do
|
202
|
-
expect(Element.id('data-ford').data('authur')).to eq('dent')
|
203
|
-
end
|
204
|
-
|
205
|
-
it "returns nil for an undefined data attribute" do
|
206
|
-
expect(Element.id('data-ford').data('not-here')).to be_nil
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
describe "Element#html" do
|
211
|
-
html <<-HTML
|
212
|
-
<div id="foo">bar</div>
|
213
|
-
HTML
|
214
|
-
|
215
|
-
it "retrieves the inner html content for the element" do
|
216
|
-
expect(Element.id('foo').html).to include('bar')
|
217
|
-
end
|
218
|
-
|
219
|
-
it "can be used to set inner html of element by passing string" do
|
220
|
-
foo = Element.id 'foo'
|
221
|
-
foo.html "different content"
|
222
|
-
|
223
|
-
expect(foo.html).to_not include('bar')
|
224
|
-
expect(foo.html).to include('different content')
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
describe 'Element.expose' do
|
229
|
-
subject(:element) { Element.new }
|
230
|
-
before do
|
231
|
-
`$.fn.exposableMethod = function() {return 123}`
|
232
|
-
`$.fn.exposableMethod2 = function() {return 12}`
|
233
|
-
end
|
234
|
-
|
235
|
-
after do
|
236
|
-
`delete $.fn.exposableMethod; delete $.fn.$exposableMethod;`
|
237
|
-
`delete $.fn.exposableMethod2; delete $.fn.$exposableMethod2;`
|
238
|
-
end
|
239
|
-
|
240
|
-
it 'exposes methods defined on $.fn' do
|
241
|
-
expect(element).not_to respond_to(:exposableMethod)
|
242
|
-
Element.expose :exposableMethod
|
243
|
-
expect(element).to respond_to(:exposableMethod)
|
244
|
-
expect(element.exposableMethod).to eq(123)
|
245
|
-
end
|
246
|
-
|
247
|
-
it 'work if exposing the same method multiple times' do
|
248
|
-
Element.expose :exposableMethod
|
249
|
-
Element.expose :exposableMethod
|
250
|
-
expect(element.exposableMethod).to eq(123)
|
251
|
-
|
252
|
-
Element.expose :exposableMethod, :exposableMethod
|
253
|
-
expect(element.exposableMethod).to eq(123)
|
254
|
-
end
|
255
|
-
|
256
|
-
it 'work if exposing multiple methods' do
|
257
|
-
Element.expose :exposableMethod, :exposableMethod2
|
258
|
-
expect(element.exposableMethod).to eq(123)
|
259
|
-
expect(element.exposableMethod2).to eq(12)
|
260
|
-
end
|
261
|
-
end
|