您的位置:首页 > 产品设计 > UI/UE

Ueditor处理微信图片

2016-01-06 18:17 337 查看
微信图文素材中的图片不允许外链

在结合使用百度编辑器时,总结了一个插件

修复了在外部网站中,不能显示微信图片的问题

附代码,使用百度编辑器时,可以直接引入。

/**
* @author Cai
*/

UE.plugins.wximage =
function() {

var u = baidu;
var a = this
, c = u.editor.ui
, b = u.editor.dom.domUtils;

function strip_stack_span(html) {
var docObj = $('<div>' + html + '</div>');
docObj.find('li,colgroup,a').each(function() {
if ($.trim($(this).text()) == "" && $(this).find('img').size() == 0) {
$(this).remove();
}
}
);
var has_secspan = false;
do
{
has_secspan = false;
docObj.find('span:has(span)').each(function(i) {
var innerobj = $(this).find('> span');
if (innerobj.size() > 1) {
$(this).find('span').each(function() {
if ($.trim($(this).text()) == "") {
$(this).replaceWith($(this).html());
}
}
)
return;
}
else if (innerobj.size() == 0) {
return;
}
if ($.trim($(this).text()) == $.trim(innerobj.text())) {
has_secspan = true;
var style = $(this).attr('style');
var innserstyle = innerobj.attr('style');
var newStyle = '';
if (style && style != "") {
newStyle += ';' + style;
}
if (innserstyle && innserstyle != "") {
newStyle += ';' + innserstyle;
}
var new_html = '';
$(this).find('> *').each(function() {
if (this.tagName == "SPAN") {
new_html += $(innerobj).html();
}
else {
new_html += $(this).prop('outerHTML');
}
}
);
$(this).attr('style', newStyle).html(new_html);
}
}
);
} while (has_secspan);return docObj.html();
}

a.addListener("beforepaste", function(b, c, g) {
b = c.html;
"function" == typeof strip_stack_span && (b = strip_stack_span(b));
b = $("<div>" + b + "</div>");
b.find("img").each(function() {
var a = ""
, a = this.src && "" != this.src ? this.src :
$(this).attr("data-src");
$(this).removeAttr("data-src");
"undefined" == typeof a || "" == a ? $(this).remove() : (a = a.replace(/http:\/\/mmbiz.qpic.cn/g, "https://mmbiz.qlogo.cn"),
a = a.replace(/https:\/\/mmbiz.qpic.cn/g, "https://mmbiz.qlogo.cn"),
a = a.replace(/http:\/\/mmbiz.qlogo.cn/g, "https://mmbiz.qlogo.cn"),
a = a.replace(/&wxfrom=\d+/g, ""),
a = a.replace(/wxfrom=\d+/g, ""),
a = a.replace(/&wx_lazy=\d+/g, ""),
a = a.replace(/wx_lazy=\d+/g, ""),
a = a.replace(/&tp=[a-z]+/g, ""),
a = a.replace(/tp=[a-z]+/g, ""),
a = a.replace(/\?&/g, "?"),
$(this).attr("src", a),
$(this).attr("_src", a))
}
);
c.html = b.html()
}
);

}
;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: