From f8ef5341c70a2aee6b22751eebc500ed24c7825f Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Thu, 2 Jul 2015 20:29:31 +0800 Subject: [PATCH] Optimized image rendering, avoid duplicated image load when content changed --- public/js/extra.js | 9 +++++++-- public/js/syncscroll.js | 9 ++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/public/js/extra.js b/public/js/extra.js index f6d476472..084ebe8a9 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -128,7 +128,7 @@ function finishView(view) { } }); //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) { var src = $(value).attr('src'); var a = $(''); @@ -136,7 +136,12 @@ function finishView(view) { a.attr('href', src); 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); }); //blockquote diff --git a/public/js/syncscroll.js b/public/js/syncscroll.js index 48829a4ae..2ed3ff030 100644 --- a/public/js/syncscroll.js +++ b/public/js/syncscroll.js @@ -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 alt = ' alt="' + (tokens[idx].alt ? Remarkable.utils.escapeHtml(Remarkable.utils.replaceEntities(tokens[idx].alt)) : '') + '"'; var suffix = options.xhtmlOut ? ' /' : ''; - var image = $(''); - image[0].onload = function (e) { - if (viewAjaxCallback) - viewAjaxCallback(); - }; - return image[0].outerHTML; -}; + return ''; +} md.renderer.rules.fence = function (tokens, idx, options, env, self) { var token = tokens[idx];