bootstrap-filestyle-rails 1.0.3 → 1.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d1bd4f051bde47327337ee77d35733bf3d063edc
4
- data.tar.gz: bf70960a3b8d2f95086e2b0f888edd6d6eebf50d
3
+ metadata.gz: 8272bbe767f69ec581b8c78426e8f2fa3ce6129d
4
+ data.tar.gz: 43bbd4b51edf6ce7551858de183abc3ac27c3920
5
5
  SHA512:
6
- metadata.gz: 0870d7e84e29769a487b52fcb6f08e669be822db60f6cad9e544be04f64fa0f96c7bf11183490c881a03f941ce8374004d1cf0222a512406bfb51aba2bb00301
7
- data.tar.gz: 154dae18695b2d169dcf6b6c7d85b662760a466220ed6ec137aec667d10dc0af0022ead42252ff101116eaf50f84633ed8763ccbfc6d9800b88f32c1ae12e7af
6
+ metadata.gz: 2a28d7052f8c7038ee7a0230836601736e2643ed9602a995452e747949f1d1ead58ba2b83f24a27f394ac107d1804d81cffb3e2444f318b91dfd6aa599f253b2
7
+ data.tar.gz: 41adb3298eb28106f5d9660fbfb3325d0f1730a640406397a3768e2c4a157ef052d27aaf7102f397cc1245c14e1af4ecdd737ed369b4dba70fb53fbe723da853
data/README.md CHANGED
@@ -16,7 +16,7 @@ Or install it yourself as:
16
16
 
17
17
  $ gem install bootstrap-filestyle-rails
18
18
 
19
- This gem's version reflects the asset version starting with `1.6.3`.
19
+ This gem's version reflects the asset version starting with `1.0.3`.
20
20
 
21
21
  ## Usage
22
22
 
@@ -24,6 +24,14 @@ Just require it in your `application.js`:
24
24
 
25
25
  //= require bootstrap-filestyle
26
26
 
27
+ And initialize your file input somehow:
28
+
29
+ $(":file").filestyle(
30
+ input: false
31
+ )
32
+
33
+ You can check more configuration options in the [bootstrap-filestyle][] site.
34
+
27
35
  ## Contributing
28
36
 
29
37
  1. Fork it
@@ -1,3 +1,3 @@
1
1
  module BootstrapFilestyleRails
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
@@ -3,12 +3,12 @@
3
3
  * http://dev.tudosobreweb.com.br/bootstrap-filestyle/
4
4
  *
5
5
  * Copyright (c) 2013 Markus Vinicius da Silva Lima
6
- * Version 1.0.3
6
+ * Version 1.0.4
7
7
  * Licensed under the MIT license.
8
8
  */
