imagedrop 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6d5e8404d28349c09cf9ce8c52ec4fb56662c2be
4
+ data.tar.gz: afa5c785d22f0d29f6186f42281a9372fe3b4902
5
+ SHA512:
6
+ metadata.gz: 5c3ee5f1bd5e62f318a43a7a4ab956e6b61a45cfe21b231c85df3c4079966fc1923f63da8b0b05f4fdcde4c75489b7f6f2414b0c1ced0d50456e9d1af5310d12
7
+ data.tar.gz: 29ea756d66376ee9a6432f8d452fc19b8da0eff6fdba538dc85147849930ad94afd6654e83b04f97dddec6076c900b1c7a5f5569328d8a9e837ccfb756e89e07
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in imagedrop.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 dave
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.
@@ -0,0 +1,103 @@
1
+ # ImageDrop
2
+
3
+ Good for avatars and such!
4
+
5
+ Transforms the lowly file input field into sophisticated looking drag-and-drop targets complete with a preview image and placeholder text.
6
+
7
+ Actually, it's nothing fancy, but very effective. ImageDrop employs a little CSS trickery to change the file input field into a drop zone.
8
+
9
+ A tiny bit of javascript validate the file type is an image and uses the parent div for an image preview. The javascript changes the parent's background image when a file is dropped on the input.
10
+
11
+ During dragging and dropping, another div (sibling to the input) is temporarily revealed to act as a placeholder. This is also done purely with CSS.
12
+
13
+ So the html structure in the form looks like this:
14
+
15
+ <div data-imagedrop>
16
+ <input type='file'>
17
+ <div>Placeholder</div>
18
+ </div>
19
+
20
+ ## Requirements/Compatibility
21
+
22
+ ImageDrop uses simple CSS that is compatible with all browsers back to IE8. Correct me if I'm wrong about that. It also uses the browser's FileReader API through javascript, and that is compatible with most everything.
23
+
24
+ * Jquery (whatever version)
25
+ * Uh, that's it...
26
+
27
+ ## Features
28
+ * It's small. (Just 989 characters of javascript.)
29
+ * Works with a *lot* of browsers; [most browsers](http://caniuse.com/#search=FileReader) in fact.
30
+ * Supports a live preview image before bugging the server about it.
31
+ * Supports placeholder text and/or images (for drag operations).
32
+ * Validates the file type before bugging the server with it.
33
+ * Can be integrated into any web framework, not just Rails although this gem is mostly for Rails.
34
+ * Plays nice with Bootstrap.
35
+
36
+ ## Installation
37
+
38
+ Be sure to already have jquery in your project and then add this line to your application's Gemfile:
39
+
40
+ gem 'image-drop'
41
+
42
+ And then execute:
43
+
44
+ $ bundle
45
+
46
+ Or install it yourself as:
47
+
48
+ $ gem install image-drop
49
+
50
+ In your application.js add:
51
+
52
+ //= require image-drop
53
+
54
+ And your application.css add:
55
+
56
+ *= require image-drop
57
+ *= require image-drop_sample // optional
58
+
59
+ `image-drop_sample.css.scss` is a good looking example, but it's just there to give you an idea of how you might style the ImageDrop. I guess you could call this the theme file_field.
60
+
61
+ ## Usage
62
+
63
+ ImageDrop was designed to be super simple to get working. To be thorough, here are step-by-step instructions.
64
+
65
+ ### In Rails
66
+
67
+ ImageDrop expects a loose html structure. Just wrap the input field with a div. Add the `data-imagedrop` attribute to this div.
68
+
69
+ The input field may have an optional sibling div to act as the placeholder text. Here is an example:
70
+
71
+ <div id='avatar' style='background-image: url(<%= asset_path @user.avatar_url %>)'>
72
+ <div class='placeholder'>Drop an image here</div>
73
+ <%= f.file_field :avatar %>
74
+ </div>
75
+
76
+ This ERB uses the rails asset_path method to preload the avatar image should one already exist.
77
+
78
+ `div.placeholder` just contains a small snippet of text. The class name is not necessary but may be so if you need to style your placeholder. The placeholder may contain any content you wish but does not accept mouse and keyboard input.
79
+
80
+ Finally, initialize the image-drop by adding this to one of the js/coffeescript files in your project:
81
+
82
+ jQuery ->
83
+ avatar = new ImageDrop '#avatar'
84
+
85
+ ### Outside of Rails
86
+
87
+ The same HTML structure expectation applies whether inside or outside of Rails (so check that out above). You can extract the coffeescript file from this repo and convert it to vanilla javascript at [js2coffee.org](http://js2coffee.org) kindly written and hosted by [Rico Sta Cruz](http://ricostacruz.com/).
88
+
89
+ The SCSS stylesheet, both of them, can be converted to whitebread CSS at [SASSMeister](http://sassmeister.com/) brilliantly offered by (Jed Foster)[http://jedfoster.com/] and (Dale Sande)[http://www.dalesande.com/].
90
+
91
+ ## Alternatives
92
+
93
+ There are alternatives to ImageDrop. I wanted to keep things small and very simple. While experimenting, I found a cool way to let CSS do the heavy lifting. That may not be enough for your purposes. You might need to drop multiple files onto the same control, realtime back-end processing, or to display upload progress. Here are some:
94
+
95
+ * [jQuery File Upload](http://blueimp.github.io/jQuery-File-Upload/)
96
+
97
+ ## Contributing
98
+
99
+ 1. Fork it ( https://github.com/[my-github-username]/image-drop/fork )
100
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
101
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
102
+ 4. Push to the branch (`git push origin my-new-feature`)
103
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,57 @@
1
+ # imagedrop.js v0.0.2
2
+ # http://github/IAmNaN/image-drop
3
+ # Copyright (c) 2014 by Dave Gerton; Licensed MIT
4
+ #
5
+ # Good for avatars and such.
6
+ #
7
+ # Transforms simple file input fields (buttons) into sophisticated looking
8
+ # drag and drop targets complete with preview image and placeholder text.
9
+ #
10
+ # Nothing fancy, it uses css to change the the size and appearance any file
11
+ # input control in a form and positions preview and placeholder divs over
12
+ # the top. It uses js to show or hide the preview or placeholder given the
13
+ # current drag event.
14
+
15
+ jQuery ->
16
+ $('*[data-imagedrop]').each ->
17
+ new ImageDrop $(this)
18
+
19
+ class @ImageDrop
20
+ constructor: (element) ->
21
+ @element = element
22
+
23
+ $(@element).find('input[type="file"]').change ->
24
+ ImageDrop.readURL this
25
+
26
+ $(@element).on 'dragenter', (event) ->
27
+ $(this).addClass 'dragging'
28
+
29
+ $(@element).on 'dragleave', (event) ->
30
+ $(this).removeClass 'dragging'
31
+
32
+ $(@element).on 'drop', (event) ->
33
+ $(this).removeClass 'dragging'
34
+
35
+ @readURL: (input) ->
36
+ if input.files and input.files[0] and ImageDrop.checkFileType(input.files[0])
37
+ reader = new FileReader()
38
+
39
+ reader.target_elem = $(input).parent()
40
+ reader.onload = (e) ->
41
+
42
+ $(reader.target_elem).fadeOut 'fast', ->
43
+ $(reader.target_elem).attr 'style', 'background-image: url(' + e.target.result + ')'
44
+ $(reader.target_elem).fadeTo 1
45
+ return
46
+
47
+ reader.readAsDataURL input.files[0]
48
+ return
49
+
50
+ @checkFileType: (file) ->
51
+ ext = file.name.substring(file.name.lastIndexOf('.')).toLowerCase()
52
+ fileTypes = ".jpg , .png , .bmp, .gif , .webp , .svg"
53
+ if (fileTypes.toLowerCase().indexOf(ext) < 0)
54
+ alert("That doesn't appear to be an image file.")
55
+ false
56
+ else
57
+ true
@@ -0,0 +1,48 @@
1
+ // imagedrop.css v0.0.2
2
+ // http://github/IAmNaN/image-drop
3
+ // Copyright (c) 2014 by Dave Gerton; Licensed MIT
4
+ //
5
+ // Good for avatars and such.
6
+ //
7
+ // Transforms simple file input fields (buttons) into sophisticated looking
8
+ // drag and drop targets complete with preview image and placeholder text.
9
+ //
10
+ // Nothing fancy, it uses css to change the the size and appearance any file
11
+ // input control in a form and positions preview and placeholder divs over
12
+ // the top. It uses js to show or hide the preview or placeholder given the
13
+ // current drag event.
14
+ //
15
+ // Wrap the image's input field with a div. Reference this div to initialize
16
+ // the ImageDrop (not the input field itself). The input field may have an
17
+ // optional sibling div to act as the placeholder text. The placeholder may
18
+ // contain any content you wish but cannot accept mouse or keyboard input.
19
+ //
20
+ // These are the basic classes needed.
21
+
22
+ *[data-imagedrop] {
23
+ position: relative;
24
+ overflow: hidden;
25
+ background-size: cover;
26
+ background-position: center;
27
+ background-repeat: no-repeat;
28
+ div {
29
+ position: absolute;
30
+ z-index: 2;
31
+ opacity: 0;
32
+ top: 50%;
33
+ left: 50%;
34
+ transform: translateX(-50%) translateY(-50%);
35
+ }
36
+ input[type='file'] {
37
+ position: absolute;
38
+ top: 0;
39
+ left: 0;
40
+ width: 100%;
41
+ height: 100%;
42
+ z-index: 2;
43
+ opacity: 0;
44
+ }
45
+ &.dragging {
46
+ div { opacity: 1; }
47
+ }
48
+ }
@@ -0,0 +1,34 @@
1
+ // imagedrop_custom.css v0.0.2
2
+ // http://github/IAmNaN/image-drop
3
+ // Copyright (c) 2014 by Dave Gerton; Licensed MIT
4
+ //
5
+ // Good for avatars and such.
6
+ //
7
+ // Transforms simple file input fields (buttons) into sophisticated looking
8
+ // drag and drop targets complete with preview image and placeholder text.
9
+ //
10
+ // It is input field's the wrapper div that becomes the preview image. The
11
+ // background image of the div is set when a file is dropped on it. The div
12
+ // may be styled as you like but the styles in image-drop.css should not be
13
+ // modified as they are functional.
14
+ //
15
+ // This is a sample css customization file. It gives the image a 1:1 aspect
16
+ // ratio and turns it into a circle. It also gives size and shadow to the
17
+ // placeholder text.
18
+
19
+ *[data-imagedrop] {
20
+ height: 128px;
21
+ width: 128px;
22
+ background-color: #fff;
23
+ border-radius: 50%;
24
+ div {
25
+ width: 100%;
26
+ text-align: center;
27
+ margin: 0;
28
+ font-size: 1.5em;
29
+ font-weight: bold;
30
+ color: white;
31
+ text-shadow: 1px 1px 2px #000;
32
+ }
33
+ & > *{ transition: opacity 0.25s; }
34
+ }
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'imagedrop/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "imagedrop"
8
+ spec.version = Imagedrop::VERSION
9
+ spec.authors = ["Dave Gerton"]
10
+ spec.email = ["dgerton@gmail.com"]
11
+ spec.summary = %q{Good for avatars and such!}
12
+ spec.description = %q{Transforms the lowly file input field into a sophisticated looking drag and drop target, complete with preview image and placeholder text.}
13
+ spec.homepage = "https://github.com/IAmNaN/imagedrop"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,5 @@
1
+ require "imagedrop/engine"
2
+ require "imagedrop/version"
3
+
4
+ module Imagedrop
5
+ end
@@ -0,0 +1,4 @@
1
+ module Imagedrop
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module Imagedrop
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: imagedrop
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dave Gerton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-25 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Transforms the lowly file input field into a sophisticated looking drag
42
+ and drop target, complete with preview image and placeholder text.
43
+ email:
44
+ - dgerton@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - app/assets/javascript/imagedrop.js.coffee
55
+ - app/assets/stylesheets/imagedrop.css.scss
56
+ - app/assets/stylesheets/imagedrop_custom.css.scss
57
+ - imagedrop.gemspec
58
+ - lib/imagedrop.rb
59
+ - lib/imagedrop/engine.rb
60
+ - lib/imagedrop/version.rb
61
+ homepage: https://github.com/IAmNaN/imagedrop
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.2.2
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Good for avatars and such!
85
+ test_files: []