From d1127b52dea9a04494ead620ea3217e9f6dec8ba Mon Sep 17 00:00:00 2001 From: Lizbeth Rika Date: Tue, 18 Nov 2014 15:02:59 +0000 Subject: [PATCH] Move over the old js. --- web/js/botania.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/web/js/botania.js b/web/js/botania.js index 8c8e3af0b..f73155928 100644 --- a/web/js/botania.js +++ b/web/js/botania.js @@ -1,3 +1,49 @@ $(function() { $.material.init(); -}); \ No newline at end of file +}); + +const censorChars = 'abcdefghijklmnopqrstuvwxyz'; +var animating = false; + +$(function() { + setInterval(changeCensor, 100); + + var hash = document.location.hash.substring(1); + var offset = $("#" + hash + "-fake").offset(); + if(offset != undefined) + $('html, body').animate({ scrollTop: offset.top - 100 }, 1000); +}); + +$('.hide-div').click(function() { + var divname = $(this).attr('id').substring('hide-'.length); + var div = $('#' + divname); + if(div.is(':visible')) { + div.hide(300); + $(this).text('(show)'); + } else { + div.show(300); + $(this).text('(hide)'); + } + +}); + +$(".hashlink").click(function() { + var hash = $(this).text(); + + if(hash == 'Back to top' || hash == '(back to top)') + $('html, body').animate({ scrollTop: 0 }, 500); + else $('html, body').animate({ scrollTop: $("#" + hash + "-fake").offset().top - 100 }, 1000); +}); + +function changeCensor() { + $('.censored').each(function() { + $(this).text(randomStr($(this).text().length)); + }); +} + +function randomStr(length) { + var str = ''; + for(var i = 0; i < length; i++) + str += censorChars.charAt(Math.floor(Math.random() * censorChars.length)); + return str; +} \ No newline at end of file