Created
November 2, 2015 23:16
-
-
Save nihilismus/9e11fc92f2eb922facea to your computer and use it in GitHub Desktop.
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
var a = (function() { | |
var _colorear = function() { | |
var colores = ["red", "blue", "pink", "yellow"]; | |
var celdas_alrededor = function(celda) { | |
var obj_salida = { "arriba": undefined, "derecha": undefined, "abajo": undefined, "izquierda": undefined }; | |
var indice = celda.cellIndex; | |
/* Celda de arriba */ | |
if (celda.parentElement.previousElementSibling !== null) { | |
if (celda.parentElement.previousElementSibling.children[indice] !== null) { | |
obj_salida.arriba = celda.parentElement.previousElementSibling.children[indice]; | |
} | |
} | |
/* Celda a la derecha */ | |
if (celda.nextElementSibling !== null) { | |
obj_salida.derecha = celda.nextElementSibling; | |
} | |
/* Celda de abajo */ | |
if (celda.parentElement.nextElementSibling !== null) { | |
if (celda.parentElement.nextElementSibling.children[indice] !== null) { | |
obj_salida.abajo = celda.parentElement.nextElementSibling.children[indice]; | |
} | |
} | |
/* Celda a la izquierda */ | |
if (celda.previousElementSibling !== null) { | |
obj_salida.izquierda = celda.previousElementSibling; | |
} | |
return obj_salida; | |
}; | |
var colorear_a = function(celda) { | |
celda.style.backgroundColor = colores[0]; | |
colores.push(colores[0]); | |
colores.splice(0, 1); | |
}; | |
var colorear_las = function(celdas) { | |
if (celdas.arriba !== undefined && celdas.arriba.style.backgroundColor === "") { | |
celdas.arriba.style.backgroundColor = colores[0]; | |
} | |
if (celdas.abajo !== undefined && celdas.abajo.style.backgroundColor === "") { | |
celdas.abajo.style.backgroundColor = colores[0]; | |
} | |
if (celdas.derecha !== undefined && celdas.derecha.style.backgroundColor === "") { | |
celdas.derecha.style.backgroundColor = colores[0]; | |
} | |
if (celdas.izquierda !== undefined && celdas.izquierda.style.backgroundColor === "") { | |
celdas.izquierda.style.backgroundColor = colores[0]; | |
} | |
}; | |
var imprimir_estado_de = function(variable_local) { | |
console.log(variable_local); | |
}; | |
return function(evento) { | |
var td = evento.originalTarget; | |
var celdas_alrededor_de_td = celdas_alrededor(td); | |
colorear_a(td); | |
colorear_las(celdas_alrededor_de_td); | |
imprimir_estado_de(colores); | |
} | |
}; | |
return { | |
"colorear": _colorear | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment