import $ from 'jquery'; import 'jquery.are-you-sure'; import {mqBinarySearch} from '../utils.js'; import createDropzone from './dropzone.js'; import {initCompColorPicker} from './comp/ColorPicker.js'; import {showGlobalErrorMessage} from '../bootstrap.js'; import {attachCheckboxAria, attachDropdownAria} from './aria.js'; import {handleGlobalEnterQuickSubmit} from './comp/QuickSubmit.js'; import {initTooltip} from '../modules/tippy.js'; const {appUrl, csrfToken} = window.config; export function initGlobalFormDirtyLeaveConfirm() { // Warn users that try to leave a page after entering data into a form. // Except on sign-in pages, and for forms marked as 'ignore-dirty'. if ($('.user.signin').length === 0) { $('form:not(.ignore-dirty)').areYouSure(); } } export function initHeadNavbarContentToggle() { const content = $('#navbar'); const toggle = $('#navbar-expand-toggle'); let isExpanded = false; toggle.on('click', () => { isExpanded = !isExpanded; if (isExpanded) { content.addClass('shown'); toggle.addClass('active'); } else { content.removeClass('shown'); toggle.removeClass('active'); } }); } export function initFootLanguageMenu() { function linkLanguageAction() { const $this = $(this); $.get($this.data('url')).always(() => { window.location.reload(); }); } $('.language-menu a[lang]').on('click', linkLanguageAction); } export function initGlobalEnterQuickSubmit() { $(document).on('keydown', '.js-quick-submit', (e) => { if (((e.ctrlKey && !e.altKey) || e.metaKey) && (e.key === 'Enter')) { handleGlobalEnterQuickSubmit(e.target); return false; } }); } export function initGlobalButtonClickOnEnter() { $(document).on('keypress', '.ui.button', (e) => { if (e.keyCode === 13 || e.keyCode === 32) { // enter key or space bar $(e.target).trigger('click'); } }); } export function initGlobalTooltips() { for (const el of document.getElementsByClassName('tooltip')) { initTooltip(el); } } export function initGlobalCommon() { // Undo Safari emoji glitch fix at high enough zoom levels if (navigator.userAgent.match('Safari')) { $(window).resize(() => { const px = mqBinarySearch('width', 0, 4096, 1, 'px'); const em = mqBinarySearch('width', 0, 1024, 0.01, 'em'); if (em * 16 * 1.25 - px <= -1) { $('body').addClass('safari-above125'); } else { $('body').removeClass('safari-above125'); } }); } // Semantic UI modules. const $uiDropdowns = $('.ui.dropdown'); $uiDropdowns.filter(':not(.custom)').dropdown({ fullTextSearch: 'exact' }); $uiDropdowns.filter('.jump').dropdown({ action: 'hide', onShow() { // hide associated tooltip while dropdown is open this._tippy?.hide(); this._tippy?.disable(); }, onHide() { this._tippy?.enable(); }, fullTextSearch: 'exact' }); $uiDropdowns.filter('.slide.up').dropdown({ transition: 'slide up', fullTextSearch: 'exact' }); $uiDropdowns.filter('.upward').dropdown({ direction: 'upward', fullTextSearch: 'exact' }); attachDropdownAria($uiDropdowns); attachCheckboxAria($('.ui.checkbox')); $('.tabular.menu .item').tab(); $('.tabable.menu .item').tab(); $('.toggle.button').on('click', function () { $($(this).data('target')).slideToggle(100); }); // make table