Advertisement
Smokli

Untitled

Oct 24th, 2014
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.54 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>New rest</title>
  5. <style>
  6.  
  7. body, div, span, h1, h2, h3, h4, h5, h6, a {
  8. border: 0px;
  9. text-decoration: none;
  10. color: black;
  11. margin: 0;
  12. padding: 0;
  13. }
  14.  
  15. body * {
  16. box-sizing: border-box;
  17. }
  18.  
  19. body {
  20. -moz-user-select: -moz-none;
  21. -khtml-user-select: none;
  22. -webkit-user-select: none;
  23. -ms-user-select: none;
  24. user-select: none;
  25. }
  26.  
  27. #main-container {
  28. width: 1030px;
  29. margin-left: auto;
  30. margin-right: auto;
  31. position: relative;
  32. }
  33.  
  34. #main-container div {
  35. display: inline-block;
  36. }
  37.  
  38. #main-menu {
  39. width: 1000px;
  40. height: 75px;
  41. float: left;
  42. }
  43.  
  44. #room {
  45. z-index: -2;
  46. width: 1000px;
  47. height: 599px;
  48. margin: 20px 0px;
  49. position: relative;
  50. float: left;
  51. background: transparent;
  52. border:2px solid #9A9A9A;
  53. }
  54.  
  55. .room-background {
  56. z-index: -3;
  57. width: 1000px;
  58. height: 599px;
  59. margin: 20px 0px;
  60. position: absolute;
  61. left: 0px;
  62. top: 75px;
  63. float: left;
  64. background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #7d5d3b), color-stop(1, #634b30));
  65. }
  66.  
  67. #room.grid-background {
  68. background-image: -webkit-linear-gradient(#927459 1px, transparent 1px), -webkit-linear-gradient(0, #927459 1px, transparent 1px);
  69. background-size: 25px 25px;
  70. }
  71.  
  72. #secondary-menu {
  73. float: right;
  74. margin-top: 66px;
  75. width: 584px;
  76. }
  77.  
  78. #secondary-menu > div {
  79. float: left;
  80. }
  81.  
  82. #rooms-list-box {
  83. margin-top: 29px;
  84. }
  85.  
  86. #rooms-list-box div {
  87. float: left;
  88. }
  89.  
  90. #rooms-list-box div:nth-child(3) {
  91. border-left: 15px solid transparent;
  92. border-bottom: 15px solid transparent;
  93. border-right: 15px solid #54381e;
  94. border-top: 15px solid #54381e;
  95. border-bottom-right-radius: 4px;
  96. }
  97.  
  98. #rooms-list-box div:nth-child(4) {
  99. border-right: 15px solid transparent;
  100. border-bottom: 15px solid transparent;
  101. border-left: 15px solid #54381e;
  102. border-top: 15px solid #54381e;
  103. float: right;
  104. border-bottom-left-radius: 4px;
  105. }
  106.  
  107.  
  108. #rooms-list-box div:nth-child(1) {
  109. border-left: 15px solid transparent;
  110. border-bottom: 15px solid transparent;
  111. border-right: 15px solid white;
  112. border-top: 15px solid white;
  113. margin-right: -29px;
  114. }
  115.  
  116. #rooms-list-box div:nth-child(2) {
  117. border-right: 15px solid transparent;
  118. border-bottom: 15px solid transparent;
  119. border-left: 15px solid white;
  120. border-top: 15px solid white;
  121. float: right;
  122. margin-left: -29px;
  123. }
  124.  
  125. #rooms-list {
  126. width: 120px;
  127. height: 30px;
  128. padding: 0;
  129. padding-left: 1px;
  130. margin: 0px -1px;
  131. border-radius: 0;
  132. border-bottom: 1px solid white;
  133. }
  134.  
  135. #rooms-list:focus, button:focus {
  136. outline: none;
  137. }
  138.  
  139. .table {
  140. position: absolute;
  141. left: 500px;
  142. top: 200px;
  143. width: 100px;
  144. height: 100px;
  145. border: 1px solid #AC800C;
  146. background: -webkit-radial-gradient(center, ellipse cover, rgba(117,73,45,1) 0%,rgba(66,31,19,1) 100%); /* Chrome10+,Safari5.1+ */
  147. }
  148.  
  149. .resize-table-diagonal, .rotate-table {
  150. width: 12px;
  151. height: 12px;
  152. position: absolute;
  153. display: none;
  154. }
  155.  
  156. .rotate-table {
  157. top: 0;
  158. left: 0;
  159. cursor: alias;
  160. }
  161.  
  162. .resize-table-diagonal {
  163. right: 0;
  164. bottom: 0;
  165. cursor: se-resize;
  166. }
  167.  
  168. .resize-table-right {
  169. position: absolute;
  170. width: 8px;
  171. right: 0;
  172. top: 0;
  173. bottom: 10px;
  174. cursor: e-resize;
  175. }
  176.  
  177. .resize-table-down {
  178. position: absolute;
  179. height: 8px;
  180. right: 12px;
  181. left: 0;
  182. bottom: 0;
  183. cursor: s-resize;
  184. }
  185.  
  186. .round {
  187. width: 70%;
  188. position: absolute;
  189. display: none;
  190. top: 43%;
  191. left: 15%;
  192. }
  193.  
  194.  
  195. #main-menu button, select, #open-restaurant {
  196. -moz-box-shadow: inset 0px 1px 0px 0px #a6827e;
  197. -webkit-box-shadow: inset 0px 1px 0px 0px #a6827e;
  198. box-shadow: inset 0px 1px 0px 0px #a6827e;
  199. background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #7d5d3b), color-stop(1, #634b30));
  200. filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#7d5d3b', endColorstr='#634b30',GradientType=0);
  201. background-color: #7d5d3b;
  202. -moz-border-radius: 3px;
  203. -webkit-border-radius: 3px;
  204. border-radius: 3px;
  205. border: 1px solid #54381e;
  206. display: inline-block;
  207. cursor: pointer;
  208. color: #ffffff;
  209. font-family: arial;
  210. font-size: 13px;
  211. padding: 6px 24px;
  212. text-align: center;
  213. text-decoration: none;
  214. width: 110px;
  215. height: 45px;
  216. text-shadow: 0px 1px 0px #4d3534;
  217. }
  218.  
  219. #main-menu button:hover, .open-project-box:hover #open-project, .open-rest-box:hover #open-restaurant {
  220. background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #634b30), color-stop(1, #7d5d3b));
  221. background: linear-gradient(to bottom, #634b30 5%, #7d5d3b 100%);
  222. filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#634b30', endColorstr='#7d5d3b',GradientType=0);
  223. background-color: #634b30;
  224. }
  225.  
  226. #main-menu button:active, .open-project-box:active #open-project, .open-rest-box:active #open-restaurant {
  227. position: relative;
  228. top: 1px;
  229. }
  230.  
  231. #main-menu #secondary-menu button {
  232. height: 29px;
  233. width: 108px;
  234. float: left;
  235. }
  236.  
  237. .open-project-box {
  238. float: left;
  239. position: relative;
  240. margin-right: 5px;
  241. }
  242.  
  243. .open-project-box button, .open-project-box input {
  244. display: inline-block;
  245. width: 100%;
  246. text-align: center;
  247. height: 41px;
  248. }
  249.  
  250. .open-rest-box {
  251. float: left;
  252. position: relative;
  253. margin-right: 5px;
  254. }
  255.  
  256. .open-rest-box input {
  257. position: absolute;
  258. width: 110px;
  259. height: 45px;
  260. top: 0;
  261. left: 0;
  262. opacity: 0;
  263. }
  264.  
  265. #open-restaurant {
  266. }
  267.  
  268. #load-restaurant {
  269. margin-top: 2px;
  270. position: absolute;
  271. top: 0;
  272. left: 0;
  273. opacity: 0;
  274. }
  275.  
  276. .load-rest-active {
  277. background-color: green;
  278. }
  279.  
  280. #create-restaurant, .open-restaurant {
  281. float: left;
  282. margin-right: 5px;
  283. }
  284.  
  285. #main-menu #save-restaurant {
  286. line-height: 27px;
  287. height: 29px;
  288. text-align: center;
  289. width: 80px;
  290. }
  291.  
  292. #save-restaurant {
  293. -moz-box-shadow: inset 0px 1px 0px 0px #a4e271;
  294. -webkit-box-shadow: inset 0px 1px 0px 0px #a4e271;
  295. box-shadow: inset 0px 1px 0px 0px #a4e271;
  296. background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #89c403), color-stop(1, #77a809));
  297. background: linear-gradient(to bottom, #89c403 5%, #77a809 100%);
  298. filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#89c403', endColorstr='#77a809',GradientType=0);
  299. background-color: #89c403;
  300. -moz-border-radius: 4px;
  301. -webkit-border-radius: 4px;
  302. border-radius: 3px;
  303. border: 1px solid #74b807;
  304. display: inline-block;
  305. cursor: pointer;
  306. color: #ffffff;
  307. font-family: arial;
  308. font-size: 15px;
  309. text-decoration: none;
  310. text-shadow: 0px 1px 0px #528009;
  311. }
  312.  
  313. #save-restaurant:hover {
  314. background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #77a809), color-stop(1, #89c403));
  315. background: linear-gradient(to bottom, #77a809 5%, #89c403 100%);
  316. filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#77a809', endColorstr='#89c403',GradientType=0);
  317. background-color: #77a809;
  318. }
  319.  
  320. #save-restaurant:active {
  321. position: relative;
  322. top: 1px;
  323. }
  324.  
  325.  
  326. .grid-box {
  327. width: 78px;
  328. height: 23px;
  329. border: 1px solid #999999;
  330. border-radius: 1px;
  331. }
  332.  
  333. .grid-box span {
  334. display: inline-block;
  335. width: 36px;
  336. margin-top: 3px;
  337. margin-left: 12px;
  338. }
  339.  
  340.  
  341. #delete-room {
  342. border-radius: 50%;
  343. width: 35px;
  344. height: 35px;
  345. margin-top: 598px;
  346. margin-left: -22px;
  347. float: left;
  348. text-align: center;
  349. line-height: 35px;
  350. font-weight: bold;
  351. color: white;
  352. font-family: cursive;
  353. cursor: pointer;
  354. background: -webkit-radial-gradient(center, ellipse cover, rgba(109,76,42,1) 0%,rgba(51,32,14,1) 100%); /* Chrome10+,Safari5.1+ */
  355. }
  356.  
  357. .delete-table {
  358. border-radius: 50%;
  359. text-align: center;
  360. width: 20px;
  361. height: 20px;
  362. line-height: 14px;
  363. text-align: center;
  364. position: absolute;
  365. right: -5px;
  366. top: -5px;
  367. font-weight: bold;
  368. color: white;
  369. font-family: cursive;
  370. cursor: pointer;
  371. border: 1px solid rgb(160, 145, 96);
  372. background: -webkit-radial-gradient(center, ellipse cover, rgba(109,76,42,1) 0%,rgba(51,32,14,1) 100%); /* Chrome10+,Safari5.1+ */
  373. }
  374.  
  375. #main-container .table-id {
  376. display: none;
  377. }
  378.  
  379. .reserve-name {
  380. margin-top: 10px;
  381. }
  382.  
  383. .reserve-name, .reserve-ppl, .reserve-clock {
  384. width: 100%;
  385. font-size: 16px;
  386. color: #e1d59c;
  387. text-align: center;
  388. }
  389.  
  390. .sec-menu-box {
  391. width: 404px;
  392. }
  393.  
  394. .table > div:first-child {
  395. width: 100%;
  396. margin: 6px;
  397. }
  398.  
  399. #user-options-box {
  400. width: 160px;
  401. border: 1px solid black;
  402. padding: 3px;
  403. position: absolute;
  404. text-align: left;
  405. background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #7d5d3b), color-stop(1, #634b30));
  406. }
  407.  
  408. #user-options-box button {
  409. border-radius: 3px;
  410. }
  411.  
  412. #user-options-box div {
  413. width: 100%;
  414. height: 30px;
  415. color: #e1d59c;
  416. }
  417.  
  418. #user-options-box input {
  419. width: 105px;
  420. float: right;
  421. }
  422.  
  423. #clear-user-options {
  424. float: right;
  425. }
  426.  
  427. </style>
  428. </head>
  429. <body>
  430. <div id="main-container">
  431. <div id="main-menu">
  432. <div id="start-menu">
  433. <div class="open-rest-box">
  434. <button id="open-restaurant">Open restaurant</button>
  435. <input type="file" id="file" name="name" value=" " />
  436. </div>
  437. <div class="open-project-box">
  438. <button id="open-project">Open project</button>
  439. <input type="file" id="load-restaurant" value="" />
  440. </div>
  441. <button id="create-restaurant">Create restaurant</button>
  442. </div>
  443. <div id="secondary-menu">
  444. <div id="rooms-list-box" style="display:none;">
  445. <div></div>
  446. <div></div>
  447. <div></div>
  448. <div></div>
  449. <select id="rooms-list"></select>
  450. </div>
  451. <div class="sec-menu-box" style="display:none;">
  452. <button id="grid">Hide grid</button>
  453. <button id="add-room">Add room</button>
  454. <button id="add-table" disabled>Add table</button>
  455. <a href="#" id="save-restaurant">Save</a>
  456. </div>
  457. </div>
  458. </div>
  459. <div class="room-background" style="display:none;"></div>
  460. <div id="room" class="grid-background" style="display:none;">
  461. </div>
  462. <div id="delete-room" style="display:none;">X</div>
  463. </div>
  464. <div id="user-options-box" style="display:none;">
  465. <div class="res-name">
  466. <label for="res-input-name">име:&nbsp;</label>
  467. <input type="text" id="res-input-name" value="" />
  468. </div>
  469. <div class="res-ppl">
  470. <label for="res-input-name">места:&nbsp;</label>
  471. <input type="number" id="res-input-ppl" value="" />
  472. </div>
  473. <div class="res-clock">
  474. <label for="res-input-name">час:&nbsp;</label>
  475. <input type="time" id="res-input-date" value="" />
  476. </div>
  477. <button id="save-user-options">Запази</button>
  478. <button id="clear-user-options">Изчисти</button>
  479. </div>
  480.  
  481. <script>
  482. //Variable that holds the entire restaurant information in JSON
  483. var restaurantObj;
  484. function restaurant() {
  485. var room = document.getElementById('room'),
  486. addTableBtn = document.getElementById('add-table'),
  487. roomsList = document.getElementById('rooms-list'),
  488. loadAdminRestBtn = document.getElementById('load-restaurant'),
  489. loadUserRestBtn = document.getElementById('file'),
  490. tableCounter = 0,
  491. roomCounter = 0,
  492. currentRoomName,
  493. showGrid = true,
  494. userOptionsBox = document.getElementById('user-options-box'),
  495. tableDiv = document.createElement('div');
  496. tableDiv.className = 'table';
  497.  
  498. restaurantObj = {};
  499.  
  500. document.getElementById('add-room').addEventListener('click', createRoom);
  501.  
  502. addTableBtn.addEventListener('click', createAdminTables);
  503.  
  504. //Get room name on select focus and save it on select change
  505. roomsList.addEventListener('focus', function () {
  506. currentRoomName = this.options[this.selectedIndex].innerText;
  507. });
  508.  
  509. //Add room to the JSON and clear current room field
  510. function createRoom(loadedFile) {
  511. var newRoomName = '';
  512. addTableBtn.disabled = false;
  513. if (!loadedFile.target) {
  514. room.innerHTML = '';
  515. roomsList.innerHTML = '';
  516. for (var prop in loadedFile) {
  517. roomsList.innerHTML += '<option value="' + prop + '">' + prop + '</option>'
  518. }
  519. showHideEls(true);
  520. createAdminTables(loadedFile[roomsList.options[roomsList.selectedIndex].innerText], 0);
  521. }
  522. else {
  523. if (room.style.display == 'inline-block') {
  524. saveCurrentRoom(currentRoomName);
  525. }
  526. newRoomName = prompt('Ednter room name: ');
  527. if (newRoomName == null) {
  528. return;
  529. }
  530. roomCounter++;
  531. room.innerHTML = '';
  532. showHideEls(true);
  533. currentRoomName = (newRoomName == '') ? 'Room ' + roomCounter : newRoomName.trim();
  534. roomsList.innerHTML += '<option value="' + currentRoomName + '">' + currentRoomName + '</option>';
  535. changeSelectedOption(roomsList.options, currentRoomName);
  536. restaurantObj[currentRoomName] = [];
  537. }
  538. };
  539.  
  540. //Save room (on change between rooms and save restaurant
  541. function saveCurrentRoom(name, resName, ppl, clock) {
  542. var tablesInRoom = room.getElementsByClassName('table');
  543. restaurantObj[name] = [];
  544.  
  545. for (var i = 0; i < tablesInRoom.length; i++) {
  546. restaurantObj[name].push({
  547. width: tablesInRoom[i].offsetWidth,
  548. height: tablesInRoom[i].offsetHeight,
  549. left: tablesInRoom[i].offsetLeft,
  550. top: tablesInRoom[i].offsetTop,
  551. borderRadius: tablesInRoom[i].style.borderRadius,
  552. transform: tablesInRoom[i].style.transform,
  553. id: tablesInRoom[i].getElementsByClassName('table-id')[0].innerText,
  554. name: tablesInRoom[i].getElementsByClassName('reserve-name')[0].innerText,
  555. ppl: tablesInRoom[i].getElementsByClassName('reserve-ppl')[0].innerText,
  556. clock: tablesInRoom[i].getElementsByClassName('reserve-clock')[0].innerText
  557. });
  558. }
  559. }
  560.  
  561. //Add table to current room/ JSON array
  562. function createAdminTables(existingTables, num) {
  563. var table = tableDiv.cloneNode(true);
  564. table.innerHTML += '<div><div class="reserve-name"></div><div class="reserve-ppl"></div><div class="reserve-clock"></div><div>';
  565.  
  566. //Check if JSON is loaded and extract table styles from it. If new table is created, generate new table ID
  567. if (Array.isArray(existingTables)) {
  568. setTableStyles(table, existingTables[num]);
  569. }
  570. else {
  571. addTableId(table);
  572. }
  573.  
  574. addTableFunctionality(table);
  575. room.appendChild(table);
  576. num += 1;
  577. if (num && num < existingTables.length) {
  578. return createAdminTables(existingTables, num);
  579. }
  580. return;
  581. }
  582.  
  583. //Set table styles from the loaded JSON(if such exists) and attach invisible div, that holds the table id
  584. function setTableStyles(table, styles) {
  585. table.style.width = styles.width + 'px';
  586. table.style.height = styles.height + 'px';
  587. table.style.left = styles.left + 'px';
  588. table.style.top = styles.top + 'px';
  589. table.style.borderRadius = styles.borderRadius;
  590. table.style.transform = styles.transform;
  591. addTableId(table, styles.id);
  592. return table;
  593. }
  594.  
  595. function addTableId(el, id) {
  596. var tableId = document.createElement('div');
  597. tableId.style.display = 'none';
  598. tableId.className = 'table-id';
  599. if (Number(id) >= 0) {
  600. tableId.innerText = id;
  601. el.appendChild(tableId);
  602. return;
  603. }
  604. tableId.innerText = tableCounter;
  605. el.appendChild(tableId);
  606. tableCounter++;
  607. return;
  608. }
  609.  
  610. document.getElementById('delete-room').addEventListener('click', function () {
  611. var decision = confirm('Are you sure you want to delete the entire room?');
  612. if (decision) {
  613. delete restaurantObj[currentRoomName];
  614. roomsList.removeChild(roomsList.options[roomsList.selectedIndex]);
  615. if (roomsList.children.length == 0) {
  616. showHideEls(false);
  617. return;
  618. }
  619. currentRoomName = roomsList.options[roomsList.selectedIndex].innerText;
  620. createRoom(restaurantObj);
  621. }
  622. });
  623.  
  624. document.getElementById('create-restaurant').addEventListener('click', function () {
  625. document.getElementsByClassName('sec-menu-box')[0].style.display = 'inline-block';
  626.  
  627. roomsList.onchange = function () {
  628. saveCurrentRoom(currentRoomName);
  629. currentRoomName = this.options[this.selectedIndex].innerText;
  630. room.innerHTML = '';
  631. var tablesToLoad = restaurantObj[currentRoomName];
  632. createAdminTables(tablesToLoad, 0);
  633. };
  634. });
  635.  
  636. document.getElementById('save-restaurant').addEventListener('click', function () {
  637. saveCurrentRoom(currentRoomName);
  638. var file = JSON.stringify(restaurantObj),
  639. blob = new Blob([file], { type: "text/text" }),
  640. url = URL.createObjectURL(blob);
  641.  
  642. // update link to new 'url'
  643. this.download = 'Untitled' + ".json";
  644. this.href = url;
  645. });
  646.  
  647. loadAdminRestBtn.addEventListener('change', function (ev) {
  648. var selectedFile = ev.target.files[0],
  649. reader = new FileReader();
  650. reader.readAsText(selectedFile);
  651. reader.onload = function () {
  652. restaurantObj = JSON.parse(reader.result);
  653. createRoom(restaurantObj);
  654. currentRoomName = roomsList.options[roomsList.selectedIndex].innerText;
  655. document.getElementsByClassName('sec-menu-box')[0].style.display = 'inline-block';
  656. showHideEls(true);
  657. roomCounter = Object.keys(restaurantObj).length;
  658. for (var prop in restaurantObj) {
  659. for (var i = 0; i < restaurantObj[prop].length; i++) {
  660. tableCounter++;
  661. }
  662. }
  663. }
  664.  
  665. //Load tables with resizing nad moving events on room change
  666. roomsList.onchange = function () {
  667. saveCurrentRoom(currentRoomName);
  668. currentRoomName = this.options[this.selectedIndex].innerText;
  669. room.innerHTML = '';
  670. var tablesToLoad = restaurantObj[currentRoomName];
  671.  
  672. createAdminTables(tablesToLoad, 0);
  673. };
  674. });
  675.  
  676. loadAdminRestBtn.addEventListener('mousedown', function () {
  677. this.previousSibling.previousSibling.className = 'load-rest-active';
  678. });
  679.  
  680. document.getElementById('grid').addEventListener('click', function () {
  681. showGrid = !showGrid;
  682. if (showGrid) {
  683. room.className = 'grid-background';
  684. this.innerText = 'Hide grid';
  685. }
  686. else {
  687. room.className = '';
  688. this.innerText = 'Show grid';
  689. }
  690. });
  691.  
  692. //Table functionality (rotate, resize, border-radius, drag-to-move, delete table)
  693. function addTableFunctionality(parentEl) {
  694.  
  695. (function resizeRight() {
  696. var resizingDiv = document.createElement('div');
  697. resizingDiv.classList.add('resize-table-right');
  698. resizingDiv.onmousedown = function (ev) {
  699. var startX = ev.pageX,
  700. tableWidth = parentEl.offsetWidth;
  701. document.onmousemove = function (ev) {
  702. parentEl.style.width = (ev.pageX - startX) + tableWidth + 'px';
  703. }
  704. clearMouseMoveEvent();
  705. return;
  706. }
  707. parentEl.appendChild(resizingDiv);
  708. }());
  709.  
  710. (function resizeDown() {
  711. var resizingDiv = document.createElement('div');
  712. resizingDiv.classList.add('resize-table-down');
  713. resizingDiv.onmousedown = function (ev) {
  714. var startY = ev.pageY,
  715. tableHeight = parentEl.offsetHeight;
  716. document.onmousemove = function (ev) {
  717. parentEl.style.height = (ev.pageY - startY) + tableHeight + 'px';
  718. }
  719. clearMouseMoveEvent();
  720. return;
  721. }
  722. parentEl.appendChild(resizingDiv);
  723. }());
  724.  
  725. (function resizeDiagonal() {
  726. var resizingDiv = document.createElement('div');
  727. resizingDiv.classList.add('resize-table-diagonal');
  728. resizingDiv.onmousedown = function (ev) {
  729. var startX = ev.pageX,
  730. startY = ev.pageY,
  731. tableWidth = parentEl.offsetWidth,
  732. tableHeight = parentEl.offsetHeight,
  733. currentDegree = getCurrentRotation(parentEl);
  734. if (currentDegree >= 25 && currentDegree <= 65) {
  735. document.onmousemove = function (ev) {
  736. parentEl.style.width = (ev.pageY - startY) + tableWidth + 'px';
  737. parentEl.style.height = (ev.pageY - startY) + tableHeight + 'px';
  738. }
  739. return;
  740. }
  741. else if (currentDegree < -24 && currentDegree > -66) {
  742.  
  743. document.onmousemove = function (ev) {
  744. parentEl.style.width = (ev.pageX - startX) + tableWidth + 'px';
  745. parentEl.style.height = (ev.pageX - startX) + tableHeight + 'px';
  746. }
  747. return;
  748. }
  749.  
  750. document.onmousemove = function (ev) {
  751. parentEl.style.width = (ev.pageX - startX) + tableWidth + 'px';
  752. parentEl.style.height = (ev.pageY - startY) + tableHeight + 'px';
  753. }
  754. clearMouseMoveEvent();
  755. return;
  756. }
  757. parentEl.appendChild(resizingDiv);
  758. }());
  759.  
  760. (function roundTable() {
  761. var roundTable = document.createElement('input');
  762. roundTable.type = 'range';
  763. roundTable.classList.add('round');
  764. roundTable.min = '0';
  765. roundTable.max = '10';
  766. roundTable.step = '1';
  767. roundTable.value = '0';
  768. roundTable.oninput = function () {
  769. var step = this.value * 5,
  770. diagonalArrow = this.previousSibling,
  771. rotateArrow = this.nextSibling,
  772. delBtn = rotateArrow.nextSibling;
  773. parentEl.style.borderRadius = step + '%';
  774. diagonalArrow.style.bottom = (this.value * 1.5) + '%';
  775. diagonalArrow.style.right = (this.value * 1.5) + '%';
  776. rotateArrow.style.top = (this.value * 1.5) + '%';
  777. rotateArrow.style.left = (this.value * 1.5) + '%';
  778. delBtn.style.top = (this.value * 1.5) + '%';
  779. delBtn.style.right = (this.value * 1.5) + '%';
  780. }
  781. parentEl.appendChild(roundTable);
  782. }());
  783.  
  784. (function rotateTable() {
  785. var rotateDiv = document.createElement('div');
  786. rotateDiv.classList.add('rotate-table');
  787. rotateDiv.draggable = false;
  788. rotateDiv.onmousedown = function (ev) {
  789. var startX = ev.pageX,
  790. startY = ev.pageY,
  791. currentDegree = getCurrentRotation(parentEl),
  792. degree;
  793. document.onmousemove = function (ev) {
  794. degree = ((ev.pageX - startX) / 2) + currentDegree;
  795. if (degree > 95 || degree < -95) {
  796. return;
  797. }
  798. parentEl.style.webkitTransform = 'rotate(' + degree + 'deg)';
  799. parentEl.style.mozTransform = 'rotate(' + degree + 'deg)';
  800. parentEl.style.msTransform = 'rotate(' + degree + 'deg)';
  801. parentEl.style.oTransform = 'rotate(' + degree + 'deg)';
  802. parentEl.style.transform = 'rotate(' + degree + 'deg)';
  803. }
  804. clearMouseMoveEvent();
  805.  
  806. }
  807. parentEl.appendChild(rotateDiv);
  808. }());
  809.  
  810. (function deleteTable() {
  811. var deleteTableBtn = document.createElement('div');
  812. deleteTableBtn.classList.add('delete-table');
  813. deleteTableBtn.draggable = false;
  814. deleteTableBtn.style.display = 'none';
  815. deleteTableBtn.innerText = 'x';
  816. deleteTableBtn.addEventListener('click', function () {
  817. parentEl.parentNode.removeChild(parentEl);
  818. });
  819. parentEl.appendChild(deleteTableBtn);
  820. }());
  821.  
  822. parentEl.onmouseover = function () {
  823. var currentTable = this,
  824. tableOptions = this.children;
  825. for (var i = 2; i < tableOptions.length; i++) {
  826. tableOptions[i].style.display = 'inline-block';
  827. }
  828. };
  829. parentEl.onmouseout = function () {
  830. var currentTable = this,
  831. tableOptions = this.children;
  832. for (var i = 0; i < tableOptions.length; i++) {
  833. tableOptions[i].style.display = 'none';
  834. }
  835. };
  836. parentEl.onmousedown = function (ev) {
  837. if (ev.target.className != this.className) {
  838. return;
  839. }
  840. var currentEl = this,
  841. elParentX = this.parentNode.offsetLeft,
  842. elParentY = this.parentNode.offsetTop,
  843. startX = ev.pageX - (currentEl.offsetLeft + elParentX),
  844. startY = ev.pageY - (currentEl.offsetTop + elParentY);
  845.  
  846. document.onmousemove = function (ev) {
  847. currentEl.style.left = (ev.pageX - elParentX) - startX + 'px';
  848. currentEl.style.top = (ev.pageY - elParentY) - startY + 'px';
  849. };
  850. clearMouseMoveEvent();
  851. };
  852.  
  853. return parentEl;
  854. };
  855.  
  856. //Load user restaurant
  857. loadUserRestBtn.addEventListener('change', function (ev) {
  858. var selectedFile = ev.target.files[0],
  859. reader = new FileReader(),
  860. secMenuBox = document.getElementsByClassName('sec-menu-box')[0];
  861. reader.readAsText(selectedFile);
  862. reader.onload = function () {
  863. restaurantObj = JSON.parse(reader.result);
  864. createUserRoom(restaurantObj);
  865. room.style.display = '';
  866. room.className = '';
  867. secMenuBox.style.display = '';
  868. for (var i = 0; i < 4; i++) {
  869. secMenuBox.children[i].style.display = 'none';
  870. if (i == 3) {
  871. secMenuBox.children[i].style.display = '';
  872. secMenuBox.children[i].style.float = 'right';
  873. }
  874. }
  875. document.getElementById('rooms-list-box').style.display = '';
  876. document.getElementsByClassName('room-background')[0].style.display = '';
  877. }
  878.  
  879. roomsList.onchange = function () {
  880. saveCurrentRoom(currentRoomName);
  881. currentRoomName = this.options[this.selectedIndex].innerText;
  882. userOptionsBox.style.display = 'none';
  883. room.innerHTML = '';
  884. for (var i = 0; i < restaurantObj[currentRoomName].length; i++) {
  885. addUserTables(restaurantObj[currentRoomName][i]);
  886. }
  887. };
  888. });
  889.  
  890. //Generate rooms list from JSON and load current room tables
  891. function createUserRoom(loadedFile) {
  892. room.innerHTML = '';
  893. roomsList.innerHTML = '';
  894. for (var prop in loadedFile) {
  895. roomsList.innerHTML += '<option value="' + prop + '">' + prop + '</option>'
  896. }
  897. currentRoomName = roomsList.options[roomsList.selectedIndex].innerText;
  898.  
  899. for (var i = 0; i < loadedFile[currentRoomName].length; i++) {
  900. addUserTables(loadedFile[currentRoomName][i]);
  901. }
  902. };
  903.  
  904. //Load tables with styles, reservation information and fix the css transform rotate for the reservation fields
  905. function addUserTables(loadedTable) {
  906. var table = tableDiv.cloneNode(true);
  907. setTableStyles(table, loadedTable);
  908. var setZeroDeg = table.style.transform != '' ? table.style.transform : 0;
  909. setZeroDeg = setZeroDeg != 0 ? setZeroDeg.slice(setZeroDeg.lastIndexOf('(') + 1, setZeroDeg.lastIndexOf('deg)')) : 0;
  910. setZeroDeg = (setZeroDeg >= 0) ? setZeroDeg - (setZeroDeg * 2) : setZeroDeg + (setZeroDeg * 2);
  911. table.innerHTML = '<div><div class="reserve-name">' + loadedTable.name + '</div><div class="reserve-ppl">' + loadedTable.ppl +
  912. '</div><div class="reserve-clock">' + loadedTable.clock + '</div>' + '<div class="table-id">' + loadedTable.id + '</div></div>';
  913. table.children[0].style.transform = 'rotate(' + setZeroDeg + 'deg)';
  914. table.children[0].style.height = loadedTable.height + 'px';
  915. table.addEventListener('click', openTableOptions);
  916. room.appendChild(table);
  917. };
  918.  
  919. //Show user-options-box on mouse-click location
  920. function openTableOptions(ev) {
  921. userOptionsBox.style.left = ev.pageX + 'px';
  922. userOptionsBox.style.top = ev.pageY + 'px';
  923. userOptionsBox.style.display = '';
  924. var currentTable = (this.className = 'table') ? this : this.parentNode;
  925. currentTable = (currentTable.className = 'table') ? currentTable : currentTable.parentNode;
  926.  
  927. userOptionsBox.children[3].onclick = function () {
  928. currentTable.children[0].children[0].innerText = userOptionsBox.children[0].children[1].value;
  929. currentTable.children[0].children[1].innerText = userOptionsBox.children[1].children[1].value;
  930. currentTable.children[0].children[2].innerText = userOptionsBox.children[2].children[1].value;
  931. userOptionsBox.style.display = 'none';
  932. };
  933. userOptionsBox.children[4].onclick = function () {
  934. currentTable.children[0].children[0].innerText = '';
  935. currentTable.children[0].children[1].innerText = '';
  936. currentTable.children[0].children[2].innerText = '';
  937. userOptionsBox.style.display = 'none';
  938. };
  939. }
  940.  
  941. //Change selected option when switching rooms or open restaurant file
  942. function changeSelectedOption(opts, val) {
  943. for (var i = 0; i < opts.length; i++) {
  944. if (opts[i].value == val) {
  945. opts[i].selected = 'selected';
  946. }
  947. }
  948. }
  949.  
  950. //Disable dragging or other events that use document.onmousemove
  951. function clearMouseMoveEvent() {
  952. document.onmouseup = function () {
  953. document.onmousemove = null;
  954. }
  955. }
  956.  
  957. function showHideEls(show) {
  958. var displayStyle;
  959. if (show) {
  960. displayStyle = 'inline-block';
  961. }
  962. else {
  963. displayStyle = 'none';
  964. }
  965. document.getElementById('room').style.display = displayStyle;
  966. document.getElementsByClassName('room-background')[0].style.display = displayStyle;
  967. document.getElementById('delete-room').style.display = displayStyle;
  968. document.getElementById('rooms-list-box').style.display = displayStyle;
  969. }
  970.  
  971. //Function for calculating the current element css rotation degree
  972. function getCurrentRotation(elid) {
  973. var st = window.getComputedStyle(elid, null);
  974. var tr = st.getPropertyValue("-webkit-transform") ||
  975. st.getPropertyValue("-moz-transform") ||
  976. st.getPropertyValue("-ms-transform") ||
  977. st.getPropertyValue("-o-transform") ||
  978. st.getPropertyValue("transform") ||
  979. "fail...";
  980.  
  981. if (tr !== "none") {
  982. var values = tr.split('(')[1];
  983. values = values.split(')')[0];
  984. values = values.split(',');
  985. var a = values[0];
  986. var b = values[1];
  987. var c = values[2];
  988. var d = values[3];
  989.  
  990. var scale = Math.sqrt(a * a + b * b);
  991.  
  992. // arc sin, convert from radians to degrees, round
  993. /** /
  994. var sin = b/scale;
  995. var angle = Math.round(Math.asin(sin) * (180/Math.PI));
  996. /*/
  997. var angle = Math.round(Math.atan2(b, a) * (180 / Math.PI));
  998. /**/
  999.  
  1000. } else {
  1001. var angle = 0;
  1002. }
  1003. return angle;
  1004. }
  1005.  
  1006. };
  1007. restaurant();
  1008.  
  1009. </script>
  1010. </body>
  1011. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement