Remove jQuery dependency

Created on 24 September 2021, over 3 years ago
Updated 12 July 2024, 10 months ago

Problem/Motivation

D10 will remove jQuery dependency. Any progress to remove this from extlink Module?

Steps to reproduce

Proposed resolution

Replace jQuery code with JavaScript

Remaining tasks

Test/review and add it to a new version of the module

User interface changes

none

API changes

none

Data model changes

none

✨ Feature request
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡¨πŸ‡­Switzerland cola

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡―πŸ‡΅Japan tyler36 Osaka

    Tested on Drupal `10.0.3`

    ## Test

    1. Added internal-only Link field to 'Article' node.
    2. Added external-only Link field to 'Article' node.
    3. Created new article with internal & external links.

    ## Other

    https://www.drupal.org/project/extlink β†’ will also need updating to remove the `jQuery` reference from the first paragraph.

  • Status changed to Needs work over 1 year ago
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Thanks! Conflicts need to be resolved!

  • Status changed to Needs review over 1 year ago
  • πŸ‡¦πŸ‡ΉAustria granik Vienna

    @Anybody, thanks. Just rebased, but would be ok if you test your new mailto feature again after my rebase.

  • Status changed to Needs work about 1 year ago
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica
  • Status changed to Needs review about 1 year ago
  • πŸ‡¦πŸ‡ΉAustria granik Vienna
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave
  • Status changed to Needs work 11 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Would like to include with 2.0.x but appears to breaking a number of tests.

  • Pipeline finished with Canceled
    11 months ago
    Total: 53s
    #208788
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Woo got main pipeline all green so any change should be legit issues.

  • Pipeline finished with Failed
    11 months ago
    Total: 297s
    #208792
  • Pipeline finished with Canceled
    11 months ago
    Total: 254s
    #208794
  • Pipeline finished with Failed
    11 months ago
    Total: 309s
    #208798
  • Pipeline finished with Failed
    11 months ago
    Total: 306s
    #208805
  • Pipeline finished with Canceled
    11 months ago
    Total: 157s
    #208817
  • Pipeline finished with Failed
    11 months ago
    Total: 314s
    #208821
  • The rebase had lots of commits, because I merged once instead of rebasing prior to that.

  • I fixed almost all of the eslint issues. There are a few that I don't know if they should be ignored or changed.

  • Pipeline finished with Failed
    11 months ago
    Total: 269s
    #208828
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Wouldn't worry about those, but the test failures could be showing an issue.

  • Both failing tests are because it's not finding the external settings file.

    It has

        $this->drupalLogin($this->adminUser);
        $this->drupalGet(self::EXTLINK_ADMIN_PATH);
        $this->assertSession()->checkboxNotChecked('extlink_exclude_admin_routes');
        $this->assertSession()->responseContains('/extlink/js/extlink.js');
    
        // Disable Extlink on admin routes.
        $this->drupalGet(self::EXTLINK_ADMIN_PATH);
        $this->submitForm(['extlink_exclude_admin_routes' => TRUE], 'Save configuration');
        $this->assertSession()->responseNotContains('/extlink/js/extlink.js');
    

    Should it be this instead, with /extlink/settings.js?

        $this->drupalLogin($this->adminUser);
        $this->drupalGet(self::EXTLINK_ADMIN_PATH);
        $this->assertSession()->checkboxNotChecked('extlink_exclude_admin_routes');
        $this->assertSession()->responseContains('/extlink/settings.js');
    
        // Disable Extlink on admin routes.
        $this->drupalGet(self::EXTLINK_ADMIN_PATH);
        $this->submitForm(['extlink_exclude_admin_routes' => TRUE], 'Save configuration');
        $this->assertSession()->responseNotContains('/extlink/settings.js');
    
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Ah that took me forever to figure out yesterday. So the test may need to be updated to check the host. Gitlab running with localhost/web was causing all tests to fail before.

  • I think this will fix the tests. The functionality with the external settings is actually working when I run it. It's just checking for the wrong string in the response.

  • Status changed to Needs review 11 months ago
  • Pipeline finished with Failed
    11 months ago
    #208866
  • Status changed to Needs work 11 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Reverted the changes to the test as don't think we should update those. If the jquery removal is correct then nothing should break. So think maybe the js changes around the nofollow/referrer needs some work.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Don't have the why yet but appears to be when the link has a target already set that the js fails to add a rel attribute

  • Status changed to Needs review 11 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    So I moved the filter part of the js down after the rel is added. Wasn't needed before but tests appear green. Thoughts?

  • Status changed to Needs work 11 months ago
  • It's better, but I don't think it's quite right. The externalLinks variable is filtered down, meaning that later when noreferrer is added, it won't be added to links that already had the target attribute set, even if the target is _blank. Is that the desired functionality? The form setting says this:

    A link that specifies target='_self' will not be changed to target='_blank'.

    My understanding of the "no override" setting was that it shouldn't override the target attribute, but that the nofollow and noreferrer should still be set on the link.

    Personally, I think this

          // Apply the target attribute to all links.
          externalLinks = externalLinks.filter((link) => {
            // Filter out links with target set if option specified.
            return !(drupalSettings.data.extlink.extTargetNoOverride && link.matches('a[target]'));
          });
    
          // Add target attr to open link in a new tab.
          externalLinks.forEach((link, i) => {
            externalLinks[i].setAttribute('target', '_blank');
          });
    

    Should be modified so that externalLinks is not changed. Something like this:

          // Add target attr to open link in a new tab if not set.
          externalLinks.forEach((link, i) => {
            if (!(drupalSettings.data.extlink.extTargetNoOverride && link.matches('a[target]'))) {
              externalLinks[i].setAttribute('target', '_blank');
            }
          });
    
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Applied suggestion but have to run. If it works and we are happy I can merge this evening.

  • Status changed to Needs review 11 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Tests passed

  • Status changed to RTBC 11 months ago
  • Looks good to me. Do we need to add a test to cover that noreferrer is added to links with a target attribute already set?

  • Status changed to Fixed 10 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Think we are probably good.

    Down to 2 issue so will plan a beta1 release in the next few days.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024