Commit 53c6c4d7 by sopham

comment code

parent cba22584
//delete all tasks
function deleteAll() {
var e = document.getElementById("doList");
while (e.firstChild) {
e.removeChild(e.firstChild);
}
}
//scrolling
window.onscroll = function() {myFunction()};
function myFunction() {
......@@ -15,8 +7,10 @@ function myFunction() {
document.getElementById("myBar").style.width = scrolled + "%";
}
//display input from database
$(document).ready(function() {
//display input from database
$.ajax({
dataType: 'JSON',
url: 'display.php',
......@@ -28,10 +22,54 @@ $(document).ready(function() {
})
}
});
});
//add user input to database
$("#addAction").submit(function(event) {
event.preventDefault();
var task = $("#add-task").val();
if (task == '') return;
$.ajax({
url: "insert.php",
type:"POST",
data:{
"task": task },
success: function(data) {
var new_id = data;
if (document.getElementById('add-task').value!='') {
var title = document.getElementById('add-task').value;
var node = document.createElement('div');
node.innerHTML = '<input id="' + new_id + '" type="checkbox" class="hidden" name="checkbox"><label for="' + new_id + '" class="check--label"><span class="check--label-box"></span><span class="check--label-text">' + title + '</span>';
document.getElementById('doList').appendChild(node);
}
$("#add-task").val("");
}
});
});
//delete completed tasks
$(document).ready(function() {
//enter to add to list
var input = document.getElementById("add-task");
input.addEventListener("keyup", function(event) {
if (event.keyCode === 13) {
event.preventDefault();
document.getElementById("add").click();
}
});
//delete all from database
$("#delete-button").click(function() {
$.ajax({
url: "delete-all.php",
type: "POST",
success: function(data) {
var e = document.getElementById("doList");
while(e.firstChild) {
e.removeChild(e.firstChild);
}
}
});
});
//delete completed tasks
$('#delete-complete').click(function() {
$("input.hidden:checkbox:checked").each(function() {
$.ajax({
......@@ -43,11 +81,9 @@ $(document).ready(function() {
});
$(this).parent().remove();
});
});
});
});
//upload image
$(document).ready(function() {
//upload and display image after uploading
$('#imageUpload').change(function() {
var fd = new FormData();
var files = $('#imageUpload')[0].files[0];
......@@ -59,21 +95,22 @@ $(document).ready(function() {
contentType: false,
processData: false,
success: function(data) {
console.log(data);
$('#imagePreview').css('background-image', 'url('+data +')');
$('#imagePreview').hide();
$('#imagePreview').fadeIn(650);
}
});
});
});
//display image
$(document).ready(function() {
//display image when refresh
$.ajax({
type: "POST",
url: "avatar-display.php",
success: function(data) {
$('#imagePreview').css('background-image', 'url('+data +')');
$('#imagePreview').css('background-image', 'url('+ data +')');
}
});
});
//add user input to database
$("#addAction").submit(function(event) {
event.preventDefault();
var task = $("#add-task").val();
if (task == '') return;
$.ajax({
url: "insert.php",
type:"POST",
data:{
"task": task },
success: function(data) {
var new_id = data;
if (document.getElementById('add-task').value!='') {
var title = document.getElementById('add-task').value;
var node = document.createElement('div');
node.innerHTML = '<input id="' + new_id + '" type="checkbox" class="hidden" name="checkbox"><label for="' + new_id + '" class="check--label"><span class="check--label-box"></span><span class="check--label-text">' + title + '</span>';
document.getElementById('doList').appendChild(node);
}
$("#add-task").val("");
}
});
});
//enter to add to list
var input = document.getElementById("add-task");
input.addEventListener("keyup", function(event) {
if (event.keyCode === 13) {
event.preventDefault();
document.getElementById("add").click();
}
});
//delete all from database
$("#delete-button").click(function() {
$.ajax({
url: "delete-all.php",
type: "POST",
success: function(data) {
var e = document.getElementById("doList");
while(e.firstChild) {
e.removeChild(e.firstChild);
}
}
});
});
//upload image
<?php
session_start();
//if the user is not logged in, redirect to login page
if(!isset($_SESSION['loggedin'])) {
session_destroy();
$params = session_get_cookie_params();
......@@ -18,7 +20,6 @@ if(!isset($_SESSION['loggedin'])) {
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="function.js" type="text/javascript"></script>
<script async src="function1.js" type="text/javascript"></script>
</head>
<body>
<div class="row">
......@@ -26,7 +27,6 @@ if(!isset($_SESSION['loggedin'])) {
<div class="list-card">
<div class="avatar-upload">
<div class="avatar-edit">
<!--<input type="file" accept="image/gif, image/jpeg, image/png" id="imageUpload" onchange="readURL(this);">-->
<input type="file" accept="image/gif, image/jpeg, image/png" id="imageUpload" name="image">
<label for="imageUpload"></label>
</div>
......@@ -48,11 +48,10 @@ if(!isset($_SESSION['loggedin'])) {
</div>
<div class="main">
<div class="card">
<div class="card">
<form action="dbconnection.php" method="POST" id="addAction">
<input type="text" id="add-task" onkeypress="return event.keyCode != 13" name="add-task" placeholder="Add tasks..." autocomplete="off">
<input type="submit" class="add-button" id="add" onkeypress="return searchKeyPress(event);" name="add-button" value="Add">
<input type="text" id="add-task"name="add-task" placeholder="Add tasks..." autocomplete="off">
<input type="submit" class="add-button" id="add" name="add-button" value="Add">
</form>
<form class="task-board card" class="list" id="form">
<div class="list-item" id="doList">
......
......@@ -12,7 +12,6 @@
$query->execute();
$query->close();
$link->close();
//echo $_SESSION['name'];
echo $targetPath;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment