diff --git a/app/views/bids/edit.html.erb b/app/views/bids/edit.html.erb index 37121d720..da3d19267 100644 --- a/app/views/bids/edit.html.erb +++ b/app/views/bids/edit.html.erb @@ -1,4 +1,4 @@ -<%= javascript_include_tag "/assets/kindeditor/kindeditor" %> +<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %> <%= labelled_form_for @bid,:html => { :multipart => true } do |f| %> <%= render :partial => 'new_homework_form', :locals => { :bid => @bid, :bid_id => "edit_bid_#{@bid.id}",:f=>f,:edit_mode => true} %> -<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/boards/show.html.erb b/app/views/boards/show.html.erb index 10383ff00..b49b4a960 100644 --- a/app/views/boards/show.html.erb +++ b/app/views/boards/show.html.erb @@ -34,7 +34,7 @@ else if (window.attachEvent) window.attachEvent("onload", buildsubmenus) -<%= javascript_include_tag "/assets/kindeditor/kindeditor" %> +<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %> <%#= javascript_include_tag "/assets/kindeditor/kindeditor-min" %> <% if @project %> @@ -227,4 +227,4 @@ function nh_init_board(params){ } - \ No newline at end of file + diff --git a/app/views/courses/_courses_jours.html.erb b/app/views/courses/_courses_jours.html.erb index 2cb22ce89..03adc2fd7 100644 --- a/app/views/courses/_courses_jours.html.erb +++ b/app/views/courses/_courses_jours.html.erb @@ -11,7 +11,7 @@ div.recall_con{width:570px;} div.recall_con .reply_btn{margin-left:525px;margin-top:5px;} -<%= javascript_include_tag "/assets/kindeditor/kindeditor" %> +<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %>
<%# reply_allow = JournalsForMessage.create_by_user? User.current %>

<%= l(:label_leave_message) %>

@@ -207,4 +207,4 @@ }); }); }); - \ No newline at end of file + diff --git a/app/views/forums/edit.html.erb b/app/views/forums/edit.html.erb index 9fe72fdb7..0a40120c7 100644 --- a/app/views/forums/edit.html.erb +++ b/app/views/forums/edit.html.erb @@ -1,4 +1,4 @@

编辑讨论区

-<%= javascript_include_tag "/assets/kindeditor/kindeditor" %> +<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %> <%= render 'form_edit_mode' %> diff --git a/app/views/forums/new.html.erb b/app/views/forums/new.html.erb index 35814d843..9bce17416 100644 --- a/app/views/forums/new.html.erb +++ b/app/views/forums/new.html.erb @@ -5,7 +5,7 @@ <% @nav_dispaly_forum_label = 1%>

<%= l :label_forum_new %>

-<%= javascript_include_tag "/assets/kindeditor/kindeditor" %> +<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %> <%= render 'form_create_mode' %> <%#= link_to l(:button_back), forums_path %> diff --git a/app/views/homework_common/edit.html.erb b/app/views/homework_common/edit.html.erb index f9d3f8b70..50feca946 100644 --- a/app/views/homework_common/edit.html.erb +++ b/app/views/homework_common/edit.html.erb @@ -1,4 +1,4 @@ -<%= javascript_include_tag "/assets/kindeditor/kindeditor" %> +<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %> <%= error_messages_for 'homework_common' %>
@@ -13,4 +13,4 @@ <%= link_to '取消',homework_common_index_path(:course => @course.id),:class => 'grey_btn fl'%> <% end%>
-
\ No newline at end of file +
diff --git a/app/views/homework_common/new.html.erb b/app/views/homework_common/new.html.erb index b0fdc5299..dc67b5079 100644 --- a/app/views/homework_common/new.html.erb +++ b/app/views/homework_common/new.html.erb @@ -1,4 +1,4 @@ -<%= javascript_include_tag "/assets/kindeditor/kindeditor" %> +<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %> <%= error_messages_for 'homework_common' %>
@@ -14,4 +14,4 @@ <%= link_to '取消',homework_common_index_path(:course => @course.id),:class => 'grey_btn fl'%> <% end%>
-
\ No newline at end of file +
diff --git a/app/views/issues/new.html.erb b/app/views/issues/new.html.erb index 77f3baf31..26aff7d61 100644 --- a/app/views/issues/new.html.erb +++ b/app/views/issues/new.html.erb @@ -1,4 +1,4 @@ -<%= javascript_include_tag "/assets/kindeditor/kindeditor" %> +<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %>

