opal-rails 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  module Opal
2
2
  module Rails
3
- VERSION = '0.0.4'
4
- OPAL_VERSION = '0.3.19'
3
+ VERSION = '0.0.5'
4
+ OPAL_VERSION = '0.3.20'
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal-rails
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,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-18 00:00:00.000000000 Z
12
+ date: 2012-06-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: opal
16
- requirement: &70218857882800 !ruby/object:Gem::Requirement
16
+ requirement: &70228974772800 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - =
20
20
  - !ruby/object:Gem::Version
21
- version: 0.3.19
21
+ version: 0.3.20
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70218857882800
24
+ version_requirements: *70228974772800
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: railties
27
- requirement: &70218857882340 !ruby/object:Gem::Requirement
27
+ requirement: &70228974772180 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 3.2.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70218857882340
35
+ version_requirements: *70228974772180
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sprockets
38
- requirement: &70218857881840 !ruby/object:Gem::Requirement
38
+ requirement: &70228974771200 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '2.1'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70218857881840
46
+ version_requirements: *70228974771200
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &70218857881340 !ruby/object:Gem::Requirement
49
+ requirement: &70228974770560 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '2.4'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70218857881340
57
+ version_requirements: *70228974770560
58
58
  description: Rails bindings for opal JS engine
59
59
  email:
60
60
  - elia@schito.me
@@ -68,11 +68,8 @@ files:
68
68
  - Gemfile
69
69
  - README.md
70
70
  - Rakefile
71
+ - lib/assets/javascripts/opal-dom.js
71
72
  - lib/assets/javascripts/opal.js
72
- - lib/assets/javascripts/rquery.js
73
- - lib/assets/javascripts/rquery/document.js.opal
74
- - lib/assets/javascripts/rquery/element.js.opal
75
- - lib/assets/javascripts/rquery/sizzle.js
76
73
  - lib/opal-rails.rb
77
74
  - lib/opal/rails/engine.rb
78
75
  - lib/opal/rails/haml_filter.rb
