rapscallion 0.0.7 → 0.0.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 362a385fd5ff4c892e6496b8d14612a056b151d2
4
- data.tar.gz: ce018ef72b205c548b0ada2249612a532b5672bb
3
+ metadata.gz: 6cfeac8718cce596dbbc18fb0a5b4f45e82b8fe6
4
+ data.tar.gz: 2dac14a100ba87b78b1ab169df807f30dbc7f7b2
5
5
  SHA512:
6
- metadata.gz: ad8673f0b8a36b248f69c94279502db85969c91c54f2cba5e28122d78fb2f8f944190e2017aad606cba539a601ade7d2e1c5ca8f2d9461a77d3cb8e54e2ecc6a
7
- data.tar.gz: 7d6475ac9da06f44877858a93e5d697ddc70383c46d5b5f4d2ef20d5720bae9245a4b738e5d33cb8ec27f6bc396582bca147f4a044ab974b14691bb4817a57cf
6
+ metadata.gz: 1151d793fa4ae3ba7242aa251c1446c6096384daa2d4f7e72ba5ad9eef48a1d848d3e65303e57f24de581fb9fedc11d996517cfc7738501e0f3c287a87b57f14
7
+ data.tar.gz: a053bd7e80b31938b20c87bb70839dccb31f3264054b532eb5a5a8b567a0e001df13bdef311d126fe4192e1b218855d334501fbd9ed93bd4132735de484ff208
@@ -8,21 +8,21 @@
8
8
 
9
9
  */
10
10
 
11
- (function($){
11
+ (function ($) {
12
12
 
13
- $.fn.rapscallion = function(options){
13
+ $.fn.rapscallion = function (options) {
14
14
 
15
15
  var settings = $.extend({
16
-
16
+
17
17
  /* error messages will be shown in a div set the class for that here */
18
18
  error_message_container_class: "error_messages",
19
-
19
+
20
20
  /* fields with errors will get a class to indicate errors, change that class name here */
21
21
  field_with_error_class: 'has_error',
22
-
22
+
23
23
  /* valid fields will get a class to indicate success, change that class name here */
24
24
  field_valid_class: 'is_valid',
25
-
25
+
26
26
  /* error messages will be remove from input container, eg closest(:selector), set that here */
27
27
  field_container: 'div.input',
28
28
 
@@ -31,43 +31,43 @@
31
31
 
32
32
  }, options);
33
33
 
34
- return this.each(function() {
35
-
36
- $(this).on(settings.trigger, function(){
34
+ return this.each(function () {
37
35
 
38
- /* the input in question */
36
+ $(this).on(settings.trigger, function () {
37
+
38
+ /* the input in question */
39
39
  var el = $(this);
40
-
40
+
41
41
  /* the form */
42
42
  var form = el.closest('form');
43
-
43
+
44
44
  /* model reference from field name eg user from user[username] */
45
- var klass = el.prop('name').replace(/\[.*\]/,'');
46
-
45
+ var klass = el.prop('name').replace(/\[.*\]/, '');
46
+
47
47
  /* field name eg username from user[username] */
48
- var attr = el.prop('id').replace(klass+"_",'');
49
-
48
+ var attr = el.prop('id').replace(klass + "_", '');
49
+
50
50
  /* field value */
51
51
  var field_val = el.val();
52
-
52
+
53
53
  /* set up basic hash for validation */
54
- validation_data = {klass: klass, attr: attr, field_val: field_val}
54
+ validation_data = {klass: klass, attr: attr, field_val: field_val};
55
55
 
56
56
  /*
57
57
  confirmation fields are special cases, and add the field to confirm for
58
58
  eg password and password_confirmation
59
59
  */
60
- if(attr.match(/.*_confirmation/) != undefined){
61
- var confirmation_field = attr.replace('_confirmation','');
60
+ if (attr.match(/.*_confirmation/) !== undefined) {
61
+ var confirmation_field = attr.replace('_confirmation', '');
62
62
  var confirmation_value = form.find('#' + klass + "_" + confirmation_field).val();
63
- };
63
+ }
64
64
 
65
65
  validation_data[confirmation_field] = confirmation_value;
66
66
 
67
67
  /* existing record? */
68
- if(form.data('existing-record') != undefined) {
68
+ if (form.data('existing-record') !== undefined) {
69
69
  validation_data['existing_record'] = form.data('existing-record');
70
- };
70
+ }
71
71
 
72
72
  /* do ajax request */
73
73
  $.ajax({
@@ -76,24 +76,24 @@
76
76
  dataType: 'json',
77
77
  data: validation_data,
78
78
 
79
- success: function(data, status, xhr) {
80
-
79
+ success: function (data) {
80
+
81
81
  /* remove existing error messages */
82
- el.closest(settings.field_container).find('.'+settings.error_message_container_class).remove();
83
-
82
+ el.closest(settings.field_container).find('.' + settings.error_message_container_class).remove();
83
+ el.closest(settings.field_container).find('.errors').remove();
84
+
84
85
  /* if no errors present field is valid, add is_valid css class */
85
- if(data.length == 0) {
86
+ if (data.length === 0) {
86
87
  el.removeClass(settings.field_with_error_class).addClass(settings.field_valid_class);
87
88
 
88
- /* if error present field is not valid, add has_error class to input, and error messages after input */
89
-
89
+ /* if error present field is not valid, add has_error class to input, and error messages after input */
90
90
  } else {
91
91
  /* cycle through json response adding errors for each */
92
- $.each( data, function( key, val ) {
92
+ $.each(data, function (key, val) {
93
93
  el.after('<div class="' + settings.error_message_container_class + '">' + val + '</div>');
94
- el.removeClass(settings.field_valid_class).addClass(settings.field_with_error_class)
94
+ el.removeClass(settings.field_valid_class).addClass(settings.field_with_error_class);
95
95
  });
96
- }; /* end if errors or not */
96
+ } /* end if errors or not */
97
97
 
98
98
  } /* end success */
99
99
 
@@ -101,10 +101,10 @@
101
101
 
102
102
 
103
103
  });
104
-
104
+
105
105
 
106
106
  });
107
-
108
-
107
+
108
+
109
109
  };
110
110
  }(jQuery));
@@ -1,3 +1,3 @@
1
1
  module Rapscallion
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rapscallion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gordon Isnor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-30 00:00:00.000000000 Z
11
+ date: 2015-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails