forked from inker/draw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
1 lines (1 loc) · 17.8 KB
/
script.js
1
!function t(e,n,r){function o(s,a){if(!n[s]){if(!e[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(i)return i(s,!0);var l=new Error("Cannot find module '"+s+"'");throw l.code="MODULE_NOT_FOUND",l}var c=n[s]={exports:{}};e[s][0].call(c.exports,function(t){var n=e[s][1][t];return o(n?n:t)},c,c.exports,t,e,n,r)}return n[s].exports}for(var i="function"==typeof require&&require,s=0;s<r.length;s++)o(r[s]);return o}({1:[function(t,e,n){"use strict";function r(t,e){return void 0===e&&(e=!0),o(t).then(e?i:s)}function o(t){return d("https://proxy-antonv.rhcloud.com/?url="+encodeURIComponent(t)+"&encoding=latin1").then(function(t){return t.text()}).catch(function(t){return alert("Proxies are down. Refreshing the page may help.")})}function i(t){return d("json/pairings.json").then(function(t){return t.json()}).then(function(e){return u(a(t),e)}).then(function(t){return l(t)})}function s(t){t=t.slice(t.lastIndexOf("--------------"));for(var e,n=[[],[]],r=/\s*(.+?)(\s\*+\d?|\([CE]L-TH\)?\s+)?\s{2,}(\w{3})\s+/g,o=0;o<16&&null!==(e=r.exec(t));++o)n[o%2].push(new c.Last16Team(e[1],e[3],o>>1));return n}function a(t){var e=/\s*(.+?)\s*(\*+\d?|\([CE]L-TH\))?\s+(\w{3})\s+(\d{1,3}\.\d{3})/g;t=t.slice(t.indexOf("Pot 1"));for(var n,r=[];null!==(n=e.exec(t));)r.push(new c.GSTeam(n[1],n[3],+n[4]));return r}function u(t,e){for(var n=0,r=e;n<r.length;n++){var o=r[n],i=o.map(function(e){return t.find(function(t){return t.name.includes(e)})});i[0].pairing=i[1],i[1].pairing=i[0]}return t}function l(t){for(var e=[[],[],[],[]],n=0;n<t.length;++n)e[n>>4<<1|n%2].push(t[n]);return e}var c=t("./team");"Promise"in window&&"fetch"in window||alert("The draw simulation only works in Chrome, Opera & Firefox.");var d=(window.Promise,window.fetch);Object.defineProperty(n,"__esModule",{value:!0}),n.default=r,n.fetchPots=o,n.parseGS=i,n.parseLast16Teams=s},{"./team":7}],2:[function(t,e,n){"use strict";var r=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)},o=t("./possible-groups"),i=t("../util"),s=t("../visualizer"),a=function(t){function e(){return t.apply(this,arguments)||this}return r(e,t),e.prototype.prepareDraw=function(t){var e=this,n=window.fetch("json/country-names.json").then(function(t){return t.json()});this.pots=t.map(function(t){return t.slice()}),this.groups=[];for(var r=0;r<t[0].length;++r)this.groups.push([]);var o=document.createElement("div");o.id="tables-div",this.potsDiv=document.createElement("div"),this.potsDiv.id="pots-div";for(var r=0;r<t.length;++r){var i=t[r],s=document.createElement("table");s.innerHTML="<thead><tr><th>Pot "+(r+1)+"</th></tr></thead><tbody></tbody>";for(var a=s.tBodies[0],u=0,l=i;u<l.length;u++){var c=l[u],d=a.insertRow().insertCell();d.textContent=c.name,void 0!==c.pairing&&(d.title="paired with "+c.pairing.name)}this.potsDiv.appendChild(s)}n.then(function(n){for(var r=e.potsDiv.children.length,o=0;o<r;++o)for(var i=e.potsDiv.children[o],s=i.tBodies[0].rows,a=0;a<s.length;++a){var u=n[t[o][a].country.toLowerCase()].replace(" ","-"),l="http://icons.iconarchive.com/icons/gosquared/flag/16/"+u+"-flat-icon.png";s[a].cells[0].style.backgroundImage="url("+l+")"}}),o.appendChild(this.potsDiv),this.groupsDiv=document.createElement("div"),this.groupsDiv.id="groups-div";for(var h=document.createDocumentFragment(),r=0;r<t[0].length;++r){var s=document.createElement("table");s.innerHTML="<thead><tr><th>Group "+String.fromCharCode(65+r)+"</th></tr></thead><tbody>"+"<tr><td/></tr>".repeat(t.length)+"</tbody>",h.appendChild(s)}this.groupsDiv.appendChild(h),o.appendChild(this.groupsDiv),document.body.appendChild(o);var p=document.createElement("div");p.id="bowls-div",this.teamBowl=document.createElement("div"),this.teamBowl.id="team-bowl",this.teamBowl.classList.add("bowl"),p.appendChild(this.teamBowl),this.announcement=document.createElement("div"),this.announcement.id="announcement",p.appendChild(this.announcement),this.groupBowl=document.createElement("div"),this.groupBowl.id="group-bowl",this.groupBowl.classList.add("bowl"),p.appendChild(this.groupBowl),document.body.appendChild(p),this.currentPotNum=0},e.prototype.runDraw=function(){if(this.currentPotNum>0||this.groups.some(function(t){return t.length>0})||this.pots.some(function(t){return t.length<8}))throw new Error("cannot start draw");this.fillTeamBowl(),t.prototype.runDraw.call(this)},e.prototype.fillTeamBowl=function(){for(var t=this.pots[this.currentPotNum],e=0,n=i.shuffle(t.map(function(t,e){return e}));e<n.length;e++){var r=n[e],o=document.createElement("div");o.classList.add("ball"),o.textContent=t[r].name,o.dataset.team=r.toString(),o.addEventListener("click",this.onTeamBallPick.bind(this)),this.teamBowl.appendChild(o)}},e.prototype.onTeamBallPick=function(t){this.teamBowl.classList.add("dont-touch");var e=t.target;e.classList.add("ball-picked");var n=this.pots[this.currentPotNum],r=n.findIndex(function(t){return t.name===e.textContent});this.pickedTeam=n.splice(r,1)[0];for(var s=o.default(this.pots,this.groups,this.pickedTeam,this.currentPotNum),a=0,u=s;a<u.length;a++){var l=u[a],c=i.getCell(this.groupsDiv.children[l],this.currentPotNum);c.classList.add("possible-group")}var d=i.getCell(this.potsDiv.children[this.currentPotNum],parseInt(e.getAttribute("data-team")));d.classList.add("team-selected");var h=s.map(function(t){return String.fromCharCode(65+t)}).join(", ");this.announcement.textContent="Possible groups for "+this.pickedTeam.name+": "+h,this.fillGroupBowl(s)},e.prototype.fillGroupBowl=function(t){for(var e=0,n=i.shuffle(t);e<n.length;e++){var r=n[e],o=document.createElement("div");o.classList.add("ball"),o.textContent=String.fromCharCode(65+r),o.dataset.group=r.toString(),o.addEventListener("click",this.onGroupBallPicked.bind(this)),this.groupBowl.appendChild(o)}},e.prototype.onGroupBallPicked=function(t){var e=this,n=+t.target.dataset.group;this.groups[n].push(this.pickedTeam),this.pickedTeam=null;var r=this.teamBowl.querySelector(".ball-picked");this.teamBowl.removeChild(r);var o=i.getCell(this.groupsDiv.children[n],this.currentPotNum),s=i.getCell(this.potsDiv.children[this.currentPotNum],+r.getAttribute("data-team"));s.classList.remove("team-selected"),s.classList.add("greyed"),i.animateContentTransfer(s,o,300).then(function(){o.classList.remove("possible-group"),o.classList.add("team-emerge")}),this.announcement.textContent="Group "+String.fromCharCode(65+n)+"!",i.removeAllChildren(this.groupBowl),this.teamBowl.classList.remove("dont-touch"),this.teamBowl.onclick=null;for(var a=this.groupsDiv.children,u=0;u<a.length;++u)u!==n&&i.getCell(a[u],this.currentPotNum).classList.remove("possible-group");if(!(this.pots[this.currentPotNum].length>0))if(this.potsDiv.children[this.currentPotNum].tHead.classList.add("greyed"),this.currentPotNum<3)++this.currentPotNum,this.fillTeamBowl(),this.announcement.textContent="Pick a ball";else{var l=this.groupBowl.parentElement;l.removeChild(this.groupBowl),l.removeChild(this.teamBowl),this.announcement.innerHTML="Draw completed! ";var c=document.getElementById("restart").cloneNode(!0);c.addEventListener("click",function(t){return e.restart()}),this.announcement.appendChild(c)}},e}(s.default);Object.defineProperty(n,"__esModule",{value:!0}),n.default=a},{"../util":8,"../visualizer":9,"./possible-groups":3}],3:[function(t,e,n){"use strict";function r(t,e,n,r){return console.log(n),e.every(function(t){return 0===t.length})?e.map(function(t,e){return e}):i(e,n,r).filter(function(i){e[i].push(n);var s=o(t,e,r);return e[i].pop(),s})}function o(t,e,n){if(0===t[n].length&&++n===t.length)return!0;for(var r=t[n],s=r.pop(),a=!1,u=0,l=i(e,s,n);u<l.length;u++){var c=l[u],d=e[c];if(d.push(s),a=o(t,e,n),d.pop(),a)break}return r.push(s),a}function i(t,e,n){var r=s(t,e,n,0,t.length>>1),o=s(t,e,n,t.length>>1,t.length);return 0===r.length?o:0===o.length?r:r.concat(o)}function s(t,e,n,r,o){for(var i=[],s="Rus"===e.country?function(t){return"Ukr"===t.country}:"Ukr"===e.country?function(t){return"Rus"===t.country}:function(t){return!1},a=r;a<o;++a){for(var u=t[a],l=!0,c=0,d=u;c<d.length;c++){var h=d[c];if(h.country===e.country||s(h)){if(l=!1,h.pairing===e)return[];break}}l&&u.length<=n&&i.push(a)}return i}Object.defineProperty(n,"__esModule",{value:!0}),n.default=r},{}],4:[function(t,e,n){"use strict";var r=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)},o=t("./last16"),i=t("../util"),s=t("../visualizer"),a=function(t){function e(){return t.apply(this,arguments)||this}return r(e,t),e.prototype.prepareDraw=function(t){var e=this,n=window.fetch("json/country-names.json").then(function(t){return t.json()});this.pots=t.map(function(t){return t.slice()}),this.matchups=[];for(var r=0;r<t[0].length;++r)this.matchups.push([]);var o=document.createElement("div");o.id="tables-div",o.style.width="400px",o.style.minWidth="400px",this.potsDiv=document.createElement("div"),this.potsDiv.id="pots-div";for(var i=["Group winners","Runners-up"],r=0;r<t.length;++r){var s=t[r],a=document.createElement("table");a.innerHTML="<thead><tr><th>"+i[r]+"</th></tr></thead><tbody></tbody>";for(var u=a.tBodies[0],l=0,c=s;l<c.length;l++){var d=c[l];u.insertRow().insertCell().textContent=d.name}this.potsDiv.appendChild(a)}n.then(function(n){for(var r=e.potsDiv.children,o=0;o<r.length;++o)for(var i=e.potsDiv.children[o],s=i.tBodies[0].rows,a=0;a<s.length;++a){var u=n[t[o][a].country.toLowerCase()].replace(" ","-"),l="http://icons.iconarchive.com/icons/gosquared/flag/16/"+u+"-flat-icon.png";s[a].cells[0].style.backgroundImage="url("+l+")"}}),o.appendChild(this.potsDiv),this.matchupDiv=document.createElement("div"),this.matchupDiv.innerHTML='<table id="matchups"><thead><tr><th colspan="3">Matchups</th></tr></thead><tbody>'+"<tr><td/><td>v</td><td/></tr>".repeat(t[0].length)+"</tbody></table>",o.appendChild(this.matchupDiv),document.body.appendChild(o);var h=document.createElement("div");h.id="bowls-div",this.runnerUpBowl=document.createElement("div"),this.runnerUpBowl.id="team-bowl",this.runnerUpBowl.classList.add("bowl"),h.appendChild(this.runnerUpBowl),this.announcement=document.createElement("div"),this.announcement.id="announcement",h.appendChild(this.announcement),this.groupWinnerBowl=document.createElement("div"),this.groupWinnerBowl.id="group-bowl",this.groupWinnerBowl.classList.add("bowl"),h.appendChild(this.groupWinnerBowl),document.body.appendChild(h),this.currentMatchupNum=0},e.prototype.runDraw=function(){if(this.currentMatchupNum>0||this.matchups.some(function(t){return t.length>0})||this.pots.some(function(t){return t.length<8}))throw console.log("current matchup",this.currentMatchupNum,"matchups",this.matchups.map(function(t){return t.length}),"pots",this.pots.map(function(t){return t.length})),new Error("cannot start draw");this.fillBowl(1,this.pots[1].map(function(t,e){return e})),t.prototype.runDraw.call(this)},e.prototype.fillBowl=function(t,e){for(var n=(1===t?this.onRunnerUpBallPick:this.onGroupWinnerBallPicked).bind(this),r=1===t?this.runnerUpBowl:this.groupWinnerBowl,o=this.pots[t],s=i.shuffle(e),a=document.createDocumentFragment(),u=0,l=s;u<l.length;u++){var c=l[u],d=document.createElement("div");d.classList.add("ball"),d.textContent=o[c].name,d.dataset.team=c.toString(),d.addEventListener("click",n),a.appendChild(d)}r.appendChild(a),0===t&&1===e.length&&setTimeout(function(){return r.firstElementChild.click()},200)},e.prototype.onRunnerUpBallPick=function(t){this.runnerUpBowl.classList.add("dont-touch");var e=t.target;e.classList.add("ball-picked");var n=this.pots,r=n[0],s=n[1],a=s.findIndex(function(t){return t.name===e.textContent}),u=s.splice(a,1)[0];this.matchups[this.currentMatchupNum].push(u);var l=i.getCell(this.potsDiv.lastElementChild,+e.getAttribute("data-team")),c=this.matchupDiv.firstElementChild.tBodies[0].rows[this.currentMatchupNum].cells[0];i.animateContentTransfer(l,c,300).then(function(){return c.classList.add("team-emerge")}),l.classList.add("greyed");for(var d=o.default(this.pots,this.matchups,this.currentMatchupNum),h=d.map(function(t){return r[t].name}),p=this.potsDiv.firstElementChild.tBodies[0].rows,m=0,f=[].map.call(p,function(t){return t.cells[0]});m<f.length;m++){var v=f[m];h.indexOf(v.textContent)>-1&&(v.style.color="#00f")}var g=d.map(function(t){return r[t].name}).join(", ");this.announcement.textContent="Possible opponents for "+u.name+": "+g,this.fillBowl(0,d),this.groupWinnerBowl.classList.remove("dont-touch")},e.prototype.onGroupWinnerBallPicked=function(t){var e=this;this.groupWinnerBowl.classList.add("dont-touch");var n=this.pots,r=n[0],o=n[1],s=t.target,a=r.findIndex(function(t){return t.name===s.textContent}),u=r.splice(a,1)[0];this.matchups[this.currentMatchupNum].push(u);for(var l=[].map.call(this.potsDiv.firstElementChild.tBodies[0].rows,function(t){return t.cells[0]}),c=0,d=l;c<d.length;c++){var h=d[c];h.style.color=null}var p=l.find(function(t){return t.textContent===u.name}),m=this.matchupDiv.firstElementChild.tBodies[0].rows[this.currentMatchupNum].cells[2];i.animateContentTransfer(p,m,300).then(function(){return m.classList.add("team-emerge")}),p.classList.add("greyed");var f=this.runnerUpBowl.querySelector(".ball-picked");if(this.runnerUpBowl.removeChild(f),this.announcement.textContent=u+"!",i.removeAllChildren(this.groupWinnerBowl),this.runnerUpBowl.classList.remove("dont-touch"),this.runnerUpBowl.onclick=null,this.currentMatchupNum<7)++this.currentMatchupNum,this.announcement.textContent="Pick a ball",1===o.length&&setTimeout(function(){return e.runnerUpBowl.firstElementChild.click()},200);else{var v=this.groupWinnerBowl.parentElement;v.removeChild(this.groupWinnerBowl),v.removeChild(this.runnerUpBowl),this.potsDiv.classList.add("greyed"),this.announcement.innerHTML="Draw completed! ";var g=document.getElementById("restart").cloneNode(!0);g.addEventListener("click",function(t){return e.restart()}),this.announcement.appendChild(g)}},e}(s.default);Object.defineProperty(n,"__esModule",{value:!0}),n.default=a},{"../util":8,"../visualizer":9,"./last16":5}],5:[function(t,e,n){"use strict";function r(t,e,n){function r(t,n){var r=e[n],s=r[0],a=i[t];if(a.country===s.country||a.group===s.group)return!1;i.splice(t,1),r.push(a);var u=++n===e.length||o(e,n);return r.pop(),i.splice(t,0,a),u}function o(t,e){var n=t[e],o=i.map(function(t,e){return e});return s.some(function(t,i){var a=s.splice(i,1)[0];n.push(a);var u=o.some(function(t){return r(t,e)});return n.pop(),s.splice(i,0,a),u})}var i=t[0],s=t[1];return i.map(function(t,e){return e}).filter(function(t){return r(t,n)})}Object.defineProperty(n,"__esModule",{value:!0}),n.default=r},{}],6:[function(t,e,n){"use strict";function r(){console.log(d[h]),d[h].disabled&&alert("mode "+d[h--].name+" not available yet")}function o(t){return new(1===h?l.default:u.default)(t)}function i(){r(),history.pushState({},"","?mode="+d[h].url),p.textContent="Go to "+d[1-h].name;var t=1===h?a.parseLast16Teams:a.parseGS;c.then(t).then(o).then(function(t){return t.restart()})}function s(t){document.body.removeChild(document.getElementById("tables-div")),document.body.removeChild(document.getElementById("bowls-div")),getSelection().empty(),t&&++h>=d.length&&(h=0),r(),i()}var a=t("./fetch-parse-pots"),u=t("./gs/draw-visualizer"),l=t("./last16/draw-visualizer"),c=a.fetchPots("http://kassiesa.home.xs4all.nl/bert/uefa/seedcl2016.html"),d=[{url:"gs",name:"Group stage draw"},{url:"last16",name:"Last 16 draw",disabled:!1}],h=location.search.endsWith("mode=gs")?0:1;document.getElementById("restart").addEventListener("click",function(t){return s(!1)});var p=document.getElementById("change-mode");p.addEventListener("click",function(t){return s(!0)}),i()},{"./fetch-parse-pots":1,"./gs/draw-visualizer":2,"./last16/draw-visualizer":4}],7:[function(t,e,n){"use strict";var r=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)},o=function(){function t(t,e){this.name=t,this.country=e}return t}();n.Team=o;var i=function(t){function e(e,n,r,o){var i=t.call(this,e,n)||this;return i.coefficient=r,i.pairing=o,i}return r(e,t),e}(o);n.GSTeam=i;var s=function(t){function e(e,n,r){var o=t.call(this,e,n)||this;return o.group=r,o}return r(e,t),e}(o);n.Last16Team=s},{}],8:[function(t,e,n){"use strict";function r(t){for(var e,n,r=t.length;r;e=Math.floor(Math.random()*r),n=t[--r],t[r]=t[e],t[e]=n);return t}function o(t,e){return t.tBodies[0].rows[e].cells[0]}function i(t){for(var e;e=t.firstChild;)t.removeChild(e)}function s(t,e,n){return new Promise(function(r){var o=e.style;o.fontSize="0px",e.textContent=t.textContent;var i=document.createElement("td"),s=i.style;s.opacity=null,s.position="absolute",s.backgroundRepeat="no-repeat",i.textContent=t.textContent;for(var a=getComputedStyle(t),u=0,l=["width","border","padding","padding-left","background-position","background-image"];u<l.length;u++){var c=l[u];s[c]=a[c]}var d=t.getBoundingClientRect();s.transform="translate("+d.left+"px, "+d.top+"px)",s.height=d.height-5+"px",s.borderColor="rgba(0,0,0,0)",s.paddingTop="3px",s.backgroundColor=null,document.body.appendChild(i);var h=e.getBoundingClientRect();s.transition="transform "+n+"ms ease-in-out",s.transform="translate3d("+h.left+"px, "+h.top+"px, 0px)",i.addEventListener("transitionend",function(e){document.body.removeChild(i),o.fontSize=null,o.backgroundImage=t.style.backgroundImage,r()})})}n.shuffle=r,n.getCell=o,n.removeAllChildren=i,n.animateContentTransfer=s},{}],9:[function(t,e,n){"use strict";var r=function(){function t(t){this.initialPots=t,this.prepareDraw(t)}return t.prototype.prepareDraw=function(t){},t.prototype.runDraw=function(){this.announcement.textContent="Pick a ball"},t.prototype.restart=function(){document.body.removeChild(document.getElementById("tables-div")),document.body.removeChild(document.getElementById("bowls-div")),this.prepareDraw(this.initialPots),this.runDraw()},t}();Object.defineProperty(n,"__esModule",{value:!0}),n.default=r},{}],10:[function(t,e,n){},{}]},{},[10,6]);