From b868681068c9cfdde629f543c21198bc90214cbe Mon Sep 17 00:00:00 2001 From: opethrocks Date: Wed, 28 Oct 2020 14:55:34 -0500 Subject: [PATCH] Refactor for dataset --- public/scripts/AppFlip.js | 4 ++-- public/scripts/AppIcon.js | 2 +- public/scripts/AppSortable.js | 2 +- public/scripts/TodoCustomList.js | 6 ++---- public/scripts/TodoDay.js | 2 +- public/scripts/TodoFrameCustom.js | 4 ++-- public/scripts/TodoFrameDays.js | 4 ++-- public/scripts/TodoList.js | 4 ++-- 8 files changed, 13 insertions(+), 15 deletions(-) diff --git a/public/scripts/AppFlip.js b/public/scripts/AppFlip.js index 0714b72..5bbb242 100644 --- a/public/scripts/AppFlip.js +++ b/public/scripts/AppFlip.js @@ -46,7 +46,7 @@ VT.AppFlip = function (el, options) { var map = new Map(); el.querySelectorAll(options.selector).forEach(function (el) { - var key = el.getAttribute('data-key') || el; + var key = el.dataset.key || el; // parse original transform // i.e. strip inverse transform using "scale(1)" marker @@ -73,7 +73,7 @@ VT.AppFlip = function (el, options) { var current = entry.el.parentNode; while (current && current !== el) { - var ancestor = map.get(current.getAttribute('data-key') || current); + var ancestor = map.get(current.dataset.key || current); if (ancestor) { entry.ancestor = ancestor; diff --git a/public/scripts/AppIcon.js b/public/scripts/AppIcon.js index 833d04d..edb0d2d 100644 --- a/public/scripts/AppIcon.js +++ b/public/scripts/AppIcon.js @@ -4,7 +4,7 @@ window.VT = window.VT || {}; VT.AppIcon = function (el) { if (el.children.length > 0) return; - var id = el.getAttribute('data-id'); + var id = el.dataset.id; var promise = VT.AppIcon.cache[id]; if (!promise) { diff --git a/public/scripts/AppSortable.js b/public/scripts/AppSortable.js index 5f9b283..6af6ec7 100644 --- a/public/scripts/AppSortable.js +++ b/public/scripts/AppSortable.js @@ -107,7 +107,7 @@ VT.AppSortable = function (el, options) { for (var i = 0, l = el.children.length; i < l; ++i) { var child = el.children[i]; - if (child && child.getAttribute('data-key') === key) { + if (child && child.dataset.key === key) { el.removeChild(child); } } diff --git a/public/scripts/TodoCustomList.js b/public/scripts/TodoCustomList.js index 047593b..9da6182 100644 --- a/public/scripts/TodoCustomList.js +++ b/public/scripts/TodoCustomList.js @@ -133,10 +133,8 @@ VT.TodoCustomList = function (el) { titleEl.innerText = state.list.title || '...'; el.querySelector('.todo-list').todoList.update({ items: state.list.items }); - el.querySelector('.todo-list > .todo-item-input').setAttribute( - 'data-key', - 'todo-item-input-' + state.list.id - ); + el.querySelector('.todo-list > .todo-item-input').dataset.key = + 'todo-item-input' + state.list.id; el.classList.toggle('-editing', state.editing); diff --git a/public/scripts/TodoDay.js b/public/scripts/TodoDay.js index 607c7d3..ecdf8a9 100644 --- a/public/scripts/TodoDay.js +++ b/public/scripts/TodoDay.js @@ -3,7 +3,7 @@ window.VT = window.VT || {}; VT.TodoDay = function (el) { var state = { - dateId: el.getAttribute('data-key'), + dateId: el.dataset.key, items: [], }; diff --git a/public/scripts/TodoFrameCustom.js b/public/scripts/TodoFrameCustom.js index 1eb616c..1d22a97 100644 --- a/public/scripts/TodoFrameCustom.js +++ b/public/scripts/TodoFrameCustom.js @@ -78,7 +78,7 @@ VT.TodoFrameCustom = function (el) { var childrenByKey = new Map(); obsolete.forEach(function (child) { - childrenByKey.set(child.getAttribute('data-key'), child); + childrenByKey.set(child.dataset.key, child); }); var children = lists.map(function (list) { @@ -89,7 +89,7 @@ VT.TodoFrameCustom = function (el) { } else { child = document.createElement('div'); child.className = 'card todo-custom-list'; - child.setAttribute('data-key', list.id); + child.dataset.key = list.id; VT.TodoCustomList(child); } diff --git a/public/scripts/TodoFrameDays.js b/public/scripts/TodoFrameDays.js index c7e8c95..adfcfc6 100644 --- a/public/scripts/TodoFrameDays.js +++ b/public/scripts/TodoFrameDays.js @@ -61,7 +61,7 @@ VT.TodoFrameDays = function (el) { var childrenByKey = new Map(); obsolete.forEach(function (child) { - childrenByKey.set(child.getAttribute('data-key'), child); + childrenByKey.set(child.dataset.key, child); }); var children = days.map(function (day) { @@ -72,7 +72,7 @@ VT.TodoFrameDays = function (el) { } else { child = document.createElement('div'); child.className = 'card todo-day'; - child.setAttribute('data-key', day.id); + child.dataset.key = day.id; VT.TodoDay(child); } diff --git a/public/scripts/TodoList.js b/public/scripts/TodoList.js index 1e08989..9421a68 100644 --- a/public/scripts/TodoList.js +++ b/public/scripts/TodoList.js @@ -34,7 +34,7 @@ VT.TodoList = function (el) { var childrenByKey = new Map(); obsolete.forEach(function (child) { - childrenByKey.set(child.getAttribute('data-key'), child); + childrenByKey.set(child.dataset.key, child); }); var children = state.items.map(function (item) { @@ -45,7 +45,7 @@ VT.TodoList = function (el) { } else { child = document.createElement('div'); child.classList.add('todo-item'); - child.setAttribute('data-key', item.id); + child.dataset.key = item.id; VT.TodoItem(child); }