diff --git a/app/javascript/controllers/seats_controller.js b/app/javascript/controllers/seats_controller.js index b40260ab..35b26ce8 100644 --- a/app/javascript/controllers/seats_controller.js +++ b/app/javascript/controllers/seats_controller.js @@ -1,12 +1,28 @@ import { Controller } from "stimulus" +import svgPanZoom from "svg-pan-zoom" export default class extends Controller { static targets = [ "map", "seat", "section", "selection" ] connect() { + this.map = svgPanZoom(this.mapTarget, { + viewportSelector: "#map-viewport", + center: true, + fit: true, + zoomEnabled: false, + zoomScaleSensitivity: 0.75, + minZoom: 1.0, + maxZoom: 8, + }) this.selectSeats() } + disconnect() { + if (!this.mapTarget.hasAttribute("data-turbolinks-permanent")) { + this.map.destroy() + } + } + discardMap() { this.mapTarget.removeAttribute("data-turbolinks-permanent") } @@ -46,4 +62,12 @@ export default class extends Controller { section.removeAttribute("aria-hidden") }) } + + zoomIn() { + this.map.zoomIn() + } + + zoomOut() { + this.map.zoomOut() + } } diff --git a/app/views/seats/_frame.html.erb b/app/views/seats/_frame.html.erb index 27793ded..891b8e6e 100644 --- a/app/views/seats/_frame.html.erb +++ b/app/views/seats/_frame.html.erb @@ -91,42 +91,45 @@ - <% sections.each do |section| %> - = section.price %> - opacity="1.0" - <% else %> - opacity="0.3" - aria-hidden="true" - <% end %> - data-target="seats.section" - data-price="<%= section.price %>" - data-included-opacity="1.0" - data-excluded-opacity="0.3" - > - <% section.seats.each do |seat| %> - - - - - <% end %> - - <% end %> + + <% sections.each do |section| %> + = section.price %> + opacity="1.0" + <% else %> + opacity="0.3" + aria-hidden="true" + <% end %> + data-target="seats.section" + data-price="<%= section.price %>" + data-included-opacity="1.0" + data-excluded-opacity="0.3" + > + <% section.seats.each do |seat| %> + + + + + <% end %> + + <% end %> +