9
9
  (function ($) {
10
10
  "use strict";
11
-
11
+
12
12
  var Filestyle = function (element, options) {
13
13
  this.options = options;
14
14
  this.$elementFilestyle = [];
@@ -153,17 +153,54 @@
153
153
  this.$element.attr({'id': id});
154
154
  }
155
155
 
156
- html = this.htmlInput()+
157
- '<label for="'+id+'" class="'+this.options.classButton+'">'+
158
- this.htmlIcon()+
159
- '<span>'+this.options.buttonText+'</span>'+
160
- '</label>';
156
+ var inputContainerOpen = (this.options.classInputContainerClass != '') ? '<div class="'+this.options.classInputContainerClass+'">' : '';
157
+ var inputContainerClose = (inputContainerOpen != '') ? '</div>' : '';
158
+
159
+ var buttonContainerOpen = (this.options.classButtonContainerClass != '') ? '<div class="'+this.options.classButtonContainerClass+'">' : '';
160
+ var buttonContainerClose = (buttonContainerOpen != '') ? '</div>' : '';
161
+
162
+ if(this.options.buttonBefore)
163
+ {
164
+ html =
165
+ buttonContainerOpen+
166
+ '<label for="'+id+'" class="'+this.options.classButton+'">'+
167
+ this.htmlIcon()+
168
+ '<span>'+this.options.buttonText+'</span>'+
169
+ '</label>'+
170
+ buttonContainerClose+
171
+ inputContainerOpen+
172
+ this.htmlInput()+
173
+ inputContainerClose;
174
+ } else {
175
+ html =
176
+ inputContainerOpen+
177
+ this.htmlInput()+
178
+ inputContainerClose+
179
+ buttonContainerOpen+
180
+ '<label for="'+id+'" class="'+this.options.classButton+'">'+
181
+ this.htmlIcon()+
182
+ '<span>'+this.options.buttonText+'</span>'+
183
+ '</label>'+
184
+ buttonContainerClose;
185
+ }
186
+
187
+ this.$elementFilestyle = $('<div class="'+this.options.containerClass+' bootstrap-filestyle">'+html+'</div>');
161
188
 
162
- this.$elementFilestyle = $('<div class="bootstrap-filestyle" style="display: inline;">'+html+'</div>');
189
+ var $label = this.$elementFilestyle.find('label');
190
+ var $labelFocusableContainer = $label.parent();
191
+
192
+ $labelFocusableContainer
193
+ .attr('tabindex', "0")
194
+ .keypress(function(e) {
195
+ if (e.keyCode === 13 || e.charCode === 32) {
196
+ $label.click();
197
+ }
198
+ });
163
199
 
164
200
  // hidding input file and add filestyle
165
201
  this.$element
166
- .css({'position':'fixed','left':'-500px'})
202
+ .css({'position':'absolute','clip':'rect(0,0,0,0)'})
203
+ .attr('tabindex', "-1")
167
204
  .after(this.$elementFilestyle);
168
205
 
169
206
  // Getting input file value
@@ -181,6 +218,8 @@
181
218
 
182
219
  if (content !== '') {
183
220
  _self.$elementFilestyle.find(':text').val(content.replace(/\, $/g, ''));
221
+ } else {
222
+ _self.$elementFilestyle.find(':text').val('');
184
223
  }
185
224
  });
186
225
 
@@ -227,9 +266,14 @@
227
266
  'buttonText': 'Choose file',
228
267
  'input': true,
229
268
  'icon': true,
230
- 'classButton': 'btn',
231
- 'classInput': 'input-large',
232
- 'classIcon': 'icon-folder-open'
269
+ 'buttonBefore': false,
270
+
271
+ 'containerClass': 'form-group', // bootstrap-filestyle
272
+ 'classButtonContainerClass': '',
273
+ 'classButton': 'btn btn-default',
274
+ 'classInputContainerClass': '',
275
+ 'classInput': 'form-control',
276
+ 'classIcon': 'glyphicon glyphicon-folder-open'
233
277
  };
234
278
 
235
279
  $.fn.filestyle.noConflict = function () {
@@ -238,18 +282,19 @@
238
282
  };
239
283
 
240
284
  // Data attributes register
241
- $('.filestyle').each(function () {
242
- var $this = $(this),
243
- options = {
244
- 'buttonText': $this.attr('data-buttonText'),
245
- 'input': $this.attr('data-input') === 'false' ? false : true,
246
- 'icon': $this.attr('data-icon') === 'false' ? false : true,
247
- 'classButton': $this.attr('data-classButton'),
248
- 'classInput': $this.attr('data-classInput'),
249
- 'classIcon': $this.attr('data-classIcon')
250
- };
251
-
252
- $this.filestyle(options);
285
+ $(function() {
286
+ $('.filestyle').each(function () {
287
+ var $this = $(this),
288
+ options = {
289
+ 'buttonText': $this.attr('data-buttonText'),
290
+ 'input': $this.attr('data-input') === 'false' ? false : true,
291
+ 'icon': $this.attr('data-icon') === 'false' ? false : true,
292
+ 'classButton': $this.attr('data-classButton'),
293
+ 'classInput': $this.attr('data-classInput'),
294
+ 'classIcon': $this.attr('data-classIcon')
295
+ };
296
+
297
+ $this.filestyle(options);
298
+ });
253
299
  });
254
-
255
- })(window.jQuery);
300
+ })(window.jQuery);
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap-filestyle-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mauricio Pasquier Juan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-16 00:00:00.000000000 Z
11
+ date: 2014-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler