this.small_blind = this.summary.settings.small_blind;
this.big_blind = this.small_blind * 2;
+ this.mouse_clicked = false;
+ document.addEventListener("mousedown", () => this.mouse_clicked = true);
+ document.addEventListener("mouseup", () => this.mouse_clicked = false);
+
this.svg = document.createElementNS(svgns, "svg");
this.svg.classList.add("knock-out-whist");
this.svg.setAttribute("viewBox", "0 0 500 500");
- this.mouse_clicked = false;
- this.svg.onmousedown = () => this.mouse_clicked = true;
- this.svg.onmouseup = () => this.mouse_clicked = false;
const background = document.createElementNS(svgns, "rect");
background.setAttribute("width", "500");
this.bet_size.append(this.bet_size_text);
this.svg.append(this.bet_size);
+ const move_slider = e => {
+ point.x = e.clientX;
+ point.y = e.clientY;
+ const coords = point.matrixTransform(this.svg.getScreenCTM().inverse());
+ const x = Math.max(360, Math.min(475, coords.x - 5));
+ const p = Math.pow((x - 360) / 115, 2);
+ const bet = Math.round(this.min_bet() * (1 - p) + this.all_in_bet() * p);
+ this.bet_size_text.textContent = bet;
+ this.bet_slider_thumb.setAttribute("x", x);
+ };
+
this.bet_slider = document.createElementNS(svgns, "g");
this.bet_slider.classList.add("bet-slider");
+ this.bet_slider_area = document.createElementNS(svgns, "rect");
+ this.bet_slider_area.setAttribute("x", "360");
+ this.bet_slider_area.setAttribute("y", "417");
+ this.bet_slider_area.setAttribute("width", "125");
+ this.bet_slider_area.setAttribute("height", "16");
+ this.bet_slider_area.onmousedown = move_slider;
+ this.bet_slider_area.onmousemove = e => { if (this.mouse_clicked) move_slider(e); };
+ this.bet_slider_area.ontouchmove = e => move_slider(e.touches.item(0));
+ this.bet_slider_area.classList.add("bet-slider-area");
+ this.bet_slider.append(this.bet_slider_area);
+
this.bet_slider_track = document.createElementNS(svgns, "rect");
this.bet_slider_track.setAttribute("x", "360");
this.bet_slider_track.setAttribute("y", "422");
this.bet_slider_track.setAttribute("height", "6");
this.bet_slider_track.classList.add("bet-slider-track");
const point = this.svg.createSVGPoint();
- this.bet_slider_track.onmousemove = e => {
- if (this.mouse_clicked) {
- point.x = e.clientX;
- point.y = e.clientY;
- const coords = point.matrixTransform(this.svg.getScreenCTM().inverse());
- const x = Math.max(360, Math.min(475, coords.x - 5));
- const p = Math.pow((x - 360) / 115, 2);
- const bet = Math.round(this.min_bet() * (1 - p) + this.all_in_bet() * p);
- this.bet_size_text.textContent = bet;
- this.bet_slider_thumb.setAttribute("x", x);
- }
- };
- this.bet_slider_track.onclick = e => {
- point.x = e.clientX;
- point.y = e.clientY;
- const coords = point.matrixTransform(this.svg.getScreenCTM().inverse());
- const x = Math.max(360, Math.min(475, coords.x - 5));
- const p = Math.pow((x - 360) / 115, 2);
- const bet = Math.round(this.min_bet() * (1 - p) + this.all_in_bet() * p);
- this.bet_size_text.textContent = bet;
- this.bet_slider_thumb.setAttribute("x", x);
- };
+ this.bet_slider_track.onmousedown = move_slider;
+ this.bet_slider_track.onmousemove = e => { if (this.mouse_clicked) move_slider(e); };
+ this.bet_slider_track.ontouchmove = e => move_slider(e.touches.item(0));
this.bet_slider.append(this.bet_slider_track);
this.bet_slider_thumb = document.createElementNS(svgns, "rect");
this.bet_slider_thumb.setAttribute("width", "10");
this.bet_slider_thumb.setAttribute("height", "12");
this.bet_slider_thumb.classList.add("bet-slider-thumb");
- this.bet_slider_thumb.onmousemove = this.bet_slider_track.onmousemove;
- this.bet_slider_thumb.onclick = this.bet_slider_track.onclick;
+ this.bet_slider_thumb.onmousedown = move_slider;
+ this.bet_slider_thumb.onmousemove = e => { if (this.mouse_clicked) move_slider(e); };
+ this.bet_slider_thumb.ontouchmove = e => move_slider(e.touches.item(0));
this.bet_slider.append(this.bet_slider_thumb);
this.svg.append(this.bet_slider);