-
-
Notifications
You must be signed in to change notification settings - Fork 243
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
Enable multiple zips per tutorial page #298
base: gh-pages
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,64 @@ | ||
var UserInterface = { | ||
selector: "a[href=download]" | ||
selector: 'a[href|="#download"]' | ||
}; | ||
|
||
UserInterface.setup = function(zipper, downloader) { | ||
|
||
var downloadLink = document.body.querySelector(UserInterface.selector); | ||
var downloadLinks = document.body.querySelectorAll(UserInterface.selector); | ||
|
||
var createZip = function() { | ||
zipper.createZip(downloader); | ||
var createZip = function(files) { | ||
zipper.createZip(downloader, files); | ||
}; | ||
|
||
var registerListener = function(link) { | ||
console.log("adding listener to", link); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I personally wouldn't include debugging code in commits that may end up in production, but that's maybe a personal choice. You can use |
||
|
||
link.addEventListener("click", function(event) { | ||
event.preventDefault(); | ||
createZip(); | ||
|
||
// Get the file list on the fly | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also usually don't commit comments... again, probably just a personal choice. |
||
var files = getFileList(event.target); | ||
console.log('files', files); | ||
|
||
console.log('creating zip'); | ||
createZip(files); | ||
}, false); | ||
}; | ||
|
||
var checkIfDownloadLinkExist = function() { | ||
if (downloadLink) { | ||
registerListener(downloadLink); | ||
if (downloadLinks) { | ||
foreach(downloadLinks, function() { | ||
registerListener(this); | ||
|
||
hideAccessibleFileLinks(this); | ||
}); | ||
} | ||
}; | ||
|
||
var locateAnchorForDownloadLink = function(link) { | ||
var anchorName = link.href.replace(/^[^#]*#/, ''); | ||
return document.body.querySelector('a[name="' + anchorName + '"') | ||
} | ||
|
||
var hideAccessibleFileLinks = function(link) { | ||
var anchor = locateAnchorForDownloadLink(link); | ||
var next = getNextSiblingInDom(anchor); | ||
|
||
addClass(anchor, 'hidden'); // could be made an expander button | ||
addClass(next, 'hidden'); | ||
}; | ||
|
||
var getFileList = function(link) { | ||
var anchor = locateAnchorForDownloadLink(link); | ||
var next = getNextSiblingInDom(anchor); | ||
|
||
var fileLinks = next.querySelectorAll('a'), | ||
files = []; | ||
foreach(fileLinks, function() { | ||
files.push(this.href); | ||
}); | ||
return files; | ||
} | ||
|
||
checkIfDownloadLinkExist(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
function foreach(list, callback) { | ||
for (var idx = 0; idx < list.length; idx++) { | ||
if (callback.apply(list[idx]) === false) { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
function getNextSiblingInDom(element) { | ||
var allChildrenOfParent = element.parentNode.children, | ||
nextSibling = false, | ||
foundCurrent = false; | ||
|
||
foreach(allChildrenOfParent, function() { | ||
if (this === element) { | ||
foundCurrent = true; | ||
} else { | ||
if (foundCurrent === true) { | ||
nextSibling = this; | ||
return false; | ||
} | ||
} | ||
}); | ||
return nextSibling; | ||
} | ||
|
||
function addClass(element, className) { | ||
var classes = element.className.split(' '); | ||
if (classes.indexOf(className) !== false) { | ||
element.className += " " + className; | ||
} | ||
} |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,14 @@ | |
layout: page | ||
title: Introduction to jQuery | ||
files: | ||
- files/index.html | ||
- files/jquery.js | ||
- files/script.js | ||
- files/style.css | ||
- zipname: example1 | ||
files: | ||
- files/index.html | ||
- files/jquery.js | ||
- zipname: example2 | ||
files: | ||
- files/script.js | ||
- files/style.css | ||
--- | ||
|
||
|
||
|
@@ -46,7 +50,7 @@ Using jQuery and JavaScript functions, we are going to build a small | |
todo list. | ||
|
||
Download the files that you will need to work through the example | ||
[here](download). | ||
[here](#download-example1). and [example2](#download-example2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Download the files that you will need to work through the example here. and example2" doesn't read very well to me. But I would only download the files for Exercise 1 in the section for exercise 1. The files for exercise 2 should be downloaded from exercise 2. Also, Exercise 2 still has a link in "Download the files required to begin working through the example." pointing to the gist file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is only the test illustration, if you notice the file list is the exercise 1 zip split in 2 |
||
<!-- https://gist.github.com/despo/309f684b7a6e002aaf1f/download --> | ||
|
||
Alternatively, if you've already learned how to use git and would like | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,15 @@ footer { | |
min-width: 680px; | ||
margin: 0 auto; | ||
} | ||
|
||
.tutorial-filelist__list { | ||
} | ||
|
||
.hidden { | ||
display: none; | ||
visibility: hidden; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But I do want to hide it from screen readers if the JS is available because the zip links will work and are accessible, right? |
||
} | ||
|
||
.compact-list > * { | ||
margin: 3px 0px; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name attribute is obsolete in
a
tags (not in form elements, though).You can use
id="download-{{zip.zipname}}"
instead.Also, I personally wouldn't use an
a
element here, but a heading, so that there is an indication that this is a different section from what is strictly the tutorial copy. So something like, either:or maybe:
Or even:
where
zip.zipname
is the corresponding name.