Sha256: aa9cf490f09fd7b12fc6aab72bbfeba726af8955c05fec6ca717383e26ab06be

Contents?: true

Size: 1.4 KB

Versions: 15

Compression:

Stored size: 1.4 KB

Contents

tinymce.PluginManager.add("alchemy_link", function (editor) {
  const getAnchor = (selectedElm) => {
    return editor.dom.getParent(selectedElm, "a[href]")
  }

  const openLinkDialog = () => {
    if (Alchemy.currentDialog()) return

    let link = {}
    const anchor = getAnchor(editor.selection.getNode())
    if (anchor) {
      link = {
        url: anchor.getAttribute("href"), // avoid getting an absolute URL
        title: anchor.title,
        target: anchor.target,
        type: anchor.className
      }
    }
    const linkDialog = new Alchemy.LinkDialog(link)
    editor.focus()
    linkDialog.open().then((link) => {
      editor.execCommand("mceInsertLink", false, {
        href: link.url,
        class: link.type,
        title: link.title,
        target: link.target
      })
      editor.selection.collapse()
    })
  }

  editor.ui.registry.addToggleButton("alchemy_link", {
    icon: "link",
    tooltip: "Insert/edit link",
    onSetup(buttonApi) {
      const onNodeChange = () => {
        buttonApi.setActive(getAnchor(editor.selection.getNode()) !== null)
      }
      onNodeChange()
      editor.on("NodeChange", onNodeChange)
      return () => {
        editor.off("NodeChange", onNodeChange)
      }
    },
    onAction: openLinkDialog
  })

  // Replace the default link command with our own
  editor.addCommand("mceLink", openLinkDialog)
  editor.addShortcut("Meta+K", "", openLinkDialog)
})

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
alchemy_cms-7.4.0 app/javascript/tinymce/plugins/alchemy_link/index.js
alchemy_cms-7.3.5 app/assets/javascripts/tinymce/plugins/alchemy_link/plugin.min.js
alchemy_cms-7.2.8 app/assets/javascripts/tinymce/plugins/alchemy_link/plugin.min.js
alchemy_cms-7.3.4 app/assets/javascripts/tinymce/plugins/alchemy_link/plugin.min.js
alchemy_cms-7.3.3 app/assets/javascripts/tinymce/plugins/alchemy_link/plugin.min.js
alchemy_cms-7.3.2 app/assets/javascripts/tinymce/plugins/alchemy_link/plugin.min.js
alchemy_cms-7.2.7 app/assets/javascripts/tinymce/plugins/alchemy_link/plugin.min.js
alchemy_cms-7.3.1 app/assets/javascripts/tinymce/plugins/alchemy_link/plugin.min.js
alchemy_cms-7.3.0 app/assets/javascripts/tinymce/plugins/alchemy_link/plugin.min.js
alchemy_cms-7.2.6 app/assets/javascripts/tinymce/plugins/alchemy_link/plugin.min.js
alchemy_cms-7.2.5 app/assets/javascripts/tinymce/plugins/alchemy_link/plugin.min.js
alchemy_cms-7.2.4 app/assets/javascripts/tinymce/plugins/alchemy_link/plugin.min.js
alchemy_cms-7.2.3 app/assets/javascripts/tinymce/plugins/alchemy_link/plugin.min.js
alchemy_cms-7.2.2 app/assets/javascripts/tinymce/plugins/alchemy_link/plugin.min.js
alchemy_cms-7.2.1 app/assets/javascripts/tinymce/plugins/alchemy_link/plugin.min.js