simple_form_fileinput 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 182371b71bf8d6de597bed86bacfc5f61cf7080d
4
+ data.tar.gz: 4242e9654997d1d2fbd4f62108b5601961a4e29e
5
+ SHA512:
6
+ metadata.gz: 32415d44369580676bc4a508dc2b6a5d41294cf52469324402cc8dcfb3b7a19df2f04d03708ba2a9458f18ce22ab1c0236d945f18b93e0d4835d8d313afbb7ae
7
+ data.tar.gz: d54dd2a75dec5a0af3651a439e1cfccd7a08d7e7359edaec1fd1525106f84753b3fce0ba4256ae9204a430c20d914c6244fcc820e05a8080464c59e44ae02828
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ /.idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in simple_form_fileinput.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 smit1625
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,29 @@
1
+ # SimpleFormFileinput
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'simple_form_fileinput'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install simple_form_fileinput
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ require 'rails/generators'
2
+
3
+ module SimpleFormFileinput
4
+ module Generators
5
+ class InstallGenerator < ::Rails::Generators::Base
6
+ desc "Installs SimpleFormFileinput"
7
+
8
+ def self.source_root
9
+ @source_root ||= File.join(File.dirname(__FILE__), 'templates')
10
+ end
11
+
12
+ def copy_initializer
13
+ copy_file 'simple_form_fileinput.rb', 'config/initializers/simple_form_fileinput.rb'
14
+ inject_into_file 'app/assets/javascripts/application.js', :before => '//= require_tree .' do
15
+ "//= require simple_form_fileinput/init\n"
16
+ end
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ module SimpleForm
2
+ module Inputs
3
+ class FileInput < Base
4
+ def input
5
+ input_html_options[:title] = 'Drop a file here, or click to browse...'
6
+ if input_html_options.key?(:data)
7
+ input_html_options[:data][:filename_placement] = 'inside'
8
+ else
9
+ input_html_options[:data] = {:filename_placement => 'inside'}
10
+ end
11
+ @builder.file_field(attribute_name, input_html_options)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleFormFileinput
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,6 @@
1
+ require "simple_form_fileinput/version"
2
+
3
+ module SimpleFormFileinput
4
+ class Engine < ::Rails::Engine
5
+ end
6
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'simple_form_fileinput/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "simple_form_fileinput"
8
+ spec.version = SimpleFormFileinput::VERSION
9
+ spec.authors = ["smit1625"]
10
+ spec.email = ["smit1625@msu.edu"]
11
+ spec.description = %q{Beautifies the default file input for SimpleForm}
12
+ spec.summary = %q{Uses bootstrap-fileinput to enhance SimpleForm's default datetime input}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_dependency "railties"
24
+ spec.add_dependency "simple_form"
25
+ end
@@ -0,0 +1,129 @@
1
+ /*
2
+ Bootstrap - File Input
3
+ ======================
4
+
5
+ This is meant to convert all file input tags into a set of elements that displays consistently in all browsers.
6
+
7
+ Converts all
8
+ <input type="file">
9
+ into Bootstrap buttons
10
+ <a class="btn">Browse</a>
11
+
12
+ */
13
+ (function($) {
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
+ };
119
+
120
+ // Add the styles before the first stylesheet
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);
@@ -0,0 +1,20 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require ./bootstrap.file-input
14
+ //= require_self
15
+
16
+ (function($){
17
+ $(document).ready(function(){
18
+ $('input[type=file]').bootstrapFileInput();
19
+ });
20
+ })(jQuery);
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_form_fileinput
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - smit1625
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-23 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
+ - !ruby/object:Gem::Dependency
42
+ name: railties
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simple_form
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Beautifies the default file input for SimpleForm
70
+ email:
71
+ - smit1625@msu.edu
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/generators/simple_form_fileinput/install/install_generator.rb
82
+ - lib/generators/simple_form_fileinput/install/templates/simple_form_fileinput.rb
83
+ - lib/simple_form_fileinput.rb
84
+ - lib/simple_form_fileinput/version.rb
85
+ - simple_form_fileinput.gemspec
86
+ - vendor/assets/javascripts/simple_form_fileinput/bootstrap.file-input.js
87
+ - vendor/assets/javascripts/simple_form_fileinput/init.js
88
+ homepage: ''
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.2.2
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Uses bootstrap-fileinput to enhance SimpleForm's default datetime input
112
+ test_files: []