index.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <?php require_once('../config.inc'); ?>
  2. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  3. <style type="text/css">
  4. html,body {
  5. margin: 0px;
  6. padding: 0px;
  7. }
  8. .navigation {
  9. height: 5%;
  10. }
  11. .content {
  12. width: 100%;
  13. height: 95%;
  14. display: flex;
  15. }
  16. .calendar-view {
  17. width: 80%;
  18. max-height: 80%;
  19. text-align: center;
  20. padding-right: 3px;
  21. margin: 5px;
  22. }
  23. #calendar {
  24. background-color: lightgray;
  25. max-width: 100%;
  26. width: 100%;
  27. }
  28. #calendar-header {
  29. border-top: 2px solid black;
  30. border-left: 2px solid black;
  31. border-right: 2px solid black;
  32. padding: 30px;
  33. }
  34. #calendar-header h1 {
  35. margin: 0px;
  36. }
  37. .sticker-sidebar {
  38. width: 20%;
  39. height: 100%;
  40. overflow-x: hidden;
  41. overflow-y: scroll;
  42. padding-left: 3px;
  43. }
  44. .sticker-sidebar button {
  45. width: 100%;
  46. margin-top: 20px;
  47. margin-bottom: 20px;
  48. }
  49. .sticker-sidebar img {
  50. max-width: 90%;
  51. margin-left: auto;
  52. margin-right: auto;
  53. }
  54. </style>
  55. <div class="navigation"><a href="/">Today</a> <a href="/chart">Chart</a></div>
  56. <div class="content">
  57. <div class="calendar-view">
  58. <div id="calendar-header"><h1><a href="">&lt;&lt</a> September 2017 <a href="">&gt;&gt</a></h1></div>
  59. <canvas id="calendar"></canvas>
  60. </div>
  61. <div class="sticker-sidebar">
  62. <button>Upload Sticker</button>
  63. <img class="sticker" id="sticker-B7875B4B" src="/images/stickers/sticker_1.png" draggable="true" />
  64. <img class="sticker" id="sticker-EC13AB35" src="/images/stickers/sticker_2.png" draggable="true" />
  65. <img class="sticker" id="sticker-29B49FCE" src="/images/stickers/sticker_3.png" draggable="true" />
  66. <img class="sticker" id="sticker-ACDABF8A" src="/images/stickers/sticker_4.png" draggable="true" />
  67. <img class="sticker" id="sticker-64AFE39D" src="/images/stickers/sticker_5.png" draggable="true" />
  68. <img class="sticker" id="sticker-F0919683" src="/images/stickers/sticker_6.png" draggable="true" />
  69. <img class="sticker" id="sticker-081B2451" src="/images/stickers/sticker_7.png" draggable="true" />
  70. <img class="sticker" id="sticker-DEFB64A3" src="/images/stickers/sticker_8.png" draggable="true" />
  71. <img class="sticker" id="sticker-017BB5B7" src="/images/stickers/sticker_9.png" draggable="true" />
  72. </div>
  73. </div>
  74. <footer class="footer"></footer>
  75. <script type="text/javascript">
  76. window.addEventListener("resize", function(event){
  77. resizeCanvas();
  78. drawCalendar();
  79. });
  80. document.addEventListener("DOMContentLoaded", function() {
  81. resizeCanvas();
  82. drawCalendar();
  83. var stickers = document.getElementsByClassName("sticker");
  84. for(var i = 0; i < stickers.length; i++) {
  85. stickers[i].addEventListener("dragstart", function(event) {
  86. event.dataTransfer.setData("image", event.target.id);
  87. event.dataTransfer.setData("grab-location-x", event.offsetX);
  88. event.dataTransfer.setData("grab-location-y", event.offsetY);
  89. //event.dataTransfer.setDragImage(image, event.offsetX, event.offsetY);
  90. });
  91. }
  92. var canvas = document.getElementById("calendar");
  93. canvas.addEventListener("dragover", function(event) {
  94. event.preventDefault();
  95. }, false);
  96. canvas.addEventListener("drop", function(event) {
  97. event.preventDefault();
  98. var imageId = event.dataTransfer.getData("image");
  99. var grabX = event.dataTransfer.getData('grab-location-x');
  100. var grabY = event.dataTransfer.getData('grab-location-y');
  101. var sticker = document.getElementById(imageId);
  102. addStickerToDay(sticker, event.offsetX - grabX, event.offsetY - grabY);
  103. }, false);
  104. });
  105. function addStickerToDay(sticker, x, y) {
  106. var canvas = document.getElementById("calendar");
  107. var context = canvas.getContext("2d");
  108. var width = canvas.width;
  109. var height = canvas.height;
  110. var dayColumns = parseInt(width / 7);
  111. var weekColumns = parseInt(height / 5);
  112. //var scaled = scaleImage(sticker.width, sticker.height, dayColumns - 10, weekColumns - 10);
  113. //context.drawImage(sticker, x, y, scaled.width, scaled.height);
  114. context.drawImage(sticker, x, y);
  115. }
  116. function resizeCanvas() {
  117. var canvas = document.getElementById("calendar");
  118. var container = canvas.parentNode;
  119. var containerStyle = window.getComputedStyle(container, null);
  120. var fullWidth = containerStyle.getPropertyValue("width");
  121. var fullHeight = containerStyle.getPropertyValue("height");
  122. canvas.width = parseInt(fullWidth);
  123. canvas.height = parseInt(fullHeight);
  124. }
  125. function populateCalendarData() {
  126. var canvas = document.getElementById("calendar");
  127. canvas.setAttribute("data-month", 9);
  128. }
  129. function drawCalendar() {
  130. populateCalendarData();
  131. var canvas = document.getElementById("calendar");
  132. var context = canvas.getContext("2d");
  133. var width = canvas.width;
  134. var height = canvas.height;
  135. var dayColumns = parseInt(width / 7);
  136. var weekColumns = parseInt(height / 5);
  137. context.fillStyle = "#FFFFFF";
  138. context.strokeStyle = "#000000";
  139. context.lineWidth = 2;
  140. context.fillRect(0, 0, width, height);
  141. context.rect(1,1,width - 2, height - 2);
  142. context.stroke();
  143. for(var x = 0; x < 7; x++) {
  144. context.beginPath();
  145. context.moveTo(x * dayColumns,0);
  146. context.lineTo(x * dayColumns, height);
  147. context.stroke();
  148. }
  149. for(var y = 0; y < 5; y++) {
  150. context.beginPath();
  151. context.moveTo(0, y * weekColumns);
  152. context.lineTo(width, y * weekColumns);
  153. context.stroke();
  154. }
  155. context.fillStyle = "#808080";
  156. context.font = "16px Arial";
  157. var calendarData = [
  158. {"number" : 27, "currentmonth": false, stickers: ["B7875B4B"]},
  159. {"number" : 28, "currentmonth": false, stickers: ["EC13AB35"]},
  160. {"number" : 29, "currentmonth": false, stickers: ["29B49FCE"]},
  161. {"number" : 30, "currentmonth": false, stickers: ["ACDABF8A"]},
  162. {"number" : 31, "currentmonth": false, stickers: ["64AFE39D"]},
  163. {"number" : 1, "currentmonth": true, stickers: ["F0919683"]},
  164. {"number" : 2, "currentmonth": true, stickers: ["081B2451"]},
  165. {"number" : 3, "currentmonth": true, stickers: ["DEFB64A3"]},
  166. {"number" : 4, "currentmonth": true, stickers: ["017BB5B7"]},
  167. {"number" : 5, "currentmonth": true, stickers: ["E6AF1DD5"]},
  168. {"number" : 6, "currentmonth": true, stickers: []},
  169. {"number" : 7, "currentmonth": true, stickers: []},
  170. {"number" : 8, "currentmonth": true, stickers: []},
  171. {"number" : 9, "currentmonth": true, stickers: []},
  172. {"number" : 10, "currentmonth": true, stickers: ["F0919683"]},
  173. {"number" : 11, "currentmonth": true, stickers: ["F0919683"]},
  174. {"number" : 12, "currentmonth": true, stickers: []},
  175. {"number" : 13, "currentmonth": true, stickers: ["F0919683"]},
  176. {"number" : 14, "currentmonth": true, stickers: []},
  177. {"number" : 15, "currentmonth": true, stickers: []},
  178. {"number" : 16, "currentmonth": true, stickers: []},
  179. {"number" : 17, "currentmonth": true, stickers: []},
  180. {"number" : 18, "currentmonth": true, stickers: []},
  181. {"number" : 19, "currentmonth": true, stickers: ["F0919683","081B2451"]},
  182. {"number" : 20, "currentmonth": true, stickers: ["081B2451"]},
  183. {"number" : 21, "currentmonth": true, stickers: ["081B2451"]},
  184. {"number" : 22, "currentmonth": true, stickers: ["081B2451"]},
  185. {"number" : 23, "currentmonth": true, stickers: ["081B2451"]},
  186. {"number" : 24, "currentmonth": true, stickers: ["081B2451"]},
  187. {"number" : 25, "currentmonth": true, stickers: ["081B2451"]},
  188. {"number" : 26, "currentmonth": true, stickers: []},
  189. {"number" : 27, "currentmonth": true, stickers: []},
  190. {"number" : 28, "currentmonth": true, stickers: ["F0919683"]},
  191. {"number" : 29, "currentmonth": true, stickers: ["F0919683"]},
  192. {"number" : 30, "currentmonth": true, stickers: ["F0919683"]}
  193. ];
  194. var calendarGridIndex = 0;
  195. for(var y = 0; y < 5; y++) {
  196. for(var x = 0; x < 7; x++) {
  197. var dayData = calendarData[calendarGridIndex++];
  198. //stickers
  199. for(var i = 0; i < dayData.stickers.length; i++) {
  200. var image = document.getElementById("sticker-"+dayData.stickers[i]);
  201. if(image == null) {
  202. continue;
  203. }
  204. var scaled = scaleImage(image.width, image.height, dayColumns - 10, weekColumns - 10);
  205. context.drawImage(image,x * dayColumns + 5, y * weekColumns + 5, scaled.width, scaled.height);
  206. }
  207. //number labels
  208. if(!dayData.currentmonth) {
  209. context.fillStyle = "#808080";
  210. } else {
  211. context.fillStyle = "#000000";
  212. }
  213. context.fillText(dayData.number,x * dayColumns + 3, y * weekColumns + 16);
  214. }
  215. }
  216. }
  217. function scaleImage(imageWidth, imageHeight, targetWidth, targetHeight) {
  218. var newSize = {width: imageWidth, height: imageHeight};
  219. var imageRatio = imageWidth / imageHeight;
  220. if(newSize.width > targetWidth) {
  221. //shrink by width
  222. newSize.width = targetWidth;
  223. newSize.height = newSize.width / imageRatio;
  224. }
  225. if(newSize.height > targetHeight) {
  226. //shrink by height
  227. newSize.height = targetHeight;
  228. newSize.width = newSize.height * imageRatio;
  229. }
  230. return newSize;
  231. }
  232. </script>