mack-javascript 0.8.3 → 0.8.3.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -41,7 +41,7 @@ module Mack
|
|
41
41
|
|
42
42
|
if options[:method] && options[:method].to_sym == :put || options[:method] == :delete
|
43
43
|
js_options['data'] = append_ajax_data(js_options['data'], "_method=#{options[:method]}")
|
44
|
-
|
44
|
+
end
|
45
45
|
|
46
46
|
if js_options['type'] == "'post'" && options[:authenticity_token]
|
47
47
|
js_options['data'] = append_ajax_data(js_options['data'], "__authenticity_token=#{options.delete(:authenticity_token)}")
|
@@ -52,11 +52,11 @@ module Mack
|
|
52
52
|
|
53
53
|
def append_ajax_data(data, new_data)
|
54
54
|
if data
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
55
|
+
data << " + '&"
|
56
|
+
else
|
57
|
+
data = "'"
|
58
|
+
end
|
59
|
+
data << "#{new_data}'"
|
60
60
|
end
|
61
61
|
|
62
62
|
def options_for_javascript(options)
|
@@ -127,12 +127,12 @@ module Mack
|
|
127
127
|
# page.select('.rakim').children would give you a collection consisting of
|
128
128
|
# the ul element, the p element, and the div with id 'technique'
|
129
129
|
def children
|
130
|
-
|
130
|
+
add "children()"
|
131
131
|
end
|
132
132
|
|
133
133
|
# returns a collection of the immediate parent of each selected element
|
134
|
-
|
135
|
-
|
134
|
+
def parent
|
135
|
+
add "parent()"
|
136
136
|
end
|
137
137
|
|
138
138
|
# returns a collection of every parent up the chain to the root of the document
|
@@ -154,38 +154,38 @@ module Mack
|
|
154
154
|
# of both divs and the ul.
|
155
155
|
# page.select('#featuring').ancestors('#long_live') will give you the div with
|
156
156
|
# id 'long_live'
|
157
|
-
|
158
|
-
|
157
|
+
def ancestors(selector = nil)
|
158
|
+
add "parents(#{optional_selector(selector)})"
|
159
159
|
end
|
160
160
|
|
161
161
|
# gets all siblings for each element selected
|
162
162
|
# Takes an optional selector as an argument
|
163
|
-
|
164
|
-
|
163
|
+
def siblings(selector = nil)
|
164
|
+
add "siblings(#{optional_selector(selector)})"
|
165
165
|
end
|
166
166
|
|
167
167
|
# gets the next immediate sibling for each element selected
|
168
168
|
# Takes an optional selector as an argument
|
169
|
-
|
170
|
-
|
169
|
+
def next(selector = nil)
|
170
|
+
add "next(#{optional_selector(selector)})"
|
171
171
|
end
|
172
172
|
|
173
173
|
# gets the previous immediate sibling for each element selected
|
174
174
|
# Takes an optional selector as an argument
|
175
|
-
|
176
|
-
|
175
|
+
def previous(selector = nil)
|
176
|
+
add "prev(#{optional_selector(selector)})"
|
177
177
|
end
|
178
178
|
|
179
179
|
# gets every next sibling for each element selected
|
180
180
|
# Takes an optional selector as an argument
|
181
|
-
|
182
|
-
|
181
|
+
def all_next(selector = nil)
|
182
|
+
add "nextAll(#{optional_selector(selector)})"
|
183
183
|
end
|
184
184
|
|
185
185
|
# gets every previous sibling for each element selected
|
186
186
|
# Takes an optional selector as an argument
|
187
|
-
|
188
|
-
|
187
|
+
def all_previous(selector = nil)
|
188
|
+
add "prevAll(#{optional_selector(selector)})"
|
189
189
|
end
|
190
190
|
|
191
191
|
|
@@ -200,8 +200,8 @@ module Mack
|
|
200
200
|
|
201
201
|
|
202
202
|
def remove_class(klass = '')
|
203
|
-
|
204
|
-
|
203
|
+
add "removeClass('#{klass}')"
|
204
|
+
end
|
205
205
|
|
206
206
|
def set_attribute(name, value)
|
207
207
|
value = "'#{value}'" if value.is_a? String
|
@@ -209,17 +209,17 @@ module Mack
|
|
209
209
|
end
|
210
210
|
|
211
211
|
def remove_attribute(name)
|
212
|
-
|
213
|
-
|
212
|
+
add "removeAttr('#{name}')"
|
213
|
+
end
|
214
214
|
|
215
215
|
|
216
216
|
|
217
217
|
|
218
|
-
|
218
|
+
#-- DOM Manipulation --#
|
219
219
|
|
220
220
|
# inserts html into the selected place for the specfied elemets
|
221
221
|
#
|
222
|
-
|
222
|
+
# +position+ may be one of:
|
223
223
|
#
|
224
224
|
# <tt>:top</tt>:: HTML is inserted inside the element, before the
|
225
225
|
# element's existing content.
|
@@ -264,7 +264,7 @@ module Mack
|
|
264
264
|
#
|
265
265
|
# Tip: use this with a partial containing your html:
|
266
266
|
# page.select('.rakim').insert(:before, render(:partial, 'the_r', :format => :html))
|
267
|
-
|
267
|
+
def insert(position, html)
|
268
268
|
position = {:bottom => 'append', :top => 'prepend'}[position.to_sym] || position.to_s
|
269
269
|
add "#{position}('#{escape_javascript(html)}')"
|
270
270
|
end
|
@@ -318,7 +318,7 @@ module Mack
|
|
318
318
|
|
319
319
|
|
320
320
|
|
321
|
-
|
321
|
+
#-- Effects --#
|
322
322
|
#
|
323
323
|
# All five effects methods in JquerySelector (morph, effect, show, hide, toggle)
|
324
324
|
# take the same options hash. This can consist of:
|
@@ -338,79 +338,79 @@ module Mack
|
|
338
338
|
# http://www.robertpenner.com/easing/easing_demo.html
|
339
339
|
#
|
340
340
|
# The full list of jquery easing options:
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
341
|
+
# linear, swing, easeInQuad, easeOutQuad, easeInOutQuad, easeInCubic, easeOutCubic,
|
342
|
+
# easeInOutCubic, easeInQuart, easeOutQuart, easeInOutQuart, easeInQuint, easeOutQuint,
|
343
|
+
# easeInOutQuint, easeInSine, easeOutSine, easeInOutSine, easeInExpo, easeOutExpo,
|
344
|
+
# easeInOutExpo, easeInCirc, easeOutCirc, easeInOutCirc, easeInElastic, easeOutElastic,
|
345
|
+
# easeInOutElastic, easeInBack, easeOutBack, easeInOutBack, easeInBounce, easeOutBounce,
|
346
|
+
# easeInOutBounce:
|
347
|
+
#
|
348
|
+
# --Callback--
|
349
|
+
#
|
350
|
+
# this is a function that will get called when your effect is done. You can use
|
351
|
+
# page.function to build it. Note: This function gets called for each element selected.
|
352
|
+
# For instance, in the following example, if there are 10 elements with the class 'rakim'
|
353
|
+
# then the function will be called 10 times. If you want to target each of the 10 elements
|
354
|
+
# in the callback function, use page.select('this')
|
355
|
+
#
|
356
|
+
# func = page.function.body do |p|
|
357
357
|
# p.select('this').insert(:top, '<h1>Cool Effects</h1>').effect(:highlight)
|
358
358
|
# end
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
359
|
+
# page.select('.rakim').effect(:slide_down, :callback => func)
|
360
|
+
#
|
361
|
+
# The above code will make every element with class 'rakim' slide down. When they are done
|
362
|
+
# sliding, the h1 tag will be inserted in the top of each element, and each element will
|
363
|
+
# be highlighted. Instead of this, you could do the following
|
364
|
+
# page.select('.rakim').effect(:slide_down).insert(:top, '<h1>Cool Effects</h1>').effect(:highlight)
|
365
|
+
# But this way, the insertion won't wait for the first animation to be done before occurring.
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
# Takes a hash of css properties you want the selected elements to 'morph' into.
|
370
|
+
# Say you want all elements with class rakim to transition to only having half
|
371
|
+
# the opacity and having a red background, and you want the transition to last 4
|
372
|
+
# seconds
|
373
|
+
# page.select('.rakim').morph({:opacity => 0.5, :backgroundColor => '#f00'}, :duration => 4000)
|
374
|
+
# You can see a list of css properties here http://www.w3schools.com/CSS/css_reference.asp
|
375
|
+
# The properties in your hash should be camelcase: :backgroundColor instead of
|
376
|
+
# background-color
|
377
|
+
def morph(hsh, options = nil)
|
378
378
|
options[:complete] = options.delete(:callback) if options && options[:callback]
|
379
379
|
args = [options_for_javascript(hsh), options_for_effects(options)]
|
380
|
-
|
380
|
+
add "animate(#{args.compact.join(',')})"
|
381
381
|
end
|
382
382
|
|
383
383
|
#This general mapping taken from the awesome JRails plugin
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
384
|
+
@@effects = {
|
385
|
+
:appear => {:function => 'fadeIn'},
|
386
|
+
:blind_down => {:mode => 'blind', :function => 'show', :options => {:direction => 'vertical'}},
|
387
|
+
:blind_up => {:mode => 'blind', :function => 'hide', :options => {:direction => 'vertical'}},
|
388
|
+
:blind_right => {:mode => 'blind', :function => 'show', :options => {:direction => 'horizontal'}},
|
389
|
+
:blind_left => {:mode => 'blind', :function => 'hide', :options => {:direction => 'horizontal'}},
|
390
|
+
:bounce_in => {:mode => 'bounce', :function => 'show', :options => {:direction => 'up'}},
|
391
|
+
:bounce_out => {:mode => 'bounce', :function => 'hide', :options => {:direction => 'up'}},
|
392
|
+
:drop_in => {:mode => 'drop', :function => 'show', :options => {:direction => 'up'}},
|
393
|
+
:drop_out => {:mode => 'drop', :function => 'hide', :options => {:direction => 'down'}},
|
394
|
+
:fade => {:function => 'fadeOut'},
|
395
|
+
:fold_in => {:mode => 'fold', :function => 'hide'},
|
396
|
+
:fold_out => {:mode => 'fold', :function => 'show'},
|
397
|
+
:grow => {:mode => 'scale', :function => 'show'},
|
398
|
+
:highlight => {:mode => 'highlight', :function => 'show'},
|
399
|
+
:puff => {:mode => 'puff', :function => 'hide'},
|
400
|
+
:pulsate => {:mode => 'pulsate', :function => 'show'},
|
401
|
+
:shake => {:mode => 'shake', :function => 'show'},
|
402
|
+
:shrink => {:mode => 'scale', :function => 'hide'},
|
403
|
+
:slide_down => {:mode => 'slide', :function => 'show', :options => {:direction => 'up'}},
|
404
|
+
:slide_up => {:mode => 'slide', :function => 'hide', :options => {:direction => 'up'}},
|
405
|
+
:slide_right => {:mode => 'slide', :function => 'show', :options => {:direction => 'left'}},
|
406
|
+
:slide_left => {:mode => 'slide', :function => 'hide', :options => {:direction => 'left'}},
|
407
|
+
:squish => {:mode => 'scale', :function => 'hide', :options => {:origin => "['top','left']"}},
|
408
|
+
:switch_on => {:mode => 'clip', :function => 'show', :options => {:direction => 'vertical'}},
|
409
|
+
:switch_off => {:mode => 'clip', :function => 'hide', :options => {:direction => 'vertical'}},
|
410
|
+
:toggle_appear => {:function => 'fadeToggle'},
|
411
|
+
:toggle_slide => {:mode => 'slide', :function => 'toggle', :options => {:direction => 'up'}},
|
412
|
+
:toggle_blind => {:mode => 'blind', :function => 'toggle', :options => {:direction => 'vertical'}},
|
413
|
+
}
|
414
414
|
|
415
415
|
#custom effects. 'name' corresponds to the keys of the hash above
|
416
416
|
def effect(name, options = nil)
|
@@ -463,17 +463,17 @@ module Mack
|
|
463
463
|
# goes to its href url) isn't done.
|
464
464
|
# This can also be used in conjunction with trigger to make and call custom events.
|
465
465
|
def peep(event_name, options = {}, &block)
|
466
|
-
|
466
|
+
add "bind('#{event_name}', #{event_function(options[:prevent_default], &block)})"
|
467
467
|
end
|
468
468
|
|
469
469
|
#takes away any event listeners on the 'event_name' event fot the selected elements
|
470
|
-
|
471
|
-
|
470
|
+
def stop_peeping(event_name)
|
471
|
+
add "unbind('#{event_name}')"
|
472
472
|
end
|
473
473
|
|
474
474
|
# triggers the 'event_name' event on the selected elements.
|
475
|
-
|
476
|
-
|
475
|
+
def trigger(event_name)
|
476
|
+
add "trigger('#{event_name}')"
|
477
477
|
end
|
478
478
|
|
479
479
|
|
@@ -552,12 +552,12 @@ module Mack
|
|
552
552
|
if remote_options || block_given?
|
553
553
|
func = Mack::JavaScript::Function.new(session_id, 'ev', 'ui')
|
554
554
|
if remote_options
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
555
|
+
remote_options[:with] ||= "'id=' + $(ui.draggable).attr('id')"
|
556
|
+
func << Mack::JavaScript::ScriptGenerator.new(session_id).ajax(remote_options)
|
557
|
+
end
|
558
|
+
func.body(&block) if block_given?
|
559
|
+
options.merge!(:drop => func)
|
560
|
+
end
|
561
561
|
add "droppable(#{drag_and_drop_options(options)})"
|
562
562
|
end
|
563
563
|
|
@@ -161,6 +161,10 @@ module Mack
|
|
161
161
|
@generator.<<(".#{statement}", :add_to_last => true)
|
162
162
|
self
|
163
163
|
end
|
164
|
+
|
165
|
+
def to_s
|
166
|
+
@generator.to_s
|
167
|
+
end
|
164
168
|
|
165
169
|
end
|
166
170
|
|
@@ -186,12 +190,10 @@ module Mack
|
|
186
190
|
to_s
|
187
191
|
end
|
188
192
|
|
189
|
-
|
190
193
|
def to_s
|
191
194
|
"function(#{@arguments.join(', ')}){#{@generator.to_s}}"
|
192
195
|
end
|
193
196
|
|
194
|
-
|
195
197
|
end
|
196
198
|
end
|
197
199
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mack-javascript
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.3
|
4
|
+
version: 0.8.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerardo Pis-Lopez
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-01-
|
12
|
+
date: 2009-01-27 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|