diff --git a/Readme.md b/Readme.md index 5a04a5a..804a1ab 100644 --- a/Readme.md +++ b/Readme.md @@ -2,7 +2,7 @@ This is a funny universal scoreboard originally developed for the -beerpong tournament at a scoutparty +beer-pong tournament at a scout party This thing is based on Express with handlebars, socketio, bootstrap and some other fun @@ -12,7 +12,7 @@ Run it with `npm start` Develop on it with `npm run mon` -This app is intended to be simple, the initial loaing of the state is done using the handlebar templates, after that actions and state changes are performed using websocket requests, no forther reloads are required as long as you are not changing between the main 2 views. +This app is intended to be simple, the initial loading of the state is done using the handlebar templates, after that actions and state changes are performed using websocket requests, no further reloads are required as long as you are not changing between the main 2 views. TODO: diff --git a/public/css/jquery.bracket.min.css b/public/css/jquery.bracket.min.css index ae4c552..fdfc001 100755 --- a/public/css/jquery.bracket.min.css +++ b/public/css/jquery.bracket.min.css @@ -1,2 +1,2 @@ -/* jQuery Bracket | Copyright (c) Teijo Laine 2011-2016 | Licenced under the MIT licence */ -div.jQBracket{font-family:Arial;font-size:14px;position:relative}div.jQBracket .tools{position:absolute;top:0;color:#FFF}div.jQBracket .tools span{cursor:pointer;margin:5px;display:block;text-align:center;width:18px;height:18px;background-color:#666}div.jQBracket .tools span:hover{background-color:#999}div.jQBracket .finals{float:right;right:0;clear:right;position:relative}div.jQBracket .bracket{float:right;clear:left}div.jQBracket .loserBracket{float:right;clear:left;position:relative}div.jQBracket .round{position:relative;float:left}div.jQBracket .match{position:relative}div.jQBracket .editable{cursor:pointer}div.jQBracket .team{position:relative;z-index:1;float:left;background-color:#EEE;cursor:default}div.jQBracket .team:first-child{border-bottom:1px solid #999}div.jQBracket .team input{font-size:14px;padding:0;width:100%;border:0;margin:0;outline:0}div.jQBracket .team div.label{padding:3px;position:absolute;height:22px;white-space:nowrap;overflow:hidden;box-sizing:border-box}div.jQBracket .team div.label[disabled]{cursor:default}div.jQBracket .team div.score{float:right;padding:3px;background-color:rgba(255,255,255,.3);text-align:center;box-sizing:border-box}div.jQBracket .team div.score input{text-align:center}div.jQBracket .team div.score[disabled]{color:#999;cursor:default}div.jQBracket .team div.label input.error,div.jQBracket .team div.score input.error{background-color:#FCC}div.jQBracket .team.np{background-color:#666;color:#EEE}div.jQBracket .team.na{background-color:#999;color:#CCC}div.jQBracket .team.win{color:#333}div.jQBracket .team.win div.score{color:#060}div.jQBracket .team.lose div.score{color:#900}div.jQBracket .team.lose{background-color:#DDD;color:#999}div.jQBracket .team.tie div.score{color:#00F}div.jQBracket .team.highlightWinner{background-color:#DA0;color:#000}div.jQBracket .team.highlightLoser{background-color:#CCC;color:#000}div.jQBracket .team.highlight{background-color:#3C0;color:#000}div.jQBracket .team.bye{background-color:#999;color:#CCC}div.jQBracket .teamContainer{z-index:1;position:relative;float:left}div.jQBracket .connector{border:2px solid #666;border-left-style:none;position:absolute;z-index:1}div.jQBracket .connector div.connector{border:0;border-bottom:2px solid #666;height:0;position:absolute}div.jQBracket .connector.highlightWinner,div.jQBracket .connector div.connector.highlightWinner{border-color:#DA0}div.jQBracket .connector.highlightLoser,div.jQBracket .connector div.connector.highlightLoser{border-color:#CCC}div.jQBracket .connector.highlight,div.jQBracket .connector div.connector.highlight{border-color:#0C0}div.jQBracket .np .connector,div.jQBracket .np .connector div.connector{border-color:#999}div.jQBracket .bubble{height:22px;line-height:22px;width:30px;right:-35px;position:absolute;text-align:center;font-size:11px}div.jQBracket .bubble:after{content:'';position:absolute;top:6px;width:0;height:0;border-top:5px solid transparent;border-left:5px solid transparent;border-right:5px solid transparent;border-bottom:5px solid transparent}div.jQBracket .bubble:after{left:-5px;border-left:0}div.jQBracket .win .bubble{background-color:#DA0;color:#960}div.jQBracket .win .bubble:after{border-right-color:#DA0}div.jQBracket .win .bubble.third{background-color:#963;color:#D95}div.jQBracket .win .bubble.third:after{border-right:6px solid #963}div.jQBracket .lose .bubble{background-color:#CCC;color:#333}div.jQBracket .lose .bubble:after{border-right-color:#CCC}div.jQBracket .lose .bubble.fourth{background-color:#678;color:#CCD}div.jQBracket .lose .bubble.fourth:after{border-right:6px solid #678}div.jQBracket.rl .finals{float:left;left:0;clear:left}div.jQBracket.rl .bracket{float:left;clear:right}div.jQBracket.rl .loserBracket{float:left;clear:right}div.jQBracket.rl .round{margin-right:0;float:right}div.jQBracket.rl .team{float:right}div.jQBracket.rl .team div.label{right:0}div.jQBracket.rl .team div.score{float:left}div.jQBracket.rl .teamContainer{float:right}div.jQBracket.rl .connector{border-left-style:solid;border-right-style:none;border-width:2px}div.jQBracket.rl .connector.highlightWinner,div.jQBracket.rl .connector div.connector.highlightWinner{border-color:#DA0}div.jQBracket.rl .connector.highlightLoser,div.jQBracket.rl .connector div.connector.highlightLoser{border-color:#CCC}div.jQBracket.rl .connector.highlight,div.jQBracket.rl .connector div.connector.highlight{border-color:#0C0}div.jQBracket.rl .bubble{left:-35px}div.jQBracket.rl .bubble.third{background-color:#963;color:#310}div.jQBracket.rl .bubble.fourth{background-color:#678;color:#CCD}div.jQBracket.rl .bubble:after{left:auto;right:-5px;border-left:5px solid transparent;border-right:0}div.jQBracket.rl .bubble.third:after{border-right:0;border-left:6px solid #963}div.jQBracket.rl .bubble.fourth:after{border-right:0;border-left:6px solid #678}div.jQBracket.rl .highlightWinner .bubble:after{border-left-color:#DA0}div.jQBracket.rl .highlightLoser .bubble:after{border-left-color:#CCC} \ No newline at end of file +/* jQuery Bracket | Copyright (c) Teijo Laine 2011-2018 | Licenced under the MIT licence */ +div.jQBracket{font-family:Arial;font-size:14px;position:relative}div.jQBracket .tools{position:absolute;top:0;color:#fff}div.jQBracket .tools span{cursor:pointer;margin:5px;display:block;text-align:center;width:18px;height:18px;background-color:#666}div.jQBracket .tools span:hover{background-color:#999}div.jQBracket .finals{float:right;right:0;clear:right;position:relative}div.jQBracket .bracket{float:right;clear:left}div.jQBracket .loserBracket{float:right;clear:left;position:relative}div.jQBracket .round{position:relative;float:left}div.jQBracket .match{position:relative}div.jQBracket .editable{cursor:pointer}div.jQBracket .team{position:relative;z-index:1;float:left;background-color:#eee;cursor:default}div.jQBracket .team:first-child{border-bottom:1px solid #999}div.jQBracket .team input{font-size:14px;padding:0;width:100%;border:0;margin:0;outline:0}div.jQBracket .team div.label{padding:3px;position:absolute;height:22px;white-space:nowrap;overflow:hidden;box-sizing:border-box}div.jQBracket .team div.label[disabled]{cursor:default}div.jQBracket .team div.score{float:right;padding:3px;background-color:rgba(255,255,255,.3);text-align:center;box-sizing:border-box}div.jQBracket .team div.score input{text-align:center}div.jQBracket .team div.score[disabled]{color:#999;cursor:default}div.jQBracket .team div.label input.error,div.jQBracket .team div.score input.error{background-color:#fcc}div.jQBracket .team.np{background-color:#666;color:#eee}div.jQBracket .team.na{background-color:#999;color:#ccc}div.jQBracket .team.win{color:#333}div.jQBracket .team.win div.score{color:#060}div.jQBracket .team.lose div.score{color:#900}div.jQBracket .team.lose{background-color:#ddd;color:#999}div.jQBracket .team.tie div.score{color:#00f}div.jQBracket .team.highlightWinner{background-color:#da0;color:#000}div.jQBracket .team.highlightLoser{background-color:#ccc;color:#000}div.jQBracket .team.highlight{background-color:#3c0;color:#000}div.jQBracket .team.bye{background-color:#999;color:#ccc}div.jQBracket .teamContainer{z-index:1;position:relative;float:left}div.jQBracket .connector{border:2px solid #666;border-left-style:none;position:absolute;z-index:1}div.jQBracket .connector div.connector{border:0;border-bottom:2px solid #666;height:0;position:absolute}div.jQBracket .connector.highlightWinner,div.jQBracket .connector div.connector.highlightWinner{border-color:#da0}div.jQBracket .connector.highlightLoser,div.jQBracket .connector div.connector.highlightLoser{border-color:#ccc}div.jQBracket .connector.highlight,div.jQBracket .connector div.connector.highlight{border-color:#0c0}div.jQBracket .np .connector,div.jQBracket .np .connector div.connector{border-color:#999}div.jQBracket .bubble{height:22px;line-height:22px;width:30px;right:-35px;position:absolute;text-align:center;font-size:11px}div.jQBracket .bubble:after{content:"";position:absolute;top:6px;width:0;height:0;border-top:5px solid transparent;border-left:5px solid transparent;border-right:5px solid transparent;border-bottom:5px solid transparent}div.jQBracket .bubble:after{left:-5px;border-left:0}div.jQBracket .win .bubble{background-color:#da0;color:#960}div.jQBracket .win .bubble:after{border-right-color:#da0}div.jQBracket .win .bubble.third{background-color:#963;color:#d95}div.jQBracket .win .bubble.third:after{border-right:6px solid #963}div.jQBracket .lose .bubble{background-color:#ccc;color:#333}div.jQBracket .lose .bubble:after{border-right-color:#ccc}div.jQBracket .lose .bubble.fourth{background-color:#678;color:#ccd}div.jQBracket .lose .bubble.fourth:after{border-right:6px solid #678}div.jQBracket.rl .finals{float:left;left:0;clear:left}div.jQBracket.rl .bracket{float:left;clear:right}div.jQBracket.rl .loserBracket{float:left;clear:right}div.jQBracket.rl .round{margin-right:0;float:right}div.jQBracket.rl .team{float:right}div.jQBracket.rl .team div.label{right:0}div.jQBracket.rl .team div.score{float:left}div.jQBracket.rl .teamContainer{float:right}div.jQBracket.rl .connector{border-left-style:solid;border-right-style:none;border-width:2px}div.jQBracket.rl .connector.highlightWinner,div.jQBracket.rl .connector div.connector.highlightWinner{border-color:#da0}div.jQBracket.rl .connector.highlightLoser,div.jQBracket.rl .connector div.connector.highlightLoser{border-color:#ccc}div.jQBracket.rl .connector.highlight,div.jQBracket.rl .connector div.connector.highlight{border-color:#0c0}div.jQBracket.rl .bubble{left:-35px}div.jQBracket.rl .bubble.third{background-color:#963;color:#310}div.jQBracket.rl .bubble.fourth{background-color:#678;color:#ccd}div.jQBracket.rl .bubble:after{left:auto;right:-5px;border-left:5px solid transparent;border-right:0}div.jQBracket.rl .bubble.third:after{border-right:0;border-left:6px solid #963}div.jQBracket.rl .bubble.fourth:after{border-right:0;border-left:6px solid #678}div.jQBracket.rl .highlightWinner .bubble:after{border-left-color:#da0}div.jQBracket.rl .highlightLoser .bubble:after{border-left-color:#ccc} \ No newline at end of file diff --git a/public/js/jquery.bracket.min.js b/public/js/jquery.bracket.min.js index db05ac6..e902b64 100755 --- a/public/js/jquery.bracket.min.js +++ b/public/js/jquery.bracket.min.js @@ -1,2 +1,3 @@ -/* jQuery Bracket | Copyright (c) Teijo Laine 2011-2016 | Licenced under the MIT licence */ -var __extends=this&&this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);a.prototype=null===b?Object.create(b):(c.prototype=b.prototype,new c)};!function(a){function b(a){return!isNaN(parseFloat(a))&&isFinite(a)}function c(){this.message="Root of information for this team",this.name="EndOfBranchException"}function d(a){function b(a,c){return a instanceof Array?b(a[0],c+1):c}return b(a,0)}function e(a,b){return b>0&&(a=e([a],b-1)),a}function f(b,c,d){var e=d.find(".team[data-teamid="+b+"]"),f=c?c:"highlight";return{highlight:function(){e.each(function(){a(this).addClass(f),a(this).hasClass("win")&&a(this).parent().find(".connector").addClass(f)})},deHighlight:function(){e.each(function(){a(this).removeClass(f),a(this).parent().find(".connector").removeClass(f)})}}}function g(b,c,d){var e=d||c,g=e.winner(),h=e.loser();g&&h&&(g.name.isEmpty()||f(g.seed.get(),"highlightWinner",b).highlight(),h.name.isEmpty()||f(h.seed.get(),"highlightLoser",b).highlight()),b.find(".team").mouseover(function(){var c=a(this).attr("data-teamid");if(void 0!==c){var d=f(parseInt(c,10),null,b);d.highlight(),a(this).mouseout(function(){d.deHighlight(),a(this).unbind("mouseout")})}})}function h(b,c,d){var e=a('');e.val(c),b.empty().append(e),e.focus(),e.blur(function(){d(e.val())}),e.keydown(function(a){var b=a.keyCode||a.which;9!==b&&13!==b&&27!==b||(a.preventDefault(),d(e.val(),27!==b))})}function i(a,b,c,d){switch(d){case"empty-bye":return void a.append("BYE");case"empty-tbd":return void a.append("TBD");case"entry-no-score":case"entry-default-win":case"entry-complete":return void a.append(b)}}function j(a){var b=a.el,c=b.find(".team.win");c.append('
1st
');var d=b.find(".team.lose");return d.append('
2nd
'),!0}function k(a){var b=a.el,c=b.find(".team.win");c.append('
3rd
');var d=b.find(".team.lose");return d.append('
4th
'),!0}function l(a,b,c,d,e){for(var f,g=Math.log(2*b.length)/Math.log(2),h=b.length,i=0;i1&&!d.skipConsolationRound)){var o=a.final().getRound().prev(),p=o.map(function(a){return function(){return a.match(0).loser()}}).toNull(),q=o.map(function(a){return function(){return a.match(1).loser()}}).toNull(),r=f.addMatch(function(){return[{source:p},{source:q}]},u.of(k));r.setAlignCb(function(b){var c=a.el.height()/2;r.el.css("height",c+"px");var e=b.height()/2+d.matchMargin;b.css("top",e+"px")}),r.setConnectorCb(u.empty())}}function m(a,b,c,d,e){for(var f=Math.log(2*c)/Math.log(2)-1,g=c/2,h=0;h2)throw new Error("Unexpected number of final rounds");return j(e)}if(2===a.size())return!1;var h=function(){var b=!e.winner().name.isEmpty()&&e.winner().name===c.winner().name;return g===!1&&b&&(g=!0,f()),!b&&g&&(g=!1,a.dropRound(),f()),b},i=a.addRound(u.of(h)),k=i.addMatch(function(){return[{source:function(){return e.first()}},{source:function(){return e.second()}}]},u.of(j));return e.setConnectorCb(u.of(function(a){return{height:0,shift:a.height()/2}})),k.setConnectorCb(u.empty()),k.setAlignCb(function(a){var d=b.el.height()+c.el.height();k.el.css("height",d+"px");var e=(b.el.height()/2+b.el.height()+c.el.height()/2)/2-a.height();a.css("top",e+"px")}),!1}));if(h.setAlignCb(function(a){var e=b.el.height()+c.el.height();d.skipConsolationRound||(e/=2),h.el.css("height",e+"px");var f=(b.el.height()/2+b.el.height()+c.el.height()/2)/2-a.height();a.css("top",f+"px")}),!d.skipConsolationRound){var i=c.final().getRound().prev(),l=g.addMatch(function(){return[{source:function(){return i.get().match(0).loser()}},{source:function(){return c.loser()}}]},u.of(k));l.setAlignCb(function(a){var d=(b.el.height()+c.el.height())/2;l.el.css("height",d+"px");var e=(b.el.height()/2+b.el.height()+c.el.height()/2)/2+a.height()/2-d;a.css("top",e+"px")}),h.setConnectorCb(u.empty()),l.setConnectorCb(u.empty())}b.final().setConnectorCb(u.of(function(a){var e=a.height()/4,f=(b.el.height()/2+b.el.height()+c.el.height()/2)/2-a.height()/2,g=f-b.el.height()/2,h=b.winner().order.map(function(a){return a.map({height:g+e*(d.centerConnectors?2:1),shift:e*(d.centerConnectors?2:1)},{height:g+e*(d.centerConnectors?2:0),shift:e*(d.centerConnectors?2:3)})}).orElse({height:g+e*(d.centerConnectors?2:1),shift:2*e}),i=h.height,j=h.shift;return i-=a.height()/2,{height:i,shift:j}})),c.final().setConnectorCb(u.of(function(a){var e=a.height()/4,f=(b.el.height()/2+b.el.height()+c.el.height()/2)/2-a.height()/2,g=f-b.el.height()/2,h=c.winner().order.map(function(a){return a.map({height:g+e*(d.centerConnectors?2:0),shift:e*(d.centerConnectors?2:3)},{height:g+2*e,shift:e*(d.centerConnectors?2:1)})}).orElse({height:g+e*(d.centerConnectors?2:1),shift:2*e}),i=h.height,j=h.shift;return i+=a.height()/2,{height:-i,shift:-j}}))}function o(b,c,d,e){var f=c.height,g=c.shift,h=b/2,i=!0;f<0&&(i=!1,f=-f),f<2&&(f=0);var j=a('
').appendTo(d);j.css("height",f),j.css("width",h+"px"),j.css(e,-h-2+"px"),g>=0?j.css("top",g-1+"px"):j.css("bottom",-g-1+"px"),i?j.css("border-bottom","none"):j.css("border-top","none");var k=a('
').appendTo(j);return k.css("width",h+"px"),k.css(e,-h+"px"),i?k.css("bottom","0px"):k.css("top","0px"),j}function p(a,b,c,d,e){if(b)return Math.log(2*a)/Math.log(2);if(c)return Math.max(2,2*(Math.log(2*a)/Math.log(2)-1)-1);var f=!d&&3===e.length&&2===e[2].length;return 2*(Math.log(2*a)/Math.log(2)-1)+1+(f?1:0)}function q(b){var c=a.extend(!0,{},b);return c.teams=c.teams.map(function(a){return a.map(function(a){return a.toNull()})}),c.results=c.results.map(function(a){return a.map(function(a){return a.map(function(a){var b=[a.first.toNull(),a.second.toNull()];return void 0!==a.userData&&b.push(a.userData),b})})}),c}function r(c,d,e,f,g,h,i,j,k,l){var m=e.name.isEmpty()||f.name.isEmpty()?"":'data-resultid="result-'+j.getNext()+'"',n=a('
"),o=e.name.isEmpty()||f.name.isEmpty()||!g?u.empty():e.score.map(function(a){return""+a}),p=o.orElse("--");n.text(p);var q=e.name.map(function(){return o.map(function(){return"entry-complete"}).orElseGet(function(){return f.emptyBranch()===t.BYE?"entry-default-win":"entry-no-score"})}).orElseGet(function(){var a=e.emptyBranch();switch(a){case t.BYE:return"empty-bye";case t.TBD:return"empty-tbd";default:throw new Error("Unexpected branch type "+a)}}),r=a('
'),s=a('
').appendTo(r);if(i.decorator.render(s,e.name.toNull(),p,q),e.seed.forEach(function(a){r.attr("data-teamid",a)}),e.name.isEmpty()?r.addClass("na"):d.winner().name===e.name?r.addClass("win"):d.loser().name===e.name&&r.addClass("lose"),r.append(n),(!e.name.isEmpty()||e.name.isEmpty()&&0===c&&h)&&"function"==typeof i.save&&(i.disableTeamEdit||(s.addClass("editable"),s.click(function(){function b(){function f(f,g){var h=e.seed.get();i.init.teams[~~(h/2)][h%2]=u.of(f||null),l(!0),d.click(b);var j=i.el.find(".team[data-teamid="+(h+1)+"] div.label:first");j.length&&g===!0&&0===c&&a(j).click()}d.unbind(),i.decorator.edit(d,e.name.toNull(),f)}var d=a(this);b()})),!e.name.isEmpty()&&!f.name.isEmpty()&&g)){var w=j.get();n.addClass("editable"),n.click(function(){function c(){d.unbind();var f=b(e.score)?d.text():"0",g=a('');g.val(f),d.empty().append(g),g.focus().select(),g.keydown(function(c){b(a(this).val())?a(this).removeClass("error"):a(this).addClass("error");var d=c.keyCode||c.which;if(9===d||13===d||27===d){if(c.preventDefault(),a(this).blur(),27===d)return;var e=k.find("div.score[data-resultid=result-"+(w+1)+"]");e&&e.click()}}),g.blur(function(){var a=g.val();a&&b(a)||b(e.score)?a&&b(a)||!b(e.score)||(a=e.score):a="0",d.html(a),b(a)&&(e.score=v.of(parseInt(a,10)),l(!0)),d.click(c)})}var d=a(this);c()})}return r}function s(b,c,d){var e=a('
').appendTo(b),f=a('+').appendTo(e);if(f.click(function(){for(var a=c.teams.length,b=0;b1&&1===c.results.length||c.teams.length>2&&3===c.results.length){var g=a('-').appendTo(e);g.click(function(){if(c.teams.length>1)return c.teams=c.teams.slice(0,c.teams.length/2),K(d)})}if(1===c.results.length&&c.teams.length>1){var h=a('de').appendTo(e);h.click(function(){if(c.teams.length>1&&c.results.length<3)return c.results.push([],[]),K(d)})}else if(3===c.results.length&&c.teams.length>1){var h=a('se').appendTo(e);h.click(function(){if(3===c.results.length)return c.results=c.results.slice(0,1),K(d)})}}var t,u=function(){function a(b){if(this.val=b,b instanceof a)throw new Error("Trying to wrap Option into an Option");if(void 0===this.val)throw new Error("Option cannot contain undefined")}return a.of=function(b){return new a(b)},a.empty=function(){return new a(null)},a.prototype.get=function(){if(null===this.val)throw new Error("Trying to get() empty Option");return this.val},a.prototype.orElse=function(a){return null===this.val?a:this.val},a.prototype.orElseGet=function(a){return null===this.val?a():this.val},a.prototype.map=function(b){return null===this.val?a.empty():new a(b(this.val))},a.prototype.forEach=function(a){return null!==this.val&&a(this.val),this},a.prototype.toNull=function(){return null===this.val?null:this.val},a.prototype.isEmpty=function(){return null===this.val},a}(),v=function(a){function b(){a.apply(this,arguments)}return __extends(b,a),b.of=function(a){var b=typeof a,c="number";if(null!==a&&b!==c)throw new Error("Invalid score format, expected "+c+", got "+b);return u.of(a)},b.empty=function(){return u.empty()},b}(u),w=function(){function a(a,b,c){if(this.first=a,this.second=b,this.userData=c,!a||!b)throw new Error("Cannot create ResultObject with undefined scores")}return a}();!function(a){a[a.TBD=0]="TBD",a[a.BYE=1]="BYE"}(t||(t={}));var x=function(){function a(a){this.isFirst=a}return a.first=function(){return new a(!0)},a.second=function(){return new a(!1)},a.prototype.map=function(a,b){return this.isFirst?a:b},a}(),y=function(){function a(a,b,c,d,e){this.source=a,this.name=b,this.order=c,this.seed=d,this.score=e}return a.prototype.emptyBranch=function(){if(!this.name.isEmpty())return t.TBD;try{return this.source().emptyBranch()}catch(a){if(a instanceof c)return t.BYE;throw new Error("Unexpected exception type")}},a}(),z=function(){function a(a,b){this.a=a,this.b=b}return a.teamsInResultOrder=function(a){var b=a.a.name.isEmpty(),c=a.b.name.isEmpty();if(c&&!b)return a.b.emptyBranch()===t.BYE?[a.a,a.b]:[];if(b&&!c)return a.a.emptyBranch()===t.BYE?[a.b,a.a]:[];if(!a.a.score.isEmpty()&&!a.b.score.isEmpty()){if(a.a.score.get()>a.b.score.get())return[a.a,a.b];if(a.a.score.get()'),this.matches=[]}return Object.defineProperty(b.prototype,"el",{get:function(){return this.roundCon},enumerable:!0,configurable:!0}),b.prototype.addMatch=function(a,b){var c=this,d=this.matches.length,e=null!==a?a():[{source:function(){return c.bracket.round(c.roundNumber-1).match(2*d).winner()}},{source:function(){return c.bracket.round(c.roundNumber-1).match(2*d+1).winner()}}],f=function(){return e[0].source()},g=function(){return e[1].source()},h=new z(new y(f,f().name,u.of(x.first()),f().seed,v.empty()),new y(g,g().name,u.of(x.second()),g().seed,v.empty())),i=this.mkMatch(this,h,d,this._results.map(function(a){return void 0===a[d]?null:a[d]}),b,this.isFirstBracket,this.opts);return this.matches.push(i),i},b.prototype.match=function(a){return this.matches[a]},b.prototype.prev=function(){return this.previousRound},b.prototype.size=function(){return this.matches.length},b.prototype.render=function(){this.roundCon.empty(),(this.doRenderCb.isEmpty()||this.doRenderCb.get()())&&(this.roundCon.appendTo(this.bracket.el),this.matches.forEach(function(a){return a.render()}))},b.prototype.results=function(){return this.matches.reduce(function(a,b){return a.concat([b.results()])},[])},b}(),F=function(){function a(a,b,c,d,e){this.bracketCon=a,this.initResults=b,this.mkMatch=c,this.isFirstBracket=d,this.opts=e,this.rounds=[]}return Object.defineProperty(a.prototype,"el",{get:function(){return this.bracketCon},enumerable:!0,configurable:!0}),a.prototype.addRound=function(a){var b=this.rounds.length,c=b>0?u.of(this.rounds[b-1]):u.empty(),d=this.initResults.map(function(a){return void 0===a[b]?new w(v.empty(),v.empty(),void 0):a[b]}),e=new E(this,c,b,d,a,this.mkMatch,this.isFirstBracket,this.opts);return this.rounds.push(e),e},a.prototype.dropRound=function(){this.rounds.pop()},a.prototype.round=function(a){return this.rounds[a]},a.prototype.size=function(){return this.rounds.length},a.prototype.final=function(){return this.rounds[this.rounds.length-1].match(0)},a.prototype.winner=function(){return this.rounds[this.rounds.length-1].match(0).winner()},a.prototype.loser=function(){return this.rounds[this.rounds.length-1].match(0).loser()},a.prototype.render=function(){this.bracketCon.empty();for(var a=0;a'),this.teamCon=a('
'),this.alignCb=null,this.matchUserData=f.isEmpty()?void 0:f.get().userData,!i.save){var m=this.matchUserData;i.onMatchHover&&this.teamCon.hover(function(){i.onMatchHover(m,!0)},function(){i.onMatchHover(m,!1)}),i.onMatchClick&&this.teamCon.click(function(){i.onMatchClick(m)})}d.a.name=d.a.source().name,d.b.name=d.b.source().name,d.a.score=f.map(function(a){return a.first.toNull()}),d.b.score=f.map(function(a){return a.second.toNull()}),d.a.name&&d.b.name||!b(d.a.score)&&!b(d.b.score)||(console.log("ERROR IN SCORE DATA: "+d.a.source().name+": "+d.a.score+", "+d.b.source().name+": "+d.b.score),d.a.score=d.b.score=v.empty())}return Object.defineProperty(c.prototype,"el",{get:function(){return this.matchCon},enumerable:!0,configurable:!0}),c.prototype.getRound=function(){return this.round},c.prototype.setConnectorCb=function(a){this.connectorCb=a},c.prototype.connect=function(a){var b=this,c="lr"===this.opts.dir?"right":"left",d=this.teamCon.height()/4,e=this.matchCon.height()/2,f=a.map(function(a){return a(b.teamCon,b)}).orElseGet(function(){return b.seed%2===0?b.winner().order.map(function(a){return a.map({shift:d*(b.opts.centerConnectors?2:1),height:e},{shift:d*(b.opts.centerConnectors?2:3),height:e-d*(b.opts.centerConnectors?0:2)})}).orElse({shift:2*d,height:e-d*(b.opts.centerConnectors?0:1)}):b.winner().order.map(function(a){return a.map({shift:-d*(b.opts.centerConnectors?2:3),height:-e+d*(b.opts.centerConnectors?0:2)},{shift:-d*(b.opts.centerConnectors?2:1),height:-e})}).orElse({shift:2*-d,height:-e+d*(b.opts.centerConnectors?0:1)})});this.teamCon.append(o(this.opts.roundMargin,f,this.teamCon,c))},c.prototype.winner=function(){return this.match.winner()},c.prototype.loser=function(){return this.match.loser()},c.prototype.first=function(){return this.match.a},c.prototype.second=function(){return this.match.b},c.prototype.setAlignCb=function(a){this.alignCb=a},c.prototype.render=function(){var a=this;this.matchCon.empty(),this.teamCon.empty(),this.match.a.name=this.match.a.source().name,this.match.b.name=this.match.b.source().name,this.match.a.seed=this.match.a.source().seed,this.match.b.seed=this.match.b.source().seed;var b=this.match.a.name.isEmpty()&&this.match.b.name.isEmpty();b?this.teamCon.addClass("np"):this.match.winner().name?this.teamCon.removeClass("np"):this.teamCon.addClass("np");var c=!this.match.a.name.isEmpty()&&!this.match.b.name.isEmpty();this.teamCon.append(r(this.round.roundNumber,this.match,this.match.a,this.match.b,c,this.isFirstBracket,this.opts,this.resultId,this.topCon,this.renderAll)),this.teamCon.append(r(this.round.roundNumber,this.match,this.match.b,this.match.a,c,this.isFirstBracket,this.opts,this.resultId,this.topCon,this.renderAll)),this.matchCon.appendTo(this.round.el),this.matchCon.append(this.teamCon),this.el.css("height",this.round.bracket.el.height()/this.round.size()+"px"),this.teamCon.css("top",this.el.height()/2-this.teamCon.height()/2+"px"),null!==this.alignCb&&this.alignCb(this.teamCon);var d=this.renderCb.map(function(b){return b(a)}).orElse(!1);d||this.connect(this.connectorCb)},c.prototype.results=function(){var a=this.match.a.name.isEmpty()||this.match.b.name.isEmpty();return a&&(this.match.a.score=this.match.b.score=v.empty()),new w(this.match.a.score,this.match.b.score,this.matchUserData)},c}(),I=function(a){return void 0===a?null:a},J=function(a){return a.map(function(a){return a.map(function(a){return a.map(function(a){return new w(v.of(I(a[0])),v.of(I(a[1])),a[2])})})})},K=function(b){function c(){var a=p(j.teams.length,k,b.skipGrandFinalComeback,b.skipSecondaryFinal,j.results);b.disableToolbar?r.css("width",a*(b.teamWidth+b.scoreWidth+b.roundMargin)+10):r.css("width",a*(b.teamWidth+b.scoreWidth+b.roundMargin)+40),k&&j.teams.length<=2&&!b.skipConsolationRound&&r.css("height",o+40)}function d(a){i.reset(),e.render(),f&&f.render(),h&&!b.skipGrandFinalComeback&&h.render(),b.disableHighlight||g(r,e,h),a&&(j.results[0]=e.results(),f&&(j.results[1]=f.results()),h&&!b.skipGrandFinalComeback&&(j.results[2]=h.results()),c(),b.save&&b.save(q(j),b.userData))}var e,f,h,i=new G,j=b.init,k=j.results.length<=1,o=45*j.teams.length+j.teams.length*b.matchMargin,r=a('
').appendTo(b.el.empty());b.skipSecondaryFinal&&k&&a.error("skipSecondaryFinal setting is viable only in double elimination mode"),b.disableToolbar||s(r,j,b);var t,v,w;k?v=a('
').appendTo(r):(b.skipGrandFinalComeback||(t=a('
').appendTo(r)),v=a('
').appendTo(r),w=a('
').appendTo(r)),v.css("height",o),w&&w.css("height",v.height()/2),c();var x=function(a,b,c,e,f,g,h){return new H(a,b,c,e,f,g,h,i,r,d)};return e=new F(v,u.of(j.results[0]||null),x,!0,b),k||(f=new F(w,u.of(j.results[1]||null),x,!1,b),b.skipGrandFinalComeback||(h=new F(t,u.of(j.results[2]||null),x,!1,b))),l(e,j.teams,k,b,b.skipGrandFinalComeback&&!k),k||(m(e,f,j.teams.length,b.skipGrandFinalComeback,b.centerConnectors),b.skipGrandFinalComeback||n(h,e,f,b,r,c)),d(!1),{data:function(){return q(b.init)}}},L=function(a,b){if(a.hasOwnProperty(b)){var c="number",d=typeof a[b];if(d!==c)throw new Error('Option "'+b+'" is '+d+" instead of "+c)}},M=function(a,b){var c=a[b],d="boolean",e=typeof c;if(e!==d)throw new Error("Value of "+b+" must be boolean, got "+d+", got "+e)},N=function(a,b,c){var d=b[c];if(d t.b.score.get()) return [t.a, t.b]; if (t.a.score.get() < t.b.score.get()) return [t.b, t.a] } return [] }, t.emptyTeam = function (t, e) { var i = new a(t, n.empty(), n.empty(), n.empty(), r.empty()); return i.sibling = function () { return e }, i }, t.prototype.winner = function () { return t.teamsInResultOrder(this)[0] || t.emptyTeam(this.a.source, this.b) }, t.prototype.loser = function () { return t.teamsInResultOrder(this)[1] || t.emptyTeam(this.b.source, this.a) }, t }(); (p = u || (u = {})).EMPTY_BYE = "empty-bye", p.EMPTY_TBD = "empty-tbd", p.ENTRY_NO_SCORE = "entry-no-score", p.ENTRY_DEFAULT_WIN = "entry-default-win", p.ENTRY_COMPLETE = "entry-complete"; var p; function d(e, n, r) { var i = r.find(".team[data-teamid=" + e + "]"), o = n || "highlight"; return { highlight: function () { i.each(function () { t(this).addClass(o), t(this).hasClass("win") && t(this).parent().find(".connector").addClass(o) }) }, deHighlight: function () { i.each(function () { t(this).removeClass(o), t(this).parent().find(".connector").removeClass(o) }) } } } function f(e, n, r) { var i = t(''); i.val(n), e.empty().append(i), i.focus(), i.blur(function () { r(i.val()) }), i.keydown(function (t) { var e = t.keyCode || t.which; 9 !== e && 13 !== e && 27 !== e || (t.preventDefault(), r(i.val(), 27 !== e)) }) } function m(t, e, n, r) { switch (r) { case u.EMPTY_BYE: return void t.append("BYE"); case u.EMPTY_TBD: return void t.append("TBD"); case u.ENTRY_NO_SCORE: case u.ENTRY_DEFAULT_WIN: case u.ENTRY_COMPLETE: return void t.append(e) } } function g(t) { var e = t.el; e.find(".team.win").append('
1st
'); return e.find(".team.lose").append('
2nd
'), !0 } function b(t) { var e = t.el; e.find(".team.win").append('
3rd
'); return e.find(".team.lose").append('
4th
'), !0 } var v = function () { throw new c }, y = function (t, e) { return function () { var i = new a(v, function () { return t[e][0] }, n.of(s.first()), n.of(2 * e), r.empty()), o = new a(v, function () { return t[e][1] }, n.of(s.second()), n.of(2 * e + 1), r.empty()); return i.sibling = function () { return o }, o.sibling = function () { return i }, [{ source: function () { return i } }, { source: function () { return o } }] } }, C = function (t, e) { return function (n) { n.css("top", ""), n.css("position", "absolute"), e ? n.css("top", t.el.height() / 2 - n.height() / 2 + "px") : n.css("bottom", -n.height() / 2 + "px") } }; var E = function (t, e, n, r, i, o) { return function () { if (i % 2 == 0 && 0 === o) return [{ source: function () { return t.round(0).match(2 * r).loser() } }, { source: function () { return t.round(0).match(2 * r + 1).loser() } }]; var s = o % 2 == 0 ? n - r - 1 : r; return [{ source: function () { return e.round(2 * o).match(r).winner() } }, { source: function () { return t.round(o + 1).match(s).loser() } }] } }, w = function (t, e) { return function () { return t.css("top", e.el.height() / 2 - t.height() / 2 + "px") } }, k = function (t) { return function (e, n) { var r = e.height() / 4, i = { height: 0, shift: 2 * r }; return n.winner().order.map(function (e) { return e.map(t ? i : { height: 0, shift: r }, t ? i : { height: 2 * -r, shift: r }) }).orElse(i) } }; var T = function () { function e(e, n, r, i, o, s, a, h) { this.bracket = e, this.previousRound = n, this.roundNumber = r, this.roundResults = i, this.doRenderCb = o, this.mkMatch = s, this.isFirstBracket = a, this.opts = h, this.containerWidth = this.opts.teamWidth + this.opts.scoreWidth, this.roundCon = t('
'), this.matches = [] } return Object.defineProperty(e.prototype, "el", { get: function () { return this.roundCon }, enumerable: !0, configurable: !0 }), e.prototype.addMatch = function (t, e) { var i = this, o = this.matches.length, h = null !== t ? t() : [{ source: function () { return i.bracket.round(i.roundNumber - 1).match(2 * o).winner() } }, { source: function () { return i.bracket.round(i.roundNumber - 1).match(2 * o + 1).winner() } }], c = function () { return h[0].source() }, u = function () { return h[1].source() }, p = new a(c, c().name, n.of(s.first()), c().seed, r.empty()), d = new a(u, u().name, n.of(s.second()), u().seed, r.empty()); p.sibling = function () { return d }, d.sibling = function () { return p }; var f = new l(p, d), m = this.mkMatch(this, f, o, this.roundResults.map(function (t) { return void 0 === t[o] ? null : t[o] }), e, this.isFirstBracket, this.opts); return this.matches.push(m), m }, e.prototype.match = function (t) { return this.matches[t] }, e.prototype.prev = function () { return this.previousRound }, e.prototype.size = function () { return this.matches.length }, e.prototype.render = function () { this.roundCon.empty(), (this.doRenderCb.isEmpty() || this.doRenderCb.get()()) && (this.roundCon.appendTo(this.bracket.el), this.matches.forEach(function (t) { return t.render() })) }, e.prototype.results = function () { return this.matches.reduce(function (t, e) { return t.concat([e.results()]) }, []) }, e }(), M = function () { function t(t, e, n, r, i) { this.bracketCon = t, this.initResults = e, this.mkMatch = n, this.isFirstBracket = r, this.opts = i, this.rounds = [] } return Object.defineProperty(t.prototype, "el", { get: function () { return this.bracketCon }, enumerable: !0, configurable: !0 }), t.prototype.addRound = function (t) { var e = this.rounds.length, o = e > 0 ? n.of(this.rounds[e - 1]) : n.empty(), s = this.initResults.map(function (t) { return void 0 === t[e] ? new i(r.empty(), r.empty(), void 0) : t[e] }), a = new T(this, o, e, s, t, this.mkMatch, this.isFirstBracket, this.opts); return this.rounds.push(a), a }, t.prototype.dropRound = function () { this.rounds.pop() }, t.prototype.round = function (t) { return this.rounds[t] }, t.prototype.size = function () { return this.rounds.length }, t.prototype.final = function () { return this.rounds[this.rounds.length - 1].match(0) }, t.prototype.winner = function () { return this.rounds[this.rounds.length - 1].match(0).winner() }, t.prototype.loser = function () { return this.rounds[this.rounds.length - 1].match(0).loser() }, t.prototype.render = function () { this.bracketCon.empty(); for (var t = 0, e = this.rounds; t < e.length; t++) { e[t].render() } }, t.prototype.results = function () { return this.rounds.reduce(function (t, e) { return t.concat([e.results()]) }, []) }, t }(), R = function (t) { return t < 0 ? { height: -t, drop: !1 } : t < 2 ? { height: 0, drop: !0 } : { height: t, drop: !0 } }; function x(e) { var n = t.extend(!0, {}, e); return n.teams = n.teams.map(function (t) { return t.map(function (t) { return t.toNull() }) }), n.results = n.results.map(function (t) { return t.map(function (t) { return t.map(function (t) { var e = [t.first.toNull(), t.second.toNull()]; return void 0 !== t.userData && e.push(t.userData), e }) }) }), n } var O = function () { function t() { this.counter = 0 } return t.prototype.get = function () { return this.counter }, t.prototype.getNext = function () { return ++this.counter }, t.prototype.reset = function () { this.counter = 0 }, t }(); function B(i, o, s, a, c, l, p, d, f, m) { var g = s.name.isEmpty() || a.name.isEmpty() ? "" : 'data-resultid="result-' + d.getNext() + '"', b = t('
"), v = s.name.isEmpty() || a.name.isEmpty() || !c ? n.empty() : s.score.map(function (t) { return "" + t }), y = v.orElse("--"); b.text(y); var C = t('
'), E = t('
').appendTo(C); p.decorator.render(E, s.name.toNull(), y, (k = a, T = v, (w = s).name.map(function () { return T.map(function () { return u.ENTRY_COMPLETE }).orElseGet(function () { return k.emptyBranch() === e.BYE ? u.ENTRY_DEFAULT_WIN : u.ENTRY_NO_SCORE }) }).orElseGet(function () { var t = w.emptyBranch(); switch (t) { case e.BYE: return u.EMPTY_BYE; case e.TBD: return u.EMPTY_TBD; default: throw new Error("Unexpected branch type " + t) } }))); var w, k, T; if (s.seed.forEach(function (t) { C.attr("data-teamid", t) }), s.name.isEmpty() ? C.addClass("na") : o.winner().name === s.name ? C.addClass("win") : o.loser().name === s.name && C.addClass("lose"), C.append(b), (!s.name.isEmpty() || s.name.isEmpty() && 0 === i && l) && "function" == typeof p.save && (p.disableTeamEdit || (E.addClass("editable"), E.click(function () { var e = t(this); !function r() { e.unbind(), p.decorator.edit(e, s.name.toNull(), function (o, a) { var h = s.seed.get(); p.init.teams[~~(h / 2)][h % 2] = n.of(o || null), m(!0), e.click(r); var c = p.el.find(".team[data-teamid=" + (h + 1) + "] div.label:first"); c.length && !0 === a && 0 === i && t(c).click() }) }() })), !s.name.isEmpty() && !a.name.isEmpty() && c)) { var M = d.get(); b.addClass("editable"), b.click(function () { var e = t(this); !function n() { e.unbind(); var i = h(s.score) ? e.text() : "0", o = t(''); o.val(i), e.empty().append(o), o.focus().select(), o.keydown(function (e) { h(t(this).val()) ? t(this).removeClass("error") : t(this).addClass("error"); var n = e.keyCode || e.which; if (9 === n || 13 === n || 27 === n) { if (e.preventDefault(), t(this).blur(), 27 === n) return; var r = f.find("div.score[data-resultid=result-" + (M + 1) + "]"); r && r.click() } }), o.blur(function () { var t = o.val(); t && h(t) || h(s.score) ? t && h(t) || !h(s.score) || (t = s.score) : t = "0", e.html(t), h(t) && (s.score = r.of(parseInt(t, 10)), m(!0)), e.click(n) }) }() }) } return C } var N = function () { function e(e, i, o, s, a, c, u, l, p, d) { if (this.round = e, this.match = i, this.seed = o, this.renderCb = a, this.isFirstBracket = c, this.opts = u, this.resultId = l, this.topCon = p, this.renderAll = d, this.connectorCb = n.empty(), this.matchCon = t('
'), this.teamCon = t('
'), this.alignCb = null, this.matchUserData = s.isEmpty() ? void 0 : s.get().userData, !u.save) { var f = this.matchUserData; u.onMatchHover && this.teamCon.hover(function () { u.onMatchHover(f, !0) }, function () { u.onMatchHover(f, !1) }), u.onMatchClick && this.teamCon.click(function () { u.onMatchClick(f) }) } i.a.name = i.a.source().name, i.b.name = i.b.source().name, i.a.score = s.map(function (t) { return t.first.toNull() }), i.b.score = s.map(function (t) { return t.second.toNull() }), i.a.name && i.b.name || !h(i.a.score) && !h(i.b.score) || (console.warn("ERROR IN SCORE DATA: " + i.a.source().name + ": " + i.a.score + ", " + i.b.source().name + ": " + i.b.score), i.a.score = i.b.score = r.empty()) } return Object.defineProperty(e.prototype, "el", { get: function () { return this.matchCon }, enumerable: !0, configurable: !0 }), e.prototype.getRound = function () { return this.round }, e.prototype.setConnectorCb = function (t) { this.connectorCb = t }, e.prototype.connect = function (e) { var n = this, r = "lr" === this.opts.dir ? "right" : "left", i = this.teamCon.height() / 4, o = this.matchCon.height() / 2, s = e.map(function (t) { return t(n.teamCon, n) }).orElseGet(function () { return n.seed % 2 == 0 ? n.winner().order.map(function (t) { return t.map({ height: o, shift: i * (n.opts.centerConnectors ? 2 : 1) }, { height: o - i * (n.opts.centerConnectors ? 0 : 2), shift: i * (n.opts.centerConnectors ? 2 : 3) }) }).orElse({ height: o - i * (n.opts.centerConnectors ? 0 : 1), shift: 2 * i }) : n.winner().order.map(function (t) { return t.map({ height: -o + i * (n.opts.centerConnectors ? 0 : 2), shift: -i * (n.opts.centerConnectors ? 2 : 3) }, { height: -o, shift: -i * (n.opts.centerConnectors ? 2 : 1) }) }).orElse({ height: -o + i * (n.opts.centerConnectors ? 0 : 1), shift: 2 * -i }) }); this.teamCon.append(function (e, n, r, i) { var o = n.shift, s = R(n.height), a = s.height, h = s.drop, c = e / 2, u = t('
').appendTo(r); u.css("height", a), u.css("width", c + "px"), u.css(i, -c - 2 + "px"), o >= 0 ? u.css("top", o - 1 + "px") : u.css("bottom", -o - 1 + "px"), h ? u.css("border-bottom", "none") : u.css("border-top", "none"); var l = t('
').appendTo(u); return l.css("width", c + "px"), l.css(i, -c + "px"), h ? l.css("bottom", "0px") : l.css("top", "0px"), u }(this.opts.roundMargin, s, this.teamCon, r)) }, e.prototype.winner = function () { return this.match.winner() }, e.prototype.loser = function () { return this.match.loser() }, e.prototype.first = function () { return this.match.a }, e.prototype.second = function () { return this.match.b }, e.prototype.setAlignCb = function (t) { this.alignCb = t }, e.prototype.render = function () { var t = this; this.matchCon.empty(), this.teamCon.empty(), this.match.a.name = this.match.a.source().name, this.match.b.name = this.match.b.source().name, this.match.a.seed = this.match.a.source().seed, this.match.b.seed = this.match.b.source().seed; this.match.a.name.isEmpty() && this.match.b.name.isEmpty() ? this.teamCon.addClass("np") : this.match.winner().name ? this.teamCon.removeClass("np") : this.teamCon.addClass("np"); var e = !this.match.a.name.isEmpty() && !this.match.b.name.isEmpty(); this.teamCon.append(B(this.round.roundNumber, this.match, this.match.a, this.match.b, e, this.isFirstBracket, this.opts, this.resultId, this.topCon, this.renderAll)), this.teamCon.append(B(this.round.roundNumber, this.match, this.match.b, this.match.a, e, this.isFirstBracket, this.opts, this.resultId, this.topCon, this.renderAll)), this.matchCon.appendTo(this.round.el), this.matchCon.append(this.teamCon), this.el.css("height", this.round.bracket.el.height() / this.round.size() + "px"), this.teamCon.css("top", this.el.height() / 2 - this.teamCon.height() / 2 + "px"), null !== this.alignCb && this.alignCb(this.teamCon); this.renderCb.map(function (e) { return e(t) }).orElse(!1) || this.connect(this.connectorCb) }, e.prototype.results = function () { return (this.match.a.name.isEmpty() || this.match.b.name.isEmpty()) && (this.match.a.score = this.match.b.score = r.empty()), new i(this.match.a.score, this.match.b.score, this.matchUserData) }, e }(), _ = function (t) { return void 0 === t ? null : t }, D = function (e) { var r = new O, i = e.init, o = i.results.length <= 1, s = 45 * i.teams.length + i.teams.length * e.matchMargin, a = t('
').appendTo(e.el.empty()); function h() { var t = function (t, e, n, r, i) { if (e) return Math.log(2 * t) / Math.log(2); if (n) return Math.max(2, 2 * (Math.log(2 * t) / Math.log(2) - 1) - 1); var o = !r && 3 === i.length && 2 === i[2].length; return 2 * (Math.log(2 * t) / Math.log(2) - 1) + 1 + (o ? 1 : 0) }(i.teams.length, o, e.skipGrandFinalComeback, e.skipSecondaryFinal, i.results); e.disableToolbar ? a.css("width", t * (e.teamWidth + e.scoreWidth + e.roundMargin) + 10) : a.css("width", t * (e.teamWidth + e.scoreWidth + e.roundMargin) + 40), o && i.teams.length <= 2 && !e.skipConsolationRound && a.css("height", s + 40) } var c, u, l; function p(n) { r.reset(), c.render(), u && u.render(), l && !e.skipGrandFinalComeback && l.render(), e.disableHighlight || function (e, n, r) { var i = r || n, o = i.winner(), s = i.loser(); o && s && (o.name.isEmpty() || d(o.seed.get(), "highlightWinner", e).highlight(), s.name.isEmpty() || d(s.seed.get(), "highlightLoser", e).highlight()), e.find(".team").mouseover(function () { var n = t(this).attr("data-teamid"); if (void 0 !== n) { var r = d(parseInt(n, 10), null, e); r.highlight(), t(this).mouseout(function () { r.deHighlight(), t(this).unbind("mouseout") }) } }) }(a, c, l), n && (i.results[0] = c.results(), u && (i.results[1] = u.results()), l && !e.skipGrandFinalComeback && (i.results[2] = l.results()), h(), e.save && e.save(x(i), e.userData)) } e.skipSecondaryFinal && o && t.error("skipSecondaryFinal setting is viable only in double elimination mode"), e.disableToolbar || function (e, r, i) { var o = t('
').appendTo(e); if (t('+').appendTo(o).click(function () { for (var t = r.teams.length, e = 0; e < t; e += 1)r.teams.push([n.empty(), n.empty()]); return D(i) }), r.teams.length > 1 && 1 === r.results.length || r.teams.length > 2 && 3 === r.results.length) { var s = t('-').appendTo(o); s.click(function () { if (r.teams.length > 1) return r.teams = r.teams.slice(0, r.teams.length / 2), D(i) }) } if (1 === r.results.length && r.teams.length > 1) { var a = t('de').appendTo(o); a.click(function () { if (r.teams.length > 1 && r.results.length < 3) return r.results.push([], []), D(i) }) } else if (3 === r.results.length && r.teams.length > 1) { var a = t('se').appendTo(o); a.click(function () { if (3 === r.results.length) return r.results = r.results.slice(0, 1), D(i) }) } }(a, i, e); var f, m, v; o ? m = t('
').appendTo(a) : (e.skipGrandFinalComeback || (f = t('
').appendTo(a)), m = t('
').appendTo(a), v = t('
').appendTo(a)), m.css("height", s), v && v.css("height", m.height() / 2), h(); var T = function (t, e, n, i, o, s, h) { return new N(t, e, n, i, o, s, h, r, a, p) }; return c = new M(m, n.of(i.results[0] || null), T, !0, e), o || (u = new M(v, n.of(i.results[1] || null), T, !1, e), e.skipGrandFinalComeback || (l = new M(f, n.of(i.results[2] || null), T, !1, e))), function (t, e, r, i, o) { for (var s, a = Math.log(2 * e.length) / Math.log(2), h = e.length, c = 0; c < a; c += 1) { s = t.addRound(n.empty()); for (var u = 0; u < h; u += 1) { var l = 0 === c ? y(e, u) : null; if (c === a - 1 && r || c === a - 1 && o) { var p = s.addMatch(l, n.of(g)); o || p.setAlignCb(C(p, i.skipConsolationRound)) } else s.addMatch(l, n.empty()) } h /= 2 } if (r && (t.final().setConnectorCb(n.empty()), e.length > 1 && !i.skipConsolationRound)) { var d = t.final().getRound().prev(), f = d.map(function (t) { return function () { return t.match(0).loser() } }).toNull(), m = d.map(function (t) { return function () { return t.match(1).loser() } }).toNull(), v = s.addMatch(function () { return [{ source: f }, { source: m }] }, n.of(b)); v.setAlignCb(function (e) { var n = t.el.height() / 2; v.el.css("height", n + "px"); var r = e.height() / 2 + i.matchMargin; e.css("top", r + "px") }), v.setConnectorCb(n.empty()) } }(c, i.teams, o, e, e.skipGrandFinalComeback && !o), o || (function (t, e, r, i, o) { for (var s = Math.log(2 * r) / Math.log(2) - 1, a = r / 2, h = 0; h < s; h += 1) { for (var c = i && h === s - 1 ? 1 : 2, u = 0; u < c; u += 1)for (var l = e.addRound(n.empty()), p = 0; p < a; p += 1) { var d = u % 2 != 0 || 0 === h ? E(t, e, a, p, u, h) : null, f = h === s - 1 && i, m = l.addMatch(d, n.of(f ? b : null)); if (m.setAlignCb(w(m.el.find(".teamContainer"), m)), f) m.setConnectorCb(n.empty()); else if (h < s - 1 || u < 1) { var g = u % 2 == 0 ? k(o) : null; m.setConnectorCb(n.of(g)) } } a /= 2 } }(c, u, i.teams.length, e.skipGrandFinalComeback, e.centerConnectors), e.skipGrandFinalComeback || function (t, e, r, i, o, s) { var a = t.addRound(n.empty()), h = a.addMatch(function () { return [{ source: function () { return e.winner() } }, { source: function () { return r.winner() } }] }, n.of(function (o) { var a = !1; if (i.skipSecondaryFinal || o.winner().name.isEmpty() || o.winner().name !== r.winner().name) { if (2 === t.size()) t.dropRound(); else if (t.size() > 2) throw new Error("Unexpected number of final rounds"); return g(o) } if (2 === t.size()) return !1; var h = t.addRound(n.of(function () { var e = !o.winner().name.isEmpty() && o.winner().name === r.winner().name; return !1 === a && e && (a = !0, s()), !e && a && (a = !1, t.dropRound(), s()), e })).addMatch(function () { return [{ source: function () { return o.first() } }, { source: function () { return o.second() } }] }, n.of(g)); return o.setConnectorCb(n.of(function (t) { return { height: 0, shift: t.height() / 2 } })), h.setConnectorCb(n.empty()), h.setAlignCb(function (t) { var n = e.el.height() + r.el.height(); h.el.css("height", n + "px"); var i = (e.el.height() / 2 + e.el.height() + r.el.height() / 2) / 2 - t.height(); t.css("top", i + "px") }), !1 })); if (h.setAlignCb(function (t) { var n = e.el.height() + r.el.height(); i.skipConsolationRound || (n /= 2), h.el.css("height", n + "px"); var o = (e.el.height() / 2 + e.el.height() + r.el.height() / 2) / 2 - t.height(); t.css("top", o + "px") }), !i.skipConsolationRound) { var c = r.final().getRound().prev(), u = a.addMatch(function () { return [{ source: function () { return c.get().match(0).loser() } }, { source: function () { return r.loser() } }] }, n.of(b)); u.setAlignCb(function (t) { var n = (e.el.height() + r.el.height()) / 2; u.el.css("height", n + "px"); var i = (e.el.height() / 2 + e.el.height() + r.el.height() / 2) / 2 + t.height() / 2 - n; t.css("top", i + "px") }), h.setConnectorCb(n.empty()), u.setConnectorCb(n.empty()) } e.final().setConnectorCb(n.of(function (t) { var n = t.height() / 4, o = (e.el.height() / 2 + e.el.height() + r.el.height() / 2) / 2 - t.height() / 2 - e.el.height() / 2, s = e.winner().order.map(function (t) { return t.map({ height: o + 2 * n, shift: n * (i.centerConnectors ? 2 : 1) }, { height: o + n * (i.centerConnectors ? 2 : 0), shift: n * (i.centerConnectors ? 2 : 3) }) }).orElse({ height: o + n * (i.centerConnectors ? 2 : 1), shift: 2 * n }), a = s.height, h = s.shift; return { height: a - t.height() / 2, shift: h } })), r.final().setConnectorCb(n.of(function (t) { var n = t.height() / 4, o = (e.el.height() / 2 + e.el.height() + r.el.height() / 2) / 2 - t.height() / 2 - e.el.height() / 2, s = r.winner().order.map(function (t) { return t.map({ height: o + n * (i.centerConnectors ? 2 : 0), shift: n * (i.centerConnectors ? 2 : 3) }, { height: o + 2 * n, shift: n * (i.centerConnectors ? 2 : 1) }) }).orElse({ height: o + n * (i.centerConnectors ? 2 : 1), shift: 2 * n }), a = s.height, h = s.shift; return { height: -(a + t.height() / 2), shift: -h } })) }(l, c, u, e, 0, h)), p(!1), { data: function () { return x(e.init) } } }; var F = function (t, e) { if (t.hasOwnProperty(e)) { var n = typeof t[e]; if ("number" !== n) throw new Error('Option "' + e + '" is ' + n + " instead of number") } }, Y = function (t, e) { var n = typeof t[e]; if ("boolean" !== n) throw new Error("Value of " + e + " must be boolean, got boolean, got " + n) }, P = function (t, e, n) { var r = e[n]; if (r < t) throw new Error("Value of " + n + " must be greater than " + t + ", got " + r) }, W = { init: function (e) { var o = t.extend(!0, {}, e); if (!o) throw Error("Options not set"); if (!o.init && !o.save) throw Error("No bracket data or save callback given"); if (void 0 === o.userData && (o.userData = null), !(!o.decorator || o.decorator.edit && o.decorator.render)) throw Error("Invalid decorator input"); o.decorator || (o.decorator = { edit: f, render: m }), o.init || (o.init = { results: [], teams: [[n.empty(), n.empty()]] }), o.el = this, o.save && (o.onMatchClick || o.onMatchHover) && t.error("Match callbacks may not be passed in edit mode (in conjunction with save callback)"); var s = typeof o.disableToolbar, a = o.hasOwnProperty("disableToolbar"); a && "boolean" !== s && t.error("disableToolbar must be a boolean, got " + s), !o.save && a && t.error('disableToolbar can be used only if the bracket is editable, i.e. "save" callback given'), a || (o.disableToolbar = void 0 === o.save); var h = typeof o.disableTeamEdit, c = o.hasOwnProperty("disableTeamEdit"); c && "boolean" !== h && t.error("disableTeamEdit must be a boolean, got " + h), !o.save && c && t.error('disableTeamEdit can be used only if the bracket is editable, i.e. "save" callback given'), c || (o.disableTeamEdit = !1), !o.disableToolbar && o.disableTeamEdit && t.error('disableTeamEdit requires also resizing to be disabled, initialize with "disableToolbar: true"'); var u, l = function t(e, n) { return n > 0 && (e = t([e], n - 1)), e }(o.init.results, 4 - (u = o.init.results, function t(e, n) { return e instanceof Array ? t(e[0], n + 1) : n }(u, 0))); o.init.results = (p = l, p.map(function (t) { return t.map(function (t) { return t.map(function (t) { return new i(r.of(_(t[0])), r.of(_(t[1])), t[2]) }) }) })); var p; F(o, "teamWidth"), F(o, "scoreWidth"), F(o, "roundMargin"), F(o, "matchMargin"), o.hasOwnProperty("teamWidth") || (o.teamWidth = 70), o.hasOwnProperty("scoreWidth") || (o.scoreWidth = 30), o.hasOwnProperty("roundMargin") || (o.roundMargin = 40), o.hasOwnProperty("matchMargin") || (o.matchMargin = 20), P(0, o, "teamWidth"), P(0, o, "scoreWidth"), P(0, o, "roundMargin"), P(0, o, "matchMargin"), o.hasOwnProperty("centerConnectors") || (o.centerConnectors = !1), Y(o, "centerConnectors"), o.hasOwnProperty("disableHighlight") || (o.disableHighlight = !1), Y(o, "disableHighlight"); var d, g = (d = o.init.teams.length, d & d - 1); g !== Math.floor(g) && t.error('"teams" property must have 2^n number of team pairs, i.e. 1, 2, 4, etc. Got ' + o.init.teams.length + " team pairs."), o.dir = o.dir || "lr", o.init.teams = o.init.teams && 0 !== o.init.teams.length ? o.init.teams : [[null, null]], o.init.teams = o.init.teams.map(function (t) { return t.map(function (t) { return null === t ? n.empty() : n.of(t) }) }), o.skipConsolationRound = o.skipConsolationRound || !1, o.skipSecondaryFinal = o.skipSecondaryFinal || !1, "lr" !== o.dir && "rl" !== o.dir && t.error('Direction must be either: "lr" or "rl"'); var b = D(o); return t(this).data("bracket", { target: this, obj: b }), b }, data: function () { return t(this).data("bracket").obj.data() } }; t.fn.bracket = function (e) { return W[e] ? W[e].apply(this, Array.prototype.slice.call(arguments, 1)) : "object" != typeof e && e ? void t.error("Method " + e + " does not exist on jQuery.bracket") : W.init.apply(this, arguments) } }(jQuery); \ No newline at end of file