jquery_ujs_handlers 0.0.1 → 0.0.3
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 +4 -4
- data/app/assets/javascripts/jquery_ujsh.js +54 -44
- data/lib/jquery_ujs_handlers/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a08accdd42081d25b31116b956b90773651eb602
|
4
|
+
data.tar.gz: b0865b0f7e93266e6423040fe512b7fa7d5f9b0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8029df8199331270e540bee6a743bba2b61bbbba7becd07594d81320ecc7203694781b61f7cc617a2c76c9d70b7e7cde94664086a63d7dbb5217f78054c86af
|
7
|
+
data.tar.gz: 02d2562856903f716cb6c8bf93b9b9f16bd93bde5b092c92c0707653abf0923c29eb105bba99a9f516c4ae0384ed13154cfdff09dbfe6daa6971644dfab949d2
|
@@ -30,7 +30,7 @@
|
|
30
30
|
var dialogTmp = '' +
|
31
31
|
'<div class="ujsh-dialog ujsh-dialog__{{modifier}}">' +
|
32
32
|
'<div class="ujsh-dialog--wrapper">' +
|
33
|
-
'<div class="ujsh-dialog--container>' +
|
33
|
+
'<div class="ujsh-dialog--container">' +
|
34
34
|
'<div class="ujsh-dialog--header">' +
|
35
35
|
'<a class="ujsh-dialog--button-close" data-ujsh-dialog-close>×</a>' +
|
36
36
|
'</div>' +
|
@@ -44,22 +44,27 @@
|
|
44
44
|
error: {
|
45
45
|
hint: function (request, status, error) {
|
46
46
|
var errors = parseErrors(request);
|
47
|
-
var field, fieldErrors, $field;
|
48
|
-
var hintTmp = options.error.reporting.hint.tmp;
|
47
|
+
var field, fieldErrors, $field, fieldSelector;
|
48
|
+
var hintTmp = this.options.error.reporting.hint.tmp;
|
49
49
|
|
50
50
|
for (field in errors) {
|
51
51
|
fieldErrors = errors[field];
|
52
|
-
|
53
|
-
|
52
|
+
fieldSelector = field;
|
53
|
+
if (field.indexOf('.') > -1) {
|
54
|
+
fieldSelector = field.split('.');
|
55
|
+
fieldSelector = fieldSelector[fieldSelector.length -1];
|
56
|
+
}
|
57
|
+
$field = this.find('[type!=hidden][name*="[' + fieldSelector + ']"]');
|
58
|
+
$field.toggleClass(this.options.error.className, true);
|
54
59
|
$(hintTmp.replace(/{{content}}/, fieldErrors.join(', '))).insertAfter($field);
|
55
60
|
}
|
56
61
|
},
|
57
62
|
list: function (request, status, error) {
|
58
|
-
this.prepend(requestToErrorList(request));
|
63
|
+
this.prepend(requestToErrorList.call(this, request));
|
59
64
|
},
|
60
65
|
dialog: function (request, status, error) {
|
61
|
-
var $list = requestToErrorList(request);
|
62
|
-
var dialogTmp = options.error.reporting.dialog.tmp;
|
66
|
+
var $list = requestToErrorList.call(this, request);
|
67
|
+
var dialogTmp = this.options.error.reporting.dialog.tmp;
|
63
68
|
var $dialog = $(dialogTmp.replace(/{{content}}/, $list[0].outerHTML));
|
64
69
|
$dialog.find('[data-ujsh-dialog-close]').on('click', dialogCloseHandler.bind($dialog));
|
65
70
|
$('body').prepend($dialog);
|
@@ -67,13 +72,13 @@
|
|
67
72
|
},
|
68
73
|
success: {
|
69
74
|
list: function (data, status, request) {
|
70
|
-
var $list = $(options.error.reporting.list.tmp);
|
71
|
-
var itemTmp = options.error.reporting.list.itemTmp;
|
75
|
+
var $list = $(this.options.error.reporting.list.tmp);
|
76
|
+
var itemTmp = this.options.error.reporting.list.itemTmp;
|
72
77
|
$list.append(itemTmp.replace(/{{content}}/, data.notice));
|
73
78
|
this.prepend($list);
|
74
79
|
},
|
75
80
|
dialog: function (data, status, request) {
|
76
|
-
var dialogTmp = options.success.reporting.dialog.tmp;
|
81
|
+
var dialogTmp = this.options.success.reporting.dialog.tmp;
|
77
82
|
var $dialog = $(dialogTmp.replace(/{{content}}/, data.notice));
|
78
83
|
$dialog.find('[data-ujsh-dialog-close]').on('click', dialogCloseHandler.bind($dialog));
|
79
84
|
$('body').prepend($dialog);
|
@@ -138,8 +143,8 @@
|
|
138
143
|
function requestToErrorList (request) {
|
139
144
|
var errors = parseErrors(request);
|
140
145
|
var field, fieldErrors;
|
141
|
-
var $list = $(options.error.reporting.list.tmp);
|
142
|
-
var itemTmp = options.error.reporting.list.itemTmp;
|
146
|
+
var $list = $(this.options.error.reporting.list.tmp);
|
147
|
+
var itemTmp = this.options.error.reporting.list.itemTmp;
|
143
148
|
var items = [];
|
144
149
|
|
145
150
|
for (field in errors) {
|
@@ -173,59 +178,64 @@
|
|
173
178
|
}
|
174
179
|
|
175
180
|
function beforeHandler (e) {
|
176
|
-
if (options.before.clear) {
|
177
|
-
$('.ujsh-' + options.error.reporting.style).remove();
|
178
|
-
if (options.error.reporting.style === HINT) {
|
181
|
+
if (this.options.before.clear) {
|
182
|
+
$('.ujsh-' + this.options.error.reporting.style).remove();
|
183
|
+
if (this.options.error.reporting.style === HINT) {
|
179
184
|
this.find(
|
180
|
-
'input.' + options.error.className + ', ' +
|
181
|
-
'select.' + options.error.className + ', ' +
|
182
|
-
'textarea.' + options.error.className
|
183
|
-
).toggleClass(options.error.className, false);
|
185
|
+
'input.' + this.options.error.className + ', ' +
|
186
|
+
'select.' + this.options.error.className + ', ' +
|
187
|
+
'textarea.' + this.options.error.className
|
188
|
+
).toggleClass(this.options.error.className, false);
|
184
189
|
}
|
185
190
|
|
186
|
-
$('.ujsh-' + options.success.reporting.style).remove();
|
191
|
+
$('.ujsh-' + this.options.success.reporting.style).remove();
|
187
192
|
}
|
188
193
|
}
|
189
194
|
|
190
195
|
function errorHandler (e, request, status, error) {
|
191
|
-
if (typeof options.error.beforeFilter === 'function') {
|
192
|
-
options.error.beforeFilter.call(this, e, request, status, error)
|
196
|
+
if (typeof this.options.error.beforeFilter === 'function') {
|
197
|
+
if (!this.options.error.beforeFilter.call(this, e, request, status, error)) {
|
198
|
+
return;
|
199
|
+
}
|
193
200
|
}
|
194
|
-
if (options.error.redirect) {
|
201
|
+
if (this.options.error.redirect) {
|
195
202
|
return redirect(request);
|
196
203
|
}
|
197
|
-
reporters.error[options.error.reporting.style].call(this, request, status, error);
|
198
|
-
if (typeof options.error.afterFilter === 'function') {
|
199
|
-
options.error.afterFilter.call(this, e, request, status, error);
|
204
|
+
reporters.error[this.options.error.reporting.style].call(this, request, status, error);
|
205
|
+
if (typeof this.options.error.afterFilter === 'function') {
|
206
|
+
this.options.error.afterFilter.call(this, e, request, status, error);
|
200
207
|
}
|
201
208
|
}
|
202
209
|
|
203
210
|
function successHandler (e, data, status, request) {
|
204
|
-
if (typeof options.success.beforeFilter === 'function') {
|
205
|
-
options.success.beforeFilter.call(this, e, data, status, request)
|
211
|
+
if (typeof this.options.success.beforeFilter === 'function') {
|
212
|
+
if (!this.options.success.beforeFilter.call(this, e, data, status, request)) {
|
213
|
+
return;
|
214
|
+
}
|
206
215
|
}
|
207
|
-
if (options.success.redirect) {
|
216
|
+
if (this.options.success.redirect) {
|
208
217
|
return redirect(request);
|
209
218
|
}
|
210
|
-
reporters.success[options.success.reporting.style].call(this, data, status, request);
|
211
|
-
if (typeof options.success.afterFilter === 'function') {
|
212
|
-
options.success.afterFilter.call(this, e, data, status, request);
|
219
|
+
reporters.success[this.options.success.reporting.style].call(this, data, status, request);
|
220
|
+
if (typeof this.options.success.afterFilter === 'function') {
|
221
|
+
this.options.success.afterFilter.call(this, e, data, status, request);
|
213
222
|
}
|
214
223
|
}
|
215
224
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
if (this.data('error-reporting-style')) options.error.reporting.style = this.data('error-reporting-style')
|
220
|
-
if (this.data('success-reporting-style')) options.error.reporting.style = this.data('success-reporting-style')
|
225
|
+
return this.each(function() {
|
226
|
+
var $element = $(this),
|
227
|
+
element = this;
|
221
228
|
|
222
|
-
|
223
|
-
if (!options.error.disable) this.on('ajax:error', options.error.handler.bind(this));
|
224
|
-
if (!options.success.disable) this.on('ajax:success', options.success.handler.bind(this));
|
229
|
+
$element.options = $.extend(true, {}, defaultOptions, options || {});
|
225
230
|
|
226
|
-
|
227
|
-
|
231
|
+
if ($element.data('error-redirect')) $element.options.error.redirect = $element.data('error-redirect')
|
232
|
+
if ($element.data('success-redirect')) $element.options.success.redirect = $element.data('success-redirect')
|
233
|
+
if ($element.data('error-reporting-style')) $element.options.error.reporting.style = $element.data('error-reporting-style')
|
234
|
+
if ($element.data('success-reporting-style')) $element.options.error.reporting.style = $element.data('success-reporting-style')
|
228
235
|
|
229
|
-
|
236
|
+
if (!$element.options.before.disable) $element.on('ajax:before', $element.options.before.handler.bind($element));
|
237
|
+
if (!$element.options.error.disable) $element.on('ajax:error', $element.options.error.handler.bind($element));
|
238
|
+
if (!$element.options.success.disable) $element.on('ajax:success', $element.options.success.handler.bind($element));
|
239
|
+
});
|
230
240
|
}
|
231
241
|
})( jQuery );
|