bootstrap-filestyle-rails 0.0.1
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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +1 -0
- data/bootstrap-filestyle-rails.gemspec +24 -0
- data/lib/bootstrap-filestyle-rails/engine.rb +7 -0
- data/lib/bootstrap-filestyle-rails/railtie.rb +7 -0
- data/lib/bootstrap-filestyle-rails/version.rb +4 -0
- data/lib/bootstrap-filestyle-rails.rb +13 -0
- data/vendor/assets/javascripts/bootstrap-filestyle.js +255 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0d6865b4be174f457e04a8d80fc2bf475a322b48
|
4
|
+
data.tar.gz: 6b6dad59cb3ea35ccdc1f7084bfa95f7a804bee6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8281375afadbe82736a0a5a2e1af628c140d41c8c61157ee218fcebe955eef139d56ab869480d749dff7ee216b0297ff5f252b1f4badc965af4a9e3e60d2dcb7
|
7
|
+
data.tar.gz: 833b3ea0de96fbf8385483b6f959ec12508105838899796a45bfc8ab36922224c1235d3600ea7ca3952aa18245534d648a2feaf2b3d819d84d3b03207bd4bd48
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Mauricio Pasquier Juan
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# bootstrap-filestyle-rails
|
2
|
+
|
3
|
+
[bootstrap-filestyle][] for the asset pipeline.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'bootstrap-filestyle-rails'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install bootstrap-filestyle-rails
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Just require it in your `application.js`:
|
22
|
+
|
23
|
+
//= require bootstrap-filestyle
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
32
|
+
|
33
|
+
[bootstrap-filestyle]: http://markusslima.github.io/bootstrap-filestyle/
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bootstrap-filestyle-rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bootstrap-filestyle-rails"
|
8
|
+
spec.version = BootstrapFilestyleRails::VERSION
|
9
|
+
spec.authors = ["Mauricio Pasquier Juan"]
|
10
|
+
spec.email = ["mauricio@pasquierjuan.com.ar"]
|
11
|
+
spec.description = %Q{Bootstrap Filestyle #{BootstrapFilestyleRails::ASSET_VERSION},
|
12
|
+
packaged for rails}
|
13
|
+
spec.summary = %q{Bootstrap Filestyle for the asset pipeline}
|
14
|
+
spec.homepage = "https://github.com/mauriciopasquier/bootstrap-filestyle-rails"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files`.split($/)
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "rails"
|
2
|
+
require "bootstrap-filestyle-rails/version"
|
3
|
+
|
4
|
+
# Add bootstrap-filestyle to the asset pipeline
|
5
|
+
module BootstrapFilestyleRails
|
6
|
+
|
7
|
+
if ::Rails.version.to_s < "3.1"
|
8
|
+
require "bootstrap-filestyle-rails/railtie"
|
9
|
+
else
|
10
|
+
require "bootstrap-filestyle-rails/engine"
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,255 @@
|
|
1
|
+
/*
|
2
|
+
* bootstrap-filestyle
|
3
|
+
* http://dev.tudosobreweb.com.br/bootstrap-filestyle/
|
4
|
+
*
|
5
|
+
* Copyright (c) 2013 Markus Vinicius da Silva Lima
|
6
|
+
* Version 1.0.3
|
7
|
+
* Licensed under the MIT license.
|
8
|
+
*/
|
9
|
+
(function ($) {
|
10
|
+
"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
|
+
},
|
23
|
+
|
24
|
+
destroy: function () {
|
25
|
+
this.$element
|
26
|
+
.removeAttr('style')
|
27
|
+
.removeData('filestyle')
|
28
|
+
.val('');
|
29
|
+
this.$elementFilestyle.remove();
|
30
|
+
},
|
31
|
+
|
32
|
+
icon: function (value) {
|
33
|
+
if (value === true) {
|
34
|
+
if (!this.options.icon) {
|
35
|
+
this.options.icon = true;
|
36
|
+
this.$elementFilestyle.find('label').prepend(this.htmlIcon());
|
37
|
+
}
|
38
|
+
} else if (value === false) {
|
39
|
+
if (this.options.icon) {
|
40
|
+
this.options.icon = false;
|
41
|
+
this.$elementFilestyle.find('i').remove();
|
42
|
+
}
|
43
|
+
} else {
|
44
|
+
return this.options.icon;
|
45
|
+
}
|
46
|
+
},
|
47
|
+
|
48
|
+
input: function (value) {
|
49
|
+
if (value === true) {
|
50
|
+
if (!this.options.input) {
|
51
|
+
this.options.input = true;
|
52
|
+
this.$elementFilestyle.prepend(this.htmlInput());
|
53
|
+
|
54
|
+
var content = '',
|
55
|
+
files = [];
|
56
|
+
if (this.$element[0].files === undefined) {
|
57
|
+
files[0] = {'name': this.$element[0].value};
|
58
|
+
} else {
|
59
|
+
files = this.$element[0].files;
|
60
|
+
}
|
61
|
+
|
62
|
+
for (var i = 0; i < files.length; i++) {
|
63
|
+
content += files[i].name.split("\\").pop() + ', ';
|
64
|
+
}
|
65
|
+
if (content !== '') {
|
66
|
+
this.$elementFilestyle.find(':text').val(content.replace(/\, $/g, ''));
|
67
|
+
}
|
68
|
+
}
|
69
|
+
} else if (value === false) {
|
70
|
+
if (this.options.input) {
|
71
|
+
this.options.input = false;
|
72
|
+
this.$elementFilestyle.find(':text').remove();
|
73
|
+
}
|
74
|
+
} else {
|
75
|
+
return this.options.input;
|
76
|
+
}
|
77
|
+
},
|
78
|
+
|
79
|
+
buttonText: function (value) {
|
80
|
+
if (value !== undefined) {
|
81
|
+
this.options.buttonText = value;
|
82
|
+
this.$elementFilestyle.find('label span').html(this.options.buttonText);
|
83
|
+
} else {
|
84
|
+
return this.options.buttonText;
|
85
|
+
}
|
86
|
+
},
|
87
|
+
|
88
|
+
classButton: function (value) {
|
89
|
+
if (value !== undefined) {
|
90
|
+
this.options.classButton = value;
|
91
|
+
this.$elementFilestyle.find('label').attr({'class': this.options.classButton});
|
92
|
+
if (this.options.classButton.search(/btn-inverse|btn-primary|btn-danger|btn-warning|btn-success/i) !== -1) {
|
93
|
+
this.$elementFilestyle.find('label i').addClass('icon-white');
|
94
|
+
} else {
|
95
|
+
this.$elementFilestyle.find('label i').removeClass('icon-white');
|
96
|
+
}
|
97
|
+
} else {
|
98
|
+
return this.options.classButton;
|
99
|
+
}
|
100
|
+
},
|
101
|
+
|
102
|
+
classIcon: function (value) {
|
103
|
+
if (value !== undefined) {
|
104
|
+
this.options.classIcon = value;
|
105
|
+
if (this.options.classButton.search(/btn-inverse|btn-primary|btn-danger|btn-warning|btn-success/i) !== -1) {
|
106
|
+
this.$elementFilestyle.find('label').find('i').attr({'class': 'icon-white '+this.options.classIcon});
|
107
|
+
} else {
|
108
|
+
this.$elementFilestyle.find('label').find('i').attr({'class': this.options.classIcon});
|
109
|
+
}
|
110
|
+
} else {
|
111
|
+
return this.options.classIcon;
|
112
|
+
}
|
113
|
+
},
|
114
|
+
|
115
|
+
classInput: function (value) {
|
116
|
+
if (value !== undefined) {
|
117
|
+
this.options.classInput = value;
|
118
|
+
this.$elementFilestyle.find(':text').addClass(this.options.classInput);
|
119
|
+
} else {
|
120
|
+
return this.options.classInput;
|
121
|
+
}
|
122
|
+
},
|
123
|
+
|
124
|
+
htmlIcon: function () {
|
125
|
+
if (this.options.icon) {
|
126
|
+
var colorIcon = '';
|
127
|
+
if (this.options.classButton.search(/btn-inverse|btn-primary|btn-danger|btn-warning|btn-success/i) !== -1) {
|
128
|
+
colorIcon = ' icon-white ';
|
129
|
+
}
|
130
|
+
|
131
|
+
return '<i class="'+colorIcon+this.options.classIcon+'"></i> ';
|
132
|
+
} else {
|
133
|
+
return '';
|
134
|
+
}
|
135
|
+
},
|
136
|
+
|
137
|
+
htmlInput: function () {
|
138
|
+
if (this.options.input) {
|
139
|
+
return '<input type="text" class="'+this.options.classInput+'" disabled> ';
|
140
|
+
} else {
|
141
|
+
return '';
|
142
|
+
}
|
143
|
+
},
|
144
|
+
|
145
|
+
constructor: function () {
|
146
|
+
var _self = this,
|
147
|
+
html = '',
|
148
|
+
id = this.$element.attr('id'),
|
149
|
+
files = [];
|
150
|
+
|
151
|
+
if (id === '' || !id) {
|
152
|
+
id = 'filestyle-'+$('.bootstrap-filestyle').length;
|
153
|
+
this.$element.attr({'id': id});
|
154
|
+
}
|
155
|
+
|
156
|
+
html = this.htmlInput()+
|
157
|
+
'<label for="'+id+'" class="'+this.options.classButton+'">'+
|
158
|
+
this.htmlIcon()+
|
159
|
+
'<span>'+this.options.buttonText+'</span>'+
|
160
|
+
'</label>';
|
161
|
+
|
162
|
+
this.$elementFilestyle = $('<div class="bootstrap-filestyle" style="display: inline;">'+html+'</div>');
|
163
|
+
|
164
|
+
// hidding input file and add filestyle
|
165
|
+
this.$element
|
166
|
+
.css({'position':'fixed','left':'-500px'})
|
167
|
+
.after(this.$elementFilestyle);
|
168
|
+
|
169
|
+
// Getting input file value
|
170
|
+
this.$element.change(function () {
|
171
|
+
var content = '';
|
172
|
+
if (this.files === undefined) {
|
173
|
+
files[0] = {'name': this.value};
|
174
|
+
} else {
|
175
|
+
files = this.files;
|
176
|
+
}
|
177
|
+
|
178
|
+
for (var i = 0; i < files.length; i++) {
|
179
|
+
content += files[i].name.split("\\").pop() + ', ';
|
180
|
+
}
|
181
|
+
|
182
|
+
if (content !== '') {
|
183
|
+
_self.$elementFilestyle.find(':text').val(content.replace(/\, $/g, ''));
|
184
|
+
}
|
185
|
+
});
|
186
|
+
|
187
|
+
// Check if browser is Firefox
|
188
|
+
if (window.navigator.userAgent.search(/firefox/i) > -1) {
|
189
|
+
// Simulating choose file for firefox
|
190
|
+
this.$elementFilestyle.find('label').click(function () {
|
191
|
+
_self.$element.click();
|
192
|
+
return false;
|
193
|
+
});
|
194
|
+
}
|
195
|
+
}
|
196
|
+
};
|
197
|
+
|
198
|
+
var old = $.fn.filestyle;
|
199
|
+
|
200
|
+
$.fn.filestyle = function (option, value) {
|
201
|
+
var get = '',
|
202
|
+
element = this.each(function () {
|
203
|
+
if ($(this).attr('type') === 'file') {
|
204
|
+
var $this = $(this),
|
205
|
+
data = $this.data('filestyle'),
|
206
|
+
options = $.extend({}, $.fn.filestyle.defaults, option, typeof option === 'object' && option);
|
207
|
+
|
208
|
+
if (!data) {
|
209
|
+
$this.data('filestyle', (data = new Filestyle(this, options)));
|
210
|
+
data.constructor();
|
211
|
+
}
|
212
|
+
|
213
|
+
if (typeof option === 'string') {
|
214
|
+
get = data[option](value);
|
215
|
+
}
|
216
|
+
}
|
217
|
+
});
|
218
|
+
|
219
|
+
if (typeof get !== undefined) {
|
220
|
+
return get;
|
221
|
+
} else {
|
222
|
+
return element;
|
223
|
+
}
|
224
|
+
};
|
225
|
+
|
226
|
+
$.fn.filestyle.defaults = {
|
227
|
+
'buttonText': 'Choose file',
|
228
|
+
'input': true,
|
229
|
+
'icon': true,
|
230
|
+
'classButton': 'btn',
|
231
|
+
'classInput': 'input-large',
|
232
|
+
'classIcon': 'icon-folder-open'
|
233
|
+
};
|
234
|
+
|
235
|
+
$.fn.filestyle.noConflict = function () {
|
236
|
+
$.fn.filestyle = old;
|
237
|
+
return this;
|
238
|
+
};
|
239
|
+
|
240
|
+
// 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);
|
253
|
+
});
|
254
|
+
|
255
|
+
})(window.jQuery);
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bootstrap-filestyle-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mauricio Pasquier Juan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: |-
|
42
|
+
Bootstrap Filestyle 1.0.3,
|
43
|
+
packaged for rails
|
44
|
+
email:
|
45
|
+
- mauricio@pasquierjuan.com.ar
|
46
|
+
executables: []
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- .gitignore
|
51
|
+
- Gemfile
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- bootstrap-filestyle-rails.gemspec
|
56
|
+
- lib/bootstrap-filestyle-rails.rb
|
57
|
+
- lib/bootstrap-filestyle-rails/engine.rb
|
58
|
+
- lib/bootstrap-filestyle-rails/railtie.rb
|
59
|
+
- lib/bootstrap-filestyle-rails/version.rb
|
60
|
+
- vendor/assets/javascripts/bootstrap-filestyle.js
|
61
|
+
homepage: https://github.com/mauriciopasquier/bootstrap-filestyle-rails
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.0.3
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: Bootstrap Filestyle for the asset pipeline
|
85
|
+
test_files: []
|
86
|
+
has_rdoc:
|