diff options
author | Wu Cheng-Han | 2015-07-02 20:29:31 +0800 |
---|---|---|
committer | Wu Cheng-Han | 2015-07-02 20:29:31 +0800 |
commit | f8ef5341c70a2aee6b22751eebc500ed24c7825f (patch) | |
tree | c179325c94fe94df8e0a8071b3f555895210c570 /public/js | |
parent | 71303791a6edaf5d4b3923115ec898ea49a1b135 (diff) |
Optimized image rendering, avoid duplicated image load when content changed
Diffstat (limited to 'public/js')
-rw-r--r-- | public/js/extra.js | 9 | ||||
-rw-r--r-- | 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 f6d47647..084ebe8a 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 = $('<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 48829a4a..2ed3ff03 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 = $('<img' + src + alt + title + suffix + '>'); - image[0].onload = function (e) { - if (viewAjaxCallback) - viewAjaxCallback(); - }; - return image[0].outerHTML; -}; + return '<img class="raw"' + src + alt + title + suffix + '>'; +} md.renderer.rules.fence = function (tokens, idx, options, env, self) { var token = tokens[idx]; |