jqr-helpers 1.0.0.beta
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/Readme.md +122 -0
- data/lib/jqr-helpers/railtie.rb +9 -0
- data/lib/jqr-helpers/version.rb +5 -0
- data/lib/jqr-helpers.rb +12 -0
- metadata +70 -0
data/Readme.md
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
# Jqr-Helpers
|
2
|
+
|
3
|
+
`jqr-helpers` is a set of methods that create tags that are watched by unobtrusive JavaScript
|
4
|
+
events. It is primarily designed to cut down on JavaScript event handling and
|
5
|
+
callbacks and try to allow as much as possible to happen with Rails helpers.
|
6
|
+
|
7
|
+
The two main uses of these methods are to create dialogs and handle
|
8
|
+
Ajax requests without having to write JavaScript code. In particular, the options
|
9
|
+
available to the methods provide more support for the most common ways of using
|
10
|
+
these sorts of things in a web application environment.
|
11
|
+
|
12
|
+
Although there is some overlap with Rails 3 UJS methods, the important part
|
13
|
+
is the added options available. These make more assumptions than the built-in
|
14
|
+
helper methods, but are optimized to make it much easier to use them in
|
15
|
+
common scenarios. The existing methods are not altered.
|
16
|
+
|
17
|
+
jqr-helpers was developed using jQuery 1.10 and jQuery-UI 1.10, but it should
|
18
|
+
be compatible with earlier versions as well.
|
19
|
+
|
20
|
+
## Using jqr-helpers ##
|
21
|
+
|
22
|
+
If you are running Rails > 3.1, the required assets should be installed
|
23
|
+
automatically as part of the asset pipeline. You can require them as needed:
|
24
|
+
|
25
|
+
//= require jqr-helpers
|
26
|
+
*= require jqr-helpers
|
27
|
+
|
28
|
+
## Helper Methods ##
|
29
|
+
|
30
|
+
* `link_to_dialog` - open a dialog when a link is clicked
|
31
|
+
* `button_to_dialog` - open a dialog when a button is clicked
|
32
|
+
* `confirm_button` - open a nice jQuery confirm dialog (rather than a built-in browser one)
|
33
|
+
* `link_to_remote_dialog` - open a remote dialog when a link is clicked (i.e. load
|
34
|
+
the dialog content from a remote route)
|
35
|
+
* `button_to_remote_dialog` - open a remote dialog when a button is clicked
|
36
|
+
* `link_to_ajax` - send an Ajax request when a link is clicked
|
37
|
+
* `button_to_ajax` - send an Ajax request when a button is clicked
|
38
|
+
* `form_tag_ajax` - send an Ajax request when a form is submitted
|
39
|
+
* `form_for_ajax` - ditto but using Rails's `form_for` helper
|
40
|
+
* `tab_container` - print tab titles and contents.
|
41
|
+
|
42
|
+
There are two sets of options that recur throughout the methods here:
|
43
|
+
|
44
|
+
## Dialog Options ##
|
45
|
+
|
46
|
+
These are parameters to pass to the `jQuery.dialog()` function.
|
47
|
+
See <http://api.jqueryui.com/dialog/>.
|
48
|
+
|
49
|
+
An extra custom option is `:title` - setting it to `false` will hide the
|
50
|
+
title bar.
|
51
|
+
|
52
|
+
Another thing to note is the special values for buttons. Usually the buttons
|
53
|
+
must have JavaScript callbacks, but 99% of the time you want the classic
|
54
|
+
OK and Cancel buttons. Passing `submit` and `close` as the values
|
55
|
+
of the buttons (or the values of the "click" attribute of the buttons)
|
56
|
+
will do just that - submit the form inside the dialog or close it.
|
57
|
+
|
58
|
+
Example:
|
59
|
+
|
60
|
+
button_to_dialog('my-dialog-id', 'Open Dialog', :buttons =>
|
61
|
+
{'OK' => 'submit', 'Cancel' => 'close'})
|
62
|
+
|
63
|
+
You can also use a special option, `:default_buttons => true`, as a shortcut
|
64
|
+
to the above buttons, since it's so common to have an OK and Cancel
|
65
|
+
button.
|
66
|
+
|
67
|
+
Another option is `:close_x => true` - this will print a green X at the top
|
68
|
+
right of the dialog. Generally this is used when `:title => false`.
|
69
|
+
|
70
|
+
Note about dialog ID - you can always pass in the special value `:next` for
|
71
|
+
this. This will use whatever element is just after the clicked element
|
72
|
+
for the dialog contents. This can be useful for printing simple dialogs inside a
|
73
|
+
foreach loop that shouldn't require a totally separate route + view.
|
74
|
+
|
75
|
+
Dialogs will by default be centered on the page and have a max height of 80%
|
76
|
+
the page height.
|
77
|
+
|
78
|
+
## Ajax Options ##
|
79
|
+
|
80
|
+
By default, the `options` parameter in the various `_to_ajax` functions are
|
81
|
+
passed into the underlying function (e.g. `link_to_ajax` will pass them to
|
82
|
+
`link_to`), but there is support for several special options as well.
|
83
|
+
|
84
|
+
*Selector options* will act on another element once the request is complete.
|
85
|
+
Selectors can be IDs (`#selector`), or classes (`.selector`).
|
86
|
+
A class selector will be interpreted as an *ancestor* (parent) of the
|
87
|
+
element that sent the request that has the given class. So e.g. if you
|
88
|
+
are using `button_to_ajax`, giving `:update => '.my-parent'` will look for
|
89
|
+
an ancestor of the button tag with the class of `my-parent`.
|
90
|
+
|
91
|
+
* `:update` - update the given selector with the returned content.
|
92
|
+
* `:append` - insert the content as a child inside the given selector.
|
93
|
+
* `:delete` - delete all content of the given selector.
|
94
|
+
|
95
|
+
Other Ajax options:
|
96
|
+
|
97
|
+
* `:callback` (String) - the name of a JS function to call on completion.
|
98
|
+
The function will be in the scope of the original element, and
|
99
|
+
will be passed the result data of the Ajax request.
|
100
|
+
* `:use_dialog_opener` (Boolean) - if the Ajax request is sent from inside
|
101
|
+
a dialog, this indicates that the update/append/delete options should
|
102
|
+
look at the element that opened the dialog rather than the element that
|
103
|
+
fired the Ajax request. This is true by default for forms and false for
|
104
|
+
other elements.
|
105
|
+
* `:close_dialog` (Boolean) - if the Ajax request is sent from inside a dialog,
|
106
|
+
this indicates that the dialog should be closed when the request completes
|
107
|
+
successfully. This is true by default for forms and false for
|
108
|
+
other elements.
|
109
|
+
|
110
|
+
## jQuery Events ##
|
111
|
+
|
112
|
+
There are two special events triggered by jqr-helpers:
|
113
|
+
|
114
|
+
* `jqr.load` - this is triggered when a remote call populates an element with
|
115
|
+
data. The scope for the callback is the element which has just had data
|
116
|
+
populated.
|
117
|
+
* `jqr.beforedialogopen` - for remote dialogs, this is triggered when the
|
118
|
+
link or button is clicked to open the dialog but before the request is sent out.
|
119
|
+
|
120
|
+
***
|
121
|
+
|
122
|
+
jqr-helpers was developed by [Wishabi](http://www.wishabi.com).
|
data/lib/jqr-helpers.rb
ADDED
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jqr-helpers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.beta
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Daniel Orner
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-11-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
30
|
+
description: ! " This gem allows the use of several helper methods.\n The tags
|
31
|
+
output contain classes and data attributes that are grabbed by\n unobtrusive
|
32
|
+
JavaScript code and turned into jQuery UI widgets.\n Helpers include Ajax requests
|
33
|
+
to update elements on the page, dialogs\n (including remote dialogs), and tab
|
34
|
+
containers.\n"
|
35
|
+
email: daniel.orner@wishabi.com
|
36
|
+
executables: []
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files: []
|
39
|
+
files:
|
40
|
+
- lib/jqr-helpers/railtie.rb
|
41
|
+
- lib/jqr-helpers/version.rb
|
42
|
+
- lib/jqr-helpers.rb
|
43
|
+
- Readme.md
|
44
|
+
homepage: https://github.com/wishabi/jqr-helpers
|
45
|
+
licenses:
|
46
|
+
- MIT
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- .
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>'
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 1.3.1
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.8.24
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: Helpers to print unobtrusive jQuery-UI tags.
|
69
|
+
test_files: []
|
70
|
+
has_rdoc:
|