-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavascript
More file actions
119 lines (69 loc) · 2.98 KB
/
Javascript
File metadata and controls
119 lines (69 loc) · 2.98 KB
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
function createTweet(){
document.getElementById("modal-backdrop").classList.remove("hidden");
document.getElementById("create-twit-modal").style.display ="block";
}
function CloseModal(){
document.getElementById("modal-backdrop").classList.add("hidden");
document.getElementById("create-twit-modal").style.display ="none";
//When the modal is closed, the values of all of the input fields should be cleared
// so they don't appear the next time the modal is opened.
document.getElementById("twit-text-input").value = "";
document.getElementById("twit-attribution-input").value = "";
}
function createTwit(){
var text = document.getElementById("twit-text-input").value;
var author = document.getElementById("twit-attribution-input").value;
var elem = document.createElement('article');
//Checking whether the fields are left blank or not.
if(text=='' || author==''){
alert('Text or Author field can not be left blank!');//Displaying alert if fields are left blank
}else{
var articeElem =elem ;
elem.setAttribute('class','twit');
document.getElementById("twit-container-div").append(elem);
var innerelem = document.createElement('div');
innerelem.setAttribute('class','twit-icon');
elem.append(innerelem);
elem = innerelem;
var innerelem = document.createElement('i');
innerelem.setAttribute('class','fa fa-bullhorn');
elem.append(innerelem);
elem = innerelem;
var innerelem = document.createElement('div');
var twit_content_elem = innerelem;
innerelem.setAttribute('class','twit-content');
articeElem.append(innerelem);
elem = innerelem;
var innerelem = document.createElement('p');
innerelem.setAttribute('class','twit-text');
innerelem.textContent = text;
elem.append(innerelem);
elem = innerelem;
var innerelem = document.createElement('p');
innerelem.setAttribute('class','twit-attribution');
twit_content_elem.append(innerelem);
elem = innerelem;
var innerelem = document.createElement('a');
innerelem.setAttribute('href','#');
innerelem.textContent = author;
elem.append(innerelem);
elem = innerelem;
CloseModal();
}
}
//searching in the input
$(function() {
$("#navbar-search-button").click(search);
});
//Search Function searching the text
function search(){
var searchfield = document.getElementById("navbar-search-input").value;//Captures what user types in the search box
//Check for all the contents that is present under .twit-content whether any of those includes the text that user searched for
document.querySelectorAll('.twit-content').forEach(function(item){
var a = item.innerText.includes(searchfield); //if it matches then a stores true else false
console.log(a);
if(!a) {
item.parentNode.remove();//removing all other vtwits which doe not contain the searched text
}
})
}