Sha256: ce7ad013d943792e3fc1d2705297093897e1e39aa7304881d5f246553cf04029

Contents?: true

Size: 1.33 KB

Versions: 8

Compression:

Stored size: 1.33 KB

Contents

import $ from 'jquery'

import turbolinks from './turbolinks'

// 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)
})

// Trigger the page load events.
if (turbolinks) {
  $(document).on('turbolinks:load', triggerReady)
} else {
  $(document).ready(triggerReady)
}

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
trestle-0.9.8 frontend/js/core/events.js
trestle-0.9.7 frontend/js/core/events.js
trestle-0.9.6 frontend/js/core/events.js
trestle-0.9.5 frontend/js/core/events.js
trestle-0.9.4 frontend/js/core/events.js
trestle-0.9.3 frontend/js/core/events.js
trestle-0.9.2 frontend/js/core/events.js
trestle-0.9.1 frontend/js/core/events.js