2 lines
24 KiB
JavaScript
2 lines
24 KiB
JavaScript
|
/* 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('<input type="text">');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('<div class="bubble">1st</div>');var d=b.find(".team.lose");return d.append('<div class="bubble">2nd</div>'),!0}function k(a){var b=a.el,c=b.find(".team.win");c.append('<div class="bubble third">3rd</div>');var d=b.find(".team.lose");return d.append('<div class="bubble fourth">4th</div>'),!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;i<g;i+=1){f=a.addRound(u.empty());for(var l=0;l<h;l+=1){var m=0===i?A(b,l):null;if(i===g-1&&c||i===g-1&&e){var n=f.addMatch(m,u.of(j));e||n.setAlignCb(B(n,d.skipConsolationRound))}else f.addMatch(m,u.empty())}h/=2}if(c&&(a.final().setConnectorCb(u.empty()),b.length>1&&!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;h<f;h+=1){for(var i=d&&h===f-1?1:2,j=0;j<i;j+=1)for(var l=b.addRound(u.empty()),m=0;m<g;m+=1){var n=j%2!==0||0===h?C(a,b,g,m,j,h):null,o=h===f-1&&d,p=l.addMatch(n,u.of(o?k:null));if(p.setAlignCb(D(p.el.find(".teamContainer"),p)),o)p.setConnectorCb(u.empty());else if(h<f-1||j<1){var q=j%2===0?function(a,b){var c=a.height()/4,d={height:0,shift:2*c};return b.winner().order.map(function(a){return a.map(e?d:{height:0,shift:c},e?d:{height:2*-c,shift:c})}).orElse(d)}:null;p.setConnectorCb(u.of(q))}}g/=2}}function n(a,b,c,d,e,f){var g=a.addRound(u.empty()),h=g.addMatch(function(){return[{source:function(){return b.winner()}},{source:function(){return c.winner()}}]},u.of(function(e){var g=!1;if(d.skipSecondaryFinal||e.winner().name.isEmpty()||e.winner().name!==c.winner().name){if(2===a.size())a.dropRound();else if(a.size()>2)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.setCo
|