点击图片的时候触发\statics\js\swfupload\swf2ckeditor.js
里面的flashupload()
函数。
onclick="flashupload('thumb_images', '附件上传','thumb',thumb_images,'1,jpg|jpeg|gif|png|bmp,1,,,0','content','20','673a7bdb2c201df7d3b78a7d5b9acd7a');return false;"
给该函数加上参数注解
/** * 上传功能 * @param uploadid dialog id * @param name dialog名称 * @param textareaid 最后数据返回插入的容器id * @param funcName 回调函数 * @param args 参数 * @param module 所属模块 * @param catid 栏目id * @param authkey 参数密钥,验证args */ function flashupload(uploadid, name, textareaid, funcName, args, module, catid, authkey) { var args = args ? '&args='+args : ''; var setting = '&module='+module+'&catid='+catid+'&authkey='+authkey; window.top.art.dialog({ title:name, id:uploadid, iframe:'index.php?m=attachment&c=attachments&a=swfupload'+args+setting,width:'500',height:'420' }, function(){ if(funcName) { funcName.apply(this,[uploadid,textareaid]); }else { submit_ckeditor(uploadid,textareaid); } }, function(){ window.top.art.dialog({id:uploadid}).close() }); }
把funcName
函数对象作为参数传入flashupload
函数,然后使用apply()
方法来实现funcName
函数的动态调用。关于apply的更多说明可以参考:http://mengkang.net/234.html
根据上面onclick
的事件代码可以知道回调了thumb_images
这个函数,该函数在/statics/js/content_addtop.js
里做了申明
function thumb_images(uploadid,returnid) { var d = window.top.art.dialog({id:uploadid}).data.iframe; var in_content = d.$("#att-status").html().substring(1); if(in_content=='') return false; if(!IsImg(in_content)) { alert('选择的类型必须为图片类型'); return false; } if($('#'+returnid+'_preview').attr('src')) { $('#'+returnid+'_preview').attr('src',in_content); } $('#'+returnid).val(in_content); }
我也也可以在这个回调函数里做一些自定义的操作,比如发送一个请求生成缩略图。
但是我后来发现还是到表单提交之后去生成缩略图,因为有在确定提交表单前可能会更换很多次。那么就无谓的生成了多余的缩略图了。而且对于采集而来的文章,缩略图已经生成好了,而不会去触发点击,所以也不会触发回调。所以还是放到最后服务端处理。