Skip to content

Commit

Permalink
Criada representacao do DOM em uma matriz ;)
Browse files Browse the repository at this point in the history
  • Loading branch information
felquis committed Sep 17, 2012
1 parent 729e53c commit 206d6c8
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion ArrayWave/app/scripts/main.js
Expand Up @@ -8,6 +8,8 @@

$canvas = $('#canvas'),

MatrizDOM = [],

// Função que retorna um HTML que representa uma matriz de array
toHTML = function (matriz) {
var html = [];
Expand All @@ -31,15 +33,35 @@

$canvas.html(toHTML(Matriz));

// Cria uma matriz que representa a matriz em questão só que no DOM

(function () {
// MatrizDOM

$canvas.find('.line').each(function (i, e) {
// Cada coluna e seus itens são instancias do DOM
var colunas = (function () {
var col = [];

$(e).find('span').each(function (i, e) {
col.push($(this));
});

return col;
}());

// Marca uma linha
MatrizDOM.push(colunas);
});
}());

// Hover nos span, retorna a posição do elemento no Array
$canvas.on('hover', 'span', function () {
var $this = $(this),
line = $this.parent().index(),
col = $this.index();

console.log(line, col);
MatrizDOM[line][col].html('-');
});
});
}(jQuery, window, document));

0 comments on commit 206d6c8

Please sign in to comment.