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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 182371b71bf8d6de597bed86bacfc5f61cf7080d
4
- data.tar.gz: 4242e9654997d1d2fbd4f62108b5601961a4e29e
3
+ metadata.gz: 2a73252b4191909b159fc1f08fef1e0e02de9d83
4
+ data.tar.gz: 1bb0462bc38fffbeeb765b338498721b6d6390b8
5
5
  SHA512:
6
- metadata.gz: 32415d44369580676bc4a508dc2b6a5d41294cf52469324402cc8dcfb3b7a19df2f04d03708ba2a9458f18ce22ab1c0236d945f18b93e0d4835d8d313afbb7ae
7
- data.tar.gz: d54dd2a75dec5a0af3651a439e1cfccd7a08d7e7359edaec1fd1525106f84753b3fce0ba4256ae9204a430c20d914c6244fcc820e05a8080464c59e44ae02828
6
+ metadata.gz: 57420be71252add9c3e17af1578b644020ed06d6dded2155f35151180cbf44a5240fb10298be222bad5feaa5f5263ad62f33087ed5e2db54779fb262eb41721e
7
+ data.tar.gz: 2e249f50fe395313cc14c89123b680bef7de2e49ea2f8c51e8eaa955bdf41a5da6fe245105ff4f909c14e15e31b6c167f86573319bc7ce55ebd6237cca86205c
@@ -1,3 +1,3 @@
1
1
  module SimpleFormFileinput
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,129 +1,129 @@
1
1
  /*
2
- Bootstrap - File Input
3
- ======================
2
+ Bootstrap - File Input
3
+ ======================
4
4
 
5
- This is meant to convert all file input tags into a set of elements that displays consistently in all browsers.
5
+ This is meant to convert all file input tags into a set of elements that displays consistently in all browsers.
6
6
 
7
- Converts all
8
- <input type="file">
9
- into Bootstrap buttons
10
- <a class="btn">Browse</a>
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
- 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
- };
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
- '.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);
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')
@@ -11,6 +11,7 @@
11
11
  // about supported directives.
12
12
  //
13
13
  //= require ./bootstrap.file-input
14
+ //= require ./enhancements
14
15
  //= require_self
15
16
 
16
17
  (function($){
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.1
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-06-23 00:00:00.000000000 Z
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: