trumbowyg.pasteimage.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* ===========================================================
  2. * trumbowyg.pasteimage.js v1.0
  3. * Basic base64 paste plugin for Trumbowyg
  4. * http://alex-d.github.com/Trumbowyg
  5. * ===========================================================
  6. * Author : Alexandre Demode (Alex-D)
  7. * Twitter : @AlexandreDemode
  8. * Website : alex-d.fr
  9. */
  10. (function ($) {
  11. 'use strict';
  12. $.extend(true, $.trumbowyg, {
  13. plugins: {
  14. pasteImage: {
  15. init: function (trumbowyg) {
  16. trumbowyg.pasteHandlers.push(function (pasteEvent) {
  17. try {
  18. var items = (pasteEvent.originalEvent || pasteEvent).clipboardData.items,
  19. reader;
  20. for (var i = items.length - 1; i >= 0; i -= 1) {
  21. if (items[i].type.match(/^image\//)) {
  22. reader = new FileReader();
  23. /* jshint -W083 */
  24. reader.onloadend = function (event) {
  25. trumbowyg.execCmd('insertImage', event.target.result, false, true);
  26. };
  27. /* jshint +W083 */
  28. reader.readAsDataURL(items[i].getAsFile());
  29. }
  30. }
  31. } catch (c) {
  32. }
  33. });
  34. }
  35. }
  36. }
  37. });
  38. })(jQuery);