当前位置: 代码迷 >> Web前端 >> kindeditor 扩充,粘贴图片时,将图片保存,支持 ie和firefox
  详细解决方案

kindeditor 扩充,粘贴图片时,将图片保存,支持 ie和firefox

热度:811   发布时间:2012-11-10 10:48:50.0
kindeditor 扩展,粘贴图片时,将图片保存,支持 ie和firefox

kindeditor 扩展,粘贴图片时,将图片保存,支持 ie和firefox
<script type="text/javascript">
??? ??? KE.show({
??? ??? ??? id : 'content',
??? ??? ??? cssPath : 'kindeditor/index.css',
??? ??? ??? resizeMode:'0',
??? ??? ??? imageUploadJson:'<%=basePath%>imageUploadServlet',
??? ??? ??? fileManagerJson:'<%=basePath%>imageUploadServlet',
??? ??? ??? afterCreate : function(id) {
??? ??????????? /* 响应 ctrl + v ,保存图片
??? ??????????? KE.event.ctrl(document, 86, function() {
??? ??????????????? KE.util.setData(id);
??? ??????????? });
??? ??????????? KE.event.ctrl(KE.g[id].iframeDoc, 86, function() {
??? ??? ??? ??? ??? KE.util.setData(id);
??? ??? ??? ??? ??? var doc = KE.g[id].iframeDoc;
??? ??? ??? ??? ??? setTimeout(dealdoc(doc),100);
??? ??? ??? ??? });
??? ??? ??? ??? */
??? ??? ??? ??? //ie 中粘贴 --- 包括 toolbar 中 的粘贴和右键浏览器菜单中的粘贴
??? ??? ??? ??? KE.g[id].iframeDoc.body.onpaste = function (){
??? ??? ??? ??? ??? var doc = KE.g[id].iframeDoc;
??? ??? ??? ??? ??? setTimeout(dealdoc(doc),100);
??? ??? ??? ??? };
??? ??? ??? ??? //firefox? 粘贴 --- 包括 ctrl+v 和右键浏览器菜单中的粘贴
??? ??? ??? ??? $(KE.g[id].iframeDoc).bind('paste', null, function() {
?? ??? ??? ??? ??? ??? var doc = KE.g[id].iframeDoc;
??? ??? ??? ??? ??? setTimeout(dealdoc(doc),100);
??? ??? ??? ??? });
??? ?????? }
??? ??? });
??? ???
??? //屏蔽主页面中的右键菜单
??? ??? document.oncontextmenu = function (){
??? ??? ??? return false;
??? ??? }
??? ??? //返回 一个无参的方法,用于setTimeout
??? ??? function dealdoc(doc){
??? ??? ??? return function(){
??? ??? ??? ??? deal(doc);
??? ??? ??? }
??? ??? };

?

//粘贴时处理图片 - - 方法一:异步,只能接受一张图片
??? ??? function deal(doc){
??? ??? ??? var links = doc.getElementsByTagName("img");
??? ??? ??? for(var i=0;i<links.length;i++){
??? ??? ??? ??? var lin = $(links[i]);
??? ??? ??? ??? if($(lin).attr("add_src")){
??? ??? ??? ??? ??? ??? ???
??? ??? ??? ??? }else{
??? ??? ??? ??? ??? //links[i].src = "<c:url value='/saveImageServlet?

imageurl='/>"+links[i].src;
??? ??? ??? ??? ??? var imgurl = $(lin).attr("src");
??? ??? ??? ??? ??? $.ajax({
??? ??? ??? ??? ??? ???? ?type: "POST",
??? ??? ??? ??? ??? ??? ?url: "<c:url value='/saveImageServlet'/>",
??? ??? ??? ??? ??? ??? ?data: "imageurl="+imgurl,
??? ??? ??? ??? ??? ??? ?dataType:"html" , ???
??? ??? ??? ??? ??? ??? ?success:function(org){
??? ??? ??? ??? ??? ??? ???? $(lin).attr("src","");
??? ??? ??? ??? ??? ??? ???? $(lin).attr("src",org);
??? ??? ??? ??? ??? ??? ??? $(lin).attr("add_src","1");
??? ??? ??? ??? ??? ??? ?}
??? ??? ??? ??? ??? });
??? ??? ??? ??? ???
??? ??? ??? ??? }
??? ??? ??? }
??? ??? }

?

?


??? ??? //粘贴时处理图片-- 方法二:同步,可以接受多张图片
??? ??? function deal(doc){
??? ??? ??? var links = doc.getElementsByTagName("img");
??? ??? ??? for(var i=0;i<links.length;i++){
??? ??? ??? ??? var lin = $(links[i]);
??? ??? ??? ??? if($(lin).attr("add_src")){
??? ??? ??? ??? ??? ??? ???
??? ??? ??? ??? }else{
??? ??? ??? ??? ??? //links[i].src = "<c:url value='/saveImageServlet?

imageurl='/>"+links[i].src;
??? ??? ??? ??? ??? var imgurl = $(lin).attr("src");
??? ??? ??? ??? ??? var html = $.ajax({
??? ??? ??? ??? ??? ???? ?type: "POST",
??? ??? ??? ??? ??? ??? ?url: "<c:url value='/saveImageServlet'/>",
??? ??? ??? ??? ??? ??? ?data: "imageurl="+imgurl,
??? ??? ??? ??? ??? ??? ?dataType:"html" ,
??? ??? ??? ??? ??? ??? ?async: false ???
??? ??? ??? ??? ??? ??? ?
??? ??? ??? ??? ??? }).responseText;
??? ??? ??? ??? ??? $(lin).attr("src","");
??? ??? ??? ??? ??? $(lin).attr("src",html);
??? ??? ??? ??? ??? $(lin).attr("add_src","1");
??? ??? ??? ??? ???
??? ??? ??? ??? }
??? ??? ??? }
??? ??? }
??? </script>

?

参考 :http://zh-cn.w3support.net/index.php?db=so&id=441631

http://blog.csdn.net/nsrainbow/archive/2008/05/03/2370329.aspx

http://www.oschina.org/code/snippet_12_3291

?

?

?

  相关解决方案