Run the build scripts for all vanilla examples (#160)

This commit is contained in:
Julien Wajsberg 2023-05-19 18:36:14 +02:00 committed by GitHub
parent 898398f07f
commit f196015fa7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 58 additions and 93 deletions

View file

@ -95,9 +95,8 @@
Controller.prototype.addItem = function (title) {
var self = this;
if (title.trim() === "") {
if (title.trim() === "")
return;
}
self.model.create(title, function () {
self.view.render("clearNewTodo");
@ -189,9 +188,8 @@
});
});
if (!silent) {
if (!silent)
self._filter();
}
};
/**
@ -240,9 +238,8 @@
// If the last active route isn't "All", or we're switching routes, we
// re-create the todo item elements, calling:
// this.show[All|Active|Completed]();
if (force || this._lastActiveRoute !== "All" || this._lastActiveRoute !== activeRoute) {
if (force || this._lastActiveRoute !== "All" || this._lastActiveRoute !== activeRoute)
this[`show${activeRoute}`]();
}
this._lastActiveRoute = activeRoute;
};
@ -255,9 +252,8 @@
// items as they are marked complete or incomplete.
this._activeRoute = currentPage;
if (currentPage === "") {
if (currentPage === "")
this._activeRoute = "All";
}
this._filter();

View file

@ -23,9 +23,8 @@
var potentialElements = window.qsa(selector, target);
var hasMatch = Array.prototype.indexOf.call(potentialElements, targetElement) >= 0;
if (hasMatch) {
if (hasMatch)
handler.call(targetElement, event);
}
}
// https://developer.mozilla.org/en-US/docs/Web/Events/blur
@ -37,12 +36,12 @@
// Find the element's parent with the given tag name:
// $parent(qs('a'), 'div');
window.$parent = function (element, tagName) {
if (!element.parentNode) {
if (!element.parentNode)
return undefined;
}
if (element.parentNode.tagName.toLowerCase() === tagName.toLowerCase()) {
if (element.parentNode.tagName.toLowerCase() === tagName.toLowerCase())
return element.parentNode;
}
return window.$parent(element.parentNode, tagName);
};

View file

@ -102,11 +102,10 @@
this.storage.findAll(function (data) {
data.forEach(function (todo) {
if (todo.completed) {
if (todo.completed)
todos.completed++;
} else {
else
todos.active++;
}
todos.total++;
});

View file

@ -43,9 +43,8 @@
* });
*/
Store.prototype.find = function (query, callback) {
if (!callback) {
if (!callback)
return;
}
var todos = JSON.parse(MemoryStorage[this._dbName]).todos;
@ -53,10 +52,10 @@
this,
todos.filter(function (todo) {
for (var q in query) {
if (query[q] !== todo[q]) {
if (query[q] !== todo[q])
return false;
}
}
return true;
})
);
@ -90,9 +89,9 @@
if (id) {
for (var i = 0; i < todos.length; i++) {
if (todos[i].id === id) {
for (var key in updateData) {
for (var key in updateData)
todos[i][key] = updateData[key];
}
break;
}
}

View file

@ -92,11 +92,10 @@
* @returns {string} String containing the count
*/
Template.prototype.clearCompletedButton = function (completedTodos) {
if (completedTodos > 0) {
if (completedTodos > 0)
return "Clear completed";
} else {
else
return "";
}
};
// Export to window

View file

@ -31,9 +31,8 @@
View.prototype._removeItem = function (id) {
var elem = qs(`[data-id="${id}"]`);
if (elem) {
if (elem)
this.$todoList.removeChild(elem);
}
};
View.prototype._clearCompletedButton = function (completedCount, visible) {
@ -49,9 +48,8 @@
View.prototype._elementComplete = function (id, completed) {
var listItem = qs(`[data-id="${id}"]`);
if (!listItem) {
if (!listItem)
return;
}
listItem.className = completed ? "completed" : "";
@ -62,9 +60,8 @@
View.prototype._editItem = function (id, title) {
var listItem = qs(`[data-id="${id}"]`);
if (!listItem) {
if (!listItem)
return;
}
listItem.className = `${listItem.className} editing`;
@ -79,9 +76,8 @@
View.prototype._editItemDone = function (id, title) {
var listItem = qs(`[data-id="${id}"]`);
if (!listItem) {
if (!listItem)
return;
}
var input = qs("input.edit", listItem);
listItem.removeChild(input);

File diff suppressed because one or more lines are too long

View file

@ -57,9 +57,8 @@ class Controller {
* object and it'll handle the DOM insertion and saving of the new item.
*/
addItem(title) {
if (title.trim() === "") {
if (title.trim() === "")
return;
}
this.model.create(title, () => {
this.view.render("clearNewTodo");
@ -116,9 +115,8 @@ class Controller {
*/
removeCompletedItems() {
this.model.read({ completed: true }, (data) => {
for (let item of data) {
for (let item of data)
this.removeItem(item.id);
}
});
this._filter();
@ -138,9 +136,8 @@ class Controller {
this.view.render("elementComplete", { id, completed });
});
if (!silent) {
if (!silent)
this._filter();
}
}
/**
@ -149,9 +146,8 @@ class Controller {
*/
toggleAll(completed) {
this.model.read({ completed: !completed }, (data) => {
for (let item of data) {
for (let item of data)
this.toggleComplete(item.id, completed, true);
}
});
this._filter();
@ -189,9 +185,8 @@ class Controller {
// If the last active route isn't "All", or we're switching routes, we
// re-create the todo item elements, calling:
// this.show[All|Active|Completed]()
if (force || this._lastActiveRoute !== "All" || this._lastActiveRoute !== activeRoute) {
if (force || this._lastActiveRoute !== "All" || this._lastActiveRoute !== activeRoute)
this[`show${activeRoute}`]();
}
this._lastActiveRoute = activeRoute;
}
@ -204,9 +199,8 @@ class Controller {
// items as they are marked complete or incomplete.
this._activeRoute = currentPage;
if (currentPage === "") {
if (currentPage === "")
this._activeRoute = "All";
}
this._filter();

View file

@ -27,9 +27,8 @@ function $delegate(target, selector, type, handler) {
const potentialElements = qsa(selector, target);
const hasMatch = Array.prototype.indexOf.call(potentialElements, targetElement) >= 0;
if (hasMatch) {
if (hasMatch)
handler.call(targetElement, event);
}
};
// https://developer.mozilla.org/en-US/docs/Web/Events/blur
@ -41,13 +40,11 @@ function $delegate(target, selector, type, handler) {
// Find the element's parent with the given tag name:
// $parent(qs('a'), 'div')
function $parent(element, tagName) {
if (!element.parentNode) {
if (!element.parentNode)
return undefined;
}
if (element.parentNode.tagName.toLowerCase() === tagName.toLowerCase()) {
if (element.parentNode.tagName.toLowerCase() === tagName.toLowerCase())
return element.parentNode;
}
return $parent(element.parentNode, tagName);
}

View file

@ -100,18 +100,16 @@ class Model {
this.storage.findAll((data) => {
for (let todo of data) {
if (todo.completed) {
if (todo.completed)
todos.completed++;
} else {
else
todos.active++;
}
todos.total++;
}
if (callback) {
if (callback)
callback(todos);
}
});
}
}

View file

@ -24,9 +24,8 @@ class Store {
this.memoryStorage[name] = JSON.stringify(data);
}
if (callback) {
if (callback)
callback.call(this, JSON.parse(this.memoryStorage[name]));
}
}
/**
@ -43,9 +42,8 @@ class Store {
* })
*/
find(query, callback) {
if (!callback) {
if (!callback)
return;
}
let todos = JSON.parse(this.memoryStorage[this._dbName]).todos;
@ -53,10 +51,10 @@ class Store {
this,
todos.filter((todo) => {
for (let q in query) {
if (query[q] !== todo[q]) {
if (query[q] !== todo[q])
return false;
}
}
return true;
})
);
@ -68,9 +66,8 @@ class Store {
* @param {function} callback The callback to fire upon retrieving data
*/
findAll(callback) {
if (callback) {
if (callback)
callback.call(this, JSON.parse(this.memoryStorage[this._dbName]).todos);
}
}
/**
@ -90,18 +87,17 @@ class Store {
if (id) {
for (let i = 0; i < len; i++) {
if (todos[i].id === id) {
for (let key in updateData) {
for (let key in updateData)
todos[i][key] = updateData[key];
}
break;
}
}
this.memoryStorage[this._dbName] = JSON.stringify(data);
if (callback) {
if (callback)
callback.call(this, JSON.parse(this.memoryStorage[this._dbName]).todos);
}
} else {
// Generate an ID
updateData.id = uniqueID++;
@ -109,9 +105,8 @@ class Store {
todos.push(updateData);
this.memoryStorage[this._dbName] = JSON.stringify(data);
if (callback) {
if (callback)
callback.call(this, [updateData]);
}
}
}
@ -134,9 +129,8 @@ class Store {
this.memoryStorage[this._dbName] = JSON.stringify(data);
if (callback) {
if (callback)
callback.call(this, JSON.parse(this.memoryStorage[this._dbName]).todos);
}
}
/**
@ -147,8 +141,7 @@ class Store {
drop(callback) {
this.memoryStorage[this._dbName] = JSON.stringify({ todos: [] });
if (callback) {
if (callback)
callback.call(this, JSON.parse(this.memoryStorage[this._dbName]).todos);
}
}
}

View file

@ -13,7 +13,7 @@ const htmlEscapes = {
const reUnescapedHtml = /[&<>"'`]/g;
const reHasUnescapedHtml = new RegExp(reUnescapedHtml.source);
let escape = (str) => (str && reHasUnescapedHtml.test(str) ? str.replace(reUnescapedHtml, escapeHtmlChar) : str);
let escape = (str) => str && reHasUnescapedHtml.test(str) ? str.replace(reUnescapedHtml, escapeHtmlChar) : str;
let escapeHtmlChar = (chr) => htmlEscapes[chr];
class Template {

View file

@ -12,9 +12,8 @@ let _setFilter = (currentPage) => {
let _elementComplete = (id, completed) => {
let listItem = qs(`[data-id="${id}"]`);
if (!listItem) {
if (!listItem)
return;
}
listItem.className = completed ? "completed" : "";
@ -25,9 +24,8 @@ let _elementComplete = (id, completed) => {
let _editItem = (id, title) => {
let listItem = qs(`[data-id="${id}"]`);
if (!listItem) {
if (!listItem)
return;
}
listItem.className += " editing";
@ -68,14 +66,14 @@ class View {
this.$newTodo = qs(".new-todo");
this.viewCommands = {
showEntries: (parameter) => (this.$todoList.innerHTML = this.template.show(parameter)),
showEntries: (parameter) => this.$todoList.innerHTML = this.template.show(parameter),
removeItem: (parameter) => this._removeItem(parameter),
updateElementCount: (parameter) => (this.$todoItemCounter.innerHTML = this.template.itemCounter(parameter)),
updateElementCount: (parameter) => this.$todoItemCounter.innerHTML = this.template.itemCounter(parameter),
clearCompletedButton: (parameter) => this._clearCompletedButton(parameter.completed, parameter.visible),
contentBlockVisibility: (parameter) => (this.$main.style.display = this.$footer.style.display = parameter.visible ? "block" : "none"),
toggleAll: (parameter) => (this.$toggleAll.checked = parameter.checked),
contentBlockVisibility: (parameter) => this.$main.style.display = this.$footer.style.display = parameter.visible ? "block" : "none",
toggleAll: (parameter) => this.$toggleAll.checked = parameter.checked,
setFilter: (parameter) => _setFilter(parameter),
clearNewTodo: (parameter) => (this.$newTodo.value = ""),
clearNewTodo: (parameter) => this.$newTodo.value = "",
elementComplete: (parameter) => _elementComplete(parameter.id, parameter.completed),
editItem: (parameter) => _editItem(parameter.id, parameter.title),
editItemDone: (parameter) => this._editItemDone(parameter.id, parameter.title),
@ -85,9 +83,8 @@ class View {
_removeItem(id) {
let elem = qs(`[data-id="${id}"]`);
if (elem) {
if (elem)
this.$todoList.removeChild(elem);
}
}
_clearCompletedButton(completedCount, visible) {
@ -98,16 +95,15 @@ class View {
_editItemDone(id, title) {
let listItem = qs(`[data-id="${id}"]`);
if (!listItem) {
if (!listItem)
return;
}
let input = qs("input.edit", listItem);
listItem.removeChild(input);
listItem.className = listItem.className.replace(" editing", "");
qsa("label", listItem).forEach((label) => (label.textContent = title));
qsa("label", listItem).forEach((label) => label.textContent = title);
}
render(viewCmd, parameter) {
@ -128,9 +124,8 @@ class View {
// Remove the cursor from the input when you hit enter just like if it were a real form
$delegate(self.$todoList, "li .edit", "keypress", function (event) {
if (event.keyCode === self.ENTER_KEY) {
if (event.keyCode === self.ENTER_KEY)
this.blur();
}
});
}