guardsjs-rails 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module GuardsJS
2
2
  module Rails
3
- VERSION = "1.0.0"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Guards JavaScript jQuery Plugin v1.0.0
2
+ * Guards JavaScript jQuery Plugin v1.1.0
3
3
  * https://github.com/on-site/guards.js
4
4
  *
5
5
  * Copyright 2010-2013, On-Site.com, http://www.on-site.com/
@@ -8,7 +8,7 @@
8
8
  * Includes code for email and phone number validation from the jQuery
9
9
  * Validation plugin. http://docs.jquery.com/Plugins/Validation
10
10
  *
11
- * Date: Wed Apr 17 01:43:25 2013 -0700
11
+ * Date: Fri Jun 28 00:51:31 2013 -0700
12
12
  */
13
13
 
14
14
  /**
@@ -48,7 +48,7 @@
48
48
  return $.guards.add(selector);
49
49
  };
50
50
 
51
- $.guard.version = "1.0.0";
51
+ $.guard.version = "1.1.0";
52
52
 
53
53
  $.Guards = function() {
54
54
  var self = this;
@@ -229,6 +229,59 @@
229
229
  */
230
230
  this.name("disallow").using(this.aggregate(this.isAllValid, this.isDisallowed)).message(this.arrayMessage("Please don't enter: #{0}."));
231
231
 
232
+ /**
233
+ * @page Named Guards
234
+ * @section dateUS
235
+ * @since 1.1.0
236
+ *
237
+ * <p>
238
+ * Guard for a US date. Month and day value validations
239
+ * exist, though may not conver all invalid dates (so,
240
+ * 13/32/2013 is invalid, but 2/31/2013 might not properly
241
+ * fail at this point in time). An empty value is
242
+ * considered valid.
243
+ * </p>
244
+ *
245
+ * <div class="example">
246
+ * <div class="display">
247
+ * <script>
248
+ * $.guard(".date").using("dateUS");
249
+ * </script>
250
+ *
251
+ * <p>
252
+ * <input class="date" type="text" value="not valid" /><br />
253
+ * <small>US date of any value</small>
254
+ * </p>
255
+ * </div>
256
+ * </div>
257
+ */
258
+ this.name("dateUS").using(this.aggregate(this.isAllValid, this.isValidDateUS)).message("Please use: dd/mm/yyyy.")
259
+
260
+ /**
261
+ * @page Named Guards
262
+ * @section timeUS
263
+ * @since 1.1.0
264
+ *
265
+ * <p>
266
+ * Guard for a US time. Military time is not currently
267
+ * supported. An empty value is considered valid.
268
+ * </p>
269
+ *
270
+ * <div class="example">
271
+ * <div class="display">
272
+ * <script>
273
+ * $.guard(".time").using("timeUS");
274
+ * </script>
275
+ *
276
+ * <p>
277
+ * <input class="time" type="text" value="not valid" /><br />
278
+ * <small>US time of any value</small>
279
+ * </p>
280
+ * </div>
281
+ * </div>
282
+ */
283
+ this.name("timeUS").using(this.aggregate(this.isAllValid, this.isValidTimeUS)).message("Please use: hh:mm&nbsp;am/pm.")
284
+
232
285
  /**
233
286
  * @page Named Guards
234
287
  * @section email
@@ -597,13 +650,13 @@
597
650
  * This version of guards.js library as a string, like <code>"1.0.0"</code>.
598
651
  * </p>
599
652
  */
600
- $.Guards.prototype.version = "1.0.0";
653
+ $.Guards.prototype.version = "1.1.0";
601
654
 
