forked from lee2sman/chirp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
97 lines (82 loc) · 3.02 KB
/
script.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
function addDiv() {
let currentDate = new Date();
let hours = currentDate.getHours();
if(hours>12){
hours = hours-12;
}
let time = hours + ":" + currentDate.getMinutes();
//create a new P tag, save it in a variable
let theNewDiv = document.createElement("div");
let timeDiv = document.createElement("div");
//add a class to our new div element
theNewDiv.classList.add("auto-div");
timeDiv.classList.add("right");
//set the text inside the div
theNewDiv.innerHTML = document.getElementById("textInput").value;
timeDiv.innerHTML = time;
//find the right tag to add the div to
//we used an id of "content-area" for
//the place where we want to add the chirp
let theContentArea = document.getElementById("content-area");
//add the new div to that tag
theContentArea.appendChild(theNewDiv);
theContentArea.appendChild(timeDiv);
//play a sound when a post is made
let audio = new Audio("alert_chirp.mp3");
audio.play();
}
function addImage() {
let currentDate = new Date();
let hours = currentDate.getHours();
if(hours>12){
hours = hours-12;
}
let time = hours + ":" + currentDate.getMinutes();
//create a new P tag, save it in a variable
let theNewDiv = document.createElement("div");
let timeDiv = document.createElement("div");
//add a class to our new div element
theNewDiv.classList.add("auto-div");
timeDiv.classList.add("right");
//create image tag to put into the div
theImgTag = "<img src='" + document.getElementById("imgInput").value + "' width = 100 height = 100>";
//set the text inside the div
theNewDiv.innerHTML = theImgTag;
timeDiv.innerHTML = time;
//find the right tag to add the div to
//we used an id of "content-area" for
//the place where we want to add the twit
let theContentArea = document.getElementById("content-area");
//add the new div to that tag
theContentArea.appendChild(theNewDiv);
theContentArea.appendChild(timeDiv);
//play a sound when a post is made
let audio = new Audio("alert_image.mp3");
audio.play();
var input = document.getElementById("textInput"); //Get the input box
input.addEventListener("keyup", function(event) { //Check keys
if (event.keyCode === 13) { //Check for enter key
event.preventDefault();
// document.getElementById("my-button").click(); //Should activate the button, but doesn't.
addDiv(); //Submit the text
emptyText(); //Clear the input
}
});
var imginput = document.getElementById("imgInput"); //Get the input box
imginput.addEventListener("keyup", function(event) { //Check keys
if (event.keyCode === 13) { //Check for enter key
event.preventDefault();
// document.getElementById("my-button").click(); //Should activate the button, but doesn't.
addImage(); //Submit the image link
emptyImg(); //Clear the input
}
});
function emptyText()
{
document.getElementById("textInput").value = ""; //Clears input box for text
}
function emptyImg()
{
document.getElementById("imgInput").value = ""; //Clears input box for image links
}
}