Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • B bootstrap
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 263
    • Issues 263
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 114
    • Merge requests 114
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Bootstrap
  • bootstrap
  • Merge requests
  • !21654

Simplify retrieval of target elements (with data-target and href)

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Administrator requested to merge github/fork/pvdlg/fix-getSelectorFromElement into v4-dev Jan 10, 2017
  • Overview 0
  • Commits 18
  • Pipelines 0
  • Changes 9

Created by: pvdlg

Fixes #18641 (closed), fixes #21328 (closed).

Util.getSelectorFromElement is used to obtains the selector, (and later then the matching elements), referenced by data-target or href in JS components. If data-target is not defined it relies on a regex to determine if href is a selector or a regular link.

The problem is that there is no way to have a regex that will isolate URL from css selectors in 100% of the cases. For example href="div.class" can mean 'execute the JS action (collapse, dropdown, etc..) on all div with the class class or it can be a regular href URL redirecting to the page <context>/div.class

In order to solve this issue this PR remove the reliance on the regex and:

  • replace getSelectorFromElement by getTargets that returns a JQuery with matching targets
  • if data-target is defined, getTargets uses it
  • if data-target is not defined, getTargets try to use href and considers it as the attribute containing the target selector, if a JQuery selection on it actually returns elements

In addition the PR slightly simplifies the code to retrieve targeted elements in each modules.

Currently if a JS module trigger element (i.e. element with data-toggle) doesn't have a valid selector in data-target nor in href nothing happen except for dropdown and alert in which the parent of the trigger is considered the target. There is no error reported and the JS module is bypassed and has no effect. I kept the same behavior in the PR.

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/pvdlg/fix-getSelectorFromElement