Sha256: 54b5c625e184cd7875bfe65d1e92941712a0e75b0a3c15373482df758e2c811e

Contents?: true

Size: 1.58 KB

Versions: 15

Compression:

Stored size: 1.58 KB

Contents

((exports) => {
  const { icon } = exports.Decidim;

  const EXCLUDE_CLASSES = [
    "card--list__data__icon",
    "footer-social__icon",
    "logo-cityhall"
  ];
  const EXCLUDE_REL = ["license", "decidim"];

  const DEFAULT_MESSAGES = {
    externalLink: "External link"
  };
  let MESSAGES = DEFAULT_MESSAGES;

  class ExternalLink {
    static configureMessages(messages) {
      MESSAGES = exports.$.extend(DEFAULT_MESSAGES, messages);
    }

    constructor(link) {
      this.$link = link;

      this.setup();
    }

    setup() {
      if (EXCLUDE_CLASSES.some((cls) => this.$link.hasClass(cls))) {
        return;
      }
      if (
        EXCLUDE_REL.some((rel) => {
          const linkRels = `${this.$link.attr("rel")}`.split(" ");
          return linkRels.indexOf(rel) > -1;
        })
      ) {
        return;
      }

      this.$link.addClass("external-link-container");
      this.$link.append(` ${this.generateElement()}`);
    }

    generateElement() {
      let content = `${this.generateIcon()}${this.generateScreenReaderLabel()}`;

      return `<span class="external-link-indicator">${content}</span>`;
    }

    generateIcon() {
      return icon("external-link");
    }

    generateScreenReaderLabel() {
      return `<span class="show-for-sr">(${MESSAGES.externalLink})</span>`;
    }
  }

  exports.Decidim = exports.Decidim || {};
  exports.Decidim.ExternalLink = ExternalLink;

  $(document).ready(function() {
    $('a[target="_blank"]').each((_i, elem) => {
      const $link = $(elem);

      $link.data("external-link", new ExternalLink($link));
    });
  });
})(window);

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
decidim-core-0.24.3 app/assets/javascripts/decidim/external_link.js.es6
decidim-core-0.23.6 app/assets/javascripts/decidim/external_link.js.es6
decidim-core-0.24.2 app/assets/javascripts/decidim/external_link.js.es6
decidim-core-0.23.5 app/assets/javascripts/decidim/external_link.js.es6
decidim-core-0.24.1 app/assets/javascripts/decidim/external_link.js.es6
decidim-core-0.24.0 app/assets/javascripts/decidim/external_link.js.es6
decidim-core-0.24.0.rc2 app/assets/javascripts/decidim/external_link.js.es6
decidim-core-0.23.4 app/assets/javascripts/decidim/external_link.js.es6
decidim-core-0.24.0.rc1 app/assets/javascripts/decidim/external_link.js.es6
decidim-core-0.23.3 app/assets/javascripts/decidim/external_link.js.es6
decidim-core-0.23.2 app/assets/javascripts/decidim/external_link.js.es6
decidim-core-0.23.1 app/assets/javascripts/decidim/external_link.js.es6
decidim-core-0.23.1.rc1 app/assets/javascripts/decidim/external_link.js.es6
decidim-core-0.23.0 app/assets/javascripts/decidim/external_link.js.es6
decidim-core-0.22.0 app/assets/javascripts/decidim/external_link.js.es6