summaryrefslogtreecommitdiff
path: root/frontend/static/js/debug.js
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/static/js/debug.js')
-rw-r--r--frontend/static/js/debug.js130
1 files changed, 130 insertions, 0 deletions
diff --git a/frontend/static/js/debug.js b/frontend/static/js/debug.js
new file mode 100644
index 0000000..1a3339f
--- /dev/null
+++ b/frontend/static/js/debug.js
@@ -0,0 +1,130 @@
+var d =
+ {
+ DEBUG: false,
+ act: function (s)
+ {
+ // $('#msg').append('<strong>'+s+'</strong><br/>')
+ // d.scrollToBottom("#msg")
+ // if (d.DEBUG)
+ // console.log(s)
+ return false
+ },
+ joy: function (s)
+ {
+ // $('#msg').append('<b>'+s+'</b><br/>')
+ // d.scrollToBottom("#msg")
+ // if (d.DEBUG)
+ // console.log(s)
+ return false
+ },
+ warn: function (s)
+ {
+ // $('#msg').append(s+'<br/>')
+ // d.scrollToBottom("#msg")
+ // if (d.DEBUG)
+ // console.log(s)
+ return false
+ },
+ error: function (s)
+ {
+ // $('#msg').append('<em>ERROR: '+s+'</em><br/>')
+ // d.scrollToBottom("#msg")
+ // console.log(s)
+ return false
+ },
+ noop: function () {},
+ scrollToTop: function (elem)
+ {
+ $(elem).scrollTop( 0 )
+ },
+ scrollToBottom: function (elem)
+ {
+ try
+ {
+ $(elem).scrollTop( $(elem)[0].scrollHeight )
+ }
+ catch (err)
+ {
+ }
+ },
+ pageUp: function (div)
+ {
+ var st = $(div).scrollTop()
+ var h = $(window).height()
+ d.warn("PAGEUP: "+st+" "+h)
+ $(div).scrollTop( st - (2/3) * h )
+ var st = $(div).scrollTop()
+ d.warn("ST NOW: "+st+" "+h)
+ },
+ pageDown: function (div)
+ {
+ var st = $(div).scrollTop()
+ var h = $(window).height()
+ $(div).scrollTop( st + (2/3) * h )
+ },
+ choice: function (list)
+ {
+ return list[Math.floor (Math.random () * list.length)]
+ },
+ trim: function (s)
+ {
+ if (s)
+ return s.replace(/^\s+|\s+$/g,"")
+ else
+ return ""
+ },
+ sanitizeWithNewlines: function (s)
+ {
+ if (s)
+ return d.trim( s ).replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\"/g,"&quot;").replace(/\0/g,"")
+ return ""
+ },
+ sanitize: function (s)
+ {
+ if (s)
+ return d.trim( s ).replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\"/g,"&quot;").replace(/\n/g,"").replace(/\r/g,"").replace(/\0/g,"")
+ return ""
+ },
+ linkify: function (s)
+ {
+ var words = s.split(" ")
+ var checked = []
+ for (i in words)
+ {
+ var word = words[i]
+ if (words[i].indexOf("http") === 0)
+ {
+ var poffset = word.indexOf('//')
+ var linktext = word.substr(poffset+2, word.indexOf('/', poffset+2))
+ checked.push('<a href="'+word+'" target="_blank">'+linktext+'</a>')
+ }
+ else
+ checked.push(word)
+ }
+ return checked.join(" ")
+ },
+ enableStylesheet: function (style)
+ {
+ $("link[@rel*=style][title]").each(function (i)
+ {
+ if (this.getAttribute('title') == style)
+ this.disabled = false
+ })
+ },
+ disableStylesheet: function (style)
+ {
+ $("link[@rel*=style][title]").each(function (i)
+ {
+ if (this.getAttribute('title') == style)
+ this.disabled = true
+ })
+ },
+ buildLookup: function (list)
+ {
+ var lookup = {}
+ for (var i = 0; i < list.length; i++)
+ lookup[list[i]] = true
+ return lookup
+ }
+ }
+