SrBuj 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/SrBuj/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module SrBuj
2
- VERSION = "0.2.2"
2
+ VERSION = '0.2.3'
3
3
  end
@@ -11,27 +11,47 @@
11
11
  var SrBuj;
12
12
  $.SrBuj = SrBuj = {
13
13
  selector: '[data-remote][data-target]',
14
+ changeDom: function(method,$target,data){
15
+ switch(method){
16
+ case 'POST':
17
+ $target.append(data);
18
+ break;
19
+ case 'PUT':
20
+ case 'PATCH':
21
+ $target.replaceWith(data);
22
+ break;
23
+ case 'DELETE':
24
+ $target.remove();
25
+ break;
26
+ default:
27
+ $target.html(data);
28
+ }
14
29
 
30
+ },
15
31
  success: function(e, data){
16
32
  var $el = $(e.target),
17
- ismodal = $el.data('modal') || false,
18
- replace = $el.data('replace') || false,
19
- remove = $el.attr('method') == 'delete' || false,
20
- fn = $el.data('callback'),
21
- callback = (typeof fn == 'function') ? fn : window[fn],
22
- target = document.getElementById($el.data('target')),
23
- wrapper = document.getElementById($el.data('error')),
24
- $target = $(target);
25
- if(remove) $target.remove();
26
- else replace ? $target.replaceWith(data) : $target.html(data);
27
- if(ismodal) wrapper ? $(wrapper).modal('toggle') : $target.modal('toggle');
33
+ isModal = $el.data('modal') || false,
34
+ verb = $el.attr('method') || 'GET',
35
+ method = ( verb.toUpperCase() == 'POST' && $el.data('replace')) ? 'PUT' : verb.toUpperCase();
36
+ change = $el.attr('nochange') || true,
37
+ fn = $el.data('callback'),
38
+ callback = (typeof fn == 'function') ? fn : window[fn],
39
+ target = document.getElementById($el.data('target')),
40
+ wrapper = document.getElementById($el.data('error')),
41
+ $target = $(target);
42
+
43
+ if(change) $.SrBuj.changeDom(method.toUpperCase(),$target,data);
44
+ if(isModal) wrapper ? $(wrapper).modal('toggle') : $target.modal('toggle');
28
45
  if(callback) callback.apply(this,[e, data]);
29
46
 
30
47
  },
31
48
  fail: function(e, data){
32
49
  var $el = $(e.target),
33
50
  error = document.getElementById($el.data('error'));
34
- $(error).html(data.responseText);
51
+ if( error )
52
+ $.SrBuj.changeDom('ERROR', $(error), data.responseText);
53
+ else
54
+ throw 'cant find data-error target on element';
35
55
  },
36
56
  bind: function(){
37
57
  $(document).on('ajax:success', this.selector, this.success);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: SrBuj
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-03 00:00:00.000000000 Z
12
+ date: 2013-03-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &70118254588320 !ruby/object:Gem::Requirement
16
+ requirement: &70302604334460 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.3'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70118254588320
24
+ version_requirements: *70302604334460
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: railties
27
- requirement: &70118254586620 !ruby/object:Gem::Requirement
27
+ requirement: &70302604332220 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '3.1'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70118254586620
35
+ version_requirements: *70302604332220
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70118254585760 !ruby/object:Gem::Requirement
38
+ requirement: &70302604330220 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70118254585760
46
+ version_requirements: *70302604330220
47
47
  description: Better Unobtrusive JavaScript Request in asset pipeline
48
48
  email:
49
49
  - xeroice@gmail.com