602
655
  $.Guards.prototype.parentContext = function(element) {
603
656
  var $element = $(element);
604
657
  var context = $element.parents("form:first");
605
658
 
606
- if (context.size() == 0) {
659
+ if (context.size() === 0) {
607
660
  context = $element.parents("*:last");
608
661
  }
609
662
 
@@ -1151,6 +1204,32 @@
1151
1204
  return this.isInRange(value, options);
1152
1205
  };
1153
1206
 
1207
+ /**
1208
+ * Validates for a valid US date.
1209
+ */
1210
+ $.Guards.prototype.isValidDateUS = function(value, options) {
1211
+ value = $.trim(value);
1212
+
1213
+ if (value === "") {
1214
+ return true;
1215
+ }
1216
+
1217
+ return /^(0?[1-9]|1[0-2])\/(0?[1-9]|[1-2]\d|3[0-1])\/(\d{3}\d+)$/.test(value);
1218
+ };
1219
+
1220
+ /**
1221
+ * Validates for a valid US time.
1222
+ */
1223
+ $.Guards.prototype.isValidTimeUS = function(value, options) {
1224
+ value = $.trim(value);
1225
+
1226
+ if (value === "") {
1227
+ return true;
1228
+ }
1229
+
1230
+ return /^(0?[1-9]|1[0-2]):([0-5]\d)\s*(a|p)m$/i.test(value);
1231
+ };
1232
+
1154
1233
  /**
1155
1234
  * Validates the given value is a valid email. If options is
1156
1235
  * passed with allowDisplay as true, display emails will be
@@ -1950,26 +2029,49 @@
1950
2029
  * Clear this error and any errors linked with it (grouped guards
1951
2030
  * and radio buttons cause all elements involved to be linked).
1952
2031
  */
1953
- $.GuardError.prototype.clear = function() {
2032
+ $.GuardError.prototype.clear = function(forLinked) {
1954
2033
  if (this._cleared) {
1955
2034
  return;
1956
2035
  }
1957
2036
 
2037
+ var selected = [];
2038
+ var $selected;
2039
+
2040
+ if (!forLinked) {
2041
+ for (var i = 0; i < this._linked.length; i++) {
2042
+ selected.push(this._linked[i]._element);
2043
+ }
2044
+
2045
+ $selected = $(selected);
2046
+ var clearGuardErrorPrevented = this._guard.sendEvent("clearGuardError", $selected, false, this._errorElement).isDefaultPrevented();
2047
+ var clearGuardFormErrorPrevented = this._guard.sendEvent("clearGuardFormError", $selected, true, this._errorElement).isDefaultPrevented();
2048
+
2049
+ if (clearGuardErrorPrevented || clearGuardFormErrorPrevented) {
2050
+ return;
2051
+ }
2052
+ }
2053
+
1958
2054
  this._errorElement.remove();
1959
2055
  var index = $.inArray(this, this._element.errors);
2056
+ var $element = $(this._element);
1960
2057
 
1961
2058
  if (index >= 0) {
1962
2059
  this._element.errors.splice(index, 1);
1963
2060
  }
1964
2061
 
1965
- if (!$(this._element).hasErrorsWithInvalidClass(this._guard.getInvalidClass())) {
1966
- $(this._element).removeClass(this._guard.getInvalidClass());
2062
+ if (!$element.hasErrorsWithInvalidClass(this._guard.getInvalidClass())) {
2063
+ $element.removeClass(this._guard.getInvalidClass());
1967
2064
  }
1968
2065
 
1969
2066
  this._cleared = true;
1970
2067
 
1971
2068
  while (this._linked.length > 0) {
1972
- this._linked.shift().clear();
2069
+ this._linked.shift().clear(true);
2070
+ }
2071
+
2072
+ if (!forLinked) {
2073
+ this._guard.sendEvent("afterClearGuardError", $selected, false);
2074
+ this._guard.sendEvent("afterClearGuardFormError", $selected, true);
1973
2075
  }
1974
2076
  };
1975
2077
 
@@ -2449,7 +2551,8 @@
2449
2551
  return !!(x.errors && x.errors.length > 0);
2450
2552
  },
2451
2553
  "guardable": function(x) {
2452
- return x.tagName.toLowerCase() === "input" || x.tagName.toLowerCase() === "textarea" || x.tagName.toLowerCase() === "select";
2554
+ var tagName = x.tagName.toLowerCase();
2555
+ return tagName === "input" || tagName === "textarea" || tagName === "select" || tagName === "button";
2453
2556
  }
2454
2557
  });
2455
2558
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guardsjs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
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: 2013-04-17 00:00:00.000000000 Z
12
+ date: 2013-06-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -58,7 +58,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
58
58
  version: '0'
59
59
  segments:
60
60
  - 0
61
- hash: -3622247273886960822
61
+ hash: 1471807923169786715
62
62
  required_rubygems_version: !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements: