opal-jquery 0.1.2 → 0.2.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 +1 -0
- data/.travis.yml +2 -0
- data/CHANGELOG.md +35 -0
- data/Gemfile +3 -0
- data/Rakefile +2 -2
- data/config.ru +1 -1
- data/lib/opal/jquery/version.rb +1 -1
- data/opal-jquery.gemspec +2 -2
- data/opal/opal-jquery/document.rb +8 -0
- data/opal/opal-jquery/element.rb +12 -3
- data/opal/opal-jquery/event.rb +14 -7
- data/opal/opal-jquery/http.rb +2 -0
- data/opal/opal-jquery/local_storage.rb +31 -0
- data/spec/document_spec.rb +16 -0
- data/spec/element_spec.rb +22 -0
- data/spec/jquery/{index.html → index.html.erb} +0 -0
- data/spec/local_storage_spec.rb +22 -0
- data/spec/zepto/{index.html → index.html.erb} +0 -0
- metadata +32 -17
- checksums.yaml +0 -7
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,38 @@
|
|
1
|
+
## edge
|
2
|
+
|
3
|
+
## 0.2.0 2014-03-12
|
4
|
+
|
5
|
+
* Add `Document.body` and `Document.head` shortcut to element instances.
|
6
|
+
|
7
|
+
* Add `Event` methods: `prevented?`, `prevent`, `stopped?` and `stop` to
|
8
|
+
replace longer javascript names.
|
9
|
+
|
10
|
+
* Add `LocalStorage` implementation.
|
11
|
+
|
12
|
+
* Fix `Element#data()` to return `nil` for an undefined data attribute
|
13
|
+
instead of null.
|
14
|
+
|
15
|
+
* Expose `#detach` method on `Element`.
|
16
|
+
|
17
|
+
## 0.1.2 2013-12-01
|
18
|
+
|
19
|
+
* Support setting html content through `Element#html()`.
|
20
|
+
|
21
|
+
* Add `Element` methods: `#get`, `#attr` and `#prop` by aliasing them to
|
22
|
+
jquery implementations.
|
23
|
+
|
24
|
+
## 0.1.1 2013-11-11
|
25
|
+
|
26
|
+
* Require `native` from stdlib for `HTTP` to use.
|
27
|
+
|
28
|
+
## 0.1.0 2013-11-03
|
29
|
+
|
30
|
+
* Add `Window` and `$window` alias.
|
31
|
+
|
32
|
+
* Support `Zepto` as well as `jQuery`.
|
33
|
+
|
34
|
+
* `Event` is now a wrapper around native event from dom listeners.
|
35
|
+
|
1
36
|
## 0.0.9 2013-06-15
|
2
37
|
|
3
38
|
* Revert earlier commit, and use `$document` as reference to jquery
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -4,11 +4,11 @@ Bundler::GemHelper.install_tasks
|
|
4
4
|
|
5
5
|
require 'opal/rspec/rake_task'
|
6
6
|
Opal::RSpec::RakeTask.new(:default) do |s|
|
7
|
-
s.index_path = 'spec/jquery/index.html'
|
7
|
+
s.index_path = 'spec/jquery/index.html.erb'
|
8
8
|
end
|
9
9
|
|
10
10
|
Opal::RSpec::RakeTask.new(:zepto) do |s|
|
11
|
-
s.index_path = 'spec/zepto/index.html'
|
11
|
+
s.index_path = 'spec/zepto/index.html.erb'
|
12
12
|
end
|
13
13
|
|
14
14
|
desc "Build build/opal-jquery.js"
|
data/config.ru
CHANGED
data/lib/opal/jquery/version.rb
CHANGED
data/opal-jquery.gemspec
CHANGED
@@ -15,6 +15,6 @@ Gem::Specification.new do |s|
|
|
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', '
|
19
|
-
s.add_development_dependency 'opal-rspec'
|
18
|
+
s.add_runtime_dependency 'opal', ['>= 0.5.0', '< 1.0.0']
|
19
|
+
s.add_development_dependency 'opal-rspec', '~> 0.3.0'
|
20
20
|
end
|
@@ -14,6 +14,14 @@ class << Document
|
|
14
14
|
def title=(title)
|
15
15
|
`document.title = #{title}`
|
16
16
|
end
|
17
|
+
|
18
|
+
def head
|
19
|
+
Element.find(`document.head`)
|
20
|
+
end
|
21
|
+
|
22
|
+
def body
|
23
|
+
Element.find(`document.body`)
|
24
|
+
end
|
17
25
|
end
|
18
26
|
|
19
27
|
# TODO: this will be removed soon (here for compatibility)
|
data/opal/opal-jquery/element.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'native'
|
2
|
+
|
1
3
|
%x{
|
2
4
|
var root = $opal.global, dom_class;
|
3
5
|
|
@@ -59,7 +61,7 @@ class Element < `dom_class`
|
|
59
61
|
# Bridged functions - we just expose all core jquery functions as ruby
|
60
62
|
# methods on this class.
|
61
63
|
expose :after, :before, :parent, :parents, :prepend, :prev, :remove
|
62
|
-
expose :hide, :show, :toggle, :children, :blur, :closest, :
|
64
|
+
expose :hide, :show, :toggle, :children, :blur, :closest, :detach
|
63
65
|
expose :focus, :find, :next, :siblings, :text, :trigger, :append
|
64
66
|
expose :height, :width, :serialize, :is, :filter, :last, :first
|
65
67
|
expose :wrap, :stop, :clone, :empty
|
@@ -92,7 +94,7 @@ class Element < `dom_class`
|
|
92
94
|
def to_n
|
93
95
|
self
|
94
96
|
end
|
95
|
-
|
97
|
+
|
96
98
|
def [](name)
|
97
99
|
`self.attr(name) || ""`
|
98
100
|
end
|
@@ -182,6 +184,13 @@ class Element < `dom_class`
|
|
182
184
|
}
|
183
185
|
end
|
184
186
|
|
187
|
+
def data(*args)
|
188
|
+
%x{
|
189
|
+
var result = self.data.apply(self, args);
|
190
|
+
return result == null ? nil : result;
|
191
|
+
}
|
192
|
+
end
|
193
|
+
|
185
194
|
# Start a visual effect (e.g. fadeIn, fadeOut, …) passing its name.
|
186
195
|
# Underscored style is automatically converted (e.g. `effect(:fade_in)`).
|
187
196
|
# Also accepts additional arguments and a block for the finished callback.
|
@@ -197,7 +206,7 @@ class Element < `dom_class`
|
|
197
206
|
end
|
198
207
|
|
199
208
|
def offset
|
200
|
-
|
209
|
+
Native(`self.offset()`)
|
201
210
|
end
|
202
211
|
|
203
212
|
def each
|
data/opal/opal-jquery/event.rb
CHANGED
@@ -26,32 +26,39 @@ class Event
|
|
26
26
|
##
|
27
27
|
# Propagation
|
28
28
|
|
29
|
-
def
|
29
|
+
def prevented?
|
30
30
|
`#@native.isDefaultPrevented()`
|
31
31
|
end
|
32
32
|
|
33
|
-
def
|
33
|
+
def prevent
|
34
34
|
`#@native.preventDefault()`
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
37
|
+
def stopped?
|
38
38
|
`#@native.propagationStopped()`
|
39
39
|
end
|
40
40
|
|
41
|
-
def
|
41
|
+
def stop
|
42
42
|
`#@native.stopPropagation()`
|
43
43
|
end
|
44
44
|
|
45
|
-
def
|
45
|
+
def stop_immediate
|
46
46
|
`#@native.stopImmediatePropagation()`
|
47
47
|
end
|
48
48
|
|
49
49
|
# Stops propagation and prevents default action.
|
50
50
|
def kill
|
51
|
-
|
52
|
-
|
51
|
+
stop
|
52
|
+
prevent
|
53
53
|
end
|
54
54
|
|
55
|
+
# to be removed?
|
56
|
+
alias default_prevented? prevented?
|
57
|
+
alias prevent_default prevent
|
58
|
+
alias propagation_stopped? stopped?
|
59
|
+
alias stop_propagation stop
|
60
|
+
alias stop_immediate_propagation stop_immediate
|
61
|
+
|
55
62
|
##
|
56
63
|
# Keyboard/Mouse/Touch
|
57
64
|
|
data/opal/opal-jquery/http.rb
CHANGED
@@ -48,6 +48,7 @@ class HTTP
|
|
48
48
|
settings.success = function(data, status, xhr) {
|
49
49
|
http.body = data;
|
50
50
|
http.xhr = xhr;
|
51
|
+
http.status_code = xhr.status;
|
51
52
|
|
52
53
|
if (typeof(data) === 'object') {
|
53
54
|
http.json = #{ JSON.from_object `data` };
|
@@ -59,6 +60,7 @@ class HTTP
|
|
59
60
|
settings.error = function(xhr, status, error) {
|
60
61
|
http.body = xhr.responseText;
|
61
62
|
http.xhr = xhr;
|
63
|
+
http.status_code = xhr.status;
|
62
64
|
|
63
65
|
return #{ http.fail };
|
64
66
|
};
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module DOM
|
2
|
+
class LocalStorage
|
3
|
+
def initialize(storage)
|
4
|
+
@storage = storage
|
5
|
+
end
|
6
|
+
|
7
|
+
def []=(key, value)
|
8
|
+
%x{
|
9
|
+
#@storage.setItem(key, value);
|
10
|
+
return value;
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
def [](key)
|
15
|
+
%x{
|
16
|
+
var value = #@storage.getItem(key);
|
17
|
+
return value == null ? nil : value;
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def delete(key)
|
22
|
+
`#@storage.removeItem(key)`
|
23
|
+
end
|
24
|
+
|
25
|
+
def clear
|
26
|
+
`#@storage.clear()`
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
LocalStorage = DOM::LocalStorage.new(`window.localStorage`)
|
data/spec/document_spec.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Document do
|
4
|
+
subject { Document }
|
5
|
+
|
4
6
|
describe "ready?" do
|
5
7
|
it "accepts a block" do
|
6
8
|
Document.ready? { }
|
@@ -21,4 +23,18 @@ describe Document do
|
|
21
23
|
Document.title = old
|
22
24
|
end
|
23
25
|
end
|
26
|
+
|
27
|
+
describe "head" do
|
28
|
+
it "returns the head element as an Element instance" do
|
29
|
+
expect(subject.head).to be_kind_of(Element)
|
30
|
+
expect(subject.head.tag_name).to eq('head')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "body" do
|
35
|
+
it "returns the body element as an Element instance" do
|
36
|
+
expect(subject.body).to be_kind_of(Element)
|
37
|
+
expect(subject.body.tag_name).to eq('body')
|
38
|
+
end
|
39
|
+
end
|
24
40
|
end
|
data/spec/element_spec.rb
CHANGED
@@ -183,6 +183,28 @@ describe Element do
|
|
183
183
|
foo.class_name.should == 'bar'
|
184
184
|
end
|
185
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
|
186
208
|
end
|
187
209
|
|
188
210
|
describe "Element#html" do
|
File without changes
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'opal-jquery/local_storage'
|
3
|
+
|
4
|
+
describe LocalStorage do
|
5
|
+
before { subject.clear }
|
6
|
+
|
7
|
+
it "returns nil for undefined values" do
|
8
|
+
expect(subject['foo']).to be_nil
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should be able to create items" do
|
12
|
+
subject['foo'] = 'Ford Prefect'
|
13
|
+
expect(subject['foo']).to eq('Ford Prefect')
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should be able to delete items" do
|
17
|
+
subject['name'] = 'Arthur'
|
18
|
+
subject.delete 'name'
|
19
|
+
|
20
|
+
expect(subject['name']).to be_nil
|
21
|
+
end
|
22
|
+
end
|
File without changes
|
metadata
CHANGED
@@ -1,43 +1,54 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opal-jquery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Adam Beynon
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2014-03-12 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: opal
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
|
-
- -
|
19
|
+
- - ! '>='
|
18
20
|
- !ruby/object:Gem::Version
|
19
21
|
version: 0.5.0
|
22
|
+
- - <
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 1.0.0
|
20
25
|
type: :runtime
|
21
26
|
prerelease: false
|
22
27
|
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
23
29
|
requirements:
|
24
|
-
- -
|
30
|
+
- - ! '>='
|
25
31
|
- !ruby/object:Gem::Version
|
26
32
|
version: 0.5.0
|
33
|
+
- - <
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 1.0.0
|
27
36
|
- !ruby/object:Gem::Dependency
|
28
37
|
name: opal-rspec
|
29
38
|
requirement: !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
30
40
|
requirements:
|
31
|
-
- -
|
41
|
+
- - ~>
|
32
42
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
43
|
+
version: 0.3.0
|
34
44
|
type: :development
|
35
45
|
prerelease: false
|
36
46
|
version_requirements: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
37
48
|
requirements:
|
38
|
-
- -
|
49
|
+
- - ~>
|
39
50
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
51
|
+
version: 0.3.0
|
41
52
|
description: Opal DOM library for jquery
|
42
53
|
email: adam.beynon@gmail.com
|
43
54
|
executables: []
|
@@ -68,6 +79,7 @@ files:
|
|
68
79
|
- opal/opal-jquery/event.rb
|
69
80
|
- opal/opal-jquery/http.rb
|
70
81
|
- opal/opal-jquery/kernel.rb
|
82
|
+
- opal/opal-jquery/local_storage.rb
|
71
83
|
- opal/opal-jquery/window.rb
|
72
84
|
- spec/document_spec.rb
|
73
85
|
- spec/element/after_spec.rb
|
@@ -90,34 +102,36 @@ files:
|
|
90
102
|
- spec/fixtures/simple.txt
|
91
103
|
- spec/fixtures/user.json
|
92
104
|
- spec/http_spec.rb
|
93
|
-
- spec/jquery/index.html
|
105
|
+
- spec/jquery/index.html.erb
|
94
106
|
- spec/jquery/jquery.js
|
95
107
|
- spec/kernel_spec.rb
|
108
|
+
- spec/local_storage_spec.rb
|
96
109
|
- spec/spec_helper.rb
|
97
|
-
- spec/zepto/index.html
|
110
|
+
- spec/zepto/index.html.erb
|
98
111
|
- spec/zepto/zepto.js
|
99
112
|
homepage: http://opalrb.org
|
100
113
|
licenses: []
|
101
|
-
metadata: {}
|
102
114
|
post_install_message:
|
103
115
|
rdoc_options: []
|
104
116
|
require_paths:
|
105
117
|
- lib
|
106
118
|
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
107
120
|
requirements:
|
108
|
-
- - '>='
|
121
|
+
- - ! '>='
|
109
122
|
- !ruby/object:Gem::Version
|
110
123
|
version: '0'
|
111
124
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
112
126
|
requirements:
|
113
|
-
- - '>='
|
127
|
+
- - ! '>='
|
114
128
|
- !ruby/object:Gem::Version
|
115
129
|
version: '0'
|
116
130
|
requirements: []
|
117
131
|
rubyforge_project:
|
118
|
-
rubygems_version:
|
132
|
+
rubygems_version: 1.8.23
|
119
133
|
signing_key:
|
120
|
-
specification_version:
|
134
|
+
specification_version: 3
|
121
135
|
summary: Opal access to jquery
|
122
136
|
test_files:
|
123
137
|
- spec/document_spec.rb
|
@@ -141,9 +155,10 @@ test_files:
|
|
141
155
|
- spec/fixtures/simple.txt
|
142
156
|
- spec/fixtures/user.json
|
143
157
|
- spec/http_spec.rb
|
144
|
-
- spec/jquery/index.html
|
158
|
+
- spec/jquery/index.html.erb
|
145
159
|
- spec/jquery/jquery.js
|
146
160
|
- spec/kernel_spec.rb
|
161
|
+
- spec/local_storage_spec.rb
|
147
162
|
- spec/spec_helper.rb
|
148
|
-
- spec/zepto/index.html
|
163
|
+
- spec/zepto/index.html.erb
|
149
164
|
- spec/zepto/zepto.js
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: da6d9c3e4bac1b9222cd796fef94c76415fdaaeb
|
4
|
-
data.tar.gz: ef7adcd74505352c5efacaaef72a1ce5ff89033c
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 49b93286fe4af94808ce543a9cf4006bf7695277b524e569a147ada0569fa870d53f323176d0b78e65f1330e56fd3d9de31e02d275c2056c483eaee24db193df
|
7
|
-
data.tar.gz: 73d24b3bd5d0a792d1c1c2c331c205c3d9b092868b1508b8a063d4b88314da7868f3821f9a4b4f720ccafdd4a7c4c24e9f4002ebaa28a6beb1f259b4123dc77d
|