This repository has been archived by the owner on Feb 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial commit for random word generator - unfinished
- Loading branch information
Sumeet Adur
committed
Dec 11, 2015
1 parent
1967f32
commit 75a482a
Showing
3 changed files
with
66 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,70 @@ | ||
import oHoverable from 'o-hoverable'; | ||
import attachFastClick from 'fastclick'; | ||
|
||
var words = {}; | ||
|
||
document.addEventListener('DOMContentLoaded', () => { | ||
// make hover effects work on touch devices | ||
// // make hover effects work on touch devices | ||
oHoverable.init(); | ||
|
||
// remove the 300ms tap delay on mobile browsers | ||
// // remove the 300ms tap delay on mobile browsers | ||
attachFastClick(document.body); | ||
|
||
// YOUR CODE HERE! | ||
if (document.documentElement.className === 'enhanced') { | ||
var xmlhttp = new XMLHttpRequest(); | ||
xmlhttp.onreadystatechange = function() { | ||
if (xmlhttp.readyState === 4 && xmlhttp.status === 200) { | ||
words = JSON.parse(xmlhttp.responseText); | ||
} | ||
}; | ||
xmlhttp.open('GET', 'words.json', true); | ||
xmlhttp.send(); | ||
} | ||
|
||
}); | ||
|
||
function replaceRandomGuff() { | ||
var wordArray = Object.keys(words); | ||
|
||
var randomNumber = Math.floor(Math.random() * (wordArray.length - 1)) + 1; | ||
|
||
var randomWord = words[wordArray[randomNumber]]; | ||
|
||
var randomGuffElement = document.getElementsByClassName('random-guff')[0]; | ||
|
||
var randomGuffClone = randomGuffElement.cloneNode(true); | ||
|
||
var word = randomGuffClone.children[1]; | ||
var details = randomGuffClone.children[2]; | ||
var definition = details.children[0].children[1]; | ||
var usageExample = details.children[1]; | ||
var relatedWordsElement = details.children[2]; | ||
|
||
word.href = randomWord.slug + '/'; | ||
word.innerHTML = randomWord.word + '»'; | ||
definition.innerText = randomWord.definition; | ||
usageExample.innerText = randomWord.usageexample; | ||
|
||
if (randomWord.relatedwords) { | ||
var relatedWords = randomWord.relatedwords; | ||
var newRelatedWordsElement = document.createElement('p'); | ||
newRelatedWordsElement.className = 'detail relatedwords'; | ||
newRelatedWordsElement.innerHTML = 'Related: '; | ||
|
||
for(var relatedWord of relatedWords) { | ||
var relatedWordElement = document.createElement('a'); | ||
relatedWordElement.href = relatedWord.slug + '/'; | ||
relatedWordElement.innerHTML = relatedWord.word; | ||
newRelatedWordsElement.appendChild(relatedWordElement); | ||
} | ||
if (relatedWordsElement) { | ||
relatedWordsElement = newRelatedWordsElement; | ||
} else { | ||
details.appendChild(newRelatedWordsElement); | ||
} | ||
} else { | ||
relatedWordsElement.remove() | ||
} | ||
randomGuffElement.innerHTML = randomGuffClone.innerHTML; | ||
|
||
} |
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