-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
311 lines (246 loc) · 8.12 KB
/
app.js
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
/* Bismillah */
/*
TO-DO LIST APP (FOR WEB AND MOBILE):
- An application that keeps a to-do list.
- When the application is closed, the information is stored in local storage.
To make an android or iOS application with Apache Cordova.
https://cordova.apache.org/
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
FOR YOUR CORDOVA PROJECT:
- Add these settings to your cordova project config.xml file:
<preference name="DisallowOverscroll" value="true" />
<preference name="StatusBarOverlaysWebView" value="false" />
<preference name="StatusBarStyle" value="darkcontent" />
<preference name="Orientation" value="portrait" />
- Add these plugins to your cordova project:
cordova plugin add cordova-plugin-statusbar
*/
var USED_WIDTH = 500
var MAX_ZOOMABLE_WIDTH = 700
var taskList = []
var taskDataList = []
// BOX: Container box of home content.
var homePage
// Shortcut names for frequently used objects.
var txtNewTask
var lblSelectedCount
// First running function.
var 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(0, 0, USED_WIDTH, page.height)
that.color = "white"
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, page.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("images/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)
}
var resizeHomePage = function() {
page.fit(USED_WIDTH, MAX_ZOOMABLE_WIDTH)
homePage.height = page.height
homePage.boxTaskItemList.height = page.height - 110
homePage.center("left")
}
var addTask = function() {
var taskText = txtNewTask.text
if (taskText != "") {
addTaskItem(taskText)
addTaskData(taskText)
txtNewTask.text = ""
}
}
// Clear all tasks and recreate based on data list.
var refreshTasks = function() {
// Clear all tasks.
taskList = []
homePage.boxTaskItemList.html = ""
for (var i = (taskDataList.length - 1); i >= 0; i--) {
addTaskItem(taskDataList[i])
}
}
// Add new task item object.
var addTaskItem = function(taskText) {
var 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.
var addTaskData = function(taskText) {
taskDataList.unshift(taskText)
saveTaskDataList()
}
// Create new task item object.
var createTaskItem = function(taskText) {
// BOX: Task item container box.
var 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.3s")
// 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
}
var 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
}
}
var removeSelectedTasks = function() {
var newTaskDataList = []
var newTaskList = []
for (var 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()
repositionTasks()
// Clean and hide delete task box.
lblSelectedCount.text = "0"
homePage.boxDeleteTask.visible = 0
}
var saveTaskDataList = function() {
storage.save("todoApp-taskDataList", taskDataList)
}
var loadTaskDataList = function() {
taskDataList = storage.load("todoApp-taskDataList") || []
}
// Because object positioning uses the coordinate system.
var repositionTasks = function() {
var top = 0
for (var i = 0; i < taskList.length; i++) {
taskList[i].top = top
taskList[i].height = taskList[i].lblText.height + 20
top += taskList[i].height
}
}