Sha256: 564572973010efbc9e8f6cefd2ccf379c6a5eb8c235843f301f4ca476d9b0183
Contents?: true
Size: 1.17 KB
Versions: 32
Compression:
Stored size: 1.17 KB
Contents
(() => { const Rails = window.Rails; const DATA_ID_ATTRIBUTE = 'data-id'; const sortableStore = { get(sortable) { return Array.from(sortable.el.children, (el) => el.getAttribute(DATA_ID_ATTRIBUTE)); }, set(sortable) { fetch(`${CMS.current_path}/reorder`, { body: JSON.stringify({order: sortable.toArray()}), headers: {'Content-Type': 'application/json', 'X-CSRF-Token': Rails.csrfToken()}, credentials: 'same-origin', method: 'PUT', }); } }; const sortableInstances = []; window.CMS.sortableList = { init(root = document) { for (const sortableRoot of root.querySelectorAll('.sortable')) { sortableInstances.push(Sortable.create(sortableRoot, { handle: '.dragger', draggable: 'li', dataIdAttr: DATA_ID_ATTRIBUTE, store: sortableStore, onStart: (evt) => evt.from.classList.add('sortable-active'), onEnd: (evt) => evt.from.classList.remove('sortable-active') })); } }, dispose() { for (const sortable of sortableInstances) { sortable.destroy(); } sortableInstances.length = 0; } } })();
Version data entries
32 entries across 32 versions & 8 rubygems