cypruska / workshop Goto Github PK
View Code? Open in Web Editor NEWWorkshop for CoderHouse - SWAPI
Workshop for CoderHouse - SWAPI
`console.log('Workshop final')
/* // Mini Parallax
$(document).ready(function () {
$(document).scroll(function () {
var scrollTop = $(window).scrollTop()
$('#background1').css('top', -(scrollTop * 0.25) + 'px')
$('#background2').css('top', -(scrollTop * 0.75) + 'px')
$('#background3').css('top', -(scrollTop * 2) + 'px')
})
})
// END Mini Parallax */
/* Call API */
console.log('Init')
/* Call API People*/
var url = 'https://swapi.co/api/people'
function ajaxCall (url, cbk) {
$.ajax({
url: url,
method: 'GET'
})
.done(function (response) {
cbk(null, response)
})
.fail(function(error) {
cbk(error)
})
}
/* END Call API People*/
/* Resultado API */
var resultTotal = []
var callback = function(error, response) {
if(error) {
console.log('Error: ', error)
}
else {
resultTotal = resultTotal.concat(response.results)
if (response.next) {
ajaxCall(response.next, callback)
// Si hay una paginación nueva, la llama.
}
else {
// Si no hay una paginación nueva, muestra el resultado total concatenado.
var resultsTotalOrdered = orderByName(resultTotal)
showName(resultsTotalOrdered)
}
}
}
function showName(results) {
for(var i = 0; i < results.length; i++) {
var item = results[i]
var name = item.name
var height = tHeight(item.height)
var eye_color = translateEye_Color(item.eye_color)
var gender = translateGender(item.gender)
console.log(name + ' ' + height + ' ' + eye_color + ' ' + gender)
}
}
ajaxCall(url, callback)
$('#nav-item nav-link text-warning').click(function(event){
var value = event.target.value
var
})
//function translate(name) {
// if () {
// }
//}
function orderByName (items) {
return items.sort(function (a, b) {
if (a.name > b.name) {
return 1
}
if (a.name < b.name) {
return -1
}
return 0
})
}
function translateGender (gender) {
switch (gender) {
case 'male':
return 'Hombre'
break
case 'female':
return 'Mujer'
break
case 'hermaphrodite':
return 'Hermafrodita'
break
case 'n/a':
return 'Desconocido'
break
}
}
function translateEye_Color (key) {
switch (key) {
case 'blue':
return 'Azul'
break
case 'dark':
return 'Oscuro'
break
case 'white':
return 'Blanco'
break
case 'blue':
return 'Azul'
break
case 'black':
return 'Negro'
break
case 'yellow':
return 'Amarillo'
break
case 'red':
return 'Rojo'
break
case 'brown':
return 'Marrón'
break
case 'green':
return 'Verde'
break
case 'orange':
return 'Naranja'
break
case 'hazel':
return 'Avellana'
break
case 'unknown':
return 'Desconocido'
break
case 'pink':
return 'Rosa'
break
case 'n/a':
return 'Desconocido'
break
case undefined:
return 'Desconocido'
break
case 'default':
return 'Multiple'
break
}
}
function tHeight(height) {
if (height != 'unknown') {
var integer = parseInt(height)
return integer
}
else {
return 'Desconocida'
}
}
/*if (typeof integer != 'number') {
return 'Altura desconocida'
}
else {
return integer
}
}*/
/* END Resultado API */
`
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.