You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

170 lines
7.1 KiB

  1. var menuHidden = true;
  2. var randBgTimer = null;
  3. // Simulates PHP's date function - http://jacwright.com/projects/javascript/date_format/
  4. Date.prototype.format=function(e){var t="";var n=Date.replaceChars;for(var r=0;r<e.length;r++){var i=e.charAt(r);if(r-1>=0&&e.charAt(r-1)=="\\"){t+=i}else if(n[i]){t+=n[i].call(this)}else if(i!="\\"){t+=i}}return t};Date.replaceChars={shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],longMonths:["January","February","March","April","May","June","July","August","September","October","November","December"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],longDays:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],d:function(){return(this.getDate()<10?"0":"")+this.getDate()},D:function(){return Date.replaceChars.shortDays[this.getDay()]},j:function(){return this.getDate()},l:function(){return Date.replaceChars.longDays[this.getDay()]},N:function(){return this.getDay()+1},S:function(){return this.getDate()%10==1&&this.getDate()!=11?"st":this.getDate()%10==2&&this.getDate()!=12?"nd":this.getDate()%10==3&&this.getDate()!=13?"rd":"th"},w:function(){return this.getDay()},z:function(){var e=new Date(this.getFullYear(),0,1);return Math.ceil((this-e)/864e5)},W:function(){var e=new Date(this.getFullYear(),0,1);return Math.ceil(((this-e)/864e5+e.getDay()+1)/7)},F:function(){return Date.replaceChars.longMonths[this.getMonth()]},m:function(){return(this.getMonth()<9?"0":"")+(this.getMonth()+1)},M:function(){return Date.replaceChars.shortMonths[this.getMonth()]},n:function(){return this.getMonth()+1},t:function(){var e=new Date;return(new Date(e.getFullYear(),e.getMonth(),0)).getDate()},L:function(){var e=this.getFullYear();return e%400==0||e%100!=0&&e%4==0},o:function(){var e=new Date(this.valueOf());e.setDate(e.getDate()-(this.getDay()+6)%7+3);return e.getFullYear()},Y:function(){return this.getFullYear()},y:function(){return(""+this.getFullYear()).substr(2)},a:function(){return this.getHours()<12?"am":"pm"},A:function(){return this.getHours()<12?"AM":"PM"},B:function(){return Math.floor(((this.getUTCHours()+1)%24+this.getUTCMinutes()/60+this.getUTCSeconds()/3600)*1e3/24)},g:function(){return this.getHours()%12||12},G:function(){return this.getHours()},h:function(){return((this.getHours()%12||12)<10?"0":"")+(this.getHours()%12||12)},H:function(){return(this.getHours()<10?"0":"")+this.getHours()},i:function(){return(this.getMinutes()<10?"0":"")+this.getMinutes()},s:function(){return(this.getSeconds()<10?"0":"")+this.getSeconds()},u:function(){var e=this.getMilliseconds();return(e<10?"00":e<100?"0":"")+e},e:function(){return"Not Yet Supported"},I:function(){var e=null;for(var t=0;t<12;++t){var n=new Date(this.getFullYear(),t,1);var r=n.getTimezoneOffset();if(e===null)e=r;else if(r<e){e=r;break}else if(r>e)break}return this.getTimezoneOffset()==e|0},O:function(){return(-this.getTimezoneOffset()<0?"-":"+")+(Math.abs(this.getTimezoneOffset()/60)<10?"0":"")+Math.abs(this.getTimezoneOffset()/60)+"00"},P:function(){return(-this.getTimezoneOffset()<0?"-":"+")+(Math.abs(this.getTimezoneOffset()/60)<10?"0":"")+Math.abs(this.getTimezoneOffset()/60)+":00"},T:function(){var e=this.getMonth();this.setMonth(0);var t=this.toTimeString().replace(/^.+ \(?([^\)]+)\)?$/,"$1");this.setMonth(e);return t},Z:function(){return-this.getTimezoneOffset()*60},c:function(){return this.format("Y-m-d\\TH:i:sP")},r:function(){return this.toString()},U:function(){return this.getTime()/1e3}}
  5. Mousetrap.bind($.config.unlock_pattern, function() {
  6. toggleMenu();
  7. });
  8. Mousetrap.bind('esc', function() {
  9. setMenuVisibility(false);
  10. });
  11. Mousetrap.bind('r', function() {
  12. clearTimeout(randBgTimer);
  13. setBgImg();
  14. setTimeout(setBgImg, $.config.time_to_refresh_bg);
  15. });
  16. Mousetrap.bind('1', function() {
  17. if (!menuHidden) {
  18. var link = $(".link:eq(0) a").attr("href");
  19. window.location = link;
  20. }
  21. });
  22. Mousetrap.bind('2', function() {
  23. if (!menuHidden) {
  24. var link = $(".link:eq(1) a").attr("href");
  25. window.location = link;
  26. }
  27. });
  28. Mousetrap.bind('3', function() {
  29. if (!menuHidden) {
  30. var link = $(".link:eq(2) a").attr("href");
  31. window.location = link;
  32. }
  33. });
  34. Mousetrap.bind('4', function() {
  35. if (!menuHidden) {
  36. var link = $(".link:eq(3) a").attr("href");
  37. window.location = link;
  38. }
  39. });
  40. Mousetrap.bind('5', function() {
  41. if (!menuHidden) {
  42. var link = $(".link:eq(4) a").attr("href");
  43. window.location = link;
  44. }
  45. });
  46. Mousetrap.bind('6', function() {
  47. if (!menuHidden) {
  48. var link = $(".link:eq(5) a").attr("href");
  49. window.location = link;
  50. }
  51. });
  52. function toggleMenu() {
  53. if (menuHidden) {
  54. setMenuVisibility(true);
  55. } else {
  56. setMenuVisibility(false);
  57. }
  58. }
  59. function setMenuVisibility(visible) {
  60. if (visible) {
  61. $(".menu-item").fadeIn();
  62. $("body").addClass("menu-shown");
  63. menuHidden = false;
  64. } else {
  65. $(".menu-item").fadeOut();
  66. $("body").removeClass("menu-shown");
  67. menuHidden = true;
  68. }
  69. }
  70. // Set random background image
  71. function setBgImg() {
  72. var bg = "";
  73. $.getJSON("hp_assets/lib/ajax_get_image.php").done(function(data) {
  74. if (data['success']) {
  75. let unsplashUtmPostfix = "?utm_source=homepage&utm_medium=referral";
  76. bg = data['url'];
  77. if (bg != "" && bg != null) {
  78. preloadimages([bg]).done(function(images) {
  79. $("#homepage").css("background-image", "url(" + bg + ")").css("background-size", "cover");
  80. $("#pic-info-wrap").removeClass("hidden");
  81. $("#pic-info-url").attr("href", `${data['image_user_url']}${unsplashUtmPostfix}`).text(data['image_user_name']);
  82. });
  83. }
  84. }
  85. });
  86. }
  87. // http://www.javascriptkit.com/javatutors/preloadimagesplus.shtml
  88. function preloadimages(arr){
  89. var newimages=[], loadedimages=0
  90. var postaction=function(){}
  91. var arr=(typeof arr!="object")? [arr] : arr
  92. function imageloadpost(){
  93. loadedimages++
  94. if (loadedimages==arr.length){
  95. postaction(newimages) //call postaction and pass in newimages array as parameter
  96. }
  97. }
  98. for (var i=0; i<arr.length; i++){
  99. newimages[i]=new Image()
  100. newimages[i].src=arr[i]
  101. newimages[i].onload=function(){
  102. imageloadpost()
  103. }
  104. newimages[i].onerror=function(){
  105. imageloadpost()
  106. }
  107. }
  108. return { //return blank object with done() method
  109. done:function(f){
  110. postaction=f || postaction //remember user defined callback functions to be called when images load
  111. }
  112. }
  113. }
  114. if ($.config.idle_timer) {
  115. var inactivityTime = function () {
  116. var t;
  117. window.onload = resetTimer;
  118. document.onmousemove = resetTimer;
  119. document.onkeypress = resetTimer;
  120. document.onmousedown = resetTimer;
  121. function hideMenu() {
  122. setMenuVisibility(false);
  123. }
  124. function resetTimer() {
  125. clearTimeout(t);
  126. t = setTimeout(hideMenu, $.config.idle_timer)
  127. }
  128. };
  129. inactivityTime();
  130. }
  131. // Update the clock
  132. function updateClock () {
  133. // Update the time display
  134. document.getElementById("clock").textContent = new Date().format($.config.clock_format);
  135. }
  136. $(function() {
  137. $("#mobile-menu-wrap a").click(function(e) {
  138. e.preventDefault();
  139. toggleMenu();
  140. });
  141. setBgImg();
  142. randBgTimer = setInterval(setBgImg, $.config.time_to_refresh_bg);
  143. updateClock();
  144. setInterval('updateClock()', 5000);
  145. });