jquery-image_reader 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +8 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +8 -0
- data/config.rb +79 -0
- data/jquery-image_reader.gemspec +19 -0
- data/lib/assets/javascripts/jquery.drop_image_reader.js +58 -0
- data/lib/assets/javascripts/jquery.paste_image_reader.js +58 -0
- data/lib/jquery-image_reader/version.rb +5 -0
- data/lib/jquery-image_reader.rb +7 -0
- data/source/index.html.haml +16 -0
- data/source/javascripts/jquery.drop_image_reader.js.coffee +51 -0
- data/source/javascripts/jquery.paste_image_reader.js.coffee +51 -0
- metadata +71 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Daniel X. Moore
|
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
|
+
# Jquery::ImageReader
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'jquery-image_reader'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install jquery-image_reader
|
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 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/config.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
###
|
2
|
+
# Compass
|
3
|
+
###
|
4
|
+
|
5
|
+
# Susy grids in Compass
|
6
|
+
# First: gem install compass-susy-plugin
|
7
|
+
# require 'susy'
|
8
|
+
|
9
|
+
# Change Compass configuration
|
10
|
+
# compass_config do |config|
|
11
|
+
# config.output_style = :compact
|
12
|
+
# end
|
13
|
+
|
14
|
+
###
|
15
|
+
# Page options, layouts, aliases and proxies
|
16
|
+
###
|
17
|
+
|
18
|
+
# Per-page layout changes:
|
19
|
+
#
|
20
|
+
# With no layout
|
21
|
+
# page "/path/to/file.html", :layout => false
|
22
|
+
#
|
23
|
+
# With alternative layout
|
24
|
+
# page "/path/to/file.html", :layout => :otherlayout
|
25
|
+
#
|
26
|
+
# A path which all have the same layout
|
27
|
+
# with_layout :admin do
|
28
|
+
# page "/admin/*"
|
29
|
+
# end
|
30
|
+
|
31
|
+
# Proxy (fake) files
|
32
|
+
# page "/this-page-has-no-template.html", :proxy => "/template-file.html" do
|
33
|
+
# @which_fake_page = "Rendering a fake page with a variable"
|
34
|
+
# end
|
35
|
+
|
36
|
+
###
|
37
|
+
# Helpers
|
38
|
+
###
|
39
|
+
|
40
|
+
# Automatic image dimensions on image_tag helper
|
41
|
+
# activate :automatic_image_sizes
|
42
|
+
|
43
|
+
# Methods defined in the helpers block are available in templates
|
44
|
+
# helpers do
|
45
|
+
# def some_helper
|
46
|
+
# "Helping"
|
47
|
+
# end
|
48
|
+
# end
|
49
|
+
|
50
|
+
set :css_dir, 'stylesheets'
|
51
|
+
|
52
|
+
set :js_dir, 'javascripts'
|
53
|
+
|
54
|
+
set :images_dir, 'images'
|
55
|
+
|
56
|
+
set :build_dir, 'lib/assets'
|
57
|
+
|
58
|
+
# Build-specific configuration
|
59
|
+
configure :build do
|
60
|
+
# For example, change the Compass output style for deployment
|
61
|
+
# activate :minify_css
|
62
|
+
|
63
|
+
# Minify Javascript on build
|
64
|
+
# activate :minify_javascript
|
65
|
+
|
66
|
+
# Enable cache buster
|
67
|
+
# activate :cache_buster
|
68
|
+
|
69
|
+
# Use relative URLs
|
70
|
+
# activate :relative_assets
|
71
|
+
|
72
|
+
# Compress PNGs after build
|
73
|
+
# First: gem install middleman-smusher
|
74
|
+
# require "middleman-smusher"
|
75
|
+
# activate :smusher
|
76
|
+
|
77
|
+
# Or use a different image path
|
78
|
+
# set :http_path, "/Content/images/"
|
79
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/jquery-image_reader/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Daniel X. Moore"]
|
6
|
+
gem.email = ["yahivin@gmail.com"]
|
7
|
+
gem.description = %q{A couple of jquery plugins that allow easy binding of file drop and paste events specially targeting getting image data.}
|
8
|
+
gem.summary = %q{Paste and Drop images into web apps}
|
9
|
+
gem.homepage = "https://github.com/STRd6/jquery-image_reader"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "jquery-image_reader"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Jquery::ImageReader::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "jquery-source"
|
19
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
(function() {
|
2
|
+
|
3
|
+
(function($) {
|
4
|
+
var defaults;
|
5
|
+
$.event.fix = (function(originalFix) {
|
6
|
+
return function(event) {
|
7
|
+
event = originalFix.apply(this, arguments);
|
8
|
+
if (event.type.indexOf('drag') === 0 || event.type.indexOf('drop') === 0) {
|
9
|
+
event.dataTransfer = event.originalEvent.dataTransfer;
|
10
|
+
}
|
11
|
+
return event;
|
12
|
+
};
|
13
|
+
})($.event.fix);
|
14
|
+
defaults = {
|
15
|
+
callback: $.noop,
|
16
|
+
matchType: /image.*/
|
17
|
+
};
|
18
|
+
return $.fn.dropImageReader = function(options) {
|
19
|
+
var stopFn;
|
20
|
+
if (typeof options === "function") {
|
21
|
+
options = {
|
22
|
+
callback: options
|
23
|
+
};
|
24
|
+
}
|
25
|
+
options = $.extend({}, defaults, options);
|
26
|
+
stopFn = function(event) {
|
27
|
+
event.stopPropagation();
|
28
|
+
return event.preventDefault();
|
29
|
+
};
|
30
|
+
return this.each(function() {
|
31
|
+
var $this, element;
|
32
|
+
element = this;
|
33
|
+
$this = $(this);
|
34
|
+
$this.bind('dragenter dragover dragleave', stopFn);
|
35
|
+
return $this.bind('drop', function(event) {
|
36
|
+
stopFn(event);
|
37
|
+
return Array.prototype.forEach.call(event.dataTransfer.files, function(file) {
|
38
|
+
var reader;
|
39
|
+
if (!file.type.match(options.matchType)) {
|
40
|
+
return;
|
41
|
+
}
|
42
|
+
reader = new FileReader();
|
43
|
+
reader.onload = function(evt) {
|
44
|
+
return options.callback.call(element, {
|
45
|
+
dataURL: evt.target.result,
|
46
|
+
event: evt,
|
47
|
+
file: file,
|
48
|
+
name: file.name
|
49
|
+
});
|
50
|
+
};
|
51
|
+
return reader.readAsDataURL(file);
|
52
|
+
});
|
53
|
+
});
|
54
|
+
});
|
55
|
+
};
|
56
|
+
})(jQuery);
|
57
|
+
|
58
|
+
}).call(this);
|
@@ -0,0 +1,58 @@
|
|
1
|
+
(function() {
|
2
|
+
|
3
|
+
(function($) {
|
4
|
+
var defaults;
|
5
|
+
$.event.fix = (function(originalFix) {
|
6
|
+
return function(event) {
|
7
|
+
event = originalFix.apply(this, arguments);
|
8
|
+
if (event.type.indexOf('copy') === 0 || event.type.indexOf('paste') === 0) {
|
9
|
+
event.clipboardData = event.originalEvent.clipboardData;
|
10
|
+
}
|
11
|
+
return event;
|
12
|
+
};
|
13
|
+
})($.event.fix);
|
14
|
+
defaults = {
|
15
|
+
callback: $.noop,
|
16
|
+
matchType: /image.*/
|
17
|
+
};
|
18
|
+
return $.fn.pasteImageReader = function(options) {
|
19
|
+
if (typeof options === "function") {
|
20
|
+
options = {
|
21
|
+
callback: options
|
22
|
+
};
|
23
|
+
}
|
24
|
+
options = $.extend({}, defaults, options);
|
25
|
+
return this.each(function() {
|
26
|
+
var $this, element;
|
27
|
+
element = this;
|
28
|
+
$this = $(this);
|
29
|
+
return $this.bind('paste', function(event) {
|
30
|
+
var clipboardData, found;
|
31
|
+
found = false;
|
32
|
+
clipboardData = event.clipboardData;
|
33
|
+
return Array.prototype.forEach.call(clipboardData.types, function(type, i) {
|
34
|
+
var file, reader;
|
35
|
+
if (found) {
|
36
|
+
return;
|
37
|
+
}
|
38
|
+
if (type.match(options.matchType) || clipboardData.items[i].type.match(options.matchType)) {
|
39
|
+
file = clipboardData.items[i].getAsFile();
|
40
|
+
reader = new FileReader();
|
41
|
+
reader.onload = function(evt) {
|
42
|
+
return options.callback.call(element, {
|
43
|
+
dataURL: evt.target.result,
|
44
|
+
event: evt,
|
45
|
+
file: file,
|
46
|
+
name: file.name
|
47
|
+
});
|
48
|
+
};
|
49
|
+
reader.readAsDataURL(file);
|
50
|
+
return found = true;
|
51
|
+
}
|
52
|
+
});
|
53
|
+
});
|
54
|
+
});
|
55
|
+
};
|
56
|
+
})(jQuery);
|
57
|
+
|
58
|
+
}).call(this);
|
@@ -0,0 +1,16 @@
|
|
1
|
+
!!!
|
2
|
+
%html
|
3
|
+
%head
|
4
|
+
= javascript_include_tag "jquery"
|
5
|
+
= javascript_include_tag "jquery.drop_image_reader"
|
6
|
+
= javascript_include_tag "jquery.paste_image_reader"
|
7
|
+
%body
|
8
|
+
|
9
|
+
:coffeescript
|
10
|
+
$("html").pasteImageReader ({name, dataURL, file, event}) ->
|
11
|
+
$("body").css
|
12
|
+
backgroundImage: "url(\#{dataURL})"
|
13
|
+
|
14
|
+
$("html").dropImageReader ({name, dataURL, file, event}) ->
|
15
|
+
$("body").css
|
16
|
+
backgroundImage: "url(\#{dataURL})"
|
@@ -0,0 +1,51 @@
|
|
1
|
+
(($) ->
|
2
|
+
$.event.fix = ((originalFix) ->
|
3
|
+
(event) ->
|
4
|
+
event = originalFix.apply(this, arguments)
|
5
|
+
|
6
|
+
if event.type.indexOf('drag') == 0 || event.type.indexOf('drop') == 0
|
7
|
+
event.dataTransfer = event.originalEvent.dataTransfer
|
8
|
+
|
9
|
+
event
|
10
|
+
|
11
|
+
)($.event.fix)
|
12
|
+
|
13
|
+
defaults =
|
14
|
+
callback: $.noop
|
15
|
+
matchType: /image.*/
|
16
|
+
|
17
|
+
$.fn.dropImageReader = (options) ->
|
18
|
+
if typeof options == "function"
|
19
|
+
options =
|
20
|
+
callback: options
|
21
|
+
|
22
|
+
options = $.extend({}, defaults, options)
|
23
|
+
|
24
|
+
stopFn = (event) ->
|
25
|
+
event.stopPropagation()
|
26
|
+
event.preventDefault()
|
27
|
+
|
28
|
+
this.each ->
|
29
|
+
element = this
|
30
|
+
$this = $(this)
|
31
|
+
|
32
|
+
$this.bind 'dragenter dragover dragleave', stopFn
|
33
|
+
|
34
|
+
$this.bind 'drop', (event) ->
|
35
|
+
stopFn(event)
|
36
|
+
|
37
|
+
Array::forEach.call event.dataTransfer.files, (file) ->
|
38
|
+
return unless file.type.match(options.matchType)
|
39
|
+
|
40
|
+
reader = new FileReader()
|
41
|
+
|
42
|
+
reader.onload = (evt) ->
|
43
|
+
options.callback.call element,
|
44
|
+
dataURL: evt.target.result
|
45
|
+
event: evt
|
46
|
+
file: file
|
47
|
+
name: file.name
|
48
|
+
|
49
|
+
reader.readAsDataURL(file)
|
50
|
+
|
51
|
+
)(jQuery)
|
@@ -0,0 +1,51 @@
|
|
1
|
+
(($) ->
|
2
|
+
$.event.fix = ((originalFix) ->
|
3
|
+
(event) ->
|
4
|
+
event = originalFix.apply(this, arguments)
|
5
|
+
|
6
|
+
if event.type.indexOf('copy') == 0 || event.type.indexOf('paste') == 0
|
7
|
+
event.clipboardData = event.originalEvent.clipboardData
|
8
|
+
|
9
|
+
return event
|
10
|
+
|
11
|
+
)($.event.fix)
|
12
|
+
|
13
|
+
defaults =
|
14
|
+
callback: $.noop
|
15
|
+
matchType: /image.*/
|
16
|
+
|
17
|
+
$.fn.pasteImageReader = (options) ->
|
18
|
+
if typeof options == "function"
|
19
|
+
options =
|
20
|
+
callback: options
|
21
|
+
|
22
|
+
options = $.extend({}, defaults, options)
|
23
|
+
|
24
|
+
this.each ->
|
25
|
+
element = this
|
26
|
+
$this = $(this)
|
27
|
+
|
28
|
+
$this.bind 'paste', (event) ->
|
29
|
+
found = false
|
30
|
+
clipboardData = event.clipboardData
|
31
|
+
|
32
|
+
Array::forEach.call clipboardData.types, (type, i) ->
|
33
|
+
return if found
|
34
|
+
|
35
|
+
if type.match(options.matchType) or clipboardData.items[i].type.match(options.matchType)
|
36
|
+
file = clipboardData.items[i].getAsFile()
|
37
|
+
|
38
|
+
reader = new FileReader()
|
39
|
+
|
40
|
+
reader.onload = (evt) ->
|
41
|
+
options.callback.call element,
|
42
|
+
dataURL: evt.target.result
|
43
|
+
event: evt
|
44
|
+
file: file
|
45
|
+
name: file.name
|
46
|
+
|
47
|
+
reader.readAsDataURL(file)
|
48
|
+
|
49
|
+
found = true
|
50
|
+
|
51
|
+
)(jQuery)
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jquery-image_reader
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Daniel X. Moore
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-02 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: jquery-source
|
16
|
+
requirement: &18049760 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *18049760
|
25
|
+
description: A couple of jquery plugins that allow easy binding of file drop and paste
|
26
|
+
events specially targeting getting image data.
|
27
|
+
email:
|
28
|
+
- yahivin@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- .gitignore
|
34
|
+
- Gemfile
|
35
|
+
- LICENSE
|
36
|
+
- README.md
|
37
|
+
- Rakefile
|
38
|
+
- config.rb
|
39
|
+
- jquery-image_reader.gemspec
|
40
|
+
- lib/assets/javascripts/jquery.drop_image_reader.js
|
41
|
+
- lib/assets/javascripts/jquery.paste_image_reader.js
|
42
|
+
- lib/jquery-image_reader.rb
|
43
|
+
- lib/jquery-image_reader/version.rb
|
44
|
+
- source/index.html.haml
|
45
|
+
- source/javascripts/jquery.drop_image_reader.js.coffee
|
46
|
+
- source/javascripts/jquery.paste_image_reader.js.coffee
|
47
|
+
homepage: https://github.com/STRd6/jquery-image_reader
|
48
|
+
licenses: []
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.8.10
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: Paste and Drop images into web apps
|
71
|
+
test_files: []
|