jqr-helpers 1.0.40 → 1.0.41
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 +8 -8
- data/Readme.md +18 -6
- data/app/assets/javascripts/jqr-helpers.js +27 -3
- data/jqr-helpers.gemspec +2 -2
- data/lib/jqr-helpers/helpers.rb +21 -0
- data/lib/jqr-helpers/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDg3YTU0MDE3OGNkNTUyNTllN2IwYmYyNGI5NmZmMjY2NDE5ZDE5Nw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzY2OWUxNWJmYjY1MzAyNzU0ZjA2NTRkMGZmZmE0ZjY3MzNkOGYyZg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MjgzZDljNjI5OTBiNWEzMmZhZGYxN2M4NjE5ZGEwNmZkMTZlM2FjYjNlOTAz
|
10
|
+
YTQyNDVmOTEyM2M2N2RhODM5NzI3MDc0MTE4NDg1YzAxN2Y3NGJkZmZlNWNj
|
11
|
+
ZjVmZTcyNDEzNzhjYTlmYzQ2ZWIzMzUzOTk3NjNlZjYyNDVmNmM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MWMyNTUzZWQ4ZTA0MTVkZjEyMDY4NDBkNGVmZGQ5Njg4YjRkNzBiOGY4NjFh
|
14
|
+
ZWIwNThhNzJiYjRmNWNlY2MxNmNjYTAxNDEyYjFjOGU3NjFhNWUxZDRkNWYx
|
15
|
+
MDc2ZTU3ODgxZWNlYzNhNTgwMjcyMWExYmVhN2MyMWY3NjdlNzg=
|
data/Readme.md
CHANGED
@@ -58,6 +58,8 @@ they load a heck of a lot faster when you have dozens or hundreds of them.
|
|
58
58
|
* `button_to_external` - create a working `button_to` button inside an existing form (!)
|
59
59
|
* `will_paginate_ajax` - create a `will_paginate` interface that uses Ajax to
|
60
60
|
replace the paginated contents.
|
61
|
+
* `ajax_change` - monitor any inputs inside the given block for changes
|
62
|
+
and send to the Ajax URL when they happen.
|
61
63
|
|
62
64
|
There are two sets of options that recur throughout the methods here:
|
63
65
|
|
@@ -127,6 +129,8 @@ an ancestor of the button tag with the class of `my-parent`.
|
|
127
129
|
Other Ajax options:
|
128
130
|
|
129
131
|
* `:return_type` (String) - the expected return type, e.g. 'text' or 'html'.
|
132
|
+
* `:method` (String) - GET, POST, PUT, or DELETE, if the default is incorrect
|
133
|
+
(GET for links, POST for forms and buttons).
|
130
134
|
* `:empty` (String) - the ID of an element which should be shown when the
|
131
135
|
element you are appending/deleting from is empty. If you delete the last child
|
132
136
|
from an element, that element will be hidden and the "empty" element will
|
@@ -168,17 +172,25 @@ page).
|
|
168
172
|
of the screen. `:small` would be a small inline throbber next to the button or
|
169
173
|
link that called the dialog, and `:none` shows no throbber at all.
|
170
174
|
|
175
|
+
## Monitoring Fields ##
|
176
|
+
|
177
|
+
You can monitor a field for changes using the ``ajax_change`` method:
|
178
|
+
|
179
|
+
<%= ajax_change('/toggle_complete_url', :update => '.parent-row') do %>
|
180
|
+
<%= check_box_tag 'toggle_complete', 1, my_model.complete? %>
|
181
|
+
<% end %>
|
182
|
+
|
171
183
|
## Panel Renderers ##
|
172
184
|
|
173
185
|
Tabs (and eventually accordion panes and menus) are rendered using a "panel renderer".
|
174
186
|
This allows you to loop through the tabs in an intuitive and concise way.
|
175
187
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
188
|
+
<%= tab_container {:collapsible => true}, {:class => 'my-tabs}' do |r| %>
|
189
|
+
<% r.panel 'Tab 1' do %>
|
190
|
+
My tab content here
|
191
|
+
<% end %>
|
192
|
+
<% r.panel 'Tab 2', 'http://www.foobar.com/' %>
|
193
|
+
<% end %>
|
182
194
|
|
183
195
|
## jQuery Events ##
|
184
196
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
(function($) {
|
2
|
-
function showThrobber(element) {
|
2
|
+
function showThrobber(element, noDisable) {
|
3
3
|
switch ($(element).data('throbber')) {
|
4
4
|
case 'none':
|
5
5
|
return;
|
@@ -9,7 +9,9 @@
|
|
9
9
|
default: // small or not given
|
10
10
|
$(element).after("<img src='/images/jqr-helpers/throbber.gif' class='throbber'/>");
|
11
11
|
}
|
12
|
-
|
12
|
+
if (!noDisable) {
|
13
|
+
$(element).attr('disabled', 'disabled');
|
14
|
+
}
|
13
15
|
// refresh disabled state
|
14
16
|
$(element).attr('autocomplete', 'off');
|
15
17
|
}
|
@@ -194,7 +196,11 @@
|
|
194
196
|
else
|
195
197
|
$(element).data('throbber', 'large');
|
196
198
|
}
|
197
|
-
|
199
|
+
// can't disable form fields because then they won't receive
|
200
|
+
// the success event
|
201
|
+
var name = element.prop('tagName').toUpperCase();
|
202
|
+
showThrobber(element,
|
203
|
+
(name == 'INPUT' || name == 'SELECT' || name == 'TEXTAREA'));
|
198
204
|
}
|
199
205
|
|
200
206
|
function ujsAjaxSuccess(evt, data, status, xhr) {
|
@@ -428,6 +434,24 @@
|
|
428
434
|
$(this).tabs(options);
|
429
435
|
});
|
430
436
|
|
437
|
+
// observe fields
|
438
|
+
$('.ujs-ajax-change').each(function() {
|
439
|
+
var dataAttrs = ['type', 'callback', 'refresh', 'redirect', 'scroll-to',
|
440
|
+
'throbber', 'empty', 'container', 'selector', 'result-method', 'url',
|
441
|
+
'method', 'params'];
|
442
|
+
var dataMap = {};
|
443
|
+
var element = $(this);
|
444
|
+
$.each(dataAttrs, function(index, val) {
|
445
|
+
dataMap[val] = element.data(val);
|
446
|
+
element.removeAttr('data-' + val);
|
447
|
+
});
|
448
|
+
element.removeClass('ujs-ajax');
|
449
|
+
// we have to set a data-remote attribute because Rails uses [data-remote]
|
450
|
+
// as a selector rather than checking the actual data in the element
|
451
|
+
$(this).find('input, select').data(dataMap).addClass('ujs-ajax').
|
452
|
+
attr('data-remote', 'true');
|
453
|
+
});
|
454
|
+
|
431
455
|
}
|
432
456
|
|
433
457
|
$(function() {
|
data/jqr-helpers.gemspec
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'jqr-helpers'
|
3
3
|
s.require_paths = %w(. lib lib/jqr-helpers)
|
4
|
-
s.version = '1.0.
|
5
|
-
s.date = '2014-
|
4
|
+
s.version = '1.0.41'
|
5
|
+
s.date = '2014-05-16'
|
6
6
|
s.summary = 'Helpers to print unobtrusive jQuery-UI tags.'
|
7
7
|
s.description = <<-EOF
|
8
8
|
This gem adds helper methods to create unobtrusive jQuery code. It outputs
|
data/lib/jqr-helpers/helpers.rb
CHANGED
@@ -385,6 +385,18 @@ module JqrHelpers
|
|
385
385
|
content_tag(:button, content, options)
|
386
386
|
end
|
387
387
|
|
388
|
+
# Observe a field for changes.
|
389
|
+
# On change, post to the Ajax URL and calculate callbacks.
|
390
|
+
# @param url [String] the URL to send to.
|
391
|
+
# @param options [Hash] Ajax options - see above.
|
392
|
+
# @return [String]
|
393
|
+
def ajax_change(url, options={}, &block)
|
394
|
+
options[:class] = 'ujs-ajax-change'
|
395
|
+
options = _process_ajax_options(options)
|
396
|
+
options['data-url'] = url
|
397
|
+
content_tag :span, options, &block
|
398
|
+
end
|
399
|
+
|
388
400
|
# Generate a random string for IDs.
|
389
401
|
# @return [String]
|
390
402
|
# @private
|
@@ -536,6 +548,15 @@ module JqrHelpers
|
|
536
548
|
new_options[:'data-throbber'] = options.delete(:throbber) || 'small'
|
537
549
|
new_options[:'data-empty'] = options.delete(:empty)
|
538
550
|
new_options[:'data-container'] = options.delete(:container)
|
551
|
+
method = options[:method]
|
552
|
+
if method
|
553
|
+
if method == 'put' || method == 'delete'
|
554
|
+
new_options[:'data-params'] = "_method=#{method}"
|
555
|
+
new_options[:'data-method'] = 'post'
|
556
|
+
else
|
557
|
+
new_options[:'data-method'] = method
|
558
|
+
end
|
559
|
+
end
|
539
560
|
|
540
561
|
[:update, :append, :delete].each do |result_method|
|
541
562
|
selector = options.delete(result_method)
|
data/lib/jqr-helpers/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jqr-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.41
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Orner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|