bootstrap-filestyle-rails 1.1.0 → 1.1.2

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: a7825381a68052a8127594da8d788f6598d01012
4
- data.tar.gz: 14eba8aacd89565768ee247b27f8e8124fa99ae8
3
+ metadata.gz: ad66b3f52a0655168b4fb62cd1546e31da11cd1e
4
+ data.tar.gz: 86346109edf0e55dbde44f2248c96ee6cbd7d881
5
5
  SHA512:
6
- metadata.gz: 1299e95b30064d68ca3a30f741a2690b45fcdd0fec55fa8316f4c8ec9d3b4c54d8c0fbc6c92da42cd5de17d938086c2bb5bea72aeaf904b36ff8ea993281bdc9
7
- data.tar.gz: fe1d1ba8b7c0f518f456f85b3298aaefd2721c847c8490878c629890715ac4ed8ab9c70b58d38a2cad99dbb4967a22bc99f5bd078531ffa2574eed7d17ac84d5
6
+ metadata.gz: 07c311a3bf040958a696432e8c7e80673ea373170baac3f6b659d2bdcaf84df9cc14e2c94828201ad7e9042aec6d78401b4656162f5ba7c7ad1e80abe8607a08
7
+ data.tar.gz: 82c04c170ceb9a1436a0251f50d68a7f7adb6b2a9a685db3b2fd2c00970d88f08ee95f18edf2a42730d952d7053705b74f98b18c770381dc2d4acb58bc4d3ef9
@@ -4,21 +4,21 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'bootstrap-filestyle-rails/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "bootstrap-filestyle-rails"
7
+ spec.name = 'bootstrap-filestyle-rails'
8
8
  spec.version = BootstrapFilestyleRails::VERSION
9
- spec.authors = ["Mauricio Pasquier Juan"]
10
- spec.email = ["mauricio@pasquierjuan.com.ar"]
9
+ spec.authors = ['Mauricio Pasquier Juan']
10
+ spec.email = ['mauricio@pasquierjuan.com.ar']
11
11
  spec.description = %Q{Bootstrap Filestyle (gem version reflects assets
12
12
  version) packaged for rails}
13
13
  spec.summary = %q{Bootstrap Filestyle for the asset pipeline}
14
- spec.homepage = "https://github.com/mauriciopasquier/bootstrap-filestyle-rails"
15
- spec.license = "MIT"
14
+ spec.homepage = 'https://github.com/mauriciopasquier/bootstrap-filestyle-rails'
15
+ spec.license = 'MIT'
16
16
 
17
17
  spec.files = `git ls-files`.split($/)
18
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
- spec.require_paths = ["lib"]
20
+ spec.require_paths = ['lib']
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.3"
23
- spec.add_development_dependency "rake"
22
+ spec.add_development_dependency 'bundler', '~> 1.3'
23
+ spec.add_development_dependency 'rake'
24
24
  end
@@ -1,13 +1,11 @@
1
- require "rails"
2
- require "bootstrap-filestyle-rails/version"
1
+ require 'rails'
2
+ require 'bootstrap-filestyle-rails/version'
3
3
 
4
- # Add bootstrap-filestyle to the asset pipeline
4
+ # Public: Adds bootstrap-filestyle to the rails asset pipeline.
5
5
  module BootstrapFilestyleRails
6
-
7
- if ::Rails.version.to_s < "3.1"
8
- require "bootstrap-filestyle-rails/railtie"
6
+ if ::Rails.version.to_s < '3.1'
7
+ require 'bootstrap-filestyle-rails/railtie'
9
8
  else
10
- require "bootstrap-filestyle-rails/engine"
9
+ require 'bootstrap-filestyle-rails/engine'
11
10
  end
12
-
13
11
  end
@@ -1,3 +1,4 @@
1
1
  module BootstrapFilestyleRails
2
- VERSION = "1.1.0"
2
+ # Public: String gem version number, which reflects the asset version number.
3
+ VERSION = '1.1.2'
3
4
  end