<%= l(:label_issue_new) %>

diff --git a/app/views/issues/show.html.erb b/app/views/issues/show.html.erb index 59ad0b1d2..1bd956074 100644 --- a/app/views/issues/show.html.erb +++ b/app/views/issues/show.html.erb @@ -1,4 +1,4 @@ -<%= javascript_include_tag "/assets/kindeditor/kindeditor" %> +<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %>

<%= l(:label_issue_edit) %>

diff --git a/app/views/layouts/base_forums.html.erb b/app/views/layouts/base_forums.html.erb index 4d79f50f9..fdeb609c8 100644 --- a/app/views/layouts/base_forums.html.erb +++ b/app/views/layouts/base_forums.html.erb @@ -12,7 +12,7 @@ <%= csrf_meta_tag %> <%= favicon %> - <%= javascript_include_tag "/assets/kindeditor/kindeditor" %> + <%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %> <%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2', 'application', 'nyan', :media => 'all' %> <%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %> <%= javascript_heads %> diff --git a/app/views/memos/edit.html.erb b/app/views/memos/edit.html.erb index b7aa08abd..6fc361d27 100644 --- a/app/views/memos/edit.html.erb +++ b/app/views/memos/edit.html.erb @@ -1,6 +1,6 @@ <% @replying = !@memo.parent.nil? %> -<%= javascript_include_tag "/assets/kindeditor/kindeditor" %> +<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %>

<%=l(:label_memo_edit)%>

