Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7939987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:15:08+00:00 2026-06-03T23:15:08+00:00

How do I develop a working example using this plugin: HTML5 JavaScript Pasting Image

  • 0

How do I develop a working example using this plugin: HTML5 JavaScript Pasting Image Data in Chrome

The author has put together a great example that seems like it would suit our purposes. I’m not familiar with creating a jQuery plugin however.

The goal will be to use this plugin to paste clipboard images into a rich text editor such as TinyMCE.

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>PASTE IMAGE</title>

<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.18.custom.min.js"></script>
<script type="text/javascript">

// Created by STRd6
// MIT License
// jquery.paste_image_reader.js
(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.*/
};

$.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);

  $this.bind('paste', function(event) {
    var clipboardData, found;
    found = false;
    clipboardData = event.clipboardData;

    Array.prototype.forEach.call(clipboardData.types, function(type, i) {
      var file, reader;
      if (found) {
        return;
      }

      if (!type.match(options.matchType)) {
        return;
      }

      file = clipboardData.items[i].getAsFile();
      reader = new FileReader();

      reader.onload = function(evt) {
        options.callback.call(element, {
          filename: file.name,
          dataURL: evt.target.result
        });
      };
      reader.readAsDataURL(file);
      found = true;
    });
  });
});
 };
 })(jQuery);


$("html").pasteImageReader (results) -> 
    {filename, dataURL} = results

$("body").css
    backgroundImage: "url(#{dataURL})"

</script>
</head>

<body>
</body>
</html>

I’m confused by the plugin call:

$("html").pasteImageReader (results) -> 
    {filename, dataURL} = results

$("body").css
    backgroundImage: "url(#{dataURL})"

That doesn’t look like jQuery that I’ve seen. Is it specific to the plugin itself? Any guidance would be greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T23:15:09+00:00Added an answer on June 3, 2026 at 11:15 pm

    Those last calls are in CoffeeScript, a language that compiles into JavaScript. (http://coffeescript.org)

    $("html").pasteImageReader (results) -> 
        {filename, dataURL} = results
    
    $("body").css
        backgroundImage: "url(#{dataURL})"
    

    Im no expert – in fact i’ve never used coffeescript at all – but It would compile to:

    $("html").pasteImageReader(function(results) {
      var dataURL, filename;
      return filename = results.filename, dataURL = results.dataURL, results;
    });
    
    $("body").css({
      backgroundImage: "url(" + dataURL + ")"
    });
    

    That would probably work, but I dont like how its formatted. Here’s some cleaner code.

    $("html").pasteImageReader(function(result){
         $("body").css({backgroundImage: "url("+result.dataURL+")"});
    });
    

    Give that a shot, and see if you can make it work for you!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working to develop an application that has to query at some time, a
When using source control, the way I am used to working is to develop
We are currently using SVN to develop an internal application that has most of
Ive been trying to get an example Web Service working using SpringWS and Tomcat5.5
Quick background, I am using Netbeans to develop this (I don't have much experience
I'm using a src less iframe to develop a javascript widget to protect my
So working on getting my eclipse IDE going so I can develop my arduino
I'm working with a CMS which allows you to develop your own custom controls
I am working on Xcode 4.2 and i am trying to develop split view.
I am willing to develop a mobile application. I wish to have something working

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.