@@ -1,373 +1,338 @@
1
1
  /*
2
2
  * bootstrap-filestyle
3
- * doc: http://dev.tudosobreweb.com.br/bootstrap-filestyle/
3
+ * doc: http://markusslima.github.io/bootstrap-filestyle/
4
4
  * github: https://github.com/markusslima/bootstrap-filestyle
5
5
  *
6
6
  * Copyright (c) 2014 Markus Vinicius da Silva Lima
7
- * Version 1.1.0
7
+ * Version 1.1.2
8
8
  * Licensed under the MIT license.
9
9
  */
10
- (function ($) {
11
- "use strict";
12
-
13
- var Filestyle = function (element, options) {
14
- this.options = options;
15
- this.$elementFilestyle = [];
16
- this.$element = $(element);
17
- };
18
-
19
- Filestyle.prototype = {
20
- clear: function () {
21
- this.$element.val('');
22
- this.$elementFilestyle.find(':text').val('');
23
- },
24
-
25
- destroy: function () {
26
- this.$element
27
- .removeAttr('style')
28
- .removeData('filestyle')
29
- .val('');
30
- this.$elementFilestyle.remove();
31
- },
32
-
33
- disabled: function (value) {
34
- if (value === true) {
35
- if (!this.options.disabled) {
36
- this.$element
37
- .attr('disabled', 'true');
38
- this.$elementFilestyle.find('label').attr('disabled', 'true');
39
- this.options.disabled = true;
40
- }
41
- } else if (value === false) {
42
- if (this.options.disabled) {
43
- this.$element
44
- .removeAttr('disabled');
45
- this.$elementFilestyle.find('label').removeAttr('disabled');
46
- this.options.disabled = false;
47
- }
48
- } else {
49
- return this.options.disabled;
50
- }
51
- },
52
-
53
- buttonBefore: function (value) {
54
- if (value === true) {
55
- if (!this.options.buttonBefore) {
56
- this.options.buttonBefore = true;
57
- if (this.options.input) {
58
- this.$elementFilestyle.remove();
59
- this.constructor();
60
- this.pushNameFiles();
61
- }
62
- }
63
- } else if (value === false) {
64
- if (this.options.buttonBefore) {
65
- this.options.buttonBefore = false;
66
- if (this.options.input) {
67
- this.$elementFilestyle.remove();
68
- this.constructor();
69
- this.pushNameFiles();
70
- }
71
- }
72
- } else {
73
- return this.options.buttonBefore;
74
- }
75
- },
76
-
77
- icon: function (value) {
78
- if (value === true) {
79
- if (!this.options.icon) {
80
- this.options.icon = true;
81
- this.$elementFilestyle.find('label').prepend(this.htmlIcon());
82
- }
83
- } else if (value === false) {
84
- if (this.options.icon) {
85
- this.options.icon = false;
86
- this.$elementFilestyle.find('.glyphicon').remove();
87
- }
88
- } else {
89
- return this.options.icon;
90
- }
91
- },
92
-
93
- input: function (value) {
94
- if (value === true) {
95
- if (!this.options.input) {
96
- this.options.input = true;
97
-
98
- if (this.options.buttonBefore) {
99
- this.$elementFilestyle.append(this.htmlInput());
100
- } else {
101
- this.$elementFilestyle.prepend(this.htmlInput());
102
- }
103
-
104
- this.$elementFilestyle.find('.badge').remove();
105
-
106
- var content = '',
107
- files = [];
108
- if (this.$element[0].files === undefined) {
109
- files[0] = {'name': this.$element[0].value};
110
- } else {
111
- files = this.$element[0].files;
112
- }
113
-
114
- for (var i = 0; i < files.length; i++) {
115
- content += files[i].name.split("\\").pop() + ', ';
116
- }
117
- if (content !== '') {
118
- this.$elementFilestyle.find(':text').val(content.replace(/\, $/g, ''));
119
- }
120
-
121
- this.$elementFilestyle.find('.group-span-filestyle').addClass('input-group-btn');
122
- }
123
- } else if (value === false) {
124
- if (this.options.input) {
125
- this.options.input = false;
126
- this.$elementFilestyle.find(':text').remove();
127
- var files = [];
128
- if (this.$element[0].files === undefined) {
129
- files[0] = {'name': this.$element[0].value};
130
- } else {
131
- files = this.$element[0].files;
132
- }
133
- if (files.length > 0) {
134
- this.$elementFilestyle.find('label').append(' <span class="badge">'+files.length+'</span>');
135
- }
136
- this.$elementFilestyle.find('.group-span-filestyle').removeClass('input-group-btn');
137
- }
138
- } else {
139
- return this.options.input;
140
- }
141
- },
142
-
143
- size: function (value) {
144
- if (value !== undefined) {
145
- var btn = this.$elementFilestyle.find('label'),
146
- input = this.$elementFilestyle.find('input');
147
-
148
- btn.removeClass('btn-lg btn-sm');
149
- input.removeClass('input-lg input-sm');
150
- if (value != 'nr') {
151
- btn.addClass('btn-'+value);
152
- input.addClass('input-'+value);
153
- }
154
- } else {
155
- return this.options.size;
156
- }
157
- },
158
-
159
- buttonText: function (value) {
160
- if (value !== undefined) {
161
- this.options.buttonText = value;
162
- this.$elementFilestyle.find('label span').html(this.options.buttonText);
163
- } else {
164
- return this.options.buttonText;
165
- }
166
- },
167
-
168
- buttonName: function (value) {
169
- if (value !== undefined) {
170
- this.options.buttonName = value;
171
- this.$elementFilestyle.find('label').attr({'class': 'btn '+this.options.buttonName});
172
- } else {
173
- return this.options.buttonName;
174
- }
175
- },
176
-
177
- iconName: function (value) {
178
- if (value !== undefined) {
179
- this.$elementFilestyle.find('.glyphicon').attr({'class': '.glyphicon ' + this.options.iconName});
180
- } else {
181
- return this.options.iconName;
182
- }
183
- },
184
-
185
- htmlIcon: function () {
186
- if (this.options.icon) {
187
- return '<span class="glyphicon '+this.options.iconName+'"></span> ';
188
- } else {
189
- return '';
190
- }
191
- },
192
-
193
- htmlInput: function () {
194
- if (this.options.input) {
195
- return '<input type="text" class="form-control '+(this.options.size=='nr'?'':'input-'+this.options.size)+'" disabled> ';
196
- } else {
197
- return '';
198
- }
199
- },
200
-
201
- // puts the name of the input files
202
- pushNameFiles: function () {
203
- var content = '',
204
- files = [];
205
- if (this.$element[0].files === undefined) {
206
- files[0] = {'name': this.$element.value};
207
- } else {
208
- files = this.$element[0].files;
209
- }
210
-
211
- for (var i = 0; i < files.length; i++) {
212
- content += files[i].name.split("\\").pop() + ', ';
213
- }
214
-
215
- if (content !== '') {
216
- this.$elementFilestyle.find(':text').val(content.replace(/\, $/g, ''));
217
- } else {
218
- this.$elementFilestyle.find(':text').val('');
219
- }
220
- },
221
-
222
- constructor: function () {
223
- var _self = this,
224
- html = '',
225
- id = this.$element.attr('id'),
226
- files = [],
227
- btn = '',
228
- $label,
229
- $labelFocusableContainer;
230
-
231
- if (id === '' || !id) {
232
- id = 'filestyle-'+$('.bootstrap-filestyle').length;
233
- this.$element.attr({'id': id});
234
- }
235
-
236
- btn = '<span class="group-span-filestyle '+(this.options.input ? 'input-group-btn' : '') +'">'+
237
- '<label for="'+id+'" class="btn '+this.options.buttonName+' '+(this.options.size=='nr'?'':'btn-'+this.options.size)+'" '+(this.options.disabled?'disabled="true"':'')+'>'+
238
- this.htmlIcon()+this.options.buttonText+
239
- '</label>'+
240
- '</span>';
241
-
242
- html = this.options.buttonBefore ? btn+this.htmlInput() : this.htmlInput()+btn;
243
-
244
- this.$elementFilestyle = $('<div class="bootstrap-filestyle input-group">'+html+'</div>');
245
-
246
- $label = this.$elementFilestyle.find('label');
247
- $labelFocusableContainer = $label.parent();
248
-
249
- $labelFocusableContainer
250
- .attr('tabindex', "0")
251
- .keypress(function(e) {
252
- if (e.keyCode === 13 || e.charCode === 32) {
253
- $label.click();
254
- }
255
- });
256
-
257
- // hidding input file and add filestyle
258
- this.$element
259
- .css({'position':'absolute','clip':'rect(0,0,0,0)'})
260
- .attr('tabindex', "-1")
261
- .after(this.$elementFilestyle);
262
-
263
- if (this.options.disabled) {
264
- this.$element.attr('disabled', 'true');
265
- }
266
-
267
- // Getting input file value
268
- this.$element.change(function () {
269
- var content = '';
270
- if (this.files === undefined) {
271
- files[0] = {'name': this.value};
272
- } else {
273
- files = this.files;
274
- }
275
-
276
- for (var i = 0; i < files.length; i++) {
277
- content += files[i].name.split("\\").pop() + ', ';
278
- }
279
-
280
- if (content !== '') {
281
- _self.$elementFilestyle.find(':text').val(content.replace(/\, $/g, ''));
282
- } else {
283
- _self.$elementFilestyle.find(':text').val('');
284
- }
285
-
286
- if (_self.options.input == false) {
287
- if (_self.$elementFilestyle.find('.badge').length == 0) {
288
- _self.$elementFilestyle.find('label').append(' <span class="badge">'+files.length+'</span>');
289
- } else if (files.length == 0) {
290
- _self.$elementFilestyle.find('.badge').remove();
291
- } else {
292
- _self.$elementFilestyle.find('.badge').html(files.length);
293
- }
294
- } else {
295
- _self.$elementFilestyle.find('.badge').remove();
296
- }
297
- });
298
-
299
- // Check if browser is Firefox
300
- if (window.navigator.userAgent.search(/firefox/i) > -1) {
301
- // Simulating choose file for firefox
302
- this.$elementFilestyle.find('label').click(function () {
303
- _self.$element.click();
304
- return false;
305
- });
306
- }
307
- }
308
- };
309
-
310
- var old = $.fn.filestyle;
311
-
312
- $.fn.filestyle = function (option, value) {
313
- var get = '',
314
- element = this.each(function () {
315
- if ($(this).attr('type') === 'file') {
316
- var $this = $(this),
317
- data = $this.data('filestyle'),
318
- options = $.extend({}, $.fn.filestyle.defaults, option, typeof option === 'object' && option);
319
-
320
- if (!data) {
321
- $this.data('filestyle', (data = new Filestyle(this, options)));
322
- data.constructor();
323
- }
324
-
325
- if (typeof option === 'string') {
326
- get = data[option](value);
327
- }
328
- }
329
- });
330
-
331
- if (typeof get !== undefined) {
332
- return get;
333
- } else {
334
- return element;
335
- }
336
- };
337
-
338
- $.fn.filestyle.defaults = {
339
- 'buttonText': 'Choose file',
340
- 'iconName': 'glyphicon-folder-open',
341
- 'buttonName': 'btn-default',
342
- 'size': 'nr',
343
- 'input': true,
344
- 'icon': true,
345
- 'buttonBefore': false,
346
- 'disabled': false
347
- };
348
-
349
- $.fn.filestyle.noConflict = function () {
350
- $.fn.filestyle = old;
351
- return this;
352
- };
353
-
354
- // Data attributes register
355
- $(function() {
356
- $('.filestyle').each(function () {
357
- var $this = $(this),
358
- options = {
359
-
360
- 'input': $this.attr('data-input') === 'false' ? false : true,
361
- 'icon': $this.attr('data-icon') === 'false' ? false : true,
362
- 'buttonBefore': $this.attr('data-buttonBefore') === 'true' ? true : false,
363
- 'disabled': $this.attr('data-disabled') === 'true' ? true : false,
364
- 'size': $this.attr('data-size'),
365
- 'buttonText': $this.attr('data-buttonText'),
366
- 'buttonName': $this.attr('data-buttonName'),
367
- 'iconName': $this.attr('data-iconName')
368
- };
369
-
370
- $this.filestyle(options);
371
- });
372
- });
10
+ (function($) {"use strict";
11
+
12
+ var Filestyle = function(element, options) {
13
+ this.options = options;
14
+ this.$elementFilestyle = [];
15
+ this.$element = $(element);
16
+ };
17
+
18
+ Filestyle.prototype = {
19
+ clear : function() {
20
+ this.$element.val('');
21
+ this.$elementFilestyle.find(':text').val('');
22
+ this.$elementFilestyle.find('.badge').remove();
23
+ },
24
+
25
+ destroy : function() {
26
+ this.$element.removeAttr('style').removeData('filestyle').val('');
27
+ this.$elementFilestyle.remove();
28
+ },
29
+
30
+ disabled : function(value) {
31
+ if (value === true) {
32
+ if (!this.options.disabled) {
33
+ this.$element.attr('disabled', 'true');
34
+ this.$elementFilestyle.find('label').attr('disabled', 'true');
35
+ this.options.disabled = true;
36
+ }
37
+ } else if (value === false) {
38
+ if (this.options.disabled) {
39
+ this.$element.removeAttr('disabled');
40
+ this.$elementFilestyle.find('label').removeAttr('disabled');
41
+ this.options.disabled = false;
42
+ }
43
+ } else {
44
+ return this.options.disabled;
45
+ }
46
+ },
47
+
48
+ buttonBefore : function(value) {
49
+ if (value === true) {
50
+ if (!this.options.buttonBefore) {
51
+ this.options.buttonBefore = true;
52
+ if (this.options.input) {
53
+ this.$elementFilestyle.remove();
54
+ this.constructor();
55
+ this.pushNameFiles();
56
+ }
57
+ }
58
+ } else if (value === false) {
59
+ if (this.options.buttonBefore) {
60
+ this.options.buttonBefore = false;
61
+ if (this.options.input) {
62
+ this.$elementFilestyle.remove();
63
+ this.constructor();
64
+ this.pushNameFiles();
65
+ }
66
+ }
67
+ } else {
68
+ return this.options.buttonBefore;
69
+ }
70
+ },
71
+
72
+ icon : function(value) {
73
+ if (value === true) {
74
+ if (!this.options.icon) {
75
+ this.options.icon = true;
76
+ this.$elementFilestyle.find('label').prepend(this.htmlIcon());
77
+ }
78
+ } else if (value === false) {
79
+ if (this.options.icon) {
80
+ this.options.icon = false;
81
+ this.$elementFilestyle.find('.glyphicon').remove();
82
+ }
83
+ } else {
84
+ return this.options.icon;
85
+ }
86
+ },
87
+
88
+ input : function(value) {
89
+ if (value === true) {
90
+ if (!this.options.input) {
91
+ this.options.input = true;
92
+
93
+ if (this.options.buttonBefore) {
94
+ this.$elementFilestyle.append(this.htmlInput());
95
+ } else {
96
+ this.$elementFilestyle.prepend(this.htmlInput());
97
+ }
98
+
99
+ this.$elementFilestyle.find('.badge').remove();
100
+
101
+ this.pushNameFiles();
102
+
103
+ this.$elementFilestyle.find('.group-span-filestyle').addClass('input-group-btn');
104
+ }
105
+ } else if (value === false) {
106
+ if (this.options.input) {
107
+ this.options.input = false;
108
+ this.$elementFilestyle.find(':text').remove();
109
+ var files = this.pushNameFiles();
110
+ if (files.length > 0 && this.options.badge) {
111
+ this.$elementFilestyle.find('label').append(' <span class="badge">' + files.length + '</span>');
112
+ }
113
+ this.$elementFilestyle.find('.group-span-filestyle').removeClass('input-group-btn');
114
+ }
115
+ } else {
116
+ return this.options.input;
117
+ }
118
+ },
119
+
120
+ size : function(value) {
121
+ if (value !== undefined) {
122
+ var btn = this.$elementFilestyle.find('label'), input = this.$elementFilestyle.find('input');
123
+
124
+ btn.removeClass('btn-lg btn-sm');
125
+ input.removeClass('input-lg input-sm');
126
+ if (value != 'nr') {
127
+ btn.addClass('btn-' + value);
128
+ input.addClass('input-' + value);
129
+ }
130
+ } else {
131
+ return this.options.size;
132
+ }
133
+ },
134
+
135
+ buttonText : function(value) {
136
+ if (value !== undefined) {
137
+ this.options.buttonText = value;
138
+ this.$elementFilestyle.find('label span').html(this.options.buttonText);
139
+ } else {
140
+ return this.options.buttonText;
141
+ }
142
+ },
143
+
144
+ buttonName : function(value) {
145
+ if (value !== undefined) {
146
+ this.options.buttonName = value;
147
+ this.$elementFilestyle.find('label').attr({
148
+ 'class' : 'btn ' + this.options.buttonName
149
+ });
150
+ } else {
151
+ return this.options.buttonName;
152
+ }
153
+ },
154
+
155
+ iconName : function(value) {
156
+ if (value !== undefined) {
157
+ this.$elementFilestyle.find('.glyphicon').attr({
158
+ 'class' : '.glyphicon ' + this.options.iconName
159
+ });
160
+ } else {
161
+ return this.options.iconName;
162
+ }
163
+ },
164
+
165
+ htmlIcon : function() {
166
+ if (this.options.icon) {
167
+ return '<span class="glyphicon ' + this.options.iconName + '"></span> ';
168
+ } else {
169
+ return '';
170
+ }
171
+ },
172
+
173
+ htmlInput : function() {
174
+ if (this.options.input) {
175
+ return '<input type="text" class="form-control ' + (this.options.size == 'nr' ? '' : 'input-' + this.options.size) + '" disabled> ';
176
+ } else {
177
+ return '';
178
+ }
179
+ },
180
+
181
+ // puts the name of the input files
182
+ // return files
183
+ pushNameFiles : function() {
184
+ var content = '', files = [];
185
+ if (this.$element[0].files === undefined) {
186
+ files[0] = {
187
+ 'name' : this.$element[0] && this.$element[0].value
188
+ };
189
+ } else {
190
+ files = this.$element[0].files;
191
+ }
192
+
193
+ for (var i = 0; i < files.length; i++) {
194
+ content += files[i].name.split("\\").pop() + ', ';
195
+ }
196
+
197
+ if (content !== '') {
198
+ this.$elementFilestyle.find(':text').val(content.replace(/\, $/g, ''));
199
+ } else {
200
+ this.$elementFilestyle.find(':text').val('');
201
+ }
202
+
203
+ return files;
204
+ },
205
+
206
+ constructor : function() {
207
+ var _self = this,
208
+ html = '',
209
+ id = _self.$element.attr('id'),
210
+ files = [],
211
+ btn = '',
212
+ $label;
213
+
214
+ if (id === '' || !id) {
215
+ id = 'filestyle-' + $('.bootstrap-filestyle').length;
216
+ _self.$element.attr({
217
+ 'id' : id
218
+ });
219
+ }
220
+
221
+ btn = '<span class="group-span-filestyle ' + (_self.options.input ? 'input-group-btn' : '') + '">' +
222
+ '<label for="' + id + '" class="btn ' + _self.options.buttonName + ' ' +
223
+ (_self.options.size == 'nr' ? '' : 'btn-' + _self.options.size) + '" ' +
224
+ (_self.options.disabled ? 'disabled="true"' : '') + '>' +
225
+ _self.htmlIcon() + _self.options.buttonText +
226
+ '</label>' +
227
+ '</span>';
228
+
229
+ html = _self.options.buttonBefore ? btn + _self.htmlInput() : _self.htmlInput() + btn;
230
+
231
+ _self.$elementFilestyle = $('<div class="bootstrap-filestyle input-group">' + html + '</div>');
232
+ _self.$elementFilestyle.find('.group-span-filestyle').attr('tabindex', "0").keypress(function(e) {
233
+ if (e.keyCode === 13 || e.charCode === 32) {
234
+ _self.$elementFilestyle.find('label').click();
235
+ return false;
236
+ }
237
+ });
238
+
239
+ // hidding input file and add filestyle
240
+ _self.$element.css({
241
+ 'position' : 'absolute',
242
+ 'clip' : 'rect(0px 0px 0px 0px)' // using 0px for work in IE8
243
+ }).attr('tabindex', "-1").after(_self.$elementFilestyle);
244
+
245
+ if (_self.options.disabled) {
246
+ _self.$element.attr('disabled', 'true');
247
+ }
248
+
249
+ // Getting input file value
250
+ _self.$element.change(function() {
251
+ var files = _self.pushNameFiles();
252
+
253
+ if (_self.options.input == false && _self.options.badge) {
254
+ if (_self.$elementFilestyle.find('.badge').length == 0) {
255
+ _self.$elementFilestyle.find('label').append(' <span class="badge">' + files.length + '</span>');
256
+ } else if (files.length == 0) {
257
+ _self.$elementFilestyle.find('.badge').remove();
258
+ } else {
259
+ _self.$elementFilestyle.find('.badge').html(files.length);
260
+ }
261
+ } else {
262
+ _self.$elementFilestyle.find('.badge').remove();
263
+ }
264
+ });
265
+
266
+ // Check if browser is Firefox
267
+ if (window.navigator.userAgent.search(/firefox/i) > -1) {
268
+ // Simulating choose file for firefox
269
+ _self.$elementFilestyle.find('label').click(function() {
270
+ _self.$element.click();
271
+ return false;
272
+ });
273
+ }
274
+ }
275
+ };
276
+
277
+ var old = $.fn.filestyle;
278
+
279
+ $.fn.filestyle = function(option, value) {
280
+ var get = '', element = this.each(function() {
281
+ if ($(this).attr('type') === 'file') {
282
+ var $this = $(this), data = $this.data('filestyle'), options = $.extend({}, $.fn.filestyle.defaults, option, typeof option === 'object' && option);
283
+
284
+ if (!data) {
285
+ $this.data('filestyle', ( data = new Filestyle(this, options)));
286
+ data.constructor();
287
+ }
288
+
289
+ if ( typeof option === 'string') {
290
+ get = data[option](value);
291
+ }
292
+ }
293
+ });
294
+
295
+ if ( typeof get !== undefined) {
296
+ return get;
297
+ } else {
298
+ return element;
299
+ }
300
+ };
301
+
302
+ $.fn.filestyle.defaults = {
303
+ 'buttonText' : 'Choose file',
304
+ 'iconName' : 'glyphicon-folder-open',
305
+ 'buttonName' : 'btn-default',
306
+ 'size' : 'nr',
307
+ 'input' : true,
308
+ 'badge' : true,
309
+ 'icon' : true,
310
+ 'buttonBefore' : false,
311
+ 'disabled' : false
312
+ };
313
+
314
+ $.fn.filestyle.noConflict = function() {
315
+ $.fn.filestyle = old;
316
+ return this;
317
+ };
318
+
319
+ // Data attributes register
320
+ $(function() {
321
+ $('.filestyle').each(function() {
322
+ var $this = $(this), options = {
323
+
324
+ 'input' : $this.attr('data-input') === 'false' ? false : true,
325
+ 'icon' : $this.attr('data-icon') === 'false' ? false : true,
326
+ 'buttonBefore' : $this.attr('data-buttonBefore') === 'true' ? true : false,
327
+ 'disabled' : $this.attr('data-disabled') === 'true' ? true : false,
328
+ 'size' : $this.attr('data-size'),
329
+ 'buttonText' : $this.attr('data-buttonText'),
330
+ 'buttonName' : $this.attr('data-buttonName'),
331
+ 'iconName' : $this.attr('data-iconName'),
332
+ 'badge' : $this.attr('data-badge') === 'false' ? false : true
333
+ };
334
+
335
+ $this.filestyle(options);
336
+ });
337
+ });
373
338
  })(window.jQuery);
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap-filestyle-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.2
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-05-16 00:00:00.000000000 Z
11
+ date: 2014-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  description: |-
@@ -47,7 +47,7 @@ executables: []
47
47
  extensions: []
48
48
  extra_rdoc_files: []
49
49
  files:
50
- - .gitignore
50
+ - ".gitignore"
51
51
  - Gemfile
52
52
  - LICENSE.txt
53
53
  - README.md
@@ -68,17 +68,17 @@ require_paths:
68
68
  - lib
69
69
  required_ruby_version: !ruby/object:Gem::Requirement
70
70
  requirements:
71
- - - '>='
71
+ - - ">="
72
72
  - !ruby/object:Gem::Version
73
73
  version: '0'
74
74
  required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  requirements:
76
- - - '>='
76
+ - - ">="
77
77
  - !ruby/object:Gem::Version
78
78
  version: '0'
79
79
  requirements: []
80
80
  rubyforge_project:
81
- rubygems_version: 2.0.14
81
+ rubygems_version: 2.2.2
82
82
  signing_key:
83
83
  specification_version: 4
84
84
  summary: Bootstrap Filestyle for the asset pipeline