Reimporting GIT repository

This commit is contained in:
Carlos Solís 2017-08-14 12:09:53 -06:00
commit 57f6a03c34
37 changed files with 9949 additions and 0 deletions

101
js/chatroom.js Normal file
View file

@ -0,0 +1,101 @@
//TODO: ping chatDriver with nickname
//TODO: chatDriver must delete the nickname after X seconds without answering
//TODO: old files should be removed after X hours
//TODO: lastPost becomes undefined somewhere somehow; can't pinpoint
var lastPost = "0000-00-00 00:00:00";
var reloadChat = function(){
// Workflow:
//- Chatroom requests info starting from lastPost (default to 0)
//- Server receives lastPost and returns two arrays
//- First array contains latest lastPost
//- Second array contains a subarray with all posts from last update
$.getJSON("http://localhost/~csolisr/web/Proyecto/php/chatDriver.php",
{"lastPost": lastPost},
function(data) {
//Render the received data
var renderedData = "";
if (data["messageArray"]){
for (var i=0; i<data["messageArray"].length; ++i){
var current = data["messageArray"][i];
var usr = current["usr"];
/*var time = new Date(current["time"]*1000);
var content = current["content"];
var timeDisplay = time.getFullYear()+"-"+
time.getMonth()+"-"+
time.getDate()+" "+
time.getHours()+":"+
time.getMinutes()+":"+
time.getSeconds();
*/
var timeDisplay = current["time"];
renderedData += "<div class='renderedData'>";
renderedData += "<b> "+usr+": </b>";
renderedData += current["content"];
renderedData += " <i>(at "+timeDisplay+")</i>";
renderedData += "</div>\n";
$("#chatlog").append(renderedData);
}
}
lastPost = data["lastPost"];
});
}
var postMsg = function(msg){
//Draw the user name from your cookie
var usr = "";
if (document.cookie) {
var cookieList = document.cookie.split(";");
for (var i=0; i<cookieList.length; ++i){
var cookieValues = cookieList[i];
while (cookieValues.charAt(0) == " "){
var cookieLen = cookieValues.length;
cookieValues = cookieValues.substring(1, cookieLen);
}
if (cookieValues.indexOf("username=") == 0){
var ulen= "username=".length;
var clen = cookieValues.length;
usr = cookieValues.substring(ulen, clen);
}
}
}
//The time and id parameters are obtained server-side
//Prepare the JSON payload
var payloadUsername = usr;
//var payloadTime = new Date();
//payloadTime.setTime(payloadTime.getTime());
var payloadMessage = msg;
//var JSONPayload = JSON.stringify({"username": payloadUsername,"time": payloadTime,"message": payloadMessage});
//var JSONPayload = JSON.stringify({"username": payloadUsername,"message": payloadMessage});
var JSONPayload = {"username": payloadUsername, "message": payloadMessage};
//var JSONPayload = JSON.stringify([payloadUsername, payloadMessage] );
return JSONPayload;
}
window.setInterval(reloadChat, 1000);
//Button functions
$(document).ready(function(){
//Functionality for sendButton
$("#sendButton").click(function(){
//Draw message from the #message field
var msg = $("#message").val();
var JSONPayload = postMsg(msg);
//Send the payload
$.getJSON("http://localhost/~csolisr/web/Proyecto/php/postMessage.php",
JSONPayload,
function(data) {
//Clear the post
if (data["requestValid"]=="true"){
$("#message").val("");
}
});
});
//TODO: Functionality for attachButton
//$('#attachButton').click(function(e){
//return false;
//});
});

42
js/main.js Normal file
View file

@ -0,0 +1,42 @@
$(document).ready(function(){
$("#loginButton").click(function(){
/*
$.ajax({
url: "http://localhost/~csolisr/web/Proyecto/usersList.php",
crossDomain: true,
dataType: "json",
type: "GET",
timeout: 1000
}).done(function(data) {
*/
var username = $("#user").val();
$.getJSON("http://localhost/~csolisr/web/Proyecto/php/usersList.php",
{"usr": username},
function(data) {
if (!data["userExists"]) {
//Hide the error message
$(".help-inline").css("display", "hidden");
//TODO: Register this user in the database
$.getJSON("http://localhost/~csolisr/web/Proyecto/php/registerUser.php",
{"username":username},
function(data) {
if (data["requestValid"]=="true"){
var now = new Date();
now.setTime(now.getTime());
var expiration = 1000*60*60; //1 hour
//TODO: Expire the session and disreserve the name
//after an hour of inactivity.
var expirationDate = new Date(now.getTime() + expiration);
document.cookie = "username="+username+";"+
"expires="+expirationDate.toGMTString()+";"+
"path=/;";
//TODO: Actually reading this cookie on the chat!
window.location = "http://localhost/~csolisr/web/Proyecto/chatroom.html";
}
});
} else {
$(".help-inline").css("display", "inline");
}
});
});
});

24
js/plugins.js Executable file
View file

@ -0,0 +1,24 @@
// Avoid `console` errors in browsers that lack a console.
(function() {
var method;
var noop = function () {};
var methods = [
'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
'timeStamp', 'trace', 'warn'
];
var length = methods.length;
var console = (window.console = window.console || {});
while (length--) {
method = methods[length];
// Only stub undefined methods.
if (!console[method]) {
console[method] = noop;
}
}
}());
// Place any jQuery/helper plugins in here.

1999
js/vendor/bootstrap.js vendored Executable file

File diff suppressed because it is too large Load diff

6
js/vendor/bootstrap.min.js vendored Executable file

File diff suppressed because one or more lines are too long

6
js/vendor/jquery-1.10.1.min.js vendored Executable file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long