-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapp-todo.htm
386 lines (298 loc) · 12.5 KB
/
app-todo.htm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
<!DOCTYPE html>
<html>
<head>
<title>To-do list app</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="basic/basic.min.css">
<script src="basic/basic.min.js" type="text/javascript" charset="utf-8"></script>
<script>
/*
TO-DO LIST APP (FOR MOBILE):
- An application that keeps a to-do list.
- When the application is closed, the information is stored in local storage.
Handbook: https://bug7a.github.io/basic.js-handbook/
This template, can be used to develop mobile applications with:
- Apache Cordova Framework or
- Ionic/Capacitor Native Runtime.
*** USAGE WITH CORDOVA FRAMEWORK:
CREATE APP DOCUMENTS:
https://cordova.apache.org/docs/en/latest/guide/cli/index.html
TUTORIAL VIDEOS:
- How to make an Android application? (Language: Turkish)
https://www.youtube.com/watch?v=B6x7yKhKZbY
- How to make an iOS application? (Language: Turkish)
https://www.youtube.com/watch?v=WZZwiI_5WQA
SETTINGS FOR YOUR CORDOVA PROJECT:
- Add these settings to your cordova project config.xml file:
<preference name="DisallowOverscroll" value="true" />
<preference name="Orientation" value="portrait" />
PLUGIN LIST:
https://cordova.apache.org/plugins/
*** USAGE WITH IONIC / CAPACITOR NATIVE RUNTIME:
CREATE APP DOCUMENTS:
https://capacitorjs.com/docs/getting-started
TUTORIAL VIDEOS:
- How to make an Android and iOS application?
https://youtu.be/rx-z6-_FwU8
SETTINGS FOR CAPACITOR PROJECT:
- Set "bundledwebRuntime": true in "capacitor.config.json" file.
Then Capacitor will create a "capacitor.js" file.
PLUGIN LIST:
https://capacitorjs.com/docs/apis
PLUGIN USAGE:
- Just add "Capacitor.Plugins." before plugin name.
NOTE: Because it doesn't work as a module.
EXAMPLE CODE:
const showConfirm = async () => {
const { value } = await Capacitor.Plugins.Dialog.confirm({
title: 'Confirm',
message: `Are you sure you'd like to press the red button?`,
});
console.log('Confirmed:', value);
};
showConfirm();
NOTE: Dont forget to install the Dialog plugin to test example code: npm install @capacitor/dialog
*/
const USED_WIDTH = 500
const MAX_ZOOMABLE_WIDTH = 700
let taskList = []
let taskDataList = []
// BOX: Container box of home content.
let homePage
// Shortcut names for frequently used objects.
let txtNewTask
let lblSelectedCount
// First running function.
const start = function() {
// Support all resolutions.
page.fit(USED_WIDTH, MAX_ZOOMABLE_WIDTH)
// Restore saved information.
loadTaskDataList()
// UI: HOME PAGE:
// BOX: Container box of home content. Parameters: left, top, width, height.
homePage = createBox()
that.width = USED_WIDTH
that.height = basic.getDefaultContainerBox().height
that.color = "white"
that.top = 0
that.center("left")
// UI: ADD NEW TASK:
// BOX: Container box for adding new task.
homePage.boxNewTask = createBox(10, 10, 480, 80)
homePage.add(that)
that.color = "whitesmoke"
that.border = 0
that.round = 16
// TEXTBOX: Where the new task is written.
homePage.boxNewTask.txtNewTask = createTextBox(20, 15, 380)
homePage.boxNewTask.add(that)
that.minimal = 1
that.color = "transparent"
that.inputElement.setAttribute("placeholder", "Add a task")
that.onChange(addTask)
// Set shortcut name.
txtNewTask = homePage.boxNewTask.txtNewTask
// LABEL: Add new task label button.
homePage.boxNewTask.lblAddButton = createLabel()
homePage.boxNewTask.add(that)
that.text = "+"
that.textAlign = "center"
that.color = "#23BCC1BB"
that.textColor = "rgba(255, 255, 255, 0.95)"
that.height = 50
that.width = that.height
that.fontSize = 36
that.round = 25
that.aline(txtNewTask, "right", 5)
that.onClick(addTask)
// UI: TASK ITEMS:
// BOX: Scrollable container box of task items.
homePage.boxTaskItemList = createBox(10, 100, 480, getDefaultContainerBox().height - 110)
homePage.add(that)
that.color = "white"
that.border = 0
that.scrollY = 1
// UI: DELETE TASKS:
// BOX: Container box for delete tasks.
homePage.boxDeleteTask = createBox(10, 10, 480, 80)
homePage.add(that)
that.color = "whitesmoke"
that.round = 16
that.visible = 0
// BOX: Background box for delete image.
homePage.boxDeleteTask.boxBackground = createBox(0, 0, 55, 55)
homePage.boxDeleteTask.add(that)
that.color = "#ED6D5230"
that.round = 30
that.center()
that.onClick(removeSelectedTasks)
// IMAGE: Delete image.
homePage.boxDeleteTask.boxBackground.imgDelete = createImage(0, 0, 35, 35)
homePage.boxDeleteTask.boxBackground.add(that)
that.load("assets/todo-app/trash.svg")
that.opacity = 0.9
that.center()
// LABEL: Count of selected items on delete image.
homePage.boxDeleteTask.lblCount = createLabel()
homePage.boxDeleteTask.add(that)
that.left = homePage.boxDeleteTask.boxBackground.left + 41
that.top = homePage.boxDeleteTask.boxBackground.top - 4
that.width = "auto"
that.height = "auto"
that.color = "white"
that.text = "0"
that.textColor = "#141414"
that.fontSize = 16
that.spaceY = 2
that.spaceX = 7
that.border = 1
that.borderColor = "#141414"
that.element.style.fontFamily = "opensans-bold"
that.round = 50
that.opacity = 0.7
// Set shortcut name.
lblSelectedCount = homePage.boxDeleteTask.lblCount
// When page reopens, create old records.
refreshTasks()
// Run each time the page size changes.
page.onResize(resizeHomePage)
}
const resizeHomePage = function() {
page.fit(USED_WIDTH, MAX_ZOOMABLE_WIDTH)
homePage.height = getDefaultContainerBox().height
homePage.boxTaskItemList.height = getDefaultContainerBox().height - 110
homePage.center("left")
}
const addTask = function() {
const taskText = txtNewTask.text
if (taskText != "") {
addTaskItem(taskText)
addTaskData(taskText)
txtNewTask.text = ""
}
}
// Clear all tasks and recreate based on data list.
const refreshTasks = function() {
// Clear all tasks.
taskList = []
homePage.boxTaskItemList.html = ""
for (let i = (taskDataList.length - 1); i >= 0; i--) {
addTaskItem(taskDataList[i])
}
}
// Add new task item object.
const addTaskItem = function(taskText) {
const newItem = createTaskItem(taskText)
homePage.boxTaskItemList.add(newItem)
taskList.unshift(newItem)
// After the automatic size calculation is complete, reposition the objects.
newItem.lblText.onResize(repositionTasks)
// NOTE: .onResize() has been added for each item of the tasks;
// when a task's text changes size, all tasks are repositioned.
}
// Add new task data.
const addTaskData = function(taskText) {
taskDataList.unshift(taskText)
saveTaskDataList()
updateBarBudgeCallback()
}
// Create new task item object.
const createTaskItem = function(taskText) {
// BOX: Task item container box.
const box = createBox(0, 0, 480, 100)
that.color = "white"
that.round = 4
that.onClick(selectTask)
// Let vertical position change be with motion.
that.setMotion("top 0.2s")
// LABEL: Task text.
box.lblText = createLabel(50, 10, 410, "auto")
box.add(that)
that.color = "transparent"
that.text = taskText
// BOX: Selection circle.
box.boxTick = createBox(15, 15, 20, 20)
box.add(that)
that.round = 10
that.border = 1
that.color = "whitesmoke"
that.borderColor = "lightgray"
// Define a variable inside the object.
box.isSelected = 0
makeBasicObject(box)
return box
}
const selectTask = function(clickedTask) {
// If item is selected:
if (clickedTask.isSelected) {
// Unselect it.
clickedTask.isSelected = 0
clickedTask.boxTick.color = "whitesmoke"
clickedTask.boxTick.border = 1
clickedTask.lblText.textColor = basic.TEXT_COLOR
lblSelectedCount.text = num(lblSelectedCount.text) - 1
} else {
// Select it.
clickedTask.isSelected = 1
clickedTask.boxTick.color = "tomato"
clickedTask.boxTick.border = 0
clickedTask.lblText.textColor = "tomato"
lblSelectedCount.text = num(lblSelectedCount.text) + 1
}
// Show/hide delete task box by selected count.
if (num(lblSelectedCount.text) > 0) {
homePage.boxDeleteTask.visible = 1
} else {
homePage.boxDeleteTask.visible = 0
}
}
const removeSelectedTasks = function() {
let newTaskDataList = []
let newTaskList = []
for (let i = 0; i < taskList.length; i++) {
// If item is selected:
if(taskList[i].isSelected) {
// Remove it.
taskList[i].remove()
} else {
// Add it to the new list.
newTaskDataList.push(taskDataList[i])
newTaskList.push(taskList[i])
}
}
taskDataList = newTaskDataList
taskList = newTaskList
saveTaskDataList()
updateBarBudgeCallback()
repositionTasks()
// Clean and hide delete task box.
lblSelectedCount.text = "0"
homePage.boxDeleteTask.visible = 0
}
const saveTaskDataList = function() {
storage.save("todoApp-taskDataList", taskDataList)
}
const loadTaskDataList = function() {
taskDataList = storage.load("todoApp-taskDataList") || []
}
// Because object positioning uses the coordinate system.
const repositionTasks = function() {
let top = 0
for (let i = 0; i < taskList.length; i++) {
taskList[i].top = top
taskList[i].height = taskList[i].lblText.height + 20
top += taskList[i].height
}
}
const updateBarBudgeCallback = function() {
if (window.top.updateBottomBarTasksUIBudge) window.top.updateBottomBarTasksUIBudge(taskList.length || 0);
}
window.aaaa = function() {
alert("Google");
};
</script>
</head>
<body>
</body>
</html>