SrBuj 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/SrBuj/version.rb +1 -1
- data/lib/assets/javascripts/SrBuj.js +152 -130
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZDFjZjMwOTY4ZDk4YmMwMDg1ZmZmYWY4YWIyMjlmODViMTA2MDU1NQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZjA4YTUxYzY1NDJkMTAwYTQ0ODk3Mjk4NDgzMWUzYmMwYjFkYTYwNA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NTkxMzdjMzVmYWQ2YzZkZWI3ZWY4NTRmMjgwNTM1OThkNmZmNDBiODY5YmJl
|
10
|
+
MTYyODAxODI5NWEzNjM4YWI2ZTI5YTY4NDkxYWYyZGRlYmRlMzdkNmRiYmVl
|
11
|
+
YzJmNWU5MzUwNmJjN2UzZjVkYzk2NTlmNTU4ZTQyZmZjZTAyYzQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MjliOWM3ZmJiZTgxYWYzZDE4MjYxYjlhOTVmYWE3YjU1ZjI2YmQ4ZmZiMjYz
|
14
|
+
OTRlMGU0YzE2OWNmNDk4OTk1YTU0ZjU3YzY3YjllMjczMTZlYWFhYjVmNmI1
|
15
|
+
YzNlNDkzZmQ5NTMzZTc0ZDRlMWZjMzA0MWI1Zjc2NzEyOWM1Yzc=
|
data/lib/SrBuj/version.rb
CHANGED
@@ -1,134 +1,156 @@
|
|
1
|
-
(function($, undefined) {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
var SrBuj;
|
15
|
-
$.SrBuj = SrBuj = {
|
16
|
-
version: '0.6.1',
|
17
|
-
selector: '[data-remote][data-target]',
|
18
|
-
defaults: {
|
19
|
-
'$el': undefined,
|
20
|
-
target: undefined,
|
21
|
-
onError: undefined,
|
22
|
-
wrapper: undefined,
|
23
|
-
method: 'GET',
|
24
|
-
modal: false,
|
25
|
-
custom: false,
|
26
|
-
change: true,
|
27
|
-
custom: false,
|
28
|
-
replace: false,
|
29
|
-
callback: false,
|
30
|
-
jqueryselector: false
|
31
|
-
},
|
32
|
-
changeDom: function(method,$target,data){
|
33
|
-
switch(method){
|
34
|
-
case 'POST':
|
35
|
-
$target.append(data);
|
36
|
-
break;
|
37
|
-
case 'PUT':
|
38
|
-
case 'PATCH':
|
39
|
-
$target.replaceWith(data);
|
40
|
-
break;
|
41
|
-
case 'DELETE':
|
42
|
-
$target.remove();
|
43
|
-
break;
|
44
|
-
default:
|
45
|
-
$target.html(data);
|
46
|
-
}
|
1
|
+
(function ($, undefined) {
|
2
|
+
/**
|
3
|
+
* Better Unobtrusive javascript request for Jquery
|
4
|
+
* https://github.com/gagoar/SrBuj
|
5
|
+
*
|
6
|
+
* Requires jQuery 1.7.0 or later.
|
7
|
+
*
|
8
|
+
* Released under the MIT license
|
9
|
+
*
|
10
|
+
* JSHINT
|
11
|
+
* jshint forin:true, noarg:true, noempty:true, eqeqeq:true, bitwise:true, strict:true, undef:true, unused:true, curly:true, browser:true, jquery:true, indent:4, maxerr:50
|
12
|
+
* global jQuery
|
13
|
+
*/
|
47
14
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
return
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
'
|
76
|
-
'
|
77
|
-
|
78
|
-
|
79
|
-
'
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
15
|
+
'use strict';
|
16
|
+
|
17
|
+
$.fn.present = function () {
|
18
|
+
return this.length === 1 && this;
|
19
|
+
};
|
20
|
+
var SrBuj;
|
21
|
+
$.SrBuj = SrBuj = {
|
22
|
+
version: '0.6.2',
|
23
|
+
selector: '[data-remote][data-target]',
|
24
|
+
defaults: {
|
25
|
+
'$el': undefined,
|
26
|
+
target: undefined,
|
27
|
+
onError: undefined,
|
28
|
+
wrapper: undefined,
|
29
|
+
method: 'GET',
|
30
|
+
modal: false,
|
31
|
+
change: true,
|
32
|
+
custom: false,
|
33
|
+
replace: false,
|
34
|
+
callback: false,
|
35
|
+
jqueryselector: false
|
36
|
+
},
|
37
|
+
changeDom: function (method, $target, data) {
|
38
|
+
switch (method) {
|
39
|
+
case 'POST':
|
40
|
+
$target.append(data);
|
41
|
+
break;
|
42
|
+
case 'PUT':
|
43
|
+
case 'PATCH':
|
44
|
+
$target.replaceWith(data);
|
45
|
+
break;
|
46
|
+
case 'DELETE':
|
47
|
+
$target.remove();
|
48
|
+
break;
|
49
|
+
default:
|
50
|
+
$target.html(data);
|
51
|
+
}
|
52
|
+
},
|
53
|
+
kindOfCallback: function (callback) {
|
54
|
+
if (typeof callback === 'function') {
|
55
|
+
return callback;
|
56
|
+
} else {
|
57
|
+
if (window[callback]) {
|
58
|
+
return window[callback];
|
59
|
+
} else {
|
60
|
+
new Function(callback);
|
61
|
+
}
|
62
|
+
}
|
63
|
+
},
|
64
|
+
getVerb: function ($el) {
|
65
|
+
var respond_as = $el.data('respond-as'),
|
66
|
+
dataVerb = $el.data('method'),
|
67
|
+
replace = $el.data('replace'),
|
68
|
+
proto = $el.attr('method');
|
69
|
+
if (respond_as) {
|
70
|
+
return respond_as.toUpperCase();
|
71
|
+
} else
|
72
|
+
if (dataVerb) {
|
73
|
+
return dataVerb.toUpperCase();
|
74
|
+
} else {
|
75
|
+
if (proto) {
|
76
|
+
return replace ? 'PUT' : proto.toUpperCase();
|
77
|
+
}
|
78
|
+
}
|
79
|
+
},
|
80
|
+
getOptions: function (el, user_options) {
|
81
|
+
user_options = user_options || {};
|
82
|
+
var options = {},
|
83
|
+
$el = $(user_options.el || el).present(),
|
84
|
+
el_options = {
|
85
|
+
'$el': $el,
|
86
|
+
'target': $el.data('target'),
|
87
|
+
'method': $.SrBuj.getVerb($el),
|
88
|
+
'onError': $el.data('error'),
|
89
|
+
'callback': $el.data('callback'),
|
90
|
+
'change': !($el.data('nochange') || false),
|
91
|
+
'jqueryselector': $el.data('jqueryselector'),
|
92
|
+
'modal': $el.data('modal'),
|
93
|
+
'wrapper': $el.data('error'),
|
94
|
+
'custom': $el.data('custom'),
|
95
|
+
'replace': $el.data('replace')
|
96
|
+
};
|
97
|
+
user_options = user_options || {};
|
98
|
+
for (var attr in this.defaults) {
|
99
|
+
if (this.defaults.hasOwnProperty(attr)) {
|
100
|
+
options[attr] = user_options[attr] || el_options[attr] || this.defaults[attr];
|
101
|
+
}
|
102
|
+
}
|
103
|
+
return options;
|
104
|
+
},
|
105
|
+
success: function (e, data, status, user_options) {
|
106
|
+
var options = $.SrBuj.getOptions(e.target, user_options),
|
107
|
+
$target = options.jqueryselector ? $(options.target).present() : $(document.getElementById(options.target)),
|
108
|
+
$wrapper = options.jqueryselector ? $(options.wrapper) : $(document.getElementById(options.wrapper));
|
109
|
+
if ($target.present()) {
|
110
|
+
e.stopPropagation();
|
111
|
+
if (!options.custom) {
|
112
|
+
if (options.change) {
|
113
|
+
$.SrBuj.changeDom(options.method, $target, data);
|
114
|
+
}
|
115
|
+
if (options.modal) {
|
116
|
+
if (options.wrapper) {
|
117
|
+
$wrapper.modal('toggle');
|
118
|
+
} else {
|
119
|
+
$target.modal('toggle');
|
120
|
+
}
|
121
|
+
}
|
122
|
+
}
|
123
|
+
if (options.callback) {
|
124
|
+
var callback = $.SrBuj.kindOfCallback(options.callback);
|
125
|
+
if (callback) {
|
126
|
+
callback.apply(this, [e, data, status]);
|
127
|
+
}
|
128
|
+
}
|
129
|
+
}
|
130
|
+
},
|
110
131
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
132
|
+
fail: function (e, data, status, user_options) {
|
133
|
+
e.stopPropagation();
|
134
|
+
var $el = $(e.target).present(),
|
135
|
+
error = $el.data('error'),
|
136
|
+
jqueryselector = $el.data('jqueryselector'),
|
137
|
+
$error = jqueryselector ? $(error) : $(document.getElementById(error));
|
138
|
+
if (error) {
|
139
|
+
$.SrBuj.changeDom('ERROR', $error, data.responseText);
|
140
|
+
} else {
|
141
|
+
throw 'cant find data-error on element' + e.target;
|
142
|
+
}
|
143
|
+
|
144
|
+
},
|
145
|
+
bind: function (selector) {
|
146
|
+
selector = selector || this.selector;
|
147
|
+
$(document).on('ajax:success', selector, this.success);
|
148
|
+
$(document).on('ajax:error', selector, this.fail);
|
149
|
+
}
|
150
|
+
};
|
129
151
|
|
130
|
-
|
131
|
-
|
132
|
-
|
152
|
+
$(function () {
|
153
|
+
$.SrBuj.bind();
|
154
|
+
});
|
133
155
|
|
134
|
-
})(
|
156
|
+
})(jQuery);
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: SrBuj
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gagoar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-04-
|
11
|
+
date: 2013-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|