@@ -1,3 +0,0 @@
1
- //= require rquery/sizzle
2
- //= require rquery/document
3
- //= require rquery/element
@@ -1,100 +0,0 @@
1
- module Document
2
-
3
- # Returns the body element of the current page as an {Element}
4
- # instance. Returns nil if the document hasn't finished loading
5
- # (which might mean the body isn't actually ready yet).
6
- #
7
- # @example
8
- #
9
- # Document.body # => <body>
10
- #
11
- # @return [Element, nil] return this documents body element
12
- def self.body
13
- %x{
14
- if (this.body) {
15
- return this.body;
16
- }
17
-
18
- if (document.body) {
19
- return this.body = #{ Element.new `document.body` };
20
- }
21
-
22
- return nil;
23
- }
24
- end
25
-
26
- # Returns the head element of this document as an {Element}.
27
- #
28
- # @return [Element] head element
29
- def self.head
30
- %x{
31
- if (!this.head) {
32
- var head = document.getElementsByTagName('head')[0]
33
- this.head = #{ Element.new `head` };
34
- }
35
-
36
- return this.head;
37
- }
38
- end
39
-
40
- %x{
41
- var loaded = false, callbacks = [];
42
-
43
- var trigger = function() {
44
- if (loaded) return;
45
- loaded = true;
46
-
47
- for (var i = 0, length = callbacks.length; i < length; i++) {
48
- var callback = callbacks[i];
49
- callback.call(callback._s);
50
- }
51
- };
52
-
53
- if (document.addEventListener) {
54
- document.addEventListener('DOMContentLoaded', trigger, false);
55
- }
56
- else {
57
- console.log("No Document.ready? in this browser");
58
- }
59
- }
60
-
61
- # Used to both register blocks that should be once the Document is
62
- # ready, as well as returning a boolean to indicate the ready state.
63
- #
64
- # Multiple blocks can be passed to this method which will then be run
65
- # in order once the Document becomes ready. If no block is given then
66
- # the ready state is just returned.
67
- #
68
- # The ready state is an indication of whether the document is ready
69
- # for manipulation. Commonly, until the document is ready, there is
70
- # no guarantee that the {body} element is created.
71
- #
72
- # This method will also try and perform in a cross browser way to
73
- # eliminate any differences between browsers and their ready state.
74
- #
75
- # @example
76
- #
77
- # Document.ready? do
78
- # puts "Document is ready and loaded!"
79
- # end
80
- #
81
- # Document.ready? # => false
82
- # # page load...
83
- # Document.ready? # => true
84
- #
85
- # @return [true, false] document ready state
86
- def self.ready?(&block)
87
- %x{
88
- if (block && block !== nil) {
89
- if (loaded) {
90
- block.call(block._s);
91
- }
92
- else {
93
- callbacks.push(block);
94
- }
95
- }
96
-
97
- return loaded;
98
- }
99
- end
100
- end
@@ -1,361 +0,0 @@
1
- class Element
2
-
3
- # Returns an array of elements in the document matching the given
4
- # css {selector}. Opal internally uses Sizzle to find elements, and
5
- # each element in the returned array is already wrapped by an Opal
6
- # {Element}.
7
- #
8
- # If no matching elements can be found in the document, then the
9
- # returned array is simply empty.
10
- #
11
- # @example
12
- #
13
- # # <body>
14
- # # <div class="foo" id="a"></div>
15
- # # <div class="foo" id="b"></div>
16
- # # <p class="bar"></p>
17
- # # </body>
18
- #
19
- # Element.find('.foo')
20
- # # => [<div class="foo", id="a">, <div class="foo" id="b">]
21
- #
22
- # Element.find('.bar')
23
- # # => [<p class="bar">]
24
- #
25
- # Element.find('.baz')
26
- # # => []
27
- #
28
- # @param [String] selector css selector to search for
29
- # @return [Array<Element>] the matching elements
30
- def self.find(selector)
31
- %x{
32
- var elements = Sizzle(selector);
33
-
34
- for (var i = 0, length = elements.length; i < length; i++) {
35
- elements[i] = #{ self.new `elements[i]` };
36
- }
37
-
38
- return elements;
39
- }
40
- end
41
-
42
- # Returns an Element instance for the native element with the given
43
- # {id} if it exists. If the element cannot be found then {nil} is
44
- # returned.
45
- #
46
- # It is important to note that this method does not cache element
47
- # instances. This means that calling this method twice with the same
48
- # element id will allocate and return two seperate instances of this
49
- # class which wrap the same element. The two instances will be
50
- # {==} however.
51
- #
52
- # @example
53
- #
54
- # # <body>
55
- # # <div id="foo"></div>
56
- # # </body>
57
- #
58
- # Element.id('foo') # => <div id="foo">
59
- # Element.id('bar') # => nil
60
- #
61
- # @param [String] id element id to get
62
- # @return [Element, nil] matching element
63
- def self.id(id)
64
- %x{
65
- var el = document.getElementById(id);
66
-
67
- if (!el) {
68
- return nil;
69
- }
70
-
71
- return #{self.new `el`};
72
- }
73
- end
74
-
75
- # Alias to Element.id(). (FIXME: remove this?)
76
- def self.find_by_id(id); self.id id; end
77
-
78
- # Creates a new {Element} instance. This class can either create new
79
- # elements, or wrap existing ones. Passing a string or no args to
80
- # {Element.new} will create a new native element of the type {type}
81
- # and then wrap that.
82
- #
83
- # Alternatively a native element can be passed to this method which
84
- # will then become the wrapped element.
85
- #
86
- # The wrapped element is stored as the privat `el` property on the
87
- # receiver, but you shouldn't really access it, and instead use the
88
- # methods provided by this class to manipulate the element.
89
- #
90
- # @example Creating a new element
91
- #
92
- # e = Element.new # => <div>
93
- # f = Element.new 'script' # => <script>
94
- #
95
- # @example Wrapping an existng element
96
- #
97
- # # <html>
98
- # # <body>
99
- # # <div id="foo"></div>
100
- # # </body>
101
- # # </html>
102
- #
103
- # Element.new(`document.getElementById('foo')`)
104
- # # => <div id="foo">
105
- #
106
- # Element.new(`document.body`)
107
- # # => <body>
108
- #
109
- # @param [String] type the tag name or native element
110
- # @return [self] returns receiver
111
- def initialize(type = :div)
112
- %x{
113
- if (typeof(type) === 'string') {
114
- type = document.createElement(type);
115
- }
116
- if (!type || !type.nodeType) {
117
- throw new Error('not a valid element');
118
- }
119
-
120
- this.el = type;
121
- }
122
- end
123
-
124
- # @!group Classes
125
-
126
- # Add a CSS class name to this element. This method will add the
127
- # given class name only if it is not already set on the element.
128
- # Trying to add a duplicate class has no effect. This method will
129
- # always return the receiver for chainability.
130
- #
131
- # @example
132
- #
133
- # # <div id="foo"></div>
134
- # # <div id="bar" class="big"></div>
135
- #
136
- # foo = Element.id 'foo'
137
- # foo.add_class 'limes' # => <div id="foo" class="limes">
138
- # foo.add_class 'limes' # => <div id="foo" class="limes">
139
- #
140
- # bar = Element.id 'bar'
141
- # bar.add_class 'title' # => <div id="bar" class="big title">
142
- # bar.add_class 'big' # => <div id="bar" class="big title">
143
- #
144
- # @param [String] name class name to add
145
- # @return [Element] returns self
146
- def add_class(name)
147
- %x{
148
- var className = this.el.className;
149
-
150
- if (!className) {
151
- this.el.className = name;
152
- }
153
- else if ((' ' + className + ' ').indexOf(' ' + name + ' ') === -1) {
154
- this.el.className += (' ' + name);
155
- }
156
-
157
- return this;
158
- }
159
- end
160
-
161
- def class_name
162
- `this.el.className || ""`
163
- end
164
-
165
- def class_name=(name)
166
- `this.el.className = name`
167
- end
168
-
169
- def remove_class(name)
170
- %x{
171
- var className = ' ' + this.el.className + ' ';
172
- className = className.replace(' ' + name + ' ', ' ');
173
- className = className.replace(/^\\s+/, '').replace(/\\s+$/, '');
174
-
175
- this.el.className = className;
176
- return this;
177
- }
178
- end
179
-
180
- # @!endgroup
181
-
182
- # @!group Events
183
-
184
- def on(name, &block)
185
- return unless block_given?
186
-
187
- %x{
188
- var el = this.el;
189
-
190
- var func = function(evt) {
191
- block.call(block._s);
192
- return true;
193
- };
194
-
195
- if (el.addEventListener) {
196
- el.addEventListener(name, func, false);
197
- }
198
- else {
199
- el.attachEvent(name, func);
200
- }
201
- }
202
- block
203
- end
204
-
205
- # @!endgroup
206
-
207
- # Returns an array of elements matching the given css selector that
208
- # are within the context of this element. That means, that only
209
- # elements that are decendants of this element will be matched.
210
- #
211
- # If no elements are found, then an empty array is simply returned.
212
- #
213
- # @example
214
- #
215
- # # <div id="foo">
216
- # # <p class="a" id="bill"></p>
217
- # # <p class="b" id="tom"></p>
218
- # # </div>
219
- # # <div id="bar">
220
- # # <p class="a" id="ben"></p>
221
- # # </div>
222
- #
223
- # Element.id('foo').find '.a'
224
- # # => [<p id="bill" class="a">]
225
- #
226
- # Element.id('bar').find '.b'
227
- # # => []
228
- #
229
- # @param [String] selector css selector to match elements against
230
- # @return [Array<Element>] array of matched elements
231
- def find(selector)
232
- %x{
233
- var elements = Sizzle(selector, this.el);
234
-
235
- for (var i = 0, length = elements.length; i < length; i++) {
236
- elements[i] = #{ Element.new `elements[i]` };
237
- }
238
-
239
- return elements;
240
- }
241
- end
242
-
243
- # Hides the receiver element by setting `display: none` as a css
244
- # property on the element.
245
- #
246
- # @return [self] returns the element
247
- def hide
248
- %x{
249
- this.el.style.display = 'none';
250
- return this;
251
- }
252
- end
253
-
254
- # Remove the element from the DOM. This method will try to remove this
255
- # element from it's parent (if it has one). If the element is not
256
- # currently in the DOM then there is no affect.
257
- #
258
- # @return [self] the element is returned
259
- def remove
260
- %x{
261
- var el = this.el, parent = el.parentNode;
262
-
263
- if (parent)
264
- parent.removeChild(el);
265
-
266
- return this;
267
- }
268
- end
269
-
270
- # Attempts to make the element visible by removing any `display` css
271
- # property on the element itself. This will only affect elements that
272
- # have been hidden with a direct style property and will **not**
273
- # overwrite any styles from a stylesheet.
274
- #
275
- # @return [self] returns the element
276
- def show
277
- %x{
278
- this.el.style.display = '';
279
- return this;
280
- }
281
- end
282
-
283
- # Returns whether this element is visible or not.
284
- # @return [true, false] return if element is visible or not
285
- def visible?
286
- `this.el.style.display !== 'none'`
287
- end
288
-
289
- def append_to_body
290
- %x{
291
- document.body.appendChild(this.el);
292
- return this;
293
- }
294
- end
295
-
296
- def id
297
- `this.el.id`
298
- end
299
-
300
- def id=(id)
301
- `this.el.id = id`
302
- end
303
-
304
- def inspect
305
- %x{
306
- var val, el = this.el, str = '<' + el.tagName.toLowerCase();
307
-
308
- if (val = el.id) str += (' id="' + val + '"');
309
- if (val = el.className) str += (' class="' + val + '"');
310
-
311
- return str + '>';
312
- }
313
- end
314
-
315
- alias to_s inspect
316
-
317
- def empty?
318
- `!!(/^\s*$/.test(this.el.innerHTML))`
319
- end
320
-
321
- def clear
322
- %x{
323
- var el = this.el;
324
-
325
- while (el.firstChild)
326
- el.removeChild(el.firstChild);
327
-
328
- return this;
329
- }
330
- end
331
-
332
- def ==(other)
333
- `this.el === other.el`
334
- end
335
-
336
- def html=(html)
337
- `this.el.innerHTML = html`
338
- end
339
-
340
- def append(child)
341
- `this.el.appendChild(child.el)`
342
- end
343
-
344
- def tag
345
- %x{
346
- var tag = this.el.tagName;
347
- return tag ? tag.toLowerCase() : '';
348
- }
349
- end
350
-
351
- def has_class?(name)
352
- %x{
353
- var full = this.el.className;
354
-
355
- if (full === name) return true;
356
- if (full === '') return false;
357
-
358
- return (new RegExp("(^|\\s+)" + name + "(\\s+|$)")).test(full);
359
- }
360
- end
361
- end