1
0
mirror of https://github.com/morris/vanilla-todo.git synced 2025-08-21 05:11:20 +02:00

Refactor for dataset

This commit is contained in:
opethrocks
2020-10-28 14:55:34 -05:00
parent 6aa0cf72f9
commit b868681068
8 changed files with 13 additions and 15 deletions

View File

@@ -46,7 +46,7 @@ VT.AppFlip = function (el, options) {
var map = new Map(); var map = new Map();
el.querySelectorAll(options.selector).forEach(function (el) { el.querySelectorAll(options.selector).forEach(function (el) {
var key = el.getAttribute('data-key') || el; var key = el.dataset.key || el;
// parse original transform // parse original transform
// i.e. strip inverse transform using "scale(1)" marker // i.e. strip inverse transform using "scale(1)" marker
@@ -73,7 +73,7 @@ VT.AppFlip = function (el, options) {
var current = entry.el.parentNode; var current = entry.el.parentNode;
while (current && current !== el) { while (current && current !== el) {
var ancestor = map.get(current.getAttribute('data-key') || current); var ancestor = map.get(current.dataset.key || current);
if (ancestor) { if (ancestor) {
entry.ancestor = ancestor; entry.ancestor = ancestor;

View File

@@ -4,7 +4,7 @@ window.VT = window.VT || {};
VT.AppIcon = function (el) { VT.AppIcon = function (el) {
if (el.children.length > 0) return; if (el.children.length > 0) return;
var id = el.getAttribute('data-id'); var id = el.dataset.id;
var promise = VT.AppIcon.cache[id]; var promise = VT.AppIcon.cache[id];
if (!promise) { if (!promise) {

View File

@@ -107,7 +107,7 @@ VT.AppSortable = function (el, options) {
for (var i = 0, l = el.children.length; i < l; ++i) { for (var i = 0, l = el.children.length; i < l; ++i) {
var child = el.children[i]; var child = el.children[i];
if (child && child.getAttribute('data-key') === key) { if (child && child.dataset.key === key) {
el.removeChild(child); el.removeChild(child);
} }
} }

View File

@@ -133,10 +133,8 @@ VT.TodoCustomList = function (el) {
titleEl.innerText = state.list.title || '...'; titleEl.innerText = state.list.title || '...';
el.querySelector('.todo-list').todoList.update({ items: state.list.items }); el.querySelector('.todo-list').todoList.update({ items: state.list.items });
el.querySelector('.todo-list > .todo-item-input').setAttribute( el.querySelector('.todo-list > .todo-item-input').dataset.key =
'data-key', 'todo-item-input' + state.list.id;
'todo-item-input-' + state.list.id
);
el.classList.toggle('-editing', state.editing); el.classList.toggle('-editing', state.editing);

View File

@@ -3,7 +3,7 @@ window.VT = window.VT || {};
VT.TodoDay = function (el) { VT.TodoDay = function (el) {
var state = { var state = {
dateId: el.getAttribute('data-key'), dateId: el.dataset.key,
items: [], items: [],
}; };

View File

@@ -78,7 +78,7 @@ VT.TodoFrameCustom = function (el) {
var childrenByKey = new Map(); var childrenByKey = new Map();
obsolete.forEach(function (child) { obsolete.forEach(function (child) {
childrenByKey.set(child.getAttribute('data-key'), child); childrenByKey.set(child.dataset.key, child);
}); });
var children = lists.map(function (list) { var children = lists.map(function (list) {
@@ -89,7 +89,7 @@ VT.TodoFrameCustom = function (el) {
} else { } else {
child = document.createElement('div'); child = document.createElement('div');
child.className = 'card todo-custom-list'; child.className = 'card todo-custom-list';
child.setAttribute('data-key', list.id); child.dataset.key = list.id;
VT.TodoCustomList(child); VT.TodoCustomList(child);
} }

View File

@@ -61,7 +61,7 @@ VT.TodoFrameDays = function (el) {
var childrenByKey = new Map(); var childrenByKey = new Map();
obsolete.forEach(function (child) { obsolete.forEach(function (child) {
childrenByKey.set(child.getAttribute('data-key'), child); childrenByKey.set(child.dataset.key, child);
}); });
var children = days.map(function (day) { var children = days.map(function (day) {
@@ -72,7 +72,7 @@ VT.TodoFrameDays = function (el) {
} else { } else {
child = document.createElement('div'); child = document.createElement('div');
child.className = 'card todo-day'; child.className = 'card todo-day';
child.setAttribute('data-key', day.id); child.dataset.key = day.id;
VT.TodoDay(child); VT.TodoDay(child);
} }

View File

@@ -34,7 +34,7 @@ VT.TodoList = function (el) {
var childrenByKey = new Map(); var childrenByKey = new Map();
obsolete.forEach(function (child) { obsolete.forEach(function (child) {
childrenByKey.set(child.getAttribute('data-key'), child); childrenByKey.set(child.dataset.key, child);
}); });
var children = state.items.map(function (item) { var children = state.items.map(function (item) {
@@ -45,7 +45,7 @@ VT.TodoList = function (el) {
} else { } else {
child = document.createElement('div'); child = document.createElement('div');
child.classList.add('todo-item'); child.classList.add('todo-item');
child.setAttribute('data-key', item.id); child.dataset.key = item.id;
VT.TodoItem(child); VT.TodoItem(child);
} }