From e0b0b2f976c61225a178c7715caf2656a1f6741f Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Sat, 15 Dec 2018 21:32:51 +0100 Subject: moving stuff --- old/server/app/static/js/util.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 old/server/app/static/js/util.js (limited to 'old/server/app/static/js/util.js') diff --git a/old/server/app/static/js/util.js b/old/server/app/static/js/util.js new file mode 100644 index 00000000..851f634a --- /dev/null +++ b/old/server/app/static/js/util.js @@ -0,0 +1,32 @@ +var is_iphone = (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) +var is_ipad = (navigator.userAgent.match(/iPad/i)) +var is_android = (navigator.userAgent.match(/Android/i)) +var is_mobile = is_iphone || is_ipad || is_android +var is_desktop = ! is_mobile; + +document.body.parentNode.classList.add(is_desktop ? 'desktop' : 'mobile') + +function preventDefault(e){ + e.preventDefault() + e.stopPropagation() +} + +var decodeEntities = (function() { + // this prevents any overhead from creating the object each time + var element = document.createElement('div'); + + function decodeHTMLEntities (str) { + if(str && typeof str === 'string') { + // strip script/html tags + str = str.replace(/]*>([\S\s]*?)<\/script>/gmi, ''); + str = str.replace(/<\/?\w(?:[^"'>]|"[^"]*"|'[^']*')*>/gmi, ''); + element.innerHTML = str; + str = element.textContent; + element.textContent = ''; + } + + return str; + } + + return decodeHTMLEntities; +})(); \ No newline at end of file -- cgit v1.2.3-70-g09d2