Last active
December 14, 2018 11:10
-
-
Save yumetodo/5dccaec278f7250bde02c9419ae13946 to your computer and use it in GitHub Desktop.
improve message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener("DOMContentLoaded", () => { | |
"use strict"; | |
Array.from(document.getElementsByClassName("math-render")) | |
.filter(e => !e.mathRendered) | |
.forEach(e => { | |
try { | |
katex.render(e.textContent, e, {displayMode: true }); | |
} catch (ex) { | |
e.textContent = ex.message; | |
} | |
}); | |
Array.from(document.getElementsByClassName("entry-content")).forEach(e => { | |
renderMathInElement(e, { delimiters: [ | |
{ left: "$$", right: "$$", display: true }, | |
{ left: "$", right: "$", display: false } | |
]}); | |
}); | |
//http://developer.hateblo.jp/entry/2014/11/06/jQueryUI | |
function alertDialog(_options){ | |
var default_option = { | |
title:"", | |
body:"", | |
close: function(){ return true; } | |
} | |
var options = $.extend(default_option , _options, {}); | |
var dom = $("<div />", { title: options.title, html: options.body }); | |
dom.dialog({ | |
modal: true, | |
close: function(){ | |
var dom = $(this); | |
dom.dialog("destroy"); | |
dom.remove(); | |
options.close(); | |
}, | |
buttons: [{ | |
text: "Ok", | |
click: function() { | |
$(this).dialog("close"); | |
} | |
}] | |
}); | |
}; | |
Array.from(document.getElementsByClassName("katex")).forEach(e => { | |
const isTouch = (('ontouchstart' in window) || (navigator.MaxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0)); | |
const tooltip = (isTouch) ? "touch again to watch tex" : "long press to watch tex"; | |
//for microtip | |
//https://github.com/ghosh/microtip | |
e.setAttribute("aria-label", tooltip); | |
e.setAttribute("data-microtip-position", "up"); | |
e.setAttribute("role", "tooltip"); | |
const an = e.getElementsByTagName("annotation"); | |
if(0 === an.length) return; | |
if (isTouch) { | |
let counter = 0; | |
let timer = 0; | |
e.addEventListener("touchstart", () => { | |
if(0 !== timer) clearTimeout(timer); | |
++counter; | |
timer = setTimeout(() => { | |
counter = 0; | |
}, 10 * 1000); | |
if(2 === counter) { | |
counter = 0; | |
alertDialog({title:"tex",body:an[0].textContent}); | |
} | |
}); | |
} | |
//using https://github.com/john-doherty/long-press | |
e.addEventListener("long-press", ev => { | |
ev.preventDefault(); | |
alert(an[0].textContent); | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener("DOMContentLoaded",()=>{"use strict";Array.from(document.getElementsByClassName("math-render")).filter(t=>!t.mathRendered).forEach(t=>{try{katex.render(t.textContent,t,{displayMode:!0})}catch(e){t.textContent=e.message}}),Array.from(document.getElementsByClassName("entry-content")).forEach(t=>{renderMathInElement(t,{delimiters:[{left:"$$",right:"$$",display:!0},{left:"$",right:"$",display:!1}]})}),Array.from(document.getElementsByClassName("katex")).forEach(t=>{const e="ontouchstart"in window||navigator.MaxTouchPoints>0||navigator.msMaxTouchPoints>0,o=e?"touch again to watch tex":"long press to watch tex";t.setAttribute("aria-label",o),t.setAttribute("data-microtip-position","up"),t.setAttribute("role","tooltip");const n=t.getElementsByTagName("annotation");if(0!==n.length){if(e){let e=0,o=0;t.addEventListener("touchstart",()=>{0!==o&&clearTimeout(o),++e,o=setTimeout(()=>{e=0},1e4),2===e&&(e=0,function(t){var e=$.extend({title:"",body:"",close:function(){return!0}},t,{});$("<div />",{title:e.title,html:e.body}).dialog({modal:!0,close:function(){var t=$(this);t.dialog("destroy"),t.remove(),e.close()},buttons:[{text:"Ok",click:function(){$(this).dialog("close")}}]})}({title:"tex",body:n[0].textContent}))})}t.addEventListener("long-press",t=>{t.preventDefault(),alert(n[0].textContent)})}})}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment