From 3175616573a9346f8ae2731a8a963b28c42224c3 Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Mon, 10 Oct 2016 20:32:20 +0800 Subject: Update to support showing owner on the infobar --- public/js/extra.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'public/js/extra.js') diff --git a/public/js/extra.js b/public/js/extra.js index 77f298f9..6c2e2d4a 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -7,6 +7,7 @@ var lastchangeui = { user: $(".ui-lastchangeuser"), nouser: $(".ui-no-lastchangeuser") } +var ownerui = $(".ui-owner"); function updateLastChange() { if (!lastchangeui) return; @@ -41,6 +42,23 @@ function updateLastChangeUser() { } } +var owner = null; +var ownerprofile = null; +function updateOwner() { + if (ownerui) { + if (owner && ownerprofile && owner !== lastchangeuser) { + var icon = ownerui.children('i'); + icon.attr('title', ownerprofile.name).tooltip('fixTitle'); + var styleString = 'background-image:url(' + ownerprofile.photo + ')'; + if (ownerprofile.photo && icon.attr('style') !== styleString) + icon.attr('style', styleString); + ownerui.show(); + } else { + ownerui.hide(); + } + } +} + //get title function getTitle(view) { var title = ""; -- cgit v1.2.3 From 1d1eedce7ee8c2bd776b45afc2ccb5d626394db4 Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Mon, 10 Oct 2016 20:45:49 +0800 Subject: Improve syntax highlighting performance by moving it to finish view --- public/js/extra.js | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) (limited to 'public/js/extra.js') diff --git a/public/js/extra.js b/public/js/extra.js index 6c2e2d4a..4a6c4a67 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -435,6 +435,33 @@ function finishView(view) { height: '400px' }); }); + //syntax highlighting + view.find("pre.raw").removeClass("raw") + .each(function (key, value) { + var langDiv = $(value).find('code.hljs'); + if (langDiv.length > 0) { + var reallang = langDiv[0].className.replace('hljs', '').trim(); + var codeDiv = $(value).find('.code'); + var code = ""; + if (codeDiv.length > 0) code = codeDiv.html(); + else code = langDiv.html(); + code = md.utils.unescapeAll(code); + if (reallang == "tiddlywiki" || reallang == "mediawiki") { + var result = { + value: Prism.highlight(code, Prism.languages.wiki) + }; + } else { + var languages = hljs.listLanguages(); + if (languages.indexOf(reallang) == -1) { + var result = hljs.highlightAuto(code); + } else { + var result = hljs.highlight(reallang, code); + } + } + if (codeDiv.length > 0) codeDiv.html(result.value); + else langDiv.html(result.value); + } + }); //render title document.title = renderTitle(view); } @@ -772,19 +799,9 @@ function highlightRender(code, lang) { } else if (lang == 'mermaid') { return '
' + code + '
'; } - var reallang = lang.replace(/\=$|\=\d+$|\=\+$/, ''); - if (reallang == "tiddlywiki" || reallang == "mediawiki") { - var result = { - value: Prism.highlight(code, Prism.languages.wiki) - }; - } else { - var languages = hljs.listLanguages(); - if (languages.indexOf(reallang) == -1) { - var result = hljs.highlightAuto(code); - } else { - var result = hljs.highlight(reallang, code); - } - } + var result = { + value: code + }; var showlinenumbers = /\=$|\=\d+$|\=\+$/.test(lang); if (showlinenumbers) { var startnumber = 1; @@ -878,7 +895,7 @@ md.renderer.rules.fence = function (tokens, idx, options, env, self) { return highlighted + '\n'; } - return '
'
+    return  '
'
         + highlighted
         + '
\n'; }; -- cgit v1.2.3