Sha256: 42ba11c430857eb47de7797e19c000dd7a49a94270ea4d69d844d0cba2f1646d
Contents?: true
Size: 1.92 KB
Versions: 17
Compression:
Stored size: 1.92 KB
Contents
(() => { const isFirefox = /\bFirefox\//.test(navigator.userAgent); class FileLink { constructor(link) { this.link = link; this.isImage = !!link.dataset.cmsFileThumbUrl; link.addEventListener('dragstart', (evt) => { evt.dataTransfer.setData('text/plain', this.link.dataset.cmsFileLinkTag); }); if (this.isImage) { new bootstrap.Popover(link, { container: link.parentElement, trigger: 'hover', placement: 'top', content: this.buildFileThumbnail(), html: true }); link.addEventListener('dragstart', (evt) => { evt.dataTransfer.setDragImage(this.buildFileThumbnail(), 4, 2); this.getPopover().hide(); }); this.workAroundFirefoxPopoverGlitch(); } } buildFileThumbnail() { const img = new Image(); img.src = this.link.dataset.cmsFileThumbUrl; return img; } // To work around a Firefox bug causing the popover to re-appear after the drop: // https://github.com/comfy/comfortable-mexican-sofa/pull/799#issuecomment-369124161 // // Possibly related to: // https://bugzilla.mozilla.org/show_bug.cgi?id=505521 workAroundFirefoxPopoverGlitch() { if (!isFirefox) return; this.link.addEventListener('dragstart', () => { this.getPopover().disable(); }); this.link.addEventListener('dragend', () => { setTimeout(() => { const popover = this.getPopover(); popover.enable(); popover.hide(); }, 300); }); } // We can't keep a reference to the Popover object, because Bootstrap re-creates it internally. getPopover() { return jQuery(this.link).data(bootstrap.Popover.DATA_KEY); } } window.CMS.fileLinks = (root = document) => { for (const link of root.querySelectorAll('[data-cms-file-link-tag]')) { new FileLink(link); } }; })();
Version data entries
17 entries across 17 versions & 6 rubygems