-
-
Notifications
You must be signed in to change notification settings - Fork 78.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify retrieval of target elements (with data-target and href) #21654
Closed
+71
−97
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Added a test case for #21328 |
This was referenced Jan 12, 2017
This was referenced Jan 25, 2017
pvdlg
changed the title
Remove reliance on regex in Util.getSelectorFromElement
Simplify retrieval of target elements (with data-target and href)
Mar 19, 2017
Thank you for your PR, but we want to stop relying on jQuery as much as possible, so in the futur we will have to work with selectors instead of jQuery object. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #18641, fixes #21328.
Util.getSelectorFromElement
is used to obtains the selector, (and later then the matching elements), referenced bydata-target
orhref
in JS components.If
data-target
is not defined it relies on a regex to determine ifhref
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 alldiv
with the classclass
or it can be a regularhref
URL redirecting to the page<context>/div.class
In order to solve this issue this PR remove the reliance on the regex and:
getSelectorFromElement
bygetTargets
that returns a JQuery with matching targetsdata-target
is defined,getTargets
uses itdata-target
is not defined,getTargets
try to usehref
and considers it as the attribute containing the target selector, if a JQuery selection on it actually returns elementsIn 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 indata-target
nor inhref
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.