Sha256: 08f72a942a5924ad5b6b369f886de9369fc44bd3651919744679a3881d326434

Contents?: true

Size: 1.21 KB

Versions: 4

Compression:

Stored size: 1.21 KB

Contents

import $ from 'jquery'

// The ready function sets up a callback to run on each page load.
//
//     Trestle.ready(function() {
//       ...
//     });
//
const readyCallbacks = $.Callbacks('unique')
export function ready (callback) {
  readyCallbacks.add(callback)
}

export function triggerReady (root) {
  readyCallbacks.fire(root)
}

// The init function sets up a callback to run on each page load, as well as when elements are added to the page
// dynamically (e.g. via a modal). It is used to initialize dynamic elements such as date pickers, although it is
// preferable if they can be set up using event delegation on the document element.
//
// The callback is triggered with the applicable root/container element as the argument.
//
//     Trestle.init(function(root) {
//       $(root).find('...');
//     });
//
const initCallbacks = $.Callbacks('unique')
export function init (callback) {
  initCallbacks.add(callback)
}

export function triggerInit (root) {
  // Pass root as both parameters for backwards compatibility
  initCallbacks.fire(root, root)
}

// Initialize all elements within the document on page load.
ready(function () {
  triggerInit(document)
})

document.addEventListener('turbo:load', () => triggerReady())

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
trestle-0.10.1 frontend/js/deprecated/events.js
trestle-0.10.0 frontend/js/deprecated/events.js
trestle-0.10.0.pre2 frontend/js/deprecated/events.js
trestle-0.10.0.pre frontend/js/deprecated/events.js