/** * created by zhangbo21 on 14-9-2. */ /* * getkfcontent : 将image的src从base64替换为文件名 * param : callback -- 回调函数 其参数为替换之后的内容 * return : void * */ ue.editor.prototype.getkfcontent = function(callback){ var me = this; var actionurl = me.getactionurl(me.getopt('scrawlactionname')), params = ue.utils.serializeparam(me.querycommandvalue('serverparam')) || '', url = ue.utils.formaturl(actionurl + (actionurl.indexof('?') == -1 ? '?':'&') + params); // 找到所有的base64 var count = 0; var imgs =me.body.getelementsbytagname('img'); var base64imgs = []; ue.utils.each(imgs, function(item){ var imgtype = item.getattribute('src').match(/^[^;]+/)[0]; if ( imgtype === 'data:image/png') { base64imgs.push(item); } }); if (base64imgs.length == 0){ execcallback(); } else { ue.utils.each(base64imgs, function(item){ var opt ={}; opt[me.getopt('scrawlfieldname')]= item.getattribute('src').replace(/^[^,]+,/, ''); opt.onsuccess = function(xhr){ var json = ue.utils.str2json(xhr.responsetext), url = me.options.scrawlurlprefix + json.url; item.setattribute('src', url); item.setattribute('_src', url); count++; execcallback(); } opt.onerror = function(err){ console.error(err); count++; execcallback(); } ue.ajax.request(url, opt); }); } function execcallback(){ if (count >= base64imgs.length) { ue.sync(); callback(me.getcontent()); } } };