guardsjs-rails 1.3.2 → 1.4.0
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/app/assets/javascripts/guards.js +461 -28
- data/lib/guardsjs-rails/version.rb +1 -1
- metadata +20 -13
- checksums.yaml +0 -7
@@ -1,5 +1,5 @@
|
|
1
1
|
/*!
|
2
|
-
* Guards JavaScript jQuery Plugin v1.
|
2
|
+
* Guards JavaScript jQuery Plugin v1.4.0
|
3
3
|
* https://github.com/on-site/guards.js
|
4
4
|
*
|
5
5
|
* Copyright 2010-2014, 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:
|
11
|
+
* Date: Fri Jul 11 14:37:18 2014 -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.
|
51
|
+
$.guard.version = "1.4.0";
|
52
52
|
|
53
53
|
$.Guards = function() {
|
54
54
|
var self = this;
|
@@ -745,7 +745,7 @@
|
|
745
745
|
* This version of guards.js library as a string, like <code>"1.0.0"</code>.
|
746
746
|
* </p>
|
747
747
|
*/
|
748
|
-
$.Guards.prototype.version = "1.
|
748
|
+
$.Guards.prototype.version = "1.4.0";
|
749
749
|
|
750
750
|
$.Guards.prototype.parentContext = function(element) {
|
751
751
|
var $element = $(element);
|
@@ -926,11 +926,15 @@
|
|
926
926
|
$.Guards.prototype.camelize = function(word) {
|
927
927
|
// This code is from jQuery, but it is not a public function
|
928
928
|
// so let's juse reuse it.
|
929
|
-
return word.replace(/-([\da-z])/gi, function(
|
929
|
+
return word.replace(/-([\da-z])/gi, function(_, letter) {
|
930
930
|
return letter.toUpperCase();
|
931
931
|
});
|
932
932
|
};
|
933
933
|
|
934
|
+
$.Guards.prototype.capitalize = function(word) {
|
935
|
+
return word.substring(0, 1).toUpperCase() + word.substring(1, word.length);
|
936
|
+
};
|
937
|
+
|
934
938
|
/**
|
935
939
|
* Format all arguments into the first argument. This is a
|
936
940
|
* convenience function similar to the C sprintf function, though
|
@@ -1130,7 +1134,7 @@
|
|
1130
1134
|
if ($.isArray(values)) {
|
1131
1135
|
var result = true;
|
1132
1136
|
|
1133
|
-
$.each(values, function(
|
1137
|
+
$.each(values, function(_, x) {
|
1134
1138
|
if (!fn(x)) {
|
1135
1139
|
result = false;
|
1136
1140
|
return false;
|
@@ -1156,7 +1160,7 @@
|
|
1156
1160
|
if ($.isArray(values)) {
|
1157
1161
|
var result = false;
|
1158
1162
|
|
1159
|
-
$.each(values, function(
|
1163
|
+
$.each(values, function(_, x) {
|
1160
1164
|
if (fn(x)) {
|
1161
1165
|
result = true;
|
1162
1166
|
return false;
|
@@ -1188,7 +1192,7 @@
|
|
1188
1192
|
var found = {};
|
1189
1193
|
var result = true;
|
1190
1194
|
|
1191
|
-
$.each(values, function(
|
1195
|
+
$.each(values, function(_, x) {
|
1192
1196
|
if (found[x] === true) {
|
1193
1197
|
result = false;
|
1194
1198
|
return false;
|
@@ -1235,7 +1239,7 @@
|
|
1235
1239
|
var value = values[0];
|
1236
1240
|
var result = true;
|
1237
1241
|
|
1238
|
-
$.each(values, function(
|
1242
|
+
$.each(values, function(_, x) {
|
1239
1243
|
if (x !== value) {
|
1240
1244
|
result = false;
|
1241
1245
|
return false;
|
@@ -1485,7 +1489,7 @@
|
|
1485
1489
|
var result = true;
|
1486
1490
|
var self = this;
|
1487
1491
|
|
1488
|
-
$.each(this._guards, function(
|
1492
|
+
$.each(this._guards, function(_, guard) {
|
1489
1493
|
var fields = callback(guard);
|
1490
1494
|
|
1491
1495
|
if (fields !== false && !self.test(guard, fields)) {
|
@@ -1493,7 +1497,7 @@
|
|
1493
1497
|
}
|
1494
1498
|
});
|
1495
1499
|
|
1496
|
-
$.each(this.named, function(
|
1500
|
+
$.each(this.named, function(_, guard) {
|
1497
1501
|
var fields = callback(guard);
|
1498
1502
|
|
1499
1503
|
if (fields !== false && !self.test(guard, fields)) {
|
@@ -1504,22 +1508,69 @@
|
|
1504
1508
|
return result;
|
1505
1509
|
};
|
1506
1510
|
|
1511
|
+
$.Guards.prototype.groupByGroups = function(guard, fields) {
|
1512
|
+
if (this.isBlank(guard.name)) {
|
1513
|
+
return [fields];
|
1514
|
+
}
|
1515
|
+
|
1516
|
+
var self = this;
|
1517
|
+
var ungrouped = [];
|
1518
|
+
var grouped = {};
|
1519
|
+
var dataAttrName = "guard" + this.capitalize(this.camelize(guard.name)) + "Group";
|
1520
|
+
var dashedDataAttrName = "guard-" + guard.name + "-group";
|
1521
|
+
|
1522
|
+
fields.each(function(_, element) {
|
1523
|
+
var $element = $(element);
|
1524
|
+
var groups = $element.data(dataAttrName) || $element.data(dashedDataAttrName);
|
1525
|
+
|
1526
|
+
if (self.isBlank(groups)) {
|
1527
|
+
ungrouped.push(element);
|
1528
|
+
return;
|
1529
|
+
}
|
1530
|
+
|
1531
|
+
$.each(groups.split(" "), function(_, group) {
|
1532
|
+
if (self.isBlank(group)) {
|
1533
|
+
return;
|
1534
|
+
}
|
1535
|
+
|
1536
|
+
grouped[group] = grouped[group] || [];
|
1537
|
+
grouped[group].push(element);
|
1538
|
+
});
|
1539
|
+
});
|
1540
|
+
|
1541
|
+
var results = [];
|
1542
|
+
|
1543
|
+
if (ungrouped.length !== 0) {
|
1544
|
+
results.push($(ungrouped));
|
1545
|
+
}
|
1546
|
+
|
1547
|
+
$.each(grouped, function(_, elements) {
|
1548
|
+
results.push($(elements));
|
1549
|
+
});
|
1550
|
+
|
1551
|
+
return results;
|
1552
|
+
};
|
1553
|
+
|
1507
1554
|
/**
|
1508
1555
|
* Use the given guard to test the given guarded fields. Errors
|
1509
1556
|
* will be applied if the field doesn't have an error yet.
|
1510
1557
|
*/
|
1511
1558
|
$.Guards.prototype.test = function(guard, fields) {
|
1512
|
-
if (guard.isGrouped()) {
|
1513
|
-
return guard.test(fields);
|
1514
|
-
}
|
1515
|
-
|
1516
1559
|
var result = true;
|
1517
1560
|
|
1518
|
-
|
1519
|
-
|
1520
|
-
|
1521
|
-
|
1522
|
-
|
1561
|
+
if (guard.isGrouped()) {
|
1562
|
+
$.each(this.groupByGroups(guard, fields), function(_, groupedFields) {
|
1563
|
+
if (!guard.test(groupedFields)) {
|
1564
|
+
result = false;
|
1565
|
+
}
|
1566
|
+
});
|
1567
|
+
} else {
|
1568
|
+
fields.each(function() {
|
1569
|
+
if (!guard.test(this)) {
|
1570
|
+
result = false;
|
1571
|
+
}
|
1572
|
+
});
|
1573
|
+
}
|
1523
1574
|
|
1524
1575
|
return result;
|
1525
1576
|
};
|
@@ -1577,7 +1628,7 @@
|
|
1577
1628
|
this._guard = namedGuard._guard;
|
1578
1629
|
this._guardArguments = args;
|
1579
1630
|
this.name = guard;
|
1580
|
-
return this.message(namedGuard._message);
|
1631
|
+
return this.message(namedGuard._message, true);
|
1581
1632
|
};
|
1582
1633
|
|
1583
1634
|
/**
|
@@ -1644,7 +1695,7 @@
|
|
1644
1695
|
}
|
1645
1696
|
|
1646
1697
|
this._guard = guard;
|
1647
|
-
return this.message(this._guards.defaults.messages["undefined"]);
|
1698
|
+
return this.message(this._guards.defaults.messages["undefined"], true);
|
1648
1699
|
};
|
1649
1700
|
|
1650
1701
|
$.Guard.prototype.getPrecondition = function() {
|
@@ -1862,8 +1913,13 @@
|
|
1862
1913
|
* </div>
|
1863
1914
|
* </div>
|
1864
1915
|
*/
|
1865
|
-
$.Guard.prototype.message = function(message) {
|
1916
|
+
$.Guard.prototype.message = function(message, implicit) {
|
1917
|
+
if (implicit && this._explicitMessage === true) {
|
1918
|
+
return this;
|
1919
|
+
}
|
1920
|
+
|
1866
1921
|
this._message = message;
|
1922
|
+
this._explicitMessage = !implicit;
|
1867
1923
|
return this.resetMessageFn();
|
1868
1924
|
};
|
1869
1925
|
|
@@ -2036,6 +2092,378 @@
|
|
2036
2092
|
return this;
|
2037
2093
|
};
|
2038
2094
|
|
2095
|
+
$.Guard.prototype.bind = function(event, callback) {
|
2096
|
+
var self = this;
|
2097
|
+
this._eventHandlers = this._eventHandlers || {};
|
2098
|
+
|
2099
|
+
$.each(event.split(" "), function(_, eventName) {
|
2100
|
+
if (self._guards.isBlank(eventName)) {
|
2101
|
+
return;
|
2102
|
+
}
|
2103
|
+
|
2104
|
+
self._eventHandlers[eventName] = self._eventHandlers[eventName] || [];
|
2105
|
+
self._eventHandlers[eventName].push(callback);
|
2106
|
+
});
|
2107
|
+
|
2108
|
+
return this;
|
2109
|
+
};
|
2110
|
+
|
2111
|
+
$.Guard.prototype.trigger = function(event, target) {
|
2112
|
+
if (!this._eventHandlers || !this._eventHandlers[event.type]) {
|
2113
|
+
return;
|
2114
|
+
}
|
2115
|
+
|
2116
|
+
$.each(this._eventHandlers[event.type], function(_, handler) {
|
2117
|
+
if (event.isPropagationStopped() || event.isImmediatePropagationStopped()) {
|
2118
|
+
return false;
|
2119
|
+
}
|
2120
|
+
|
2121
|
+
handler.call(target, event);
|
2122
|
+
});
|
2123
|
+
|
2124
|
+
return this;
|
2125
|
+
};
|
2126
|
+
|
2127
|
+
/**
|
2128
|
+
* @page Guard Type
|
2129
|
+
* @section onGuardError
|
2130
|
+
* @signature guard.onGuardError(callback)
|
2131
|
+
* @since 1.4.0
|
2132
|
+
*
|
2133
|
+
* <p>
|
2134
|
+
* When a guard triggers an error, the callback provided to this function will be called with an
|
2135
|
+
* event object. This event can also be captured by binding for jQuery events on the individual
|
2136
|
+
* form fields with the "guardError" event.
|
2137
|
+
* </p>
|
2138
|
+
*
|
2139
|
+
* <p>
|
2140
|
+
* If preventDefault() is called on the event, then the error will be prevented. If
|
2141
|
+
* stopPropagation() or stopImmediatePropagation() is called on the event, then no other event
|
2142
|
+
* handlers will receive the event (including jQuery event handlers).
|
2143
|
+
* </p>
|
2144
|
+
*
|
2145
|
+
* <div class="example">
|
2146
|
+
* <div class="display">
|
2147
|
+
* <script>
|
2148
|
+
* $.guard(".guard-error1").using("required").onGuardError(function(e) {
|
2149
|
+
* alert("This guarded input is watching for errors.");
|
2150
|
+
* });
|
2151
|
+
* $.guard(".guard-error2").using("required");
|
2152
|
+
* </script>
|
2153
|
+
*
|
2154
|
+
* <p>
|
2155
|
+
* <input class="guard-error1" type="text" /><br />
|
2156
|
+
* <small>Alerts on error.</small>
|
2157
|
+
* </p>
|
2158
|
+
*
|
2159
|
+
* <p>
|
2160
|
+
* <input class="guard-error2" type="text" />
|
2161
|
+
* </p>
|
2162
|
+
* </div>
|
2163
|
+
* </div>
|
2164
|
+
*/
|
2165
|
+
$.Guard.prototype.onGuardError = function(callback) {
|
2166
|
+
return this.bind("guardError", callback);
|
2167
|
+
};
|
2168
|
+
|
2169
|
+
/**
|
2170
|
+
* @page Guard Type
|
2171
|
+
* @section onGuardFormError
|
2172
|
+
* @signature guard.onGuardFormError(callback)
|
2173
|
+
* @since 1.4.0
|
2174
|
+
*
|
2175
|
+
* <p>
|
2176
|
+
* When a guard triggers an error, the callback provided to this function will be called with an
|
2177
|
+
* event object. This event can also be captured by binding for jQuery events on the top level
|
2178
|
+
* form element with the "guardFormError" event.
|
2179
|
+
* </p>
|
2180
|
+
*
|
2181
|
+
* <p>
|
2182
|
+
* If preventDefault() is called on the event, then the error will be prevented. If
|
2183
|
+
* stopPropagation() or stopImmediatePropagation() is called on the event, then no other event
|
2184
|
+
* handlers will receive the event (including jQuery event handlers).
|
2185
|
+
* </p>
|
2186
|
+
*
|
2187
|
+
* <div class="example">
|
2188
|
+
* <div class="display">
|
2189
|
+
* <script>
|
2190
|
+
* $.guard(".guard-form-error1").using("required").onGuardFormError(function(e) {
|
2191
|
+
* alert("This guarded input is watching for errors.");
|
2192
|
+
* });
|
2193
|
+
* $.guard(".guard-form-error2").using("required");
|
2194
|
+
* </script>
|
2195
|
+
*
|
2196
|
+
* <p>
|
2197
|
+
* <input class="guard-form-error1" type="text" /><br />
|
2198
|
+
* <small>Alerts on error.</small>
|
2199
|
+
* </p>
|
2200
|
+
*
|
2201
|
+
* <p>
|
2202
|
+
* <input class="guard-form-error2" type="text" />
|
2203
|
+
* </p>
|
2204
|
+
* </div>
|
2205
|
+
* </div>
|
2206
|
+
*/
|
2207
|
+
$.Guard.prototype.onGuardFormError = function(callback) {
|
2208
|
+
return this.bind("guardFormError", callback);
|
2209
|
+
};
|
2210
|
+
|
2211
|
+
/**
|
2212
|
+
* @page Guard Type
|
2213
|
+
* @section onAfterGuardError
|
2214
|
+
* @signature guard.onAfterGuardError(callback)
|
2215
|
+
* @since 1.4.0
|
2216
|
+
*
|
2217
|
+
* <p>
|
2218
|
+
* When a guard triggers an error, the callback provided to this function will be called with an
|
2219
|
+
* event object. This event can also be captured by binding for jQuery events on the individual
|
2220
|
+
* form fields with the "afterGuardError" event. This event is triggered after the error has
|
2221
|
+
* been applied, unlike the guardError and guardFormError events.
|
2222
|
+
* </p>
|
2223
|
+
*
|
2224
|
+
* <p>
|
2225
|
+
* Calling preventDefault() has no effect. If stopPropagation() or stopImmediatePropagation() is
|
2226
|
+
* called on the event, then no other event handlers will receive the event (including jQuery
|
2227
|
+
* event handlers).
|
2228
|
+
* </p>
|
2229
|
+
*
|
2230
|
+
* <div class="example">
|
2231
|
+
* <div class="display">
|
2232
|
+
* <script>
|
2233
|
+
* $.guard(".after-guard-error1").using("required").onAfterGuardError(function(e) {
|
2234
|
+
* alert("This guarded input is watching for errors.");
|
2235
|
+
* });
|
2236
|
+
* $.guard(".after-guard-error2").using("required");
|
2237
|
+
* </script>
|
2238
|
+
*
|
2239
|
+
* <p>
|
2240
|
+
* <input class="after-guard-error1" type="text" /><br />
|
2241
|
+
* <small>Alerts on error.</small>
|
2242
|
+
* </p>
|
2243
|
+
*
|
2244
|
+
* <p>
|
2245
|
+
* <input class="after-guard-error2" type="text" />
|
2246
|
+
* </p>
|
2247
|
+
* </div>
|
2248
|
+
* </div>
|
2249
|
+
*/
|
2250
|
+
$.Guard.prototype.onAfterGuardError = function(callback) {
|
2251
|
+
return this.bind("afterGuardError", callback);
|
2252
|
+
};
|
2253
|
+
|
2254
|
+
/**
|
2255
|
+
* @page Guard Type
|
2256
|
+
* @section onAfterGuardFormError
|
2257
|
+
* @signature guard.onAfterGuardFormError(callback)
|
2258
|
+
* @since 1.4.0
|
2259
|
+
*
|
2260
|
+
* <p>
|
2261
|
+
* When a guard triggers an error, the callback provided to this function will be called with an
|
2262
|
+
* event object. This event can also be captured by binding for jQuery events on the top level
|
2263
|
+
* form element with the "afterGuardFormError" event. This event is triggered after the error
|
2264
|
+
* has been applied, unlike the guardError and guardFormError events.
|
2265
|
+
* </p>
|
2266
|
+
*
|
2267
|
+
* <p>
|
2268
|
+
* Calling preventDefault() has no effect. If stopPropagation() or stopImmediatePropagation() is
|
2269
|
+
* called on the event, then no other event handlers will receive the event (including jQuery
|
2270
|
+
* event handlers).
|
2271
|
+
* </p>
|
2272
|
+
*
|
2273
|
+
* <div class="example">
|
2274
|
+
* <div class="display">
|
2275
|
+
* <script>
|
2276
|
+
* $.guard(".after-guard-form-error1").using("required").onAfterGuardFormError(function(e) {
|
2277
|
+
* alert("This guarded input is watching for errors.");
|
2278
|
+
* });
|
2279
|
+
* $.guard(".after-guard-form-error2").using("required");
|
2280
|
+
* </script>
|
2281
|
+
*
|
2282
|
+
* <p>
|
2283
|
+
* <input class="after-guard-form-error1" type="text" /><br />
|
2284
|
+
* <small>Alerts on error.</small>
|
2285
|
+
* </p>
|
2286
|
+
*
|
2287
|
+
* <p>
|
2288
|
+
* <input class="after-guard-form-error2" type="text" />
|
2289
|
+
* </p>
|
2290
|
+
* </div>
|
2291
|
+
* </div>
|
2292
|
+
*/
|
2293
|
+
$.Guard.prototype.onAfterGuardFormError = function(callback) {
|
2294
|
+
return this.bind("afterGuardFormError", callback);
|
2295
|
+
};
|
2296
|
+
|
2297
|
+
/**
|
2298
|
+
* @page Guard Type
|
2299
|
+
* @section onClearGuardError
|
2300
|
+
* @signature guard.onClearGuardError(callback)
|
2301
|
+
* @since 1.4.0
|
2302
|
+
*
|
2303
|
+
* <p>
|
2304
|
+
* When a guard error is cleared, the callback provided to this function will be called with an
|
2305
|
+
* event object. This event can also be captured by binding for jQuery events on the individual
|
2306
|
+
* form fields with the "clearGuardError" event.
|
2307
|
+
* </p>
|
2308
|
+
*
|
2309
|
+
* <p>
|
2310
|
+
* If preventDefault() is called on the event, then the error will not be cleared. If
|
2311
|
+
* stopPropagation() or stopImmediatePropagation() is called on the event, then no other event
|
2312
|
+
* handlers will receive the event (including jQuery event handlers).
|
2313
|
+
* </p>
|
2314
|
+
*
|
2315
|
+
* <div class="example">
|
2316
|
+
* <div class="display">
|
2317
|
+
* <script>
|
2318
|
+
* $.guard(".clear-guard-error1").using("required").onClearGuardError(function(e) {
|
2319
|
+
* alert("This guarded input is watching for clearing of errors.");
|
2320
|
+
* });
|
2321
|
+
* $.guard(".clear-guard-error2").using("required");
|
2322
|
+
* </script>
|
2323
|
+
*
|
2324
|
+
* <p>
|
2325
|
+
* <input class="clear-guard-error1" type="text" /><br />
|
2326
|
+
* <small>Alerts when errors are cleared.</small>
|
2327
|
+
* </p>
|
2328
|
+
*
|
2329
|
+
* <p>
|
2330
|
+
* <input class="clear-guard-error2" type="text" />
|
2331
|
+
* </p>
|
2332
|
+
* </div>
|
2333
|
+
* </div>
|
2334
|
+
*/
|
2335
|
+
$.Guard.prototype.onClearGuardError = function(callback) {
|
2336
|
+
return this.bind("clearGuardError", callback);
|
2337
|
+
};
|
2338
|
+
|
2339
|
+
/**
|
2340
|
+
* @page Guard Type
|
2341
|
+
* @section onClearGuardFormError
|
2342
|
+
* @signature guard.onClearGuardFormError(callback)
|
2343
|
+
* @since 1.4.0
|
2344
|
+
*
|
2345
|
+
* <p>
|
2346
|
+
* When a guard error is cleared, the callback provided to this function will be called with an
|
2347
|
+
* event object. This event can also be captured by binding for jQuery events on the top level
|
2348
|
+
* form element with the "clearGuardFormError" event.
|
2349
|
+
* </p>
|
2350
|
+
*
|
2351
|
+
* <p>
|
2352
|
+
* If preventDefault() is called on the event, then the error will not be cleared. If
|
2353
|
+
* stopPropagation() or stopImmediatePropagation() is called on the event, then no other event
|
2354
|
+
* handlers will receive the event (including jQuery event handlers).
|
2355
|
+
* </p>
|
2356
|
+
*
|
2357
|
+
* <div class="example">
|
2358
|
+
* <div class="display">
|
2359
|
+
* <script>
|
2360
|
+
* $.guard(".clear-guard-form-error1").using("required").onClearGuardFormError(function(e) {
|
2361
|
+
* alert("This guarded input is watching for clearing of errors.");
|
2362
|
+
* });
|
2363
|
+
* $.guard(".clear-guard-form-error2").using("required");
|
2364
|
+
* </script>
|
2365
|
+
*
|
2366
|
+
* <p>
|
2367
|
+
* <input class="clear-guard-form-error1" type="text" /><br />
|
2368
|
+
* <small>Alerts when errors are cleared.</small>
|
2369
|
+
* </p>
|
2370
|
+
*
|
2371
|
+
* <p>
|
2372
|
+
* <input class="clear-guard-form-error2" type="text" />
|
2373
|
+
* </p>
|
2374
|
+
* </div>
|
2375
|
+
* </div>
|
2376
|
+
*/
|
2377
|
+
$.Guard.prototype.onClearGuardFormError = function(callback) {
|
2378
|
+
return this.bind("clearGuardFormError", callback);
|
2379
|
+
};
|
2380
|
+
|
2381
|
+
/**
|
2382
|
+
* @page Guard Type
|
2383
|
+
* @section onAfterClearGuardError
|
2384
|
+
* @signature guard.onAfterClearGuardError(callback)
|
2385
|
+
* @since 1.4.0
|
2386
|
+
*
|
2387
|
+
* <p>
|
2388
|
+
* When a guard error is cleared, the callback provided to this function will be called with an
|
2389
|
+
* event object. This event can also be captured by binding for jQuery events on the individual
|
2390
|
+
* form fields with the "afterClearGuardError" event. This event is triggered after the error has
|
2391
|
+
* been cleared, unlike the clearGuardError and clearGuardFormError events.
|
2392
|
+
* </p>
|
2393
|
+
*
|
2394
|
+
* <p>
|
2395
|
+
* Calling preventDefault() has no effect. If stopPropagation() or stopImmediatePropagation() is
|
2396
|
+
* called on the event, then no other event handlers will receive the event (including jQuery
|
2397
|
+
* event handlers).
|
2398
|
+
* </p>
|
2399
|
+
*
|
2400
|
+
* <div class="example">
|
2401
|
+
* <div class="display">
|
2402
|
+
* <script>
|
2403
|
+
* $.guard(".after-clear-guard-error1").using("required").onAfterClearGuardError(function(e) {
|
2404
|
+
* alert("This guarded input is watching for clearing of errors.");
|
2405
|
+
* });
|
2406
|
+
* $.guard(".after-clear-guard-error2").using("required");
|
2407
|
+
* </script>
|
2408
|
+
*
|
2409
|
+
* <p>
|
2410
|
+
* <input class="after-clear-guard-error1" type="text" /><br />
|
2411
|
+
* <small>Alerts when errors are cleared.</small>
|
2412
|
+
* </p>
|
2413
|
+
*
|
2414
|
+
* <p>
|
2415
|
+
* <input class="after-clear-guard-error2" type="text" />
|
2416
|
+
* </p>
|
2417
|
+
* </div>
|
2418
|
+
* </div>
|
2419
|
+
*/
|
2420
|
+
$.Guard.prototype.onAfterClearGuardError = function(callback) {
|
2421
|
+
return this.bind("afterClearGuardError", callback);
|
2422
|
+
};
|
2423
|
+
|
2424
|
+
/**
|
2425
|
+
* @page Guard Type
|
2426
|
+
* @section onAfterClearGuardFormError
|
2427
|
+
* @signature guard.onAfterClearGuardFormError(callback)
|
2428
|
+
* @since 1.4.0
|
2429
|
+
*
|
2430
|
+
* <p>
|
2431
|
+
* When a guard error is cleared, the callback provided to this function will be called with an
|
2432
|
+
* event object. This event can also be captured by binding for jQuery events on the top level
|
2433
|
+
* form element with the "afterClearGuardFormError" event. This event is triggered after the error
|
2434
|
+
* has been cleared, unlike the clearGuardError and clearGuardFormError events.
|
2435
|
+
* </p>
|
2436
|
+
*
|
2437
|
+
* <p>
|
2438
|
+
* Calling preventDefault() has no effect. If stopPropagation() or stopImmediatePropagation() is
|
2439
|
+
* called on the event, then no other event handlers will receive the event (including jQuery
|
2440
|
+
* event handlers).
|
2441
|
+
* </p>
|
2442
|
+
*
|
2443
|
+
* <div class="example">
|
2444
|
+
* <div class="display">
|
2445
|
+
* <script>
|
2446
|
+
* $.guard(".after-clear-guard-form-error1").using("required").onAfterClearGuardFormError(function(e) {
|
2447
|
+
* alert("This guarded input is watching for clearing of errors.");
|
2448
|
+
* });
|
2449
|
+
* $.guard(".after-clear-guard-form-error2").using("required");
|
2450
|
+
* </script>
|
2451
|
+
*
|
2452
|
+
* <p>
|
2453
|
+
* <input class="after-clear-guard-form-error1" type="text" /><br />
|
2454
|
+
* <small>Alerts when errors are cleared.</small>
|
2455
|
+
* </p>
|
2456
|
+
*
|
2457
|
+
* <p>
|
2458
|
+
* <input class="after-clear-guard-form-error2" type="text" />
|
2459
|
+
* </p>
|
2460
|
+
* </div>
|
2461
|
+
* </div>
|
2462
|
+
*/
|
2463
|
+
$.Guard.prototype.onAfterClearGuardFormError = function(callback) {
|
2464
|
+
return this.bind("afterClearGuardFormError", callback);
|
2465
|
+
};
|
2466
|
+
|
2039
2467
|
// Determine if the guard applies to given element(s)
|
2040
2468
|
$.Guard.prototype.appliesTo = function(element) {
|
2041
2469
|
return $(element).filter(this._selector).size() > 0;
|
@@ -2084,7 +2512,7 @@
|
|
2084
2512
|
|
2085
2513
|
if (!isDashed) {
|
2086
2514
|
// Un-capitalize the first letter
|
2087
|
-
attrName = attrName.replace(/^(.)/, function(
|
2515
|
+
attrName = attrName.replace(/^(.)/, function(_, letter) {
|
2088
2516
|
return letter.toLowerCase();
|
2089
2517
|
});
|
2090
2518
|
}
|
@@ -2288,7 +2716,12 @@
|
|
2288
2716
|
event.errorMessage = $(errorMessageElement)[0];
|
2289
2717
|
}
|
2290
2718
|
|
2291
|
-
|
2719
|
+
this.trigger(event, target);
|
2720
|
+
|
2721
|
+
if (!event.isPropagationStopped() && !event.isImmediatePropagationStopped()) {
|
2722
|
+
target.trigger(event);
|
2723
|
+
}
|
2724
|
+
|
2292
2725
|
return event;
|
2293
2726
|
};
|
2294
2727
|
|
@@ -2532,7 +2965,7 @@
|
|
2532
2965
|
* </div>
|
2533
2966
|
*/
|
2534
2967
|
$.fn.clearErrors = function() {
|
2535
|
-
$.each(this.errors(), function(
|
2968
|
+
$.each(this.errors(), function(_, error) {
|
2536
2969
|
error.clear();
|
2537
2970
|
});
|
2538
2971
|
|
@@ -2546,7 +2979,7 @@
|
|
2546
2979
|
$.fn.hasError = function(guard) {
|
2547
2980
|
var result = false;
|
2548
2981
|
|
2549
|
-
$.each(this.errors(), function(
|
2982
|
+
$.each(this.errors(), function(_, error) {
|
2550
2983
|
if (error._guard === guard) {
|
2551
2984
|
result = true;
|
2552
2985
|
return false;
|
@@ -2566,7 +2999,7 @@
|
|
2566
2999
|
$.fn.hasErrorsWithInvalidClass = function(invalidClass) {
|
2567
3000
|
var result = false;
|
2568
3001
|
|
2569
|
-
$.each(this.errors(), function(
|
3002
|
+
$.each(this.errors(), function(_, error) {
|
2570
3003
|
if (error._guard.getInvalidClass() === invalidClass) {
|
2571
3004
|
result = true;
|
2572
3005
|
return false;
|
metadata
CHANGED
@@ -1,33 +1,36 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guardsjs-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Mike Virata-Stone
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2014-
|
12
|
+
date: 2014-07-11 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: railties
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
|
-
- -
|
19
|
+
- - ! '>='
|
18
20
|
- !ruby/object:Gem::Version
|
19
21
|
version: '3.0'
|
20
|
-
- -
|
22
|
+
- - <
|
21
23
|
- !ruby/object:Gem::Version
|
22
24
|
version: '5.0'
|
23
25
|
type: :runtime
|
24
26
|
prerelease: false
|
25
27
|
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
26
29
|
requirements:
|
27
|
-
- -
|
30
|
+
- - ! '>='
|
28
31
|
- !ruby/object:Gem::Version
|
29
32
|
version: '3.0'
|
30
|
-
- -
|
33
|
+
- - <
|
31
34
|
- !ruby/object:Gem::Version
|
32
35
|
version: '5.0'
|
33
36
|
description: This gem wraps the guards.js jQuery validation library as a Rails asset
|
@@ -38,31 +41,35 @@ executables: []
|
|
38
41
|
extensions: []
|
39
42
|
extra_rdoc_files: []
|
40
43
|
files:
|
41
|
-
- app/assets/javascripts/guards.js
|
42
|
-
- lib/guardsjs-rails.rb
|
43
44
|
- lib/guardsjs-rails/version.rb
|
45
|
+
- lib/guardsjs-rails.rb
|
46
|
+
- app/assets/javascripts/guards.js
|
44
47
|
homepage: http://guardsjs.com/
|
45
48
|
licenses:
|
46
49
|
- MIT
|
47
|
-
metadata: {}
|
48
50
|
post_install_message:
|
49
51
|
rdoc_options: []
|
50
52
|
require_paths:
|
51
53
|
- lib
|
52
54
|
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
53
56
|
requirements:
|
54
|
-
- -
|
57
|
+
- - ! '>='
|
55
58
|
- !ruby/object:Gem::Version
|
56
59
|
version: '0'
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
hash: -1971564042185507975
|
57
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
58
65
|
requirements:
|
59
|
-
- -
|
66
|
+
- - ! '>='
|
60
67
|
- !ruby/object:Gem::Version
|
61
68
|
version: '0'
|
62
69
|
requirements: []
|
63
70
|
rubyforge_project:
|
64
|
-
rubygems_version:
|
71
|
+
rubygems_version: 1.8.25
|
65
72
|
signing_key:
|
66
|
-
specification_version:
|
73
|
+
specification_version: 3
|
67
74
|
summary: Rails asset gem for guards.js.
|
68
75
|
test_files: []
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 47e88240dd71764ae557fcf35a1b0ca1949816d3
|
4
|
-
data.tar.gz: 4347ff7620be77ae6f0fdc2cd97303bec5b65592
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 44553216c036e9b286b378ed23274db1099b8d779e471f78f9f2d5f7c56875cac8dfcc704b7eb85e9ff699cc7669991593c84206e84ae32d13050aeabbae531c
|
7
|
-
data.tar.gz: da50ff12b8e692f07d5a69f99f55585936d8b9c94158a40105ff7d8eb588f2732534107aa5a9ff446cb56fc472c18bd09ec7bf4e3f050eece654025efad660d4
|