Sha256: 75a2177121fcf9cd0c21e057eb9fdd7df9bf4cc7870a34c299e7cbe9b842a974

Contents?: true

Size: 1.64 KB

Versions: 18

Compression:

Stored size: 1.64 KB

Contents

const $ = window.$
import { Controller } from "stimulus"

// Used when a table has toggleable rows (initially hidden rows that can be toggled open
// to see e.g. notes or extended details) and each master row and its toggleable sibling are
// nested in a tbody (this is valid HTML) - ie there are probably two trs per tbody, and the last
// one is toggleable. If you need anyting more complex you'll need to clone or adapt this
// controller
export default class extends Controller {
  // This handler toggles the last tr in the current tbody. We use multiple tbodys in each table
  // to make toggling like this simpler, and to group the related (visible and toggleable) rows
  // together.
  row(event) {
    event.preventDefault
    const tbody = event.target.closest("tbody")
    tbody.classList.toggle("toggleable--open")
    // Update masonry - TODO: move to a module
    $(".mgrid > .row").masonry("layout")
  }

  // Toggle the last tr in each tbody in the current table.
  // The link that triggers this event will most likelt be a double chevron icon
  // sitting in a thead.
  table(event) {
    event.preventDefault
    const table = event.target.closest("table")
    const thead = event.target.closest("thead")
    // Use an Array rather a NodeList here as IE does not support NodeList.forEach
    const tbodies = Array.prototype.slice.call(table.querySelectorAll("tbody"))
    const hide = thead.classList.contains("toggleable--open")
    thead.classList.toggle("toggleable--open")
    tbodies.forEach(function(tbody) { tbody.classList.toggle("toggleable--open", !hide) })
    // Update masonry - TODO: move to a module
    $(".mgrid > .row").masonry("layout")
  }
}

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/javascript/renalware/controllers/toggle_controller.js
renalware-core-2.1.0 app/javascript/renalware/controllers/toggle_controller.js
renalware-core-2.0.167 app/javascript/renalware/controllers/toggle_controller.js
renalware-core-2.0.166 app/javascript/renalware/controllers/toggle_controller.js
renalware-core-2.0.165 app/javascript/renalware/controllers/toggle_controller.js
renalware-core-2.0.164 app/javascript/renalware/controllers/toggle_controller.js
renalware-core-2.0.163 app/javascript/renalware/controllers/toggle_controller.js
renalware-core-2.0.162 app/javascript/renalware/controllers/toggle_controller.js
renalware-core-2.0.161 app/javascript/renalware/controllers/toggle_controller.js
renalware-core-2.0.160 app/javascript/renalware/controllers/toggle_controller.js
renalware-core-2.0.159 app/javascript/renalware/controllers/toggle_controller.js
renalware-core-2.0.158 app/javascript/renalware/controllers/toggle_controller.js
renalware-core-2.0.157 app/javascript/renalware/controllers/toggle_controller.js
renalware-core-2.0.156 app/javascript/renalware/controllers/toggle_controller.js
renalware-core-2.0.155 app/javascript/renalware/controllers/toggle_controller.js
renalware-core-2.0.153 app/javascript/renalware/controllers/toggle_controller.js
renalware-core-2.0.152 app/javascript/renalware/controllers/toggle_controller.js
renalware-core-2.0.151 app/javascript/renalware/controllers/toggle_controller.js