-
Notifications
You must be signed in to change notification settings - Fork 53
Modify versions menu to keep you on the same page #628
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
Merged
Merged
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
d0353d9
Modify function to remain in the same page if the version is changed
steff456 395f342
Rename function
steff456 4ab650d
Fix current url path
steff456 4d941c9
Fix URL
steff456 b8c053d
fix index
steff456 11dbf78
Check if the page exists before assigning href
steff456 5b1be4c
remove callback
steff456 50424b8
change head to get
steff456 96b426f
Move appendChild
steff456 a6157d0
Add print
steff456 7a4c0a4
split function
steff456 24c1479
fix missing variable
steff456 f649007
move print
steff456 1312193
Use fetch API
steff456 8ca2b0f
add catch block
steff456 5c73a1a
add url if status is not ok
steff456 bac4929
remove prints and point to the index file
steff456 9c02495
remove unused variable
steff456 487fc3a
Use consistent style and remove console.log
kgryte 44b35f6
Add space
kgryte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
function assign_href( a, url, path ) { | ||
fetch( url + "/" + path ).then( response => { | ||
if( response.ok ){ | ||
a.href = url + "/" + path; | ||
} | ||
else { | ||
a.href = url + "/index.html"; | ||
} | ||
}).catch( error => { | ||
a.href = url + "/index.html"; | ||
}); | ||
} | ||
|
||
function add_version_dropdown(json_loc, target_loc, text) { | ||
var dropdown = document.createElement("div"); | ||
dropdown.className = "md-flex__cell md-flex__cell--shrink dropdown"; | ||
var button = document.createElement("button"); | ||
button.className = "dropdownbutton"; | ||
var content = document.createElement("div"); | ||
content.className = "dropdown-content md-hero"; | ||
dropdown.appendChild(button); | ||
dropdown.appendChild(content); | ||
$.getJSON(json_loc, function(versions) { | ||
var currentURL = window.location.href; | ||
var path = currentURL.split( "_site" )[ 1 ]; | ||
kgryte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
path = path.split('/'); | ||
path = path.slice(2, path.length); | ||
path = path.join('/'); | ||
kgryte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for (var key in versions) { | ||
if (versions.hasOwnProperty(key)) { | ||
console.log(key, versions[key]); | ||
kgryte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var a = document.createElement("a"); | ||
a.innerHTML = key; | ||
a.title = key; | ||
assign_href( a, target_loc + versions[key], path ); | ||
kgryte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
content.appendChild(a); | ||
} | ||
} | ||
}).done(function() { | ||
button.innerHTML = text; | ||
}).fail(function() { | ||
button.innerHTML = "Other Versions Not Found"; | ||
}).always(function() { | ||
$(".navheader").append(dropdown); | ||
}); | ||
}; |
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.
Uh oh!
There was an error while loading. Please reload this page.