Sha256: 35d9a18f96f9ac8adebae759f40fd38c07b06e52e8ff9935164c5e0e74681e8a

Contents?: true

Size: 921 Bytes

Versions: 12

Compression:

Stored size: 921 Bytes

Contents

/* eslint-disable require-jsdoc */

export default function updateExternalDomainLinks($target) {
  const whitelist = window.Decidim.config.get("external_domain_whitelist")

  if (window.location.pathname === "/link") {
    return;
  }

  $("a", $target).filter((_i, link) => {
    const $link = $(link);
    if (!$link[0].hasAttribute("href") || $link.parents(".editor-container").length > 0) {
      return false;
    }

    const parts = $link.attr("href").match(/^(([a-z]+):)?\/\/([^/:]+)(:[0-9]*)?(\/.*)?$/) || null;
    if (!parts) {
      return false;
    }

    const domain = parts[3].replace(/^www\./, "")
    if (whitelist.includes(domain)) {
      return false;
    }

    return true;
  }).each((_n, link) => {
    const $link = $(link);
    const externalHref = `/link?external_url=${encodeURIComponent($link.attr("href"))}`;
    $link.attr("href", externalHref)
    $link.attr("data-remote", true)
  });
}

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-core-0.27.9 app/packs/src/decidim/external_domain_warning.js
decidim-core-0.27.8 app/packs/src/decidim/external_domain_warning.js
decidim-core-0.27.7 app/packs/src/decidim/external_domain_warning.js
decidim-core-0.27.6 app/packs/src/decidim/external_domain_warning.js
decidim-core-0.27.5 app/packs/src/decidim/external_domain_warning.js
decidim-core-0.27.4 app/packs/src/decidim/external_domain_warning.js
decidim-core-0.27.3 app/packs/src/decidim/external_domain_warning.js
decidim-core-0.27.2 app/packs/src/decidim/external_domain_warning.js
decidim-core-0.27.1 app/packs/src/decidim/external_domain_warning.js
decidim-core-0.27.0 app/packs/src/decidim/external_domain_warning.js
decidim-core-0.27.0.rc2 app/packs/src/decidim/external_domain_warning.js
decidim-core-0.27.0.rc1 app/packs/src/decidim/external_domain_warning.js