Last active
December 29, 2015 08:39
-
-
Save asford/7644437 to your computer and use it in GitHub Desktop.
Code review, because brothers love sisters.
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
word_sub = { | |
"cybernetic" : "cyber", | |
"lived" : "living", | |
"relations" : "relation", | |
"changing" : "change", | |
"changes" : "change", | |
"womens" : "women", | |
"women's" : "women", | |
"movements" : "movement", | |
"discovered" : "discover", | |
"rests" : "rest", | |
"counts" : "count", | |
"object" : "thing", | |
"constructed" : "construction" | |
}; | |
function spoken (text,index) { | |
console.log(index); | |
text=text.replace(/[-\',.]/g,""); | |
var word = $.trim(text.toString()); | |
var audioElement = document.createElement('audio'); | |
if(word in word_sub) | |
{ | |
word = word_sub[word]; | |
} | |
if(word != '') { | |
audioElement.setAttribute('src','https://ssl.gstatic.com/dictionary/static/sounds/de/0/' + word + '.mp3'); | |
audioElement.setAttribute('autoplay','autoplay'); | |
} | |
// Best to make indentation level match scope of control flow. | |
//TODO Globals in use? | |
doomed=true; | |
count=0; | |
// while (doomed) { | |
// audioElement.addEventListener("ended",function () {doomed=false;}); | |
// count++; | |
// if (count > 50) {doomed=false;} | |
// console.log(count); | |
// } | |
} | |
$(document).ready(function() { | |
$('p').click(function(e) { | |
var range = document.getSelection(); | |
var word = $.trim(range.toString()); | |
var audioElement = document.createElement('audio'); | |
if(word in word_sub) | |
{ | |
word = word_sub[word]; | |
} | |
if(word != '') { | |
audioElement.setAttribute('src','https://ssl.gstatic.com/dictionary/static/sounds/de/0/' + word + '.mp3'); | |
audioElement.setAttribute('autoplay','autoplay'); | |
} | |
range.collapse(); | |
e.stopPropagation(); | |
}); | |
}); | |
$(document).ready(function(){ | |
$('span').click(function(){ | |
$(this).addClass("redact"); | |
}); | |
$('span').dblclick(function(){ | |
$(this).removeClass("redact"); | |
}); | |
$("img").click(function(){ | |
$("span").not(".redact").each(function(index) { | |
var newword = $(this).text(); | |
delay = 500*index; | |
console.log(delay); | |
setTimeout(function () {spoken(newword,index)} ,delay); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment