Permalink
Browse files

Added image reader sources

  • Loading branch information...
1 parent 6594d4b commit fa3b96a4ca497640e3a8d25456d905c241881d28 @STRd6 STRd6 committed Jun 2, 2012
View
@@ -9,6 +9,7 @@ _yardoc
coverage
doc/
lib/bundler/man
+lib/assets/index.html
pkg
rdoc
spec/reports
View
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in jquery-image_reader.gemspec
gemspec
+
+gem "coffee-filter"
+gem "middleman", "~>3.0.0.beta.3"
+gem "therubyracer"
View
@@ -0,0 +1,79 @@
+###
+# Compass
+###
+
+# Susy grids in Compass
+# First: gem install compass-susy-plugin
+# require 'susy'
+
+# Change Compass configuration
+# compass_config do |config|
+# config.output_style = :compact
+# end
+
+###
+# Page options, layouts, aliases and proxies
+###
+
+# Per-page layout changes:
+#
+# With no layout
+# page "/path/to/file.html", :layout => false
+#
+# With alternative layout
+# page "/path/to/file.html", :layout => :otherlayout
+#
+# A path which all have the same layout
+# with_layout :admin do
+# page "/admin/*"
+# end
+
+# Proxy (fake) files
+# page "/this-page-has-no-template.html", :proxy => "/template-file.html" do
+# @which_fake_page = "Rendering a fake page with a variable"
+# end
+
+###
+# Helpers
+###
+
+# Automatic image dimensions on image_tag helper
+# activate :automatic_image_sizes
+
+# Methods defined in the helpers block are available in templates
+# helpers do
+# def some_helper
+# "Helping"
+# end
+# end
+
+set :css_dir, 'stylesheets'
+
+set :js_dir, 'javascripts'
+
+set :images_dir, 'images'
+
+set :build_dir, 'lib/assets'
+
+# Build-specific configuration
+configure :build do
+ # For example, change the Compass output style for deployment
+ # activate :minify_css
+
+ # Minify Javascript on build
+ # activate :minify_javascript
+
+ # Enable cache buster
+ # activate :cache_buster
+
+ # Use relative URLs
+ # activate :relative_assets
+
+ # Compress PNGs after build
+ # First: gem install middleman-smusher
+ # require "middleman-smusher"
+ # activate :smusher
+
+ # Or use a different image path
+ # set :http_path, "/Content/images/"
+end
@@ -14,4 +14,6 @@ Gem::Specification.new do |gem|
gem.name = "jquery-image_reader"
gem.require_paths = ["lib"]
gem.version = Jquery::ImageReader::VERSION
+
+ gem.add_dependency "jquery-source"
end
@@ -0,0 +1,58 @@
+(function() {
+
+ (function($) {
+ var defaults;
+ $.event.fix = (function(originalFix) {
+ return function(event) {
+ event = originalFix.apply(this, arguments);
+ if (event.type.indexOf('drag') === 0 || event.type.indexOf('drop') === 0) {
+ event.dataTransfer = event.originalEvent.dataTransfer;
+ }
+ return event;
+ };
+ })($.event.fix);
+ defaults = {
+ callback: $.noop,
+ matchType: /image.*/
+ };
+ return $.fn.dropImageReader = function(options) {
+ var stopFn;
+ if (typeof options === "function") {
+ options = {
+ callback: options
+ };
+ }
+ options = $.extend({}, defaults, options);
+ stopFn = function(event) {
+ event.stopPropagation();
+ return event.preventDefault();
+ };
+ return this.each(function() {
+ var $this, element;
+ element = this;
+ $this = $(this);
+ $this.bind('dragenter dragover dragleave', stopFn);
+ return $this.bind('drop', function(event) {
+ stopFn(event);
+ return Array.prototype.forEach.call(event.dataTransfer.files, function(file) {
+ var reader;
+ if (!file.type.match(options.matchType)) {
+ return;
+ }
+ reader = new FileReader();
+ reader.onload = function(evt) {
+ return options.callback.call(element, {
+ dataURL: evt.target.result,
+ event: evt,
+ file: file,
+ name: file.name
+ });
+ };
+ return reader.readAsDataURL(file);
+ });
+ });
+ });
+ };
+ })(jQuery);
+
+}).call(this);
@@ -0,0 +1,58 @@
+(function() {
+
+ (function($) {
+ var defaults;
+ $.event.fix = (function(originalFix) {
+ return function(event) {
+ event = originalFix.apply(this, arguments);
+ if (event.type.indexOf('copy') === 0 || event.type.indexOf('paste') === 0) {
+ event.clipboardData = event.originalEvent.clipboardData;
+ }
+ return event;
+ };
+ })($.event.fix);
+ defaults = {
+ callback: $.noop,
+ matchType: /image.*/
+ };
+ return $.fn.pasteImageReader = function(options) {
+ if (typeof options === "function") {
+ options = {
+ callback: options
+ };
+ }
+ options = $.extend({}, defaults, options);
+ return this.each(function() {
+ var $this, element;
+ element = this;
+ $this = $(this);
+ return $this.bind('paste', function(event) {
+ var clipboardData, found;
+ found = false;
+ clipboardData = event.clipboardData;
+ return Array.prototype.forEach.call(clipboardData.types, function(type, i) {
+ var file, reader;
+ if (found) {
+ return;
+ }
+ if (type.match(options.matchType) || clipboardData.items[i].type.match(options.matchType)) {
+ file = clipboardData.items[i].getAsFile();
+ reader = new FileReader();
+ reader.onload = function(evt) {
+ return options.callback.call(element, {
+ dataURL: evt.target.result,
+ event: evt,
+ file: file,
+ name: file.name
+ });
+ };
+ reader.readAsDataURL(file);
+ return found = true;
+ }
+ });
+ });
+ });
+ };
+ })(jQuery);
+
+}).call(this);
View
@@ -0,0 +1,16 @@
+!!!
+%html
+ %head
+ = javascript_include_tag "jquery"
+ = javascript_include_tag "jquery.drop_image_reader"
+ = javascript_include_tag "jquery.paste_image_reader"
+ %body
+
+ :coffeescript
+ $("html").pasteImageReader ({name, dataURL, file, event}) ->
+ $("body").css
+ backgroundImage: "url(\#{dataURL})"
+
+ $("html").dropImageReader ({name, dataURL, file, event}) ->
+ $("body").css
+ backgroundImage: "url(\#{dataURL})"
@@ -0,0 +1,51 @@
+(($) ->
+ $.event.fix = ((originalFix) ->
+ (event) ->
+ event = originalFix.apply(this, arguments)
+
+ if event.type.indexOf('drag') == 0 || event.type.indexOf('drop') == 0
+ event.dataTransfer = event.originalEvent.dataTransfer
+
+ event
+
+ )($.event.fix)
+
+ defaults =
+ callback: $.noop
+ matchType: /image.*/
+
+ $.fn.dropImageReader = (options) ->
+ if typeof options == "function"
+ options =
+ callback: options
+
+ options = $.extend({}, defaults, options)
+
+ stopFn = (event) ->
+ event.stopPropagation()
+ event.preventDefault()
+
+ this.each ->
+ element = this
+ $this = $(this)
+
+ $this.bind 'dragenter dragover dragleave', stopFn
+
+ $this.bind 'drop', (event) ->
+ stopFn(event)
+
+ Array::forEach.call event.dataTransfer.files, (file) ->
+ return unless file.type.match(options.matchType)
+
+ reader = new FileReader()
+
+ reader.onload = (evt) ->
+ options.callback.call element,
+ dataURL: evt.target.result
+ event: evt
+ file: file
+ name: file.name
+
+ reader.readAsDataURL(file)
+
+)(jQuery)
@@ -0,0 +1,51 @@
+(($) ->
+ $.event.fix = ((originalFix) ->
+ (event) ->
+ event = originalFix.apply(this, arguments)
+
+ if event.type.indexOf('copy') == 0 || event.type.indexOf('paste') == 0
+ event.clipboardData = event.originalEvent.clipboardData
+
+ return event
+
+ )($.event.fix)
+
+ defaults =
+ callback: $.noop
+ matchType: /image.*/
+
+ $.fn.pasteImageReader = (options) ->
+ if typeof options == "function"
+ options =
+ callback: options
+
+ options = $.extend({}, defaults, options)
+
+ this.each ->
+ element = this
+ $this = $(this)
+
+ $this.bind 'paste', (event) ->
+ found = false
+ clipboardData = event.clipboardData
+
+ Array::forEach.call clipboardData.types, (type, i) ->
+ return if found
+
+ if type.match(options.matchType) or clipboardData.items[i].type.match(options.matchType)
+ file = clipboardData.items[i].getAsFile()
+
+ reader = new FileReader()
+
+ reader.onload = (evt) ->
+ options.callback.call element,
+ dataURL: evt.target.result
+ event: evt
+ file: file
+ name: file.name
+
+ reader.readAsDataURL(file)
+
+ found = true
+
+)(jQuery)

0 comments on commit fa3b96a

Please sign in to comment.