Что делает эта функция
Функция mouseObject нужна для работы драг н дропа, но что именно в ней происходит кто-то может объяснить?
//Начало перетаскивания элемента
board.ondragstart = function(e) {
hide = e.target;
e.dataTransfer.setData('card', e.target.id);
e.dataTransfer.effectAllowed = 'move';
};
//Конец перетаскивания элемента
board.ondragend = function(e) {
e.target.style.visibility = 'visible';
};
var lastEntered;
//Элемент перенесен на заданную область
board.ondragenter = function(e) {
if (hide) {
hide.style.visibility = 'hidden';
}
lastEntered = e.target;
var section = mouseObject(e.target, 'section');
if (section) {
section.classList.add('droppable');
e.preventDefault();
return false;
}
};
//Перенос над допустимой для переноса зоной
board.ondragover = function(e) {
if (mouseObject(e.target, 'section')) {
e.preventDefault();
}
};
//Элемент вышел из допустимой для переноса зоны
board.ondragleave = function(e) {
if (e.target.nodeType === 1) {
var section = mouseObject(e.target, 'section');
if (section && !section.contains(lastEntered)) {
section.classList.remove('droppable');
}
}
lastEntered = null;
};
//Перемещаемый элемент опустился на объект для перетаскивания
board.ondrop = function(e) {
var section = mouseObject(e.target, 'section');
section = section.childNodes[0];
var id = e.dataTransfer.getData('card');
if (id) {
var card = document.getElementById(id);
if (card) {
if (section !== card.parentNode) {
section.appendChild(card);
localStorage.removeItem(card.id);
localStorage.setItem(card.id, section.id.substr(8));
}
}
}
section.parentNode.classList.remove('droppable');
};
function mouseObject(target, className) {
while (target) {
if (target.classList.contains(className)) {
return target;
}
target = target.parentNode;
}
return null;
}