How to create a working example using this plugin: HTML5 JavaScript Insert images in Chrome
The author has compiled a great example that seems to be suitable for our purposes. However, I am not familiar with creating a jQuery plugin.
The goal is to use this plugin to paste clipboard images into an extended 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>
The plugin call confuses me:
$("html").pasteImageReader (results) -> {filename, dataURL} = results $("body").css backgroundImage: "url(#{dataURL})"
This is not like the jQuery I saw. Is this specific to the plugin itself? Any guidance would be greatly appreciated!
source share