Skip to content
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

add explicit check to id #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion fragmention.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@ if (!('fragmention' in window.location)) (function () {
// set location fragmention as uri-decoded text (from href, as hash may be decoded)
var
id = location.href.match(/#((?:#|%23)?)(.+)/) || [0,'',''],
node = document.getElementById(id[1]+id[2]) || getAnchorableElementByName(id[1]+id[2]),
node,
match = decodeURIComponent(id[2].replace(/\+/g, ' ')).split(' ');

location.fragmention = match[0];
location.fragmentionIndex = parseFloat(match[1]) || 0;

// check if the id exists to prevent JS warnings
if (id[1]+id[2]) {
node = document.getElementById(id[1]+id[2]) || getAnchorableElementByName(id[1]+id[2]);
}

// conditionally remove stashed element fragmention attribute
if (element) {
element.removeAttribute('fragmention');
Expand Down
5 changes: 4 additions & 1 deletion fragmention.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.