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

Version Path
comfortable_mexican_sofa-2.0.19 app/assets/javascripts/comfy/admin/cms/file_link.js
PixelForce_ETS-0.0.2 app/assets/javascripts/comfy/admin/cms/file_link.js
PixelForce_ETS-0.0.1 app/assets/javascripts/comfy/admin/cms/file_link.js
kcyEtsTest2-0.0.4 app/assets/javascripts/comfy/admin/cms/file_link.js
kcyEtsTest2-0.0.3 app/assets/javascripts/comfy/admin/cms/file_link.js
kcyEtsTest2-0.0.2 app/assets/javascripts/comfy/admin/cms/file_link.js
kcyEtsTest2-0.0.1 app/assets/javascripts/comfy/admin/cms/file_link.js
kcyEtsTest-0.0.1 app/assets/javascripts/comfy/admin/cms/file_link.js
kcyEtsTest-2.2.19 app/assets/javascripts/comfy/admin/cms/file_link.js
ComfortableMexicanSofa-2.0.18 app/assets/javascripts/comfy/admin/cms/file_link.js
kcy1-1.0 app/assets/javascripts/comfy/admin/cms/file_link.js
comfortable_mexican_sofa-2.0.18 app/assets/javascripts/comfy/admin/cms/file_link.js
comfortable_mexican_sofa-2.0.17 app/assets/javascripts/comfy/admin/cms/file_link.js
comfortable_mexican_sofa-2.0.16 app/assets/javascripts/comfy/admin/cms/file_link.js
comfortable_mexican_sofa-2.0.15 app/assets/javascripts/comfy/admin/cms/file_link.js
comfortable_mexican_sofa-2.0.14 app/assets/javascripts/comfy/admin/cms/file_link.js
comfortable_mexican_sofa-2.0.13 app/assets/javascripts/comfy/admin/cms/file_link.js