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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YWNjYjYwMjIxNzIzMDk5Y2I2NWU3ZDBkN2RmYjdkM2IyZmYwYWZiNg==
4
+ ZDFjZjMwOTY4ZDk4YmMwMDg1ZmZmYWY4YWIyMjlmODViMTA2MDU1NQ==
5
5
  data.tar.gz: !binary |-
6
- ZWY2YWYxMTQxN2YyYWNhODY0NWEzMThlN2ZkZmM5NGM5ZWY2YjM1NA==
6
+ ZjA4YTUxYzY1NDJkMTAwYTQ0ODk3Mjk4NDgzMWUzYmMwYjFkYTYwNA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NWI2NWRlMTJmNWFmZGRiZTIxMWJmNjNmYWVjY2Y1NzJmNGViYWRhYTYyZTE3
10
- ZTQxNjhkYjdkZDk4ZDNlNGI3MDQ3ODk3OTg2MDhhZjllOTlmZDUxNzc5MWRm
11
- MTM1NjljMjRkN2IzNjM1NGNhMTdkZTgzMzhmZTc0OWQxYjQwMjU=
9
+ NTkxMzdjMzVmYWQ2YzZkZWI3ZWY4NTRmMjgwNTM1OThkNmZmNDBiODY5YmJl
10
+ MTYyODAxODI5NWEzNjM4YWI2ZTI5YTY4NDkxYWYyZGRlYmRlMzdkNmRiYmVl
11
+ YzJmNWU5MzUwNmJjN2UzZjVkYzk2NTlmNTU4ZTQyZmZjZTAyYzQ=
12
12
  data.tar.gz: !binary |-
13
- NTVlMWY1YWMzODM4YTA4NzllZGU1MWVlNjA1OTM5Njg1M2VmY2FhNmEwMmY2
14
- MmZlYjFmMzBjN2NiYTQ2ZmQwMjgyOTMyMjQ5MDI0YjM5ZGRlMmQ2ODJmNjBj
15
- NGMzZWZlYTk3NzM2NzJmMTBkOTUxOTNkNDJkNWMwMGIxOThmNzE=
13
+ MjliOWM3ZmJiZTgxYWYzZDE4MjYxYjlhOTVmYWE3YjU1ZjI2YmQ4ZmZiMjYz
14
+ OTRlMGU0YzE2OWNmNDk4OTk1YTU0ZjU3YzY3YjllMjczMTZlYWFhYjVmNmI1
15
+ YzNlNDkzZmQ5NTMzZTc0ZDRlMWZjMzA0MWI1Zjc2NzEyOWM1Yzc=
data/lib/SrBuj/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module SrBuj
2
- VERSION = '0.6.1'
2
+ VERSION = '0.6.2'
3
3
  end
@@ -1,134 +1,156 @@
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
- */
11
- $.fn.present = function(){
12
- return this.length === 1 && this
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
- kindOfCallback: function(callback){
50
- if(typeof callback == 'function'){
51
- return callback
52
- }else{
53
- return window[callback] || new Function(callback);
54
- }
55
- },
56
- getVerb: function($el){
57
- var respond_as = $el.data('respond-as'),
58
- dataVerb = $el.data('method'),
59
- replace = $el.data('replace'),
60
- proto = $el.attr('method');
61
- if (respond_as)
62
- return respond_as.toUpperCase();
63
- else
64
- if( dataVerb )
65
- return dataVerb.toUpperCase();
66
- else
67
- if (proto) return replace ? 'PUT' : proto.toUpperCase();
68
- },
69
- getOptions: function(el, user_options){
70
- var options = {},
71
- user_options = user_options || {};
72
- $el = $( user_options['el'] || el ).present(),
73
- el_options = {
74
- '$el': $el,
75
- 'target': $el.data('target'),
76
- 'method': $.SrBuj.getVerb($el),
77
- 'onError': $el.data('error'),
78
- 'callback': $el.data('callback'),
79
- 'change': ! ( $el.data('nochange') || false ),
80
- 'jqueryselector': $el.data('jqueryselector'),
81
- 'modal': $el.data('modal'),
82
- 'wrapper': $el.data('error'),
83
- 'custom': $el.data('custom'),
84
- 'replace': $el.data('replace')
85
- };
86
- for(var attr in this.defaults){
87
- options[attr] = user_options[attr] || el_options[attr] || this.defaults[attr];
88
- }
89
- return options;
90
- },
91
- success: function(e, data,status,user_options){
92
- var options = $.SrBuj.getOptions(e.target, user_options),
93
- $el = options['$el'],
94
- $target = options['jqueryselector'] ? $(options['target']).present() : $(document.getElementById(options['target'])) ,
95
- $wrapper = options['jqueryselector'] ? $(options['wrapper']) : $(document.getElementById(options['wrapper']));
96
- if($target.present()){
97
- e.stopPropagation();
98
- if(!options['custom']){
99
- if(options['change'])
100
- $.SrBuj.changeDom(options['method'],$target,data);
101
- if(options['modal'])
102
- options['wrapper'] ? $wrapper.modal('toggle') : $target.modal('toggle');
103
- }
104
- if(options['callback']){
105
- callback = $.SrBuj.kindOfCallback(options['callback']);
106
- if(callback) callback.apply(this,[e, data, status]);
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
- fail: function(e, data, status, user_options){
112
- e.stopPropagation();
113
- var $el = $(e.target).present(),
114
- error = $el.data('error'),
115
- jqueryselector = $el.data('jqueryselector'),
116
- $error = jqueryselector ? $(error) :$(document.getElementById(error));
117
- if( error ){
118
- $.SrBuj.changeDom('ERROR', $error, data.responseText);
119
- }
120
- else
121
- throw 'cant find data-error on element' + e.target;
122
- },
123
- bind: function(selector){
124
- var selector = selector || this.selector;
125
- $(document).on('ajax:success', selector, this.success);
126
- $(document).on('ajax:error', selector, this.fail);
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
- $(function() {
131
- $.SrBuj.bind();
132
- });
152
+ $(function () {
153
+ $.SrBuj.bind();
154
+ });
133
155
 
134
- })( jQuery );
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.1
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-12 00:00:00.000000000 Z
11
+ date: 2013-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler