simple_form_fileinput 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/simple_form_fileinput/version.rb +1 -1
- data/vendor/assets/javascripts/simple_form_fileinput/bootstrap.file-input.js +120 -120
- data/vendor/assets/javascripts/simple_form_fileinput/enhancements.js.coffee +14 -0
- data/vendor/assets/javascripts/simple_form_fileinput/init.js +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a73252b4191909b159fc1f08fef1e0e02de9d83
|
4
|
+
data.tar.gz: 1bb0462bc38fffbeeb765b338498721b6d6390b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57420be71252add9c3e17af1578b644020ed06d6dded2155f35151180cbf44a5240fb10298be222bad5feaa5f5263ad62f33087ed5e2db54779fb262eb41721e
|
7
|
+
data.tar.gz: 2e249f50fe395313cc14c89123b680bef7de2e49ea2f8c51e8eaa955bdf41a5da6fe245105ff4f909c14e15e31b6c167f86573319bc7ce55ebd6237cca86205c
|
@@ -1,129 +1,129 @@
|
|
1
1
|
/*
|
2
|
-
|
3
|
-
|
2
|
+
Bootstrap - File Input
|
3
|
+
======================
|
4
4
|
|
5
|
-
|
5
|
+
This is meant to convert all file input tags into a set of elements that displays consistently in all browsers.
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
Converts all
|
8
|
+
<input type="file">
|
9
|
+
into Bootstrap buttons
|
10
|
+
<a class="btn">Browse</a>
|
11
11
|
|
12
|
-
*/
|
12
|
+
*/
|
13
13
|
(function($) {
|
14
14
|
|
15
|
-
$.fn.bootstrapFileInput = function() {
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
};
|
15
|
+
$.fn.bootstrapFileInput = function() {
|
16
|
+
|
17
|
+
this.each(function(i,elem){
|
18
|
+
|
19
|
+
var $elem = $(elem);
|
20
|
+
|
21
|
+
// Maybe some fields don't need to be standardized.
|
22
|
+
if (typeof $elem.attr('data-bfi-disabled') != 'undefined') {
|
23
|
+
return;
|
24
|
+
}
|
25
|
+
|
26
|
+
// Set the word to be displayed on the button
|
27
|
+
var buttonWord = 'Browse';
|
28
|
+
|
29
|
+
if (typeof $elem.attr('title') != 'undefined') {
|
30
|
+
buttonWord = $elem.attr('title');
|
31
|
+
}
|
32
|
+
|
33
|
+
var className = '';
|
34
|
+
|
35
|
+
if (!!$elem.attr('class')) {
|
36
|
+
className = ' ' + $elem.attr('class');
|
37
|
+
}
|
38
|
+
|
39
|
+
// Now we're going to wrap that input field with a Bootstrap button.
|
40
|
+
// The input will actually still be there, it will just be float above and transparent (done with the CSS).
|
41
|
+
$elem.wrap('<a class="file-input-wrapper btn btn-default ' + className + '"></a>').parent().prepend($('<span></span>').html(buttonWord));
|
42
|
+
})
|
43
|
+
|
44
|
+
// After we have found all of the file inputs let's apply a listener for tracking the mouse movement.
|
45
|
+
// This is important because the in order to give the illusion that this is a button in FF we actually need to move the button from the file input under the cursor. Ugh.
|
46
|
+
.promise().done( function(){
|
47
|
+
|
48
|
+
// As the cursor moves over our new Bootstrap button we need to adjust the position of the invisible file input Browse button to be under the cursor.
|
49
|
+
// This gives us the pointer cursor that FF denies us
|
50
|
+
$('.file-input-wrapper').mousemove(function(cursor) {
|
51
|
+
|
52
|
+
var input, wrapper,
|
53
|
+
wrapperX, wrapperY,
|
54
|
+
inputWidth, inputHeight,
|
55
|
+
cursorX, cursorY;
|
56
|
+
|
57
|
+
// This wrapper element (the button surround this file input)
|
58
|
+
wrapper = $(this);
|
59
|
+
// The invisible file input element
|
60
|
+
input = wrapper.find("input");
|
61
|
+
// The left-most position of the wrapper
|
62
|
+
wrapperX = wrapper.offset().left;
|
63
|
+
// The top-most position of the wrapper
|
64
|
+
wrapperY = wrapper.offset().top;
|
65
|
+
// The with of the browsers input field
|
66
|
+
inputWidth= input.width();
|
67
|
+
// The height of the browsers input field
|
68
|
+
inputHeight= input.height();
|
69
|
+
//The position of the cursor in the wrapper
|
70
|
+
cursorX = cursor.pageX;
|
71
|
+
cursorY = cursor.pageY;
|
72
|
+
|
73
|
+
//The positions we are to move the invisible file input
|
74
|
+
// The 20 at the end is an arbitrary number of pixels that we can shift the input such that cursor is not pointing at the end of the Browse button but somewhere nearer the middle
|
75
|
+
moveInputX = cursorX - wrapperX - inputWidth + 20;
|
76
|
+
// Slides the invisible input Browse button to be positioned middle under the cursor
|
77
|
+
moveInputY = cursorY- wrapperY - (inputHeight/2);
|
78
|
+
|
79
|
+
// Apply the positioning styles to actually move the invisible file input
|
80
|
+
input.css({
|
81
|
+
left:moveInputX,
|
82
|
+
top:moveInputY
|
83
|
+
});
|
84
|
+
});
|
85
|
+
|
86
|
+
$('body').on('change', '.file-input-wrapper input[type=file]', function(){
|
87
|
+
|
88
|
+
var fileName;
|
89
|
+
fileName = $(this).val();
|
90
|
+
|
91
|
+
// Remove any previous file names
|
92
|
+
$(this).parent().next('.file-input-name').remove();
|
93
|
+
if (!!$(this).prop('files') && $(this).prop('files').length > 1) {
|
94
|
+
fileName = $(this)[0].files.length+' files';
|
95
|
+
}
|
96
|
+
else {
|
97
|
+
fileName = fileName.substring(fileName.lastIndexOf('\\') + 1, fileName.length);
|
98
|
+
}
|
99
|
+
|
100
|
+
// Don't try to show the name if there is none
|
101
|
+
if (!fileName) {
|
102
|
+
return;
|
103
|
+
}
|
104
|
+
|
105
|
+
var selectedFileNamePlacement = $(this).data('filename-placement');
|
106
|
+
if (selectedFileNamePlacement === 'inside') {
|
107
|
+
// Print the fileName inside
|
108
|
+
$(this).siblings('span').html(fileName);
|
109
|
+
$(this).attr('title', fileName);
|
110
|
+
} else {
|
111
|
+
// Print the fileName aside (right after the the button)
|
112
|
+
$(this).parent().after('<span class="file-input-name">'+fileName+'</span>');
|
113
|
+
}
|
114
|
+
});
|
115
|
+
|
116
|
+
});
|
117
|
+
|
118
|
+
};
|
119
119
|
|
120
120
|
// Add the styles before the first stylesheet
|
121
121
|
// This ensures they can be easily overridden with developer styles
|
122
|
-
var cssHtml = '<style>'+
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
$('link[rel=stylesheet]').eq(0).before(cssHtml);
|
128
|
-
|
129
|
-
})(jQuery);
|
122
|
+
var cssHtml = '<style>'+
|
123
|
+
'.file-input-wrapper { overflow: hidden; position: relative; cursor: pointer; z-index: 1; }'+
|
124
|
+
'.file-input-wrapper input[type=file], .file-input-wrapper input[type=file]:focus, .file-input-wrapper input[type=file]:hover { position: absolute; top: 0; left: 0; cursor: pointer; opacity: 0; filter: alpha(opacity=0); z-index: 99; outline: 0; }'+
|
125
|
+
'.file-input-name { margin-left: 8px; }'+
|
126
|
+
'</style>';
|
127
|
+
$('link[rel=stylesheet]').eq(0).before(cssHtml);
|
128
|
+
|
129
|
+
})(jQuery);
|
@@ -0,0 +1,14 @@
|
|
1
|
+
$ ->
|
2
|
+
$(document).ready ->
|
3
|
+
$('body').on 'dragenter', (e)->
|
4
|
+
console.log e
|
5
|
+
$('.file-input-wrapper input[type=file]').addClass('file-in-window')
|
6
|
+
$('body').on 'dragleave', (e)->
|
7
|
+
console.log e
|
8
|
+
$('.file-input-wrapper input[type=file]').removeClass('file-in-window')
|
9
|
+
$('body').on 'dragenter', '.file-input-wrapper input[type=file]', (e)->
|
10
|
+
console.log e
|
11
|
+
$(@).addClass('file-hovering')
|
12
|
+
$('body').on 'dragleave', '.file-input-wrapper input[type=file]', (e)->
|
13
|
+
console.log e
|
14
|
+
$(@).removeClass('file-hovering')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_form_fileinput
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- smit1625
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- lib/simple_form_fileinput/version.rb
|
85
85
|
- simple_form_fileinput.gemspec
|
86
86
|
- vendor/assets/javascripts/simple_form_fileinput/bootstrap.file-input.js
|
87
|
+
- vendor/assets/javascripts/simple_form_fileinput/enhancements.js.coffee
|
87
88
|
- vendor/assets/javascripts/simple_form_fileinput/init.js
|
88
89
|
homepage: ''
|
89
90
|
licenses:
|