SrBuj 0.8.5 → 0.9.0alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +2 -0
- data/lib/SrBuj.rb +5 -1
- data/lib/SrBuj/rails/action_controller/helpers.rb +37 -0
- data/lib/SrBuj/rails/action_controller_helpers.rb +1 -0
- data/lib/SrBuj/version.rb +1 -1
- data/lib/assets/javascripts/SrBuj.js +65 -33
- data/lib/assets/stylesheets/SrBuj.css +30 -0
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MTdkZTUxYmU1ZDUzMWZkYmE4NDBmMjM2NzQxMmJmMzYzYWZjZDI5NA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZmJkZGZhMmExZjU5MjBjYWUzNTkwODdhZDMzNjhlMzcyZTljZmQ4OQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YWFmMDU1ODFmODM3ZWZkNmFlMDhjN2VmMjk4YTc4YTA5NjhlNGI2MzExY2Qy
|
10
|
+
NzQzMmE5MmY1YTliOWQ5NDE5YTNmOWU3MzVmZTUzZmFjMGY4YzdkZjFkY2Q1
|
11
|
+
NzRmODM1MDQ4NGExOTIzNThjYTAzYmExOGNjOGFkOGEyYjJhMDU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NmEzMjU5OTM5ZTllYmU1MjUyYmYwZGZmNGU3OTBkOTQxYjhkODBkZGJmNjdk
|
14
|
+
OWEwMjJjZWE5NzQ5NTg3Y2E0MTcwZmY3ZTM5ODM0NWUwZmM4MTkxM2RhMjY2
|
15
|
+
YzlmYWFiMmFhYTEwOGFlZjlhZDI5MWQ4YjE4YTI1MTBkYzI4Njg=
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
SrBuj
|
2
2
|
=
|
3
|
+
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/SrBuj.png)](https://rubygems.org/gems/SrBuj)[![Dependency Status](https://gemnasium.com/gagoar/SrBuj.png)](https://gemnasium.com/gagoar/SrBuj) [![Code Climate](https://codeclimate.com/github/gagoar/SrBuj.png)](https://codeclimate.com/github/gagoar/SrBuj.png)
|
3
5
|
|
4
6
|
Better Unobtrusive JavaScript Respond (for Rails and jquery_ujs, twitter/bootstrap modal.js)
|
5
7
|
|
data/lib/SrBuj.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
-
|
1
|
+
equire 'SrBuj/version'
|
2
|
+
require 'active_support'
|
2
3
|
|
3
4
|
module SrBuj
|
4
5
|
module Rails
|
5
6
|
class Engine < ::Rails::Engine
|
7
|
+
ActiveSupport.on_load(:action_controller) do
|
8
|
+
require 'SrBuj/rails/action_controller/helpers'
|
9
|
+
end
|
6
10
|
end
|
7
11
|
end
|
8
12
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module SrBuj
|
2
|
+
module ActionController
|
3
|
+
module Helpers
|
4
|
+
|
5
|
+
#=> helpfull method to return redirect_to in an js way.
|
6
|
+
# use: js_redirect(to: root_path)
|
7
|
+
# use: js_redirect(reload: true)
|
8
|
+
def js_redirect(opts = {})
|
9
|
+
js = if defined? opts[:to]
|
10
|
+
"window.location.href = '#{opts[:to]}';"
|
11
|
+
elsif defined? opts[:reload]
|
12
|
+
"window.location.reload();"
|
13
|
+
end
|
14
|
+
render js: js
|
15
|
+
end
|
16
|
+
|
17
|
+
#=> this method sets 2 simple headers to be handled (later on) for the SrBuj respond librery in js.
|
18
|
+
# the :type attribute could be any css class that you need to append
|
19
|
+
# options:
|
20
|
+
# type: [error, info, warning] or any other class (the first 3 clases are going to be used as alert-error, alert-info and alert-warning)
|
21
|
+
# side: [right, left] wich side the message will appear
|
22
|
+
# position: [top, bottom]
|
23
|
+
# time: [numeric] will change the time that the message will be displayed
|
24
|
+
# use: js_notify (message: 'this is madness!', type: 'error', side: 'right', position: 'top', time: 2000 )
|
25
|
+
def js_notify(options = {})
|
26
|
+
if options[:message]
|
27
|
+
response.headers['X-SRBUJ-MSG'] = options[:message].to_s
|
28
|
+
response.headers['X-SRBUJ-TYPE'] = options[:type].to_s if options[:type]
|
29
|
+
response.headers['X-SRBUJ-SIDE'] = options[:side].to_s if options[:side]
|
30
|
+
response.headers['X-SRBUJ-POS'] = options[:position].to_s if options[:position]
|
31
|
+
response.headers['X-SRBUJ-TIME'] = options[:time].to_s if options[:time]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
ActionController::Base.send(:include, SrBuj::ActionController::Helpers)
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'SrBuj/rails/action_controller/helpers'
|
data/lib/SrBuj/version.rb
CHANGED
@@ -19,8 +19,9 @@
|
|
19
19
|
};
|
20
20
|
var SrBuj;
|
21
21
|
$.SrBuj = SrBuj = {
|
22
|
-
version: '0.
|
22
|
+
version: '0.9.0alpha',
|
23
23
|
selector: '[data-remote][data-target]',
|
24
|
+
notifyHeaders: { message: 'X-SRBUJ-MSG', type: 'X-SRBUJ-TYPE', side: 'X-SRBUJ-SIDE', position: 'X-SRBUJ-POS', time: 'X-SRBUJ-TIME' },
|
24
25
|
defaults: {
|
25
26
|
'$el': undefined,
|
26
27
|
target: undefined,
|
@@ -113,50 +114,55 @@
|
|
113
114
|
'remove': $el.is('[data-srbuj]')
|
114
115
|
};
|
115
116
|
user_options = user_options || {};
|
116
|
-
for (var attr in this.defaults) {
|
117
|
-
if (this.defaults.hasOwnProperty(attr)) {
|
117
|
+
for ( var attr in this.defaults ) {
|
118
|
+
if ( this.defaults.hasOwnProperty( attr ) ) {
|
118
119
|
options[attr] = user_options[attr] || el_options[attr] || this.defaults[attr];
|
119
120
|
}
|
120
121
|
}
|
121
122
|
return options;
|
122
123
|
},
|
123
124
|
success: function (e, data, status, xhr, user_options) {
|
124
|
-
if ( xhr
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
if (options.change) {
|
134
|
-
$.SrBuj.changeDom(options.method, $target, data);
|
135
|
-
}
|
136
|
-
if (options.modal) {
|
137
|
-
if (options.wrapper) {
|
138
|
-
$wrapper.modal('toggle');
|
139
|
-
} else {
|
140
|
-
$target.modal('toggle');
|
141
|
-
}
|
142
|
-
}
|
125
|
+
if ( xhr ){
|
126
|
+
var notify = {};
|
127
|
+
for ( var attr in $.SrBuj.notifyHeaders )
|
128
|
+
if ( $.SrBuj.notifyHeaders.hasOwnProperty( attr ) ) {
|
129
|
+
notify[attr] = xhr.getResponseHeader( $.SrBuj.notifyHeaders[attr] );
|
130
|
+
}
|
131
|
+
if ( notify.message ){ $.SrBuj.Util.notify(notify) }
|
132
|
+
if ( (/javascript/).test( xhr.getResponseHeader('Content-Type') )){
|
133
|
+
return true;
|
143
134
|
}
|
144
|
-
|
145
|
-
|
135
|
+
}
|
136
|
+
var options = $.SrBuj.getOptions(e.target, user_options),
|
137
|
+
$target = options.jqueryselector ? $(options.target).present() : $(document.getElementById(options.target)),
|
138
|
+
$wrapper = options.jqueryselector ? $(options.wrapper) : $(document.getElementById(options.wrapper));
|
139
|
+
if ($target.present()) {
|
140
|
+
e.stopPropagation();
|
141
|
+
if (!options.custom) {
|
142
|
+
if (options.change) {
|
143
|
+
$.SrBuj.changeDom(options.method, $target, data);
|
146
144
|
}
|
147
|
-
if (options.
|
148
|
-
|
149
|
-
|
150
|
-
|
145
|
+
if (options.modal) {
|
146
|
+
if (options.wrapper) {
|
147
|
+
$wrapper.modal('toggle');
|
148
|
+
} else {
|
149
|
+
$target.modal('toggle');
|
151
150
|
}
|
152
151
|
}
|
153
|
-
|
154
|
-
|
152
|
+
}
|
153
|
+
if(options.url && options.push && $.SrBuj.needToChangeUrl(options.url) && $.SrBuj.browserSupportsPushState() ){
|
154
|
+
window.history.pushState({ SrBuj: true }, '', options.url)
|
155
|
+
}
|
156
|
+
if (options.callback) {
|
157
|
+
var callback = $.SrBuj.kindOfCallback(options.callback);
|
158
|
+
if (callback) {
|
159
|
+
callback.apply(this, [e, data, status]);
|
155
160
|
}
|
156
|
-
|
157
161
|
}
|
158
|
-
|
159
|
-
|
162
|
+
if (options.remove){
|
163
|
+
this.remove();
|
164
|
+
}
|
165
|
+
}},
|
160
166
|
fail: function (e, data, status, error_code, user_options) {
|
161
167
|
e.stopPropagation();
|
162
168
|
var $el = $(e.target).present(),
|
@@ -175,6 +181,32 @@
|
|
175
181
|
$(document).on('ajax:error', selector, this.fail);
|
176
182
|
},
|
177
183
|
Util: {
|
184
|
+
notify: function (options){
|
185
|
+
/* This function will show a growling element, with the message and attached class that was given.
|
186
|
+
* will endure only a few seconds and its going to be removed from DOM afterwards.
|
187
|
+
* use: $.SrBuj.Util.notify({message: 'This is Madness', type: 'info'}) this will produce
|
188
|
+
* <s id=_growlingMsg class=info>This is Madness</s>
|
189
|
+
*/
|
190
|
+
var options = options || {};
|
191
|
+
if( options.message ){
|
192
|
+
var _growlingMsg = document.createElement('s');
|
193
|
+
_growlingMsg.id = '_growlingMsg';
|
194
|
+
if ( options.type ){
|
195
|
+
_growlingMsg.className = (/^(info|warning|error)$/).test( options.type ) ?
|
196
|
+
['alert', '-' , options.type ].join('') : options.type;
|
197
|
+
}else{
|
198
|
+
_growlingMsg.className = 'alert-info';
|
199
|
+
}
|
200
|
+
_growlingMsg.textContent = options.message;
|
201
|
+
$('body').append(_growlingMsg);
|
202
|
+
_growlingMsg.className += [' alert', options.side || 'right', options.position || 'bottom', 'srbuj-notify' ].join(' ').toLowerCase();
|
203
|
+
options.time = Number( options.time ) > 0 ? options.time : 2000;
|
204
|
+
setInterval($.SrBuj.Util.removeNotify, options.time);
|
205
|
+
}
|
206
|
+
},
|
207
|
+
removeNotify: function(){
|
208
|
+
$('#_growlingMsg').remove();
|
209
|
+
},
|
178
210
|
link: function (user_options){
|
179
211
|
/* This function will create a link with options, trigger it and remove the link afterwards
|
180
212
|
* user_options must be a hash (Obj) with key: value without the data word
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#_growlingMsg.top{
|
2
|
+
top: 10px;
|
3
|
+
}
|
4
|
+
#_growlingMsg.left{
|
5
|
+
left: 10px;
|
6
|
+
}
|
7
|
+
#_growlingMsg.right{
|
8
|
+
right: 10px;
|
9
|
+
}
|
10
|
+
#_growlingMsg.bottom{
|
11
|
+
bottom: 10px;
|
12
|
+
}
|
13
|
+
|
14
|
+
s#_growlingMsg{
|
15
|
+
-webkit-transition:all 0.5s ease-in-out;
|
16
|
+
-ms-transition:all 0.5s ease-in-out;
|
17
|
+
-o-transition:all 0.5s ease-in-out;
|
18
|
+
-moz-transition:all 0.5s ease-in-out;
|
19
|
+
transition:all 0.5s ease-in-out;
|
20
|
+
opacity: 0;
|
21
|
+
display: block;
|
22
|
+
position: fixed;
|
23
|
+
margin: 0;
|
24
|
+
z-index: 1000;
|
25
|
+
text-decoration: none;
|
26
|
+
}
|
27
|
+
s#_growlingMsg.srbuj-notify{
|
28
|
+
opacity: 1;
|
29
|
+
}
|
30
|
+
|
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.
|
4
|
+
version: 0.9.0alpha
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gagoar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-06-
|
11
|
+
date: 2013-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -74,6 +74,9 @@ extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
76
|
- lib/assets/javascripts/SrBuj.js
|
77
|
+
- lib/assets/stylesheets/SrBuj.css
|
78
|
+
- lib/SrBuj/rails/action_controller/helpers.rb
|
79
|
+
- lib/SrBuj/rails/action_controller_helpers.rb
|
77
80
|
- lib/SrBuj/version.rb
|
78
81
|
- lib/SrBuj.rb
|
79
82
|
- LICENSE.txt
|
@@ -93,9 +96,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
96
|
version: '0'
|
94
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
98
|
requirements:
|
96
|
-
- - ! '
|
99
|
+
- - ! '>'
|
97
100
|
- !ruby/object:Gem::Version
|
98
|
-
version:
|
101
|
+
version: 1.3.1
|
99
102
|
requirements: []
|
100
103
|
rubyforge_project:
|
101
104
|
rubygems_version: 2.0.3
|
@@ -103,4 +106,3 @@ signing_key:
|
|
103
106
|
specification_version: 4
|
104
107
|
summary: http://github.com/gagoar/SrBuj/
|
105
108
|
test_files: []
|
106
|
-
has_rdoc:
|