jquery_ujs_extended 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +14 -6
- data/lib/assets/javascripts/jquery_ujs_extended.js.coffee +11 -3
- metadata +2 -2
data/README.md
CHANGED
@@ -14,10 +14,16 @@ Requires :
|
|
14
14
|
- jquery-rails
|
15
15
|
|
16
16
|
#Installation
|
17
|
+
In your Gemfile `assets` group, put:
|
17
18
|
|
18
|
-
|
19
|
+
gem 'jquery_ujs_extended'
|
19
20
|
|
20
|
-
|
21
|
+
Then `bundle install` as usual.
|
22
|
+
Edit `application.js` to add :
|
23
|
+
|
24
|
+
//= require jquery_ujs_extended
|
25
|
+
|
26
|
+
Restart your webserver and all should be fine
|
21
27
|
|
22
28
|
#Usage
|
23
29
|
|
@@ -40,20 +46,22 @@ This applies to <form>, <a>, <input> and <select> elemen
|
|
40
46
|
link_to "Append", url_path, data: {remote: true, append: "#div1 span .class1"}
|
41
47
|
* data-loader. Takes a DOM element. Will show the DOM element before sending the request, and hide it when the request is completed. This is best used to show a spinner image during a request.
|
42
48
|
|
43
|
-
<%= link_to "Loader", url_path, data: {remote: true,
|
44
|
-
<%= image_tag "/my/image.jpg", style:
|
49
|
+
<%= link_to "Loader", url_path, data: {remote: true, loader: ".loader"} %>
|
50
|
+
<%= image_tag "/my/image.jpg", style: 'display: none', class: 'loader' %>
|
45
51
|
* data-redirect. Takes a url. Redirects to the url on ajax success.
|
46
52
|
|
47
53
|
link_to "redirect", url_path, data: {remote: true, redirect: "/my/url"}
|
48
54
|
|
49
55
|
##Behaviour
|
50
56
|
|
51
|
-
* data-integer. If specified and applied to a text field, will prevent the field from being anything but an integer.Value: minimum value. Leave blank if you don't want one.
|
57
|
+
* data-integer. If specified and applied to a text field, will prevent the field from being anything but an integer.Value: minimum value or range like 1..10000. Leave blank if you don't want one.
|
52
58
|
|
53
59
|
text_field_tag "quantity", 1, data: {integer: 1}
|
54
|
-
|
60
|
+
text_field_tag "quantity", 1, data: {integer: 1..10000}
|
61
|
+
* data-float. If specified and applied to a text field, will prevent the field from being anything but a float.Value: minimum value or range like 1..10000. Leave blank if you don't want one.
|
55
62
|
|
56
63
|
text_field_tag "price", 1, data: {float: 0.01}
|
64
|
+
text_field_tag "price", 1, data: {float: 0.01..10000}
|
57
65
|
|
58
66
|
|
59
67
|
#Bugs? Thoughts? Ideas to make it better?
|
@@ -3,7 +3,7 @@ $ ->
|
|
3
3
|
"input[#{attribute}], a[#{attribute}], form[#{attribute}], textarea[#{attribute}], select[#{attribute}]"
|
4
4
|
|
5
5
|
#Ugly ... there must be a better way to do it ...
|
6
|
-
updateNumberField = (element, min_value, value) ->
|
6
|
+
updateNumberField = (element, min_value, max_value, value) ->
|
7
7
|
if(!isNaN(min_value) && ((value < min_value) || isNaN(value)))
|
8
8
|
element.val(min_value)
|
9
9
|
else if isNaN(min_value) && !isNaN(value)
|
@@ -13,6 +13,9 @@ $ ->
|
|
13
13
|
else
|
14
14
|
element.val(value)
|
15
15
|
|
16
|
+
if(!isNaN(max_value) && !isNaN(value) && value > max_value)
|
17
|
+
element.val(max_value)
|
18
|
+
|
16
19
|
|
17
20
|
$(document).on 'ajax:success', ajaxSelectors('data-update'), (evt, data) ->
|
18
21
|
$($(@).data 'update').html(data)
|
@@ -33,9 +36,14 @@ $ ->
|
|
33
36
|
window.location.replace($(@).data 'redirect')
|
34
37
|
|
35
38
|
$(document).on 'change', ajaxSelectors('data-integer'), (evt, data) ->
|
36
|
-
|
39
|
+
|
40
|
+
tab_value = $(@).data('integer').split("..")
|
41
|
+
|
42
|
+
min_value = parseInt(tab_value[0])
|
43
|
+
max_value = tab_value[1]
|
44
|
+
|
37
45
|
value = parseInt($(@).val())
|
38
|
-
updateNumberField($(@), min_value, value)
|
46
|
+
updateNumberField($(@), min_value, max_value, value)
|
39
47
|
|
40
48
|
$(document).on 'change', ajaxSelectors('data-float'), (evt, data) ->
|
41
49
|
min_value = parseFloat($(@).data('float'))
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jquery_ujs_extended
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-17 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email: alberto.anthony@gmail.com
|