javascript.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. function Navigate(url){
  2. window.location=url;
  3. }
  4. function CreateCookie(name, value, days) {
  5. var expires;
  6. if (days) {
  7. var date = new Date();
  8. date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
  9. expires = "; expires=" + date.toGMTString();
  10. }
  11. else {
  12. expires = "";
  13. }
  14. document.cookie = name + "=" + value + expires + "; path=/";
  15. }
  16. $(function(){
  17. var panels=$("nav > dl > .sub-pages");
  18. var goIndicators=$("nav > dl > dt .go");
  19. var expandIndicators=$("nav > dl > dt .expand");
  20. panels.hide();
  21. expandIndicators.show();
  22. $("nav > dl > dt").click(function(e){
  23. var next=$(this).next();
  24. if (!next.hasClass("sub-pages") || next.is(":visible")){
  25. Navigate($(this).children("a").attr("href"));
  26. return;
  27. }
  28. panels.slideUp();
  29. goIndicators.hide();
  30. expandIndicators.show();
  31. next.slideDown();
  32. $(this).children(".go").show();
  33. $(this).children(".expand").hide();
  34. });
  35. $("nav > dl > dt").each(function(){
  36. if ($(this).next().hasClass("sub-pages"))
  37. $(this).attr("title", "Click once to expand, click again to go");
  38. });
  39. $("nav dd").click(function(e){
  40. Navigate($(this).children("a").attr("href"));
  41. });
  42. $("nav a").click(function(e){
  43. $(this).parent().click();
  44. return false;
  45. });
  46. $("#content").css("margin-bottom",window.innerHeight-$("#buttons").offset().top);
  47. $("#cookiePopup button").click(function(){
  48. $("#cookiePopup").fadeOut();
  49. CreateCookie("cookiePopupConfirmed",true,3650); // ten years should do it
  50. });
  51. $("#menu-button").click(function(e){
  52. $("#menu").show("slide", {direction: "left", easing:'easeOutCirc'});
  53. $("body>.backdrop").fadeIn();
  54. });
  55. $("body>.backdrop").click(function(e){
  56. $("#menu").hide("slide", {direction: "left", easing:'easeInCirc'});
  57. $("body>.backdrop").fadeOut();
  58. });
  59. });
  60. $(window).resize(function(e){
  61. if (window.innerWidth>1023){
  62. $("#menu").attr("style","");
  63. $("#menu-button").attr("style","");
  64. $("body>.backdrop").hide();
  65. }
  66. });
  67. $(document).delegate('.allowTabInput', 'keydown', function (e) {
  68. var keyCode = e.keyCode || e.which;
  69. console.log(e);
  70. if (keyCode == 9) {
  71. e.preventDefault();
  72. var start = $(this).get(0).selectionStart;
  73. var end = $(this).get(0).selectionEnd;
  74. // set textarea value to: text before caret + tab + text after caret
  75. $(this).val($(this).val().substring(0, start)
  76. + "\t"
  77. + $(this).val().substring(end));
  78. // put caret at right position again
  79. $(this).get(0).selectionStart =
  80. $(this).get(0).selectionEnd = start + 1;
  81. }
  82. });