diff --git a/index.template.html b/index.template.html index a3c1f9aab..0275e41a7 100644 --- a/index.template.html +++ b/index.template.html @@ -103,6 +103,7 @@ + + diff --git a/js/client-chat-tournament.js b/js/client-chat-tournament.js new file mode 100644 index 000000000..32c9d08cd --- /dev/null +++ b/js/client-chat-tournament.js @@ -0,0 +1,574 @@ +(function($) { + + function arrayToPhrase(array, finalSeparator) { + if (array.length <= 1) + return array.join(); + finalSeparator = finalSeparator || "and"; + return array.slice(0, -1).join(", ") + " " + finalSeparator + " " + array.slice(-1)[0]; + } + + function clampPosition(element, position) { + var $element = $(element); + + var elementWidth = $element.width(); + var parentWidth = $element.parent().width(); + if (parentWidth >= elementWidth) + position.left = parentWidth / 2 - elementWidth / 2; + else if (position.left < parentWidth - elementWidth) + position.left = parentWidth - elementWidth; + else if (position.left > 0) + position.left = 0; + + var elementHeight = $element.height(); + var parentHeight = $element.parent().height(); + if (parentHeight >= elementHeight) + position.top = parentHeight / 2 - elementHeight / 2; + else if (position.top < parentHeight - elementHeight) + position.top = parentHeight - elementHeight; + else if (position.top > 0) + position.top = 0; + } + + function makeDraggable(element, position) { + var $element = $(element); + position = position || {}; + + $element.css({ + 'user-select': 'none', + cursor: 'default', + position: 'absolute' + }); + + if (!('left' in position) || position.isDefault) { + position.left = $element.parent().width() / 2 - $element.width() / 2; + position.top = 0; + position.isDefault = true; + } + + clampPosition(element, position); + $element.css({ + left: position.left, + top: position.top + }); + + var isMouseDown = false; + var innerX = 0; + var innerY = 0; + + $element.on('mousedown', function (e) { + innerX = e.pageX - this.offsetLeft; + innerY = e.pageY - this.offsetTop; + isMouseDown = true; + }); + + $(document).on('mousemove', function (e) { + if (isMouseDown) { + position.left = e.pageX - innerX; + position.top = e.pageY - innerY; + delete position.isDefault; + clampPosition(element, position); + $element.css({ + left: position.left, + top: position.top + }); + } + }).on('mouseup', function () { + isMouseDown = false; + }); + } + + var TournamentBox = this.TournamentBox = (function () { + function TournamentBox(room, $wrapper) { + this.room = room; + this.$wrapper = $wrapper; + + $wrapper.html( + '
=o.length)return n;var r=[],u=a[e++];return n.forEach(function(n,u){r.push({key:n,values:t(u,e)})}),u?r.sort(function(n,t){return u(n.key,t.key)}):r}var e,r,i={},o=[],a=[];return i.map=function(t,e){return n(e,t,0)},i.entries=function(e){return t(n(mo.map,e,0),0)},i.key=function(n){return o.push(n),i},i.sortKeys=function(n){return a[o.length-1]=n,i},i.sortValues=function(n){return e=n,i},i.rollup=function(n){return r=n,i},i},mo.set=function(n){var t=new i;if(n)for(var e=0,r=n.length;r>e;++e)t.add(n[e]);return t},r(i,{has:function(n){return zo+n in this},add:function(n){return this[zo+n]=!0,n},remove:function(n){return n=zo+n,n in this&&delete this[n]},values:function(){var n=[];return this.forEach(function(t){n.push(t)}),n},forEach:function(n){for(var t in this)t.charCodeAt(0)===Co&&n.call(this,t.substring(1))}}),mo.behavior={},mo.rebind=function(n,t){for(var e,r=1,u=arguments.length;++r=0&&(r=n.substring(e+1),n=n.substring(0,e)),n)return arguments.length<2?this[n].on(r):this[n].on(r,t);if(2===arguments.length){if(null==t)for(n in this)this.hasOwnProperty(n)&&this[n].on(r,null);return this}},mo.event=null,mo.requote=function(n){return n.replace(jo,"\\$&")};var jo=/[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g,Lo={}.__proto__?function(n,t){n.__proto__=t}:function(n,t){for(var e in t)n[e]=t[e]},Ho=function(n,t){return t.querySelector(n)},Fo=function(n,t){return t.querySelectorAll(n)},Po=bo[a(bo,"matchesSelector")],Oo=function(n,t){return Po.call(n,t)};"function"==typeof Sizzle&&(Ho=function(n,t){return Sizzle(n,t)[0]||null},Fo=function(n,t){return Sizzle.uniqueSort(Sizzle(n,t))},Oo=Sizzle.matchesSelector),mo.selection=function(){return Uo};var Ro=mo.selection.prototype=[];Ro.select=function(n){var t,e,r,u,i=[];n=d(n);for(var o=-1,a=this.length;++o=0&&(e=n.substring(0,t),n=n.substring(t+1)),Yo.hasOwnProperty(e)?{space:Yo[e],local:n}:n}},Ro.attr=function(n,t){if(arguments.length<2){if("string"==typeof n){var e=this.node();return n=mo.ns.qualify(n),n.local?e.getAttributeNS(n.space,n.local):e.getAttribute(n)}for(t in n)this.each(m(t,n[t]));return this}return this.each(m(n,t))},Ro.classed=function(n,t){if(arguments.length<2){if("string"==typeof n){var e=this.node(),r=(n=n.trim().split(/^|\s+/g)).length,u=-1;if(t=e.classList){for(;++u =0?n.substring(0,t):n,r=t>=0?n.substring(t+1):"in";return e=xc.get(e)||Mc,r=bc.get(r)||dt,Ar(r(e.apply(null,Array.prototype.slice.call(arguments,1))))},mo.interpolateHcl=Rr,mo.interpolateHsl=Yr,mo.interpolateLab=Ir,mo.interpolateRound=Ur,mo.transform=function(n){var t=xo.createElementNS(mo.ns.prefix.svg,"g");return(mo.transform=function(n){if(null!=n){t.setAttribute("transform",n);var e=t.transform.baseVal.consolidate()}return new Zr(e?e.matrix:_c)})(n)},Zr.prototype.toString=function(){return"translate("+this.translate+")rotate("+this.rotate+")skewX("+this.skew+")scale("+this.scale+")"};var _c={a:1,b:0,c:0,d:1,e:0,f:0};mo.interpolateTransform=Br,mo.layout={},mo.layout.bundle=function(){return function(n){for(var t=[],e=-1,r=n.length;++e