Optimized image rendering, avoid duplicated image load when content changed

This commit is contained in:
Wu Cheng-Han 2015-07-02 20:29:31 +08:00
parent 71303791a6
commit f8ef5341c7
2 changed files with 9 additions and 9 deletions

View file

@ -128,7 +128,7 @@ function finishView(view) {
} }
}); });
//image href new window(emoji not included) //image href new window(emoji not included)
var images = view.find("p > img[src]:not([class])"); var images = view.find("img.raw[src]").removeClass("raw");
images.each(function (key, value) { images.each(function (key, value) {
var src = $(value).attr('src'); var src = $(value).attr('src');
var a = $('<a>'); var a = $('<a>');
@ -136,7 +136,12 @@ function finishView(view) {
a.attr('href', src); a.attr('href', src);
a.attr('target', "_blank"); a.attr('target', "_blank");
} }
a.html($(value).clone()); var clone = $(value).clone();
clone[0].onload = function (e) {
if(viewAjaxCallback)
viewAjaxCallback();
};
a.html(clone);
$(value).replaceWith(a); $(value).replaceWith(a);
}); });
//blockquote //blockquote

View file

@ -74,13 +74,8 @@ md.renderer.rules.image = function (tokens, idx, options /*, env */ ) {
var title = tokens[idx].title ? (' title="' + Remarkable.utils.escapeHtml(Remarkable.utils.replaceEntities(tokens[idx].title)) + '"') : ''; var title = tokens[idx].title ? (' title="' + Remarkable.utils.escapeHtml(Remarkable.utils.replaceEntities(tokens[idx].title)) + '"') : '';
var alt = ' alt="' + (tokens[idx].alt ? Remarkable.utils.escapeHtml(Remarkable.utils.replaceEntities(tokens[idx].alt)) : '') + '"'; var alt = ' alt="' + (tokens[idx].alt ? Remarkable.utils.escapeHtml(Remarkable.utils.replaceEntities(tokens[idx].alt)) : '') + '"';
var suffix = options.xhtmlOut ? ' /' : ''; var suffix = options.xhtmlOut ? ' /' : '';
var image = $('<img' + src + alt + title + suffix + '>'); return '<img class="raw"' + src + alt + title + suffix + '>';
image[0].onload = function (e) { }
if (viewAjaxCallback)
viewAjaxCallback();
};
return image[0].outerHTML;
};
md.renderer.rules.fence = function (tokens, idx, options, env, self) { md.renderer.rules.fence = function (tokens, idx, options, env, self) {
var token = tokens[idx]; var token = tokens[idx];