Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from ArjanJ/staging
add project links on mobile through js
- Loading branch information
Showing
4 changed files
with
78 additions
and
29 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import isMobile from 'is-mobile'; | ||
|
||
/** | ||
* projectsLinks | ||
* On mobile the project links are added to the DOM | ||
* using javascript because the actual link doesn't | ||
* fit into the mobile design (it's hidden). | ||
*/ | ||
export const projectLinks = () => { | ||
const projects = document.querySelectorAll('.projects-box'); | ||
|
||
const handleClick = ({ target }) => { | ||
const projectBox = target.closest('.projects-box'); | ||
const link = projectBox.getAttribute('data-link'); | ||
|
||
// Open project link in new tab. | ||
window.open(link, '_blank'); | ||
}; | ||
|
||
const addEventListeners = () => { | ||
for (let i = 0; i < projects.length; i++) { | ||
projects[i].addEventListener('click', handleClick, false); | ||
} | ||
}; | ||
|
||
const init = () => { | ||
// If we're on a desktop machine we don't need to bother adding links. | ||
if (!isMobile()) { | ||
return null; | ||
} | ||
|
||
addEventListeners(); | ||
}; | ||
|
||
init(); | ||
}; |
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