Advertisement
Guest User

Untitled

a guest
May 24th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 16.71 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html><head><title>Seat Random - SCiUS#11 M.4/2</title><meta charset="utf-" />
  3. <script type="text/javascript">
  4.  
  5. // ===================
  6. //  EDIT SETTING HERE
  7. // ===================
  8.  
  9. // !!! CAUTION !!!
  10. // Please carefully edit this file, strictly follow the code syntax/grammar.
  11. // Any mistakes may result in unopenable file.
  12.  
  13. // If you don't to show the name, change this to false
  14. var showName = true;
  15.  
  16. /*
  17.  * This set the pattern of the seat
  18.  *
  19.  * 'x' means the seat
  20.  * '-' means the small seperator
  21.  * '_' means the large seperator (has the same size as the seat)
  22.  */
  23. var seatPattern = [
  24.     "xxx-xxx",
  25.     "xxx-xxx",
  26.     "xxx-xxx",
  27.     "xxx-xxx",
  28.     "xxx-xxx"
  29. ];
  30.  
  31. /*
  32.  * This set the showing name
  33.  */
  34. var nameList = [
  35.     "บอล",
  36.     "น้องวิลลี่",
  37.     "พาย",
  38.     "แบงค์",
  39.     "เติ้ล",
  40.     "สปาย",
  41.     "แช๊ป",
  42.     "เอิร์ท",
  43.     "ภพ",
  44.     "แฟรงค์",
  45.     "น้ำมนต์",
  46.     "ข้าวปั้น",
  47.     "ไท",
  48.     "ทาม",
  49.     "กันต์",
  50.     "อาร์ม",
  51.     "เอเธนส์",
  52.     "ณัฐฐ์",
  53.     "น้ำ",
  54.     "มะตูม",
  55.     "แพรพลอย",
  56.     "ออย",
  57.     "ขิม",
  58.     "มุก",
  59.     "ป่าน",
  60.     "ปูน",
  61.     "ฝ้าย",
  62.     "จิง",
  63.     "เจียเจีย",
  64.     "เอมมี่"
  65. ];
  66.  
  67. // ================
  68. //  END OF SETTING
  69. // ================
  70.  
  71.  
  72. var smallSeperatorSizeRatio = 0.4;
  73.  
  74. var rowCount, seatCount;
  75.  
  76. function createShuffledArray(size) {
  77.     var arr = [];
  78.     var i, j;
  79.  
  80.     // Initialize Array
  81.     for (i = 0; i < size; i++) {
  82.        arr[i] = -1;
  83.    }
  84.  
  85.    // Shuffle Operation
  86.    for (i = 0; i < size; i++) {
  87.        var num = Math.floor(Math.random() * (size - i));
  88.        // Just in case, when the floating point precision goes wrong. ??
  89.        num = Math.min(num, size - i - 1);
  90.        var pos = -1;
  91.        for (j = 0; j <= num; j++) {
  92.            do {
  93.                pos++;
  94.            } while (arr[pos] !== -1);
  95.        }
  96.        arr[pos] = i;
  97.    }
  98.  
  99.    return arr;
  100. }
  101.  
  102. function setSeatDetail(rowNum, colNum, seatVal) {
  103.    // var seatDiv = document.getElementById("seat_" + rowNum + "_" + colNum);
  104.    var mainTextDiv = document.getElementById("maintext_" + rowNum + "_" + colNum);
  105.    var subTextDiv = document.getElementById("subtext_" + rowNum + "_" + colNum);
  106.    mainTextDiv.innerHTML = seatVal + 1;
  107.    if (nameList[seatVal] !== undefined) {
  108.        subTextDiv.innerHTML = nameList[seatVal];
  109.    } else {
  110.        subTextDiv.innerHTML = "";
  111.    }
  112. }
  113.  
  114. function randomSeat() {
  115.    var i, j;
  116.    var seatVal = createShuffledArray(seatCount);
  117.    var curPos = 0;
  118.  
  119.    for (i = 0; i < rowCount; i++) {
  120.        var colCount = seatPattern[i].length;
  121.        for (j = 0; j < colCount; j++) {
  122.            if (seatPattern[i].substr(j, 1) === "x") {
  123.                setSeatDetail(i, j, seatVal[curPos]);
  124.                curPos++;
  125.            }
  126.        }
  127.    }
  128. }
  129.  
  130. function createSeatDiv(rowNum, colNum, seatType) {
  131.    var seatDiv = document.createElement("div");
  132.  
  133.    switch (seatType) {
  134.        case "x":
  135.            var centererDiv = document.createElement("div");
  136.            centererDiv.className = "center";
  137.  
  138.            var centererDiv2 = document.createElement("div");
  139.            centererDiv2.className = "center2";
  140.  
  141.            seatDiv.className = "seat";
  142.            seatDiv.id = "seat_" + rowNum + "_" + colNum;
  143.  
  144.            var mainTextDiv = document.createElement("div");
  145.            mainTextDiv.className = "mainText";
  146.            mainTextDiv.id = "maintext_" + rowNum + "_" + colNum;
  147.  
  148.            var subTextDiv = document.createElement("div");
  149.            subTextDiv.className = "subText";
  150.            subTextDiv.id = "subtext_" + rowNum + "_" + colNum;
  151.  
  152.            centererDiv2.appendChild(mainTextDiv);
  153.            centererDiv2.appendChild(subTextDiv);
  154.  
  155.            centererDiv.appendChild(centererDiv2);
  156.            seatDiv.appendChild(centererDiv);
  157.  
  158.            break;
  159.    }
  160.  
  161.    return seatDiv;
  162. }
  163.  
  164. function createSeatRowDiv(rowNum) {
  165.    var colCount = seatPattern[rowNum].length;
  166.  
  167.    var rowDiv = document.createElement("div");
  168.    rowDiv.className = "seatRow";
  169.    rowDiv.style.height = (100 / rowCount) + "%";
  170.  
  171.    // Calculating the width
  172.    var seatCount = 0;
  173.    var smallSeperatorCount = 0;
  174.    var largeSeperatorCount = 0;
  175.    for (i = 0; i < colCount; i++) {
  176.        var seatType = seatPattern[rowNum].substr(i, 1);
  177.        switch (seatType) {
  178.            case "x":
  179.                seatCount++;
  180.                break;
  181.            case "-":
  182.                smallSeperatorCount++;
  183.                break;
  184.            case "_":
  185.                largeSeperatorCount++;
  186.                break;
  187.        }
  188.    }
  189.    var totalSize = seatCount + largeSeperatorCount + smallSeperatorCount * smallSeperatorSizeRatio;
  190.    var seatSize = 100.0 / totalSize;
  191.    var smallSeperatorSize = smallSeperatorSizeRatio * 100.0 / totalSize;
  192.  
  193.    // Creating divs
  194.    for (i = 0; i < colCount; i++) {
  195.        var colDiv = document.createElement("div");
  196.        colDiv.className = "seatCol";
  197.        var seatType = seatPattern[rowNum].substr(i, 1);
  198.        switch (seatType) {
  199.            case "x":
  200.                colDiv.style.width = seatSize + "%";
  201.                colDiv.appendChild(createSeatDiv(rowNum, i, seatType));
  202.                break;
  203.            case "-":
  204.                colDiv.style.width = smallSeperatorSize + "%";
  205.                break;
  206.            case "_":
  207.                colDiv.style.width = seatSize + "%";
  208.                break;
  209.        }
  210.  
  211.        rowDiv.appendChild(colDiv);
  212.    }
  213.  
  214.    return rowDiv;
  215. }
  216.  
  217. function initializeSeatTable() {
  218.    "use strict";
  219.  
  220.    var tableDiv = document.getElementById("main-seat-grid");
  221.  
  222.    var i;
  223.    for (i = 0; i < rowCount; i++) {
  224.        tableDiv.appendChild(createSeatRowDiv(i));
  225.    }
  226. }
  227.  
  228. function processSeatPattern() {
  229.    var i, j;
  230.    rowCount = seatPattern.length;
  231.    seatCount = 0;
  232.    for (i = 0; i < rowCount; i++) {
  233.        seatPattern[i] = seatPattern[i].toLowerCase();
  234.        var colCount = seatPattern[i].length;
  235.        for (j = 0; j < colCount; j++) {
  236.            if (seatPattern[i].substr(j, 1) == "x") {
  237.                seatCount++;
  238.            }
  239.        }
  240.    }
  241. }
  242.  
  243. var isSettingPopupShowing = false;
  244. function toggleSettingPopup() {
  245.    if (isSettingPopupShowing === false) {
  246.        isSettingPopupShowing = true;
  247.        document.getElementById("setting_popup").style.display = "block";
  248.    } else {
  249.        isSettingPopupShowing = false;
  250.        document.getElementById("setting_popup").style.display = "none";
  251.    }
  252. }
  253.  
  254. window.onload = function() {
  255.    processSeatPattern();
  256.    initializeSeatTable();
  257.    randomSeat();
  258.    document.getElementById("random_btn").onclick = randomSeat;
  259.    document.getElementById("setting_btn").onclick = toggleSettingPopup;
  260.    document.getElementById("setting_close_btn").onclick = toggleSettingPopup;
  261. };
  262.  
  263. </script>
  264. <style>
  265.  
  266. /* Eric Meyer's Reset CSS v2.0 - http://cssreset.com */
  267. html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video{border:0;font-size:100%;font:inherit;vertical-align:baseline;margin:0;padding:0}article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:none}table{border-collapse:collapse;border-spacing:0}
  268.  
  269. body, html {
  270.     font-family: "Segoe UI", "Helvetica Neue", Helvetica, Roboto, Arial, sans-serif;
  271.     background-color: #F3F3F3;
  272.     color: #444;
  273.     height: 100%;
  274. }
  275. .header-row {
  276.     background: #FFF;
  277.     color: #666;
  278.     height: 1em;
  279.     padding: 1em 1.5em;
  280.     box-shadow: 0em 0em 0.5em rgba(0, 0, 0, 0.2);
  281.     position: fixed;
  282.     left: 0;
  283.     right: 0;
  284.     z-index: 2;
  285. }
  286. .left {
  287.     float: left;
  288. }
  289. .right {
  290.     float: right;
  291. }
  292.  
  293. .random-btn {
  294.     font-family: "Segoe UI", "Helvetica Neue", Helvetica, Roboto, Arial, sans-serif;
  295.     border: 1px solid #ef8f2f;
  296.     background: white;
  297.     color: #ef8f2f;
  298.     padding: 0.2em 1em;
  299.     margin-top: -0.4em;
  300.     border-radius: 0.2em;
  301.     font-size: 1.0em;
  302. }
  303. .random-btn:hover {
  304.     background: #f6f6f6;
  305. }
  306. .random-btn:active {
  307.     background: #ef8f2f;
  308.     color: #FFF;
  309. }
  310. .random-btn:focus {
  311.     outline: 0;
  312. }
  313.  
  314. .setting-btn, .close-button {
  315.     font-family: "Segoe UI", "Helvetica Neue", Helvetica, Roboto, Arial, sans-serif;
  316.     border: 1px solid #CCC;
  317.     background: white;
  318.     color: #CCC;
  319.     padding: 0.2em 1em;
  320.     margin-top: -0.4em;
  321.     margin-right: 0.5em;
  322.     border-radius: 0.2em;
  323.     font-size: 1.0em;
  324. }
  325. .setting-btn:hover, .close-button:hover {
  326.     border: 1px solid #999;
  327.     color: #999;
  328. }
  329. .setting-btn:active, .close-button:active {
  330.     border: 1px solid #999;
  331.     background: #f6f6f6;
  332.     color: #999;
  333. }
  334. .setting-btn:focus, .close-button:focus {
  335.     outline: 0;
  336. }
  337.  
  338. .main-section {
  339.     position: absolute;
  340.     top: 3.5em;
  341.     bottom: 0.5em;
  342.     left: 0;
  343.     right: 0;
  344. }
  345. .container {
  346.     position: relative;
  347.     height: 100%;
  348. }
  349. .seatRow {
  350.     padding: 0 1.5em;
  351.     min-height: 4.4em;
  352. }
  353. .seatCol {
  354.     box-sizing: border-box;
  355.     display: block;
  356.     float:left;
  357.     height: 100%;
  358.     padding: 0.1em 0.2em;
  359.     white-space:nowrap;
  360. }
  361. .seat {
  362.     background-color: #FFF;
  363.     width: 100%;
  364.     height: 100%;
  365.     text-align: center;
  366.     border: 1px solid #EEE;
  367.     border-radius: 0.1em;
  368.     overflow: hidden;
  369. }
  370. .seat .center {
  371.     height: 100%;
  372.     display: inline-table;
  373. }
  374. .seat .center2 {
  375.     display: table-cell;
  376.     vertical-align: middle;
  377. }
  378. .seat .mainText {
  379.     font-size: 1.8em;
  380.     white-space: nowrap;
  381. }
  382. .seat .subText {
  383.     font-size: 1.2em;
  384.     margin-top: 0.3em;
  385.     margin-bottom: 0.2em;
  386.     color: #888;
  387.     text-overflow: clip;
  388.     white-space: nowrap;
  389. }
  390.  
  391. .setting-popup {
  392.     position: fixed;
  393.     right: 7.6em;
  394.     top: 2.8em;
  395.     background: #FFF;
  396.     box-shadow: 0 0.5em 1.5em rgba(0, 0, 0, 0.4);
  397.     padding: 2em;
  398.     z-index: 1;
  399.     border-radius: 0.3em;
  400.     width: 30em;
  401.     line-height: 1.5em;
  402.     max-height: 20em;
  403.     overflow:auto;
  404. }
  405.  
  406. .setting-popup h1 {
  407.     font-size: 1.5em;
  408.     margin-bottom: 1.1em;
  409. }
  410. .setting-popup p {
  411.     margin-top: 0.8em;
  412. }
  413. em {
  414.     font-style: italic;
  415. }
  416. strong {
  417.     font-weight: bold;
  418. }
  419.  
  420. </style>
  421. </head>
  422. <body>
  423.     <div id="setting_popup" class="setting-popup" style="display: none;">
  424.         <div>
  425.             <div class="left">
  426.                 <h1>How to Adjust Settings</h1>
  427.             </div>
  428.             <div class="right">
  429.                 <button class="close-button" id="setting_close_btn">Close</button>
  430.             </div>
  431.         </div>
  432.         <div style="clear: both;">
  433.             <p>
  434.                 The settings that you are able to adjust are follow: 1) Seat Pattern 2) Names List 3) Show/Hide Names
  435.             </p>
  436.             <p>
  437.                 <strong>NOTE: Please be careful editing settings. Strictly follow the grammar and do a backup of this file (simply by cloning/copying the file) before editing so you'll be safe.</strong>
  438.             </p>
  439.             <p>
  440.                 Notice that after an array of "..." must have comma (,) afterward except the last line (see the settings for example).
  441.             </p>
  442.             <p>
  443.                 To adjust the settings, please open this file with the text editor program like Notepad (not the web browsers like Chrome).</p>
  444.             <p>
  445.  
  446.             </p>
  447.             <p>
  448.                 You can open <em>Notepad</em> by several methods: 1) Searching for the program names <em>Notepad</em> in the Start Menu. 2) Press Windows + R keys combination. The <em>Run</em> window will appear. Type <em>notepad</em>, then click OK. The Notepad will appear. 3) Right-click at a file > Open With > Notepad (if exists).
  449.             </p>
  450.             <p>
  451.                 If you need any assistance, feel free to contact Kasidit Iamthong. ??
  452.             </p>
  453.         </div>
  454.     </div>
  455.     <div class="container">
  456.         <div class="header-row">
  457.             <div class="left">Seat Randomer</div>
  458.             <div class="right">
  459.                 <button class="setting-btn" id="setting_btn">Settings</button>
  460.                 <button class="random-btn" id="random_btn">Random</button>
  461.             </div>
  462.         </div>
  463.         <div class="main-section" id="main-seat-grid">
  464.         </div>
  465.     </div>
  466. </body>
  467. </html>
  468. var rowCount, seatCount;
  469.  
  470. function createShuffledArray(size) {
  471.     var arr = [];
  472.     var i, j;
  473.  
  474.     // Initialize Array
  475.     for (i = 0; i < size; i++) {
  476.        arr[i] = -1;
  477.    }
  478.  
  479.    // Shuffle Operation
  480.    for (i = 0; i < size; i++) {
  481.        var num = Math.floor(Math.random() * (size - i));
  482.        // Just in case, when the floating point precision goes wrong. ??
  483.        num = Math.min(num, size - i - 1);
  484.        var pos = -1;
  485.        for (j = 0; j <= num; j++) {
  486.            do {
  487.                pos++;
  488.            } while (arr[pos] !== -1);
  489.        }
  490.        arr[pos] = i;
  491.    }
  492.  
  493.    return arr;
  494. }
  495.  
  496. function setSeatDetail(rowNum, colNum, seatVal) {
  497.    // var seatDiv = document.getElementById("seat_" + rowNum + "_" + colNum);
  498.    var mainTextDiv = document.getElementById("maintext_" + rowNum + "_" + colNum);
  499.    var subTextDiv = document.getElementById("subtext_" + rowNum + "_" + colNum);
  500.    mainTextDiv.innerHTML = seatVal + 1;
  501.    if (nameList[seatVal] !== undefined) {
  502.        subTextDiv.innerHTML = nameList[seatVal];
  503.    } else {
  504.        subTextDiv.innerHTML = "";
  505.    }
  506. }
  507.  
  508. function randomSeat() {
  509.    var i, j;
  510.    var seatVal = createShuffledArray(seatCount);
  511.    var curPos = 0;
  512.  
  513.    for (i = 0; i < rowCount; i++) {
  514.        var colCount = seatPattern[i].length;
  515.        for (j = 0; j < colCount; j++) {
  516.            if (seatPattern[i].substr(j, 1) === "x") {
  517.                setSeatDetail(i, j, seatVal[curPos]);
  518.                curPos++;
  519.            }
  520.        }
  521.    }
  522. }
  523.  
  524. function createSeatDiv(rowNum, colNum, seatType) {
  525.    var seatDiv = document.createElement("div");
  526.  
  527.    switch (seatType) {
  528.        case "x":
  529.            var centererDiv = document.createElement("div");
  530.            centererDiv.className = "center";
  531.  
  532.            var centererDiv2 = document.createElement("div");
  533.            centererDiv2.className = "center2";
  534.  
  535.            seatDiv.className = "seat";
  536.            seatDiv.id = "seat_" + rowNum + "_" + colNum;
  537.  
  538.            var mainTextDiv = document.createElement("div");
  539.            mainTextDiv.className = "mainText";
  540.            mainTextDiv.id = "maintext_" + rowNum + "_" + colNum;
  541.  
  542.            var subTextDiv = document.createElement("div");
  543.            subTextDiv.className = "subText";
  544.            subTextDiv.id = "subtext_" + rowNum + "_" + colNum;
  545.  
  546.            centererDiv2.appendChild(mainTextDiv);
  547.            centererDiv2.appendChild(subTextDiv);
  548.  
  549.            centererDiv.appendChild(centererDiv2);
  550.            seatDiv.appendChild(centererDiv);
  551.  
  552.            break;
  553.    }
  554.  
  555.    return seatDiv;
  556. }
  557.  
  558. function createSeatRowDiv(rowNum) {
  559.    var colCount = seatPattern[rowNum].length;
  560.  
  561.    var rowDiv = document.createElement("div");
  562.    rowDiv.className = "seatRow";
  563.    rowDiv.style.height = (100 / rowCount) + "%";
  564.  
  565.    // Calculating the width
  566.    var seatCount = 0;
  567.    var smallSeperatorCount = 0;
  568.    var largeSeperatorCount = 0;
  569.    for (i = 0; i < colCount; i++) {
  570.        var seatType = seatPattern[rowNum].substr(i, 1);
  571.        switch (seatType) {
  572.            case "x":
  573.                seatCount++;
  574.                break;
  575.            case "-":
  576.                smallSeperatorCount++;
  577.                break;
  578.            case "_":
  579.                largeSeperatorCount++;
  580.                break;
  581.        }
  582.    }
  583.    var totalSize = seatCount + largeSeperatorCount + smallSeperatorCount * smallSeperatorSizeRatio;
  584.    var seatSize = 100.0 / totalSize;
  585.    var smallSeperatorSize = smallSeperatorSizeRatio * 100.0 / totalSize;
  586.  
  587.    // Creating divs
  588.    for (i = 0; i < colCount; i++) {
  589.        var colDiv = document.createElement("div");
  590.        colDiv.className = "seatCol";
  591.        var seatType = seatPattern[rowNum].substr(i, 1);
  592.        switch (seatType) {
  593.            case "x":
  594.                colDiv.style.width = seatSize + "%";
  595.     }
  596.         }
  597.  
  598.             }
  599.  
  600. </script>
  601. </head>
  602. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement