Do nothing when pinObject is a nonexistent element #11
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.
Because
Position
normalizes pinObject (as inPosition.pin
's signature), itselement
will become aVIEWPORT
plain object whenpinObject
contains a nonexistent element.This would break the following CSS query in old IE(<=9) if the user is not meticulous enough.
However, passing empty jQuery object is quite pervasive, and it is even harder to preclude pernicious problems like this:
$('<div id="must-exist">').appendTo('#yet-another-nonexistent')
.jQuery
creates a detacheddiv
but removes it then because no container is found. The final result is still an empty $ object.In old IE, querying css property of empty jQuery will produce an exception that freezes all subsequent code in the same context, even if
Position.pin
is wrapped intry..catch..
block. In modern browsers this does not matter much but still halting futile code execution is preferred.Position
can be more care-free if the burden of validating element is placed not on users. I hope this patch can make it done.I tried to write new test case in the specs but did not manage to set up the test environment. I only tested on my local project, I wish this revision will pass.
Best wishes