<%= labelled_form_for(@memo, :url => forum_memo_path(@memo.forum_id, @memo)) do |f| %> <% if @memo.errors.any? %> diff --git a/app/views/memos/new.html.erb b/app/views/memos/new.html.erb index 8a1863047..792c8d55a 100644 --- a/app/views/memos/new.html.erb +++ b/app/views/memos/new.html.erb @@ -4,7 +4,7 @@ @nav_dispaly_main_contest_label = 1 %> <% @nav_dispaly_forum_label = 1%> -<%= javascript_include_tag "/assets/kindeditor/kindeditor" %> +<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %>
diff --git a/app/views/memos/show.html.erb b/app/views/memos/show.html.erb index 05358c32a..55a2410b0 100644 --- a/app/views/memos/show.html.erb +++ b/app/views/memos/show.html.erb @@ -4,7 +4,7 @@ margin-bottom: 13px; } -<%= javascript_include_tag "/assets/kindeditor/kindeditor" %> +<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %>
<%= render :partial => "/praise_tread/praise_tread",:locals => {:obj => @memo,:show_flag => true,:user_id =>User.current.id,:horizontal => true}%> diff --git a/app/views/messages/_form_course.html.erb b/app/views/messages/_form_course.html.erb index 1161e9f8a..7952e4820 100644 --- a/app/views/messages/_form_course.html.erb +++ b/app/views/messages/_form_course.html.erb @@ -1,4 +1,4 @@ -<%= javascript_include_tag "/assets/kindeditor/kindeditor" %> +<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %> <%= error_messages_for 'message' %> <% replying ||= false %> <% extra_option = replying ? { hidden: "hidden"} : { maxlength: 200 } %> diff --git a/app/views/news/_course_form.html.erb b/app/views/news/_course_form.html.erb index 1769c98f3..0a5488714 100644 --- a/app/views/news/_course_form.html.erb +++ b/app/views/news/_course_form.html.erb @@ -1,4 +1,4 @@ -<%= javascript_include_tag "/assets/kindeditor/kindeditor" %> +<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %>
  • @@ -37,4 +37,4 @@ <% end %>
  • - \ No newline at end of file + diff --git a/app/views/news/_course_show.html.erb b/app/views/news/_course_show.html.erb index 4d1242883..f39eb8266 100644 --- a/app/views/news/_course_show.html.erb +++ b/app/views/news/_course_show.html.erb @@ -1,4 +1,4 @@ -<%= javascript_include_tag "/assets/kindeditor/kindeditor" %> +<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %>

    <%= l(:label_course_news) %>

    @@ -76,4 +76,4 @@ <% end %> -<% html_title @news.title -%> \ No newline at end of file +<% html_title @news.title -%> diff --git a/app/views/news/_project_form.html.erb b/app/views/news/_project_form.html.erb index b9698497d..dfe1fb937 100644 --- a/app/views/news/_project_form.html.erb +++ b/app/views/news/_project_form.html.erb @@ -1,4 +1,4 @@ -<%= javascript_include_tag "/assets/kindeditor/kindeditor" %> +<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %>
  • @@ -33,4 +33,4 @@ <% end %>
  • - \ No newline at end of file + diff --git a/app/views/news/edit.html.erb b/app/views/news/edit.html.erb index 758976d1b..5fbae6f72 100644 --- a/app/views/news/edit.html.erb +++ b/app/views/news/edit.html.erb @@ -1,4 +1,4 @@ -<%= javascript_include_tag "/assets/kindeditor/kindeditor" %> +<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %>

    <%= l(:label_course_news) %>

    @@ -8,4 +8,4 @@ <%= render :partial => 'course_form', :locals => { :f => f, :is_new => false } %> <% end %>
    -
    \ No newline at end of file + diff --git a/app/views/projects/_project_jours.html.erb b/app/views/projects/_project_jours.html.erb index 353223acd..93974579f 100644 --- a/app/views/projects/_project_jours.html.erb +++ b/app/views/projects/_project_jours.html.erb @@ -11,7 +11,7 @@ div.recall_con{width:570px;} div.recall_con .reply_btn{margin-left:525px;margin-top:5px;} -<%= javascript_include_tag "/assets/kindeditor/kindeditor" %> +<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %>
    <% reply_allow = JournalsForMessage.create_by_user? User.current %>

    <%= l(:label_user_response) %>

    @@ -196,4 +196,4 @@ }); }); }); - \ No newline at end of file + diff --git a/app/views/users/_user_jours.html.erb b/app/views/users/_user_jours.html.erb index ee8d14841..aeb3a71ea 100644 --- a/app/views/users/_user_jours.html.erb +++ b/app/views/users/_user_jours.html.erb @@ -11,7 +11,7 @@ div.recall_con{width:600px;} div.recall_con .reply_btn{margin-left:555px;margin-top:5px;} -<%= javascript_include_tag "/assets/kindeditor/kindeditor" %> +<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %>
    <% reply_allow = JournalsForMessage.create_by_user? User.current %> diff --git a/lib/rails_kindeditor/lib/rails_kindeditor/helper.rb b/lib/rails_kindeditor/lib/rails_kindeditor/helper.rb index 1f4c867ba..d5f91ebf8 100644 --- a/lib/rails_kindeditor/lib/rails_kindeditor/helper.rb +++ b/lib/rails_kindeditor/lib/rails_kindeditor/helper.rb @@ -16,7 +16,8 @@ module RailsKindeditor input_html = input_html.merge(style: 'display:none') output_buffer = ActiveSupport::SafeBuffer.new output_buffer << build_text_area_tag(name, method, self, options, input_html) - output_buffer << javascript_tag(js_replace(input_html['id'],options.merge(window_onload: 'true'))) + output_buffer << javascript_tag(js_replace(input_html['id'],options.merge(window_onload: 'true', + afterCreate: 'eval(function(){enablePasteImg(self);})'))) end def kindeditor_upload_json_path(*args) @@ -52,12 +53,12 @@ module RailsKindeditor "var old_onload_#{random_name}; if(typeof window.onload == 'function') old_onload_#{random_name} = window.onload; window.onload = function() { - #{editor_id}KindEditor.create('##{dom_id}', #{get_options(options).to_json}).loadPlugin('paste'); + #{editor_id}KindEditor.create('##{dom_id}', #{get_options(options).to_json}); if(old_onload_#{random_name}) old_onload_#{random_name}(); }" else "KindEditor.ready(function(K){ - #{editor_id}K.create('##{dom_id}', #{get_options(options).to_json}).loadPlugin('paste'); + #{editor_id}K.create('##{dom_id}', #{get_options(options).to_json}); });" end end diff --git a/public/assets/kindeditor/kindeditor.js b/public/assets/kindeditor/kindeditor.js index 1695b10f7..a9633861e 100644 --- a/public/assets/kindeditor/kindeditor.js +++ b/public/assets/kindeditor/kindeditor.js @@ -5097,6 +5097,9 @@ KEditor.prototype = { } self.afterCreate(); if (self.options.afterCreate) { + if (typeof self.options.afterCreate == 'string'){ + self.options.afterCreate = eval(self.options.afterCreate); + } self.options.afterCreate.call(self); } } diff --git a/public/assets/kindeditor/pasteimg.js b/public/assets/kindeditor/pasteimg.js new file mode 100644 index 000000000..c413bbcb9 --- /dev/null +++ b/public/assets/kindeditor/pasteimg.js @@ -0,0 +1,385 @@ +// Generated by CoffeeScript 1.9.0 + +/* +paste.js is an interface to read data ( text / image ) from clipboard in different browsers. It also contains several hacks. +https://github.com/layerssss/paste.js + */ + +(function() { + var $, Paste, createHiddenEditable, dataURLtoBlob; + + $ = window.jQuery; + + $.paste = function(pasteContainer) { + var pm; + if (typeof console !== "undefined" && console !== null) { + console.log("DEPRECATED: This method is deprecated. Please use $.fn.pastableNonInputable() instead."); + } + pm = Paste.mountNonInputable(pasteContainer); + return pm._container; + }; + + $.fn.pastableNonInputable = function() { + var el, _i, _len; + for (_i = 0, _len = this.length; _i < _len; _i++) { + el = this[_i]; + Paste.mountNonInputable(el); + } + return this; + }; + + $.fn.pastableTextarea = function() { + var el, _i, _len; + for (_i = 0, _len = this.length; _i < _len; _i++) { + el = this[_i]; + Paste.mountTextarea(el); + } + return this; + }; + + $.fn.pastableContenteditable = function() { + var el, _i, _len; + for (_i = 0, _len = this.length; _i < _len; _i++) { + el = this[_i]; + Paste.mountContenteditable(el); + } + return this; + }; + + dataURLtoBlob = function(dataURL, sliceSize) { + var b64Data, byteArray, byteArrays, byteCharacters, byteNumbers, contentType, i, m, offset, slice, _ref; + if (sliceSize == null) { + sliceSize = 512; + } + if (!(m = dataURL.match(/^data\:([^\;]+)\;base64\,(.+)$/))) { + return null; + } + _ref = m, m = _ref[0], contentType = _ref[1], b64Data = _ref[2]; + byteCharacters = atob(b64Data); + byteArrays = []; + offset = 0; + while (offset < byteCharacters.length) { + slice = byteCharacters.slice(offset, offset + sliceSize); + byteNumbers = new Array(slice.length); + i = 0; + while (i < slice.length) { + byteNumbers[i] = slice.charCodeAt(i); + i++; + } + byteArray = new Uint8Array(byteNumbers); + byteArrays.push(byteArray); + offset += sliceSize; + } + return new Blob(byteArrays, { + type: contentType + }); + }; + + createHiddenEditable = function() { + return $(document.createElement('div')).attr('contenteditable', true).css({ + width: 1, + height: 1, + position: 'fixed', + left: -100, + overflow: 'hidden' + }); + }; + + Paste = (function() { + Paste.prototype._target = null; + + Paste.prototype._container = null; + + Paste.mountNonInputable = function(nonInputable) { + var paste; + paste = new Paste(createHiddenEditable().appendTo(nonInputable), nonInputable); + $(nonInputable).on('click', (function(_this) { + return function() { + return paste._container.focus(); + }; + })(this)); + paste._container.on('focus', (function(_this) { + return function() { + return $(nonInputable).addClass('pastable-focus'); + }; + })(this)); + return paste._container.on('blur', (function(_this) { + return function() { + return $(nonInputable).removeClass('pastable-focus'); + }; + })(this)); + }; + + Paste.mountTextarea = function(textarea) { + var ctlDown, paste; + if (-1 !== navigator.userAgent.toLowerCase().indexOf('chrome')) { + return this.mountContenteditable(textarea); + } + paste = new Paste(createHiddenEditable().insertBefore(textarea), textarea); + ctlDown = false; + $(textarea).on('keyup', function(ev) { + var _ref; + if ((_ref = ev.keyCode) === 17 || _ref === 224) { + return ctlDown = false; + } + }); + $(textarea).on('keydown', function(ev) { + var _ref; + if ((_ref = ev.keyCode) === 17 || _ref === 224) { + ctlDown = true; + } + if (ctlDown && ev.keyCode === 86) { + return paste._container.focus(); + } + }); + $(paste._target).on('pasteImage', (function(_this) { + return function() { + return $(textarea).focus(); + }; + })(this)); + $(paste._target).on('pasteText', (function(_this) { + return function() { + return $(textarea).focus(); + }; + })(this)); + $(textarea).on('focus', (function(_this) { + return function() { + return $(textarea).addClass('pastable-focus'); + }; + })(this)); + return $(textarea).on('blur', (function(_this) { + return function() { + return $(textarea).removeClass('pastable-focus'); + }; + })(this)); + }; + + Paste.mountContenteditable = function(contenteditable) { + var paste; + paste = new Paste(contenteditable, contenteditable); + $(contenteditable).on('focus', (function(_this) { + return function() { + return $(contenteditable).addClass('pastable-focus'); + }; + })(this)); + return $(contenteditable).on('blur', (function(_this) { + return function() { + return $(contenteditable).removeClass('pastable-focus'); + }; + })(this)); + }; + + function Paste(_at__container, _at__target) { + this._container = _at__container; + this._target = _at__target; + this._container = $(this._container); + this._target = $(this._target).addClass('pastable'); + this._container.on('paste', (function(_this) { + return function(ev) { + var clipboardData, file, item, reader, text, _i, _j, _len, _len1, _ref, _ref1, _ref2, _ref3, _results; + if (((_ref = ev.originalEvent) != null ? _ref.clipboardData : void 0) != null) { + clipboardData = ev.originalEvent.clipboardData; + if (clipboardData.items) { + _ref1 = clipboardData.items; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + item = _ref1[_i]; + if (item.type.match(/^image\//)) { + reader = new FileReader(); + reader.onload = function(event) { + return _this._handleImage(event.target.result); + }; + reader.readAsDataURL(item.getAsFile()); + } + if (item.type === 'text/plain') { + item.getAsString(function(string) { + return _this._target.trigger('pasteText', { + text: string + }); + }); + } + } + } else { + if (-1 !== Array.prototype.indexOf.call(clipboardData.types, 'text/plain')) { + text = clipboardData.getData('Text'); + _this._target.trigger('pasteText', { + text: text + }); + } + _this._checkImagesInContainer(function(src) { + return _this._handleImage(src); + }); + } + } + if (clipboardData = window.clipboardData) { + if ((_ref2 = (text = clipboardData.getData('Text'))) != null ? _ref2.length : void 0) { + return _this._target.trigger('pasteText', { + text: text + }); + } else { + _ref3 = clipboardData.files; + _results = []; + for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) { + file = _ref3[_j]; + _this._handleImage(URL.createObjectURL(file)); + _results.push(_this._checkImagesInContainer(function() {})); + } + return _results; + } + } + }; + })(this)); + } + + Paste.prototype._handleImage = function(src) { + var loader; + loader = new Image(); + loader.onload = (function(_this) { + return function() { + var blob, canvas, ctx, dataURL; + canvas = document.createElement('canvas'); + canvas.width = loader.width; + canvas.height = loader.height; + ctx = canvas.getContext('2d'); + ctx.drawImage(loader, 0, 0, canvas.width, canvas.height); + dataURL = null; + try { + dataURL = canvas.toDataURL('image/png'); + blob = dataURLtoBlob(dataURL); + } catch (_error) {} + if (dataURL) { + return _this._target.trigger('pasteImage', { + blob: blob, + dataURL: dataURL, + width: loader.width, + height: loader.height + }); + } + }; + })(this); + return loader.src = src; + }; + + Paste.prototype._checkImagesInContainer = function(cb) { + var img, timespan, _i, _len, _ref; + timespan = Math.floor(1000 * Math.random()); + _ref = this._container.find('img'); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + img = _ref[_i]; + img["_paste_marked_" + timespan] = true; + } + return setTimeout((function(_this) { + return function() { + var _j, _len1, _ref1, _results; + _ref1 = _this._container.find('img'); + _results = []; + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + img = _ref1[_j]; + if (!img["_paste_marked_" + timespan]) { + cb(img.src); + } + _results.push($(img).remove()); + } + return _results; + }; + })(this), 1); + }; + + return Paste; + + })(); + +}).call(this); + +function enablePasteImg(_editor) { + var editor = _editor, + name = 'paste'; + //òƶ༭Ͳͻ + if(editor.edit == undefined || editor.edit.iframe == undefined){ + return; + } + var contentWindow = editor.edit.iframe[0].contentWindow; + //var contentWindow = editor.iframeDoc; + //var contentWindow = document.getElementsByTagName('iframe')[0].contentWindow; + var nodeBody = contentWindow.document.getElementsByTagName('body')[0]; + console.log(nodeBody); + $(nodeBody).pastableContenteditable(); + + dataURItoBlob = function(dataURI) { + // convert base64/URLEncoded data component to raw binary data held in a string + var byteString; + if (dataURI.split(',')[0].indexOf('base64') >= 0) + byteString = atob(dataURI.split(',')[1]); + else + byteString = unescape(dataURI.split(',')[1]); + + // separate out the mime component + var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]; + + // write the bytes of the string to a typed array + var ia = new Uint8Array(byteString.length); + for (var i = 0; i < byteString.length; i++) { + ia[i] = byteString.charCodeAt(i); + } + + return new Blob([ia], {type:mimeString}); + }; + + $(nodeBody).on('pasteImage', function(ev, data) { + console.log('pasteImage'); + console.log("dataURL: " + data.dataURL); + console.log("width: " + data.width); + console.log("height: " + data.height); + console.log(data.blob); + var blob = dataURItoBlob(data.dataURL); + if (data.blob !== null) { + var data = new FormData(); + data.append("imgFile",blob, "imageFilename.png"); + console.log(data); + $.ajax({ + url: '/kindeditor/upload?dir=image', + contentType: false, + type: 'POST', + data: data, + processData: false, + success: function(data) { + editor.exec('insertimage', JSON.parse(data).url); + } + }); + } + + }); + return; + contentWindow.document.getElementsByTagName('body')[0].onpaste = function(event) { + // use event.originalEvent.clipboard for newer chrome versions + var items = (event.clipboardData || event.originalEvent.clipboardData).items; + console.log(JSON.stringify(items)); // will give you the mime types + // find pasted image among pasted items + var blob = null; + for (var i = 0; i < items.length; i++) { + if (items[i].type.indexOf("image") === 0) { + blob = items[i].getAsFile(); + } + } + // load image if there is a pasted image + if (blob !== null) { + var reader = new FileReader(); + reader.onload = function(event) { + console.log(event.target.result); // data url! + var data = new FormData(); + data.append("imgFile", blob, "imageFilename.png"); + console.log(blob); + $.ajax({ + url: '/kindeditor/upload?dir=image', + contentType: false, + type: 'POST', + data: data, + processData: false, + success: function(data) { + editor.exec('insertimage', JSON.parse(data).url); + } + }); + }; + reader.readAsDataURL(blob); + } + } +};