PageRenderTime 25ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/advent/template.html

https://github.com/infusion/HTML5-Experiments
HTML | 372 lines | 291 code | 81 blank | 0 comment | 0 complexity | 9b1618ffd325952603fa461ad08f76b9 MD5 | raw file
  1. <html>
  2. <head>
  3. <title>Advent Calendar</title>
  4. <meta charset="utf-8">
  5. <style>
  6. body {
  7. background: url(/image/bg.jpg)
  8. }
  9. #calendar {
  10. perspective: 1000px;
  11. position: relative;
  12. margin: auto;
  13. display:none;
  14. box-shadow: 0px 3px 28px 0px rgba(0,0,0,0.75);
  15. border: 5px solid white;
  16. }
  17. .frame {
  18. position:absolute;
  19. cursor: pointer;
  20. box-shadow: inset 0 0 1px #000;
  21. }
  22. .door {
  23. transform-origin: left;
  24. transform-style: preserve-3d;
  25. transition: .7s transform cubic-bezier(0.470, 0.000, 0.745, 0.715);
  26. }
  27. .open {
  28. transform: rotateY(-140deg);
  29. }
  30. .wing {
  31. position: absolute;
  32. background:white; /* necessary to make contents visible while loading */
  33. left: 0px;
  34. top: 0px;
  35. border: 1px solid rgba(0,0,0,0.2);
  36. box-shadow: 0px 0px 5px #4195fc;
  37. backface-visibility: hidden;
  38. box-sizing: border-box;
  39. box-shadow: 0px 0px 3px rgba(255,255,255,0.5);
  40. text-shadow: 0px 0px 5px rgba(255, 255, 255, 1);
  41. }
  42. #pre {
  43. background:white;
  44. width: 600px;
  45. height: 500px;
  46. display:none;
  47. border-radius: 10px;
  48. margin:auto;
  49. position:relative;
  50. box-shadow: 0px 3px 28px 0px rgba(0,0,0,0.75);
  51. }
  52. #pre canvas{
  53. position:absolute;left:0;top:0;
  54. }
  55. </style>
  56. <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
  57. </head>
  58. <body>
  59. <div id="calendar"></div>
  60. <script>
  61. (function() {
  62. var today = <?php echo $today;?>;
  63. var CALENDAR = document.getElementById('calendar');
  64. var isMobile = typeof window.orientation !== 'undefined';
  65. if (isMobile) {
  66. var scale = 100;
  67. var radii = 30;
  68. var yoff = 30;
  69. var width = 800;
  70. var height = 800;
  71. } else {
  72. var scale = 50;
  73. var radii = 10;
  74. var yoff = 30;
  75. var width = 600;
  76. var height = 500;
  77. }
  78. var isDown = false;
  79. var allCleared = false;
  80. var inCircle = -1;
  81. var prev = {x: 0, y: 0};
  82. var STATE = getCookies()['F'] || 0;
  83. var Off = {x: 0, y: 0};
  84. function setOffset(el) {
  85. var _x = 0;
  86. var _y = 0;
  87. while (el && !isNaN(el.offsetLeft) && !isNaN(el.offsetTop)) {
  88. _x += el.offsetLeft - el.scrollLeft;
  89. _y += el.offsetTop - el.scrollTop;
  90. el = el.offsetParent;
  91. }
  92. Off.x = _x;
  93. Off.y = _y;
  94. }
  95. CALENDAR.style.display = "block";
  96. function changeState(i) {
  97. STATE ^= 1 << i;
  98. setCookie('F', STATE, 31);
  99. }
  100. function setCookie(name, value, daysToLive) {
  101. var cookie = name + "=" + encodeURIComponent(value);
  102. if (typeof daysToLive === "number")
  103. cookie += "; max-age=" + (daysToLive * 60 * 60 * 24);
  104. cookie += "; path=" + location.pathname;
  105. document.cookie = cookie;
  106. }
  107. function getCookies() {
  108. var cookies = {};
  109. var all = document.cookie;
  110. if (all === "")
  111. return cookies;
  112. var list = all.split("; ");
  113. for (var i = 0; i < list.length; i++) {
  114. var cookie = list[i];
  115. var p = cookie.indexOf("=");
  116. var name = cookie.substring(0, p);
  117. var value = cookie.substring(p + 1);
  118. value = decodeURIComponent(value);
  119. cookies[name] = value;
  120. }
  121. return cookies;
  122. }
  123. function calendar(opts, doors) {
  124. var cal = CALENDAR;
  125. cal.style.width = opts.width + "px";
  126. cal.style.height = opts.height + "px";
  127. cal.style.backgroundImage = "url(" + opts.theme + ")";
  128. for (var i = 0; i < doors.length; i++) {
  129. (function(i) {
  130. var d = doors[i];
  131. var frame = document.createElement("div");
  132. var door = document.createElement("div");
  133. var cont = document.createElement("div");
  134. var front = document.createElement("div");
  135. var back = document.createElement("div");
  136. frame.style.background = d.backgroundFloor;
  137. frame.style.backgroundSize = "cover";
  138. frame.style.left = d.x + "px";
  139. frame.style.top = d.y + "px";
  140. frame.style.width = d.width + "px";
  141. frame.style.height = d.height + "px";
  142. frame.className = "frame";
  143. cont.innerHTML = d.contentFloor;
  144. cont.style.position = "absolute";
  145. if (d.open) {
  146. door.className = "door open";
  147. } else {
  148. door.className = "door";
  149. }
  150. door.onclick = function(ev) {
  151. ev.stopPropagation();
  152. if (today <= i) {
  153. alert(opts.alertTooEarly);
  154. return;
  155. }
  156. changeState(i);
  157. if (this.className === "door")
  158. this.className = "door open";
  159. else
  160. this.className = "door";
  161. };
  162. front.style.backgroundImage = "url(" + opts.theme + ")";
  163. front.style.backgroundPosition = (-d.x - 1) + "px " + (-d.y - 1) + "px";
  164. front.style.width = d.width + "px";
  165. front.style.height = d.height + "px";
  166. front.style.font = "18px Arial";
  167. front.style.textAlign = "right";
  168. front.style.padding = "70px 10px 0px 0px";
  169. front.className = "wing";
  170. front.innerHTML = d.num;
  171. back.style.background = d.backgroundWing;
  172. back.style.transform = "rotateY(180deg)";
  173. back.style.width = d.width + "px";
  174. back.style.height = d.height + "px";
  175. back.className = "wing";
  176. back.innerHTML = d.contentWing;
  177. door.appendChild(front);
  178. door.appendChild(back);
  179. frame.appendChild(cont);
  180. frame.appendChild(door);
  181. cal.appendChild(frame);
  182. })(i);
  183. }
  184. }
  185. var shuffle = function(arr) {
  186. for (var i = arr.length; i--; ) {
  187. var j = Math.random() * arr.length | 0;
  188. var t = arr[i];
  189. arr[i] = arr[j];
  190. arr[j] = t;
  191. }
  192. return arr;
  193. };
  194. var data = <?php echo json_encode($gifts);?>;
  195. var doors = [];
  196. var coord = [];
  197. for (var i = 0; i < 24; i++) {
  198. var floor = "", wing = "";
  199. var back = "white";
  200. if (data[i]) {
  201. var gift = data[i].DData;
  202. var back = "";
  203. var door = "";
  204. var click = "";
  205. if (gift[0] == '/') {
  206. back = '/image' + gift;
  207. click = "layer";
  208. } else {
  209. var m = gift.match(/v=([a-z0-9_-]+)/i);
  210. if (m !== null && m[1] !== undefined) {
  211. back = 'https://i.ytimg.com/vi/' + m[1] + '/hqdefault.jpg';
  212. click = gift;
  213. } else {
  214. back = 'https://thumbs.dreamstime.com/b/hand-cursor-clicking-click-here-button-d-render-52415076.jpg';
  215. click = gift;
  216. }
  217. var m = gift.match(/\.(gif|png|jpg)/i);
  218. if (m !== null) {
  219. back = gift;
  220. click = "layer";
  221. }
  222. }
  223. if (click === 'layer') {
  224. floor = '<a href="' + back + '" target="_blank" title="Greetings from ' + data[i].UNameFrom + '" style="display:block;width:95px;height:95px"></a>';
  225. back = "url(" + back + ")";
  226. } else {
  227. floor = '<a href="' + click + '" target="_blank" title="Greetings from ' + data[i].UNameFrom + '" style="display:block;width:95px;height:95px"></a>';
  228. back = "white url(" + back + ") center center no-repeat";
  229. }
  230. }
  231. doors.push({
  232. num: i + 1,
  233. backgroundFloor: back,
  234. backgroundWing: wing ? "white" : "white url(/image/flakes/" + (1 + Math.random() * 20 | 0) + ".png) center center no-repeat",
  235. contentWing: wing,
  236. contentFloor: floor,
  237. x: 0,
  238. y: 0,
  239. width: 95,
  240. height: 95,
  241. open: STATE & (1 << i)
  242. });
  243. coord.push([
  244. (i % 4 | 0) * 190 + 20,
  245. (i / 4 | 0) * 120 + 20]);
  246. }
  247. coord = shuffle(coord);
  248. for (var i = 0; i < 24; i++) {
  249. doors[i].x = coord[i][0];
  250. doors[i].y = coord[i][1];
  251. }
  252. calendar({
  253. height: 750,
  254. width: 705,
  255. theme: "/image<?php echo $theme ? $theme : '/cal.jpg' ;?>",
  256. alertTooEarly: "Bisschen früh, was?"
  257. }, doors);
  258. var boxes = <?php echo json_encode($boxes);?>
  259. for (var i = 0; i < boxes.length; i++) {
  260. (function(box) {
  261. var dom = '<img style="float:left" src="/image/box.png" width="' + (Math.random() * 200 + 80) + '">';
  262. var div = document.createElement('div');
  263. div.style.position = "absolute";
  264. div.style.padding = "10px";
  265. div.style.borderRadius = "10px";
  266. div.style.top = (100 + (window.innerHeight - 300) * Math.random()) + "px";
  267. div.style.left = (100 + (window.innerWidth - 500) * Math.random()) + "px";
  268. div.innerHTML = dom;
  269. var open = false;
  270. div.onclick = function(ev) {
  271. ev.preventDefault();
  272. if (open) {
  273. $.ajax({
  274. url: "/index.php?delete=" + box.GID
  275. });
  276. document.body.removeChild(div);
  277. return;
  278. }
  279. open = true;
  280. var span = document.createElement('span');
  281. span.innerHTML = box.GData + "<br><strong>&nbsp;&nbsp;&nbsp;&raquo;" + box.UNameFrom + "</strong>";
  282. this.appendChild(span);
  283. this.style.background = "rgba(255,255,255,0.9)";
  284. }
  285. document.body.appendChild(div);
  286. })(boxes[i]);
  287. }
  288. })();
  289. </script>
  290. </body>
  291. </html>