Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Week-2/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<html >
<header>
<link href="style/style.css" rel="stylesheet" />
<script src="scripts/constants.js" type="text/javascript"></script>
<script src="scripts/RenderContent.js" type="text/javascript"></script>
<script src="scripts/utility.js" type="text/javascript"></script>
<script src="scripts/source.js" type="text/javascript"></script>
</header>
<main>
<footer >
</footer>
</main>
</html>
Binary file added Week-2/resource/download.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
106 changes: 106 additions & 0 deletions Week-2/scripts/RenderContent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
function setLeftContent(fullContainer,container){
let card = document.createElement('div');
createLeftCard(card);
addDivToContainer(card,container,fullContainer);
}

function setRightContent(fullContainer,container){
let right_container = document.createElement('div');
createRightCard(right_container,container);
fullContainer.appendChild(right_container);

}
function changeContent(val,container){
container.innerHTML = '';
for(item in article_data){
if(article_data[item].postCategory===val){
let card = document.createElement('div');
createLeftCard(card,article_data[item]);
container.appendChild(card);
addDivToContainer(card,container);
}
}
}
function createLeftCard(card,channelSpecificata){
let image = document.createElement('img'),
right = document.createElement('div'),
title = document.createElement('h4'),
metaDisc = document.createElement('h6'),
description = document.createElement('p'),
btn = document.createElement('button');
card.setAttribute('class', 'box');
image.setAttribute('class','image');
right.setAttribute('class','vertical');
metaDisc.setAttribute('class','metadisc');
metaDisc.setAttribute('id','meta');
description.setAttribute('class','description');
btn.setAttribute('id',0);
if(channelSpecificata){
title.textContent = channelSpecificata.postTitle;
metaDisc.textContent = channelSpecificata.postDate;
description.textContent = channelSpecificata.postDesc;
} else{
title.textContent = defaultTitle;
metaDisc.textContent = defaultDescription;
description.textContent = defaultContent;
}
image.src=imageSource;
btn.innerHTML=buttonText;
btn.setAttribute('class','btncontinue');
right.appendChild(title);
right.appendChild(metaDisc);
right.appendChild(description);
right.appendChild(btn);
card.appendChild(image);
card.appendChild(right);
}
function createRightCard(right_container,container){
let titleSelectCategory = document.createElement('h4'),
select = document.createElement('select'),
subscribeTitle = document.createElement('h4'),
check=document.createElement('div'),
input = document.createElement('input'),
btn = document.createElement('button');
right_container.setAttribute('class', 'right-container');
titleSelectCategory.textContent = selectCategoryText;
select.setAttribute('id','ddlSelect');
select.options.add( new Option(defaultSelectChannelText,null));
fillDropDownNewsChannelList(select);
select.onchange = () => {
select.options[0].disabled = true;
let val=select.value;
changeContent(val,container);
}
subscribeTitle.textContent = subscribeText;
check.setAttribute('class','check');
input.setAttribute('id','email');
input.type = 'text';
btn.innerHTML=subscribeText;
btn.setAttribute('id','btn-email');
btn.addEventListener('click', emailSave);
check.appendChild(input);
check.appendChild(btn);
right_container.appendChild(titleSelectCategory);
right_container.appendChild(select);
right_container.appendChild(subscribeTitle);
right_container.appendChild(check);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

few places same dom manipulation function used, this can be clubbed by making a few common functions. this can reduce a lot of code lines.
discuss with me if you are not clear what i am telling

}
function fillDropDownNewsChannelList(select){
let data=[];
for(item in article_data){
if(data.indexOf(article_data[item].postCategory)!==-1){
continue;
} else{
select.options.add( new Option(article_data[item].postCategory,article_data[item].postCategory) );
data.push(article_data[item].postCategory);
}
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider splitting this function to few smaller functions

function addDivToContainer(card,container,fullContainer){
let horizontalline = document.createElement('HR');
container.appendChild(card);
container.appendChild(horizontalline);
if(fullContainer){
fullContainer.appendChild(container);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider splitting this function into few smaller functions

}
}
88 changes: 88 additions & 0 deletions Week-2/scripts/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
const defaultContent='Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
defaultDescription='created at 21 July 2019""created at 21 July 2019',
defaultTitle='SAMPLE NEWS HEADING',
buttonText='Continue Reading',
checkButtonClickRegex=/^\d+$/,
regexEmail = /\S+@\S+\.\S+/,
emailSubscribedMessage='Subscribed Successfully',
emailInvalidMessage='Invalid Email id',
closePopupText='X',
imageSource='resource/download.png',
selectCategoryText='Select Category',
subscribeText='Subscribe',
headerTagText='NEWSFEED',
headerTagSubText='yet Another Newsfeed',
footerText = ' \u00A9 NewsFeed 2019 ',
defaultSelectChannelText='Select a NEWS Channel',
article_data = [
{
imageSrc: 'images/bbc.jpg',
postTitle: 'Delhi CEO writes to EC over Modi web series',
postDate: '29th June , 2019',
postCategory: 'BBC',
postDesc: 'Delhi Chief Electoral Officer Ranbir Singh has written to the poll panel saying that a web series on Modi available on the Eros Now website was streaming without certification from the Media Certification and Monitoring Committee (MCMC).A senior official at the Delhi CEO`s office reportedly said that they have brought to the notice of the ECI that a series on PM Narendra Modi is being screened on the Eros Now platform without MCMC certification. Since it not a Delhi specific matter, the CEO office has asked the ECI to take cognizance of the matter.'
},
{
imageSrc: 'images/timesNow.jpg',
postTitle: 'New guidelines to tackle mental health of inmates',
postDate: '22th June , 2019',
postCategory: 'BBC',
postDesc: 'At present, only Pennsylvania has constituted a detailed manual on mental health for prisoners. Dr Nand Kumar, professor of psychiatry at AIIMS has framed these guidelines on mental health condition for prisoners.Doctors of AII India Institute of Medical Sciences (AIIMS) in collaboration with Delhi Prison Administration have drafted first guidelines on mental health issues for inmates in jail. The manual known as "Psychological First Aid" will be released on Tuesday.'
},
{
imageSrc: 'images/woin.jpg',
postTitle: 'City ring vowing jobs in Territorial Army busted',
postDate: '20th June , 2019',
postCategory: 'WION',
postDesc: 'The fraudsters, police said, have interstate links and they confidently organised physical and medical tests in park adjacent to cantonment area of Bhubaneswar.The entire nexus was unearthed after Delhi crime branch received a complaint from one of the job seeker on April 13. The complainant also given a lead that the accused are coming here in Mahipalpur area of Delhi to distribute admit cards.'
},
{
imageSrc: 'images/abnAJ.jpg',
postTitle: '"Traders" ire to impact election results in Delhi',
postDate: '20th June , 2019',
postCategory: 'ABN Andhrajyothi',
postDesc: 'The Delhi High Court asked Delhi Pollution Control Committee (DPCC) not to take coercive steps against traders until the next day of hearing on April 26.The violence that rocked the area a month before Delhi votes in the Lok Sabha elections left many wounded on both sides and renewed the old political slugfest over the hot button issue.Since December 2017, about 10,000 commercial establishments have been sealed across the National Capital for land misuse (converting residential units into commercial ones), non-payment of conversion charges and increased pollution emissions.'
},
{
imageSrc: 'images/tv9.jpg',
postTitle: 'Ahead of polls, MLA hostel searched in Chennai',
postDate: '29th June , 2019',
postCategory: 'TV9',
postDesc: 'With just a few days left for the Lok Sabha elections in Tamil Nadu, a team of officials from the flying squad of the Election Commission along with Income Tax officials carried out raids in Tamil Nadu MLA’s Hostel in Omandurar Government Estate.Sources in the IT department said rooms of Tamil Nadu revenue minister RB Udhayakumar and two others were searched. However, it is not clear whether the team seized any cash or incriminating documents from the minister’s room.'
},
{
imageSrc: 'images/republictv.jpg',
postTitle: 'Canada drops reference to Sikh extremism from terror threat report',
postDate: '22th June , 2019',
postCategory: 'REPUBLIC',
postDesc: 'Pro-Khalistan group Sikhs for Justice (SFJ) has called upon Canadian Prime Minister Justin Trudeau to step down for practising the politics of expediency in having his government drop Sikh extremism from a report on terror the day before he participated in Baisakhi parade.The damage has been done Mr Prime Minister and you should resign over this, said Gurpatwant Singh Pannun, SFJ legal adviser.'
},
{
imageSrc: 'images/tv5.jpg',
postTitle: 'Jet puts off date to resume foreign flights',
postDate: '20th June , 2019',
postCategory: 'TV5',
postDesc: 'Jet Airways has stopped accepting bookings for its Mumbai-Paris flight until June 10 and closed reservations for its Mumbai-London, Mumbai-Amsterdam-Mumbai and Bangalore-Amsterdam flights, up to April 18.Meanwhile, the airline`s pilots who are on the warpath have also decided to defer their strike which was scheduled from Monday as they want to give the airline a chance to survive, keeping in mind the meeting with banks tomorrow.'
},
{
imageSrc: 'images/sakshi.jpg',
postTitle: 'SP, BJP battle over national security',
postDate: '20th June , 2019',
postCategory: 'Sakshi',
postDesc: 'Prime Minster Narendra Modi also targeted SP-BSP alliance while addressing a rally in Uttar Pradesh`s Moradabad district. PM Modi said, The irony is that elephant is riding on bicycle for personal gains. They have done nothing for the poor in the state during their regimes, and now they are trying to lure public on fake promises.'
},
{
imageSrc: 'images/ntv.jpg',
postTitle: 'Summer assault! Delhi again in big water crisis',
postDate: '20th June , 2019',
postCategory: 'NTV',
postDesc: 'The crisis turns so grave that violent fights over water among neighbours in summers are common. Delhi Police said they are gearing up to tackle water clashes that left three dead and many injured last summer.All experts are unanimous that Delhi must revive its water bodies, ensure groundwater recharge through storm drains, store rainwater, and recycle and reuse its waste water.'
},
{
imageSrc: 'images/CBN.jpg',
postTitle: 'Melbourne nightclub shooting leaves 1 dead, 3 injured',
postDate: '20th June , 2019',
postCategory: 'CBN',
postDesc: 'Sunday`s shooting took place around 3.20 a.m. in the lively entertainment district of Melbourne`s southeastern suburb of Prahran, police said.Three security guards and a man queuing to enter were taken to hospital with gunshot injuries, police said in a televised news conference in Melbourne.'
},
];
34 changes: 34 additions & 0 deletions Week-2/scripts/source.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
window.onload = init;
function init(){
let fullContainer = document.createElement('div'),
container = document.createElement('div'),
popup = document.createElement('div'),
app = document.querySelector('main'),
appBody= document.createElement('div'),
headerBox=document.createElement('div'),
toptag=document.createElement('h2'),
topTagItalic=document.createElement('i'),
header = document.querySelector('header'),
footerTag=document.createElement('p'),
foot = document.querySelector('footer');

popup.setAttribute('class','popup');
app.appendChild(popup);
fullContainer.setAttribute('class', 'fullcont');
container.setAttribute('class', 'left-container');
appBody.setAttribute('class','main-container');
headerBox.setAttribute('class','headerbox');
toptag.textContent = headerTagText;
topTagItalic.textContent= headerTagSubText;
headerBox.appendChild(toptag);
headerBox.appendChild(topTagItalic);
header.appendChild(headerBox);
footerTag.setAttribute('id','footertag');
footerTag.textContent=footerText;
foot.appendChild(footerTag);
app.prepend(appBody);
appBody.append(fullContainer);
setLeftContent(fullContainer,container);
setRightContent(fullContainer,container);
document.addEventListener('click', clicked(this,fullContainer,popup));
}
39 changes: 39 additions & 0 deletions Week-2/scripts/utility.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
function emailSave(){
let emailid= document.getElementById('email').value;
if(regexEmail.test(emailid)){
window.localStorage.setItem(emailid, JSON.stringify(emailid));
alert(emailSubscribedMessage);
} else{
alert(emailInvalidMessage);
}
}
function clicked(clickEvent,fullContainer,popup){
return clickEvent => {
if(checkButtonClickRegex.test(clickEvent.srcElement.id)){
let textArea = document.createElement('div'),
horizontaLine = document.createElement('hr'),
titlePopup = document.createElement('div'),
closePopup = document.createElement('div'),
descriptionPopup = document.createElement('div');

popup.style.display = 'block';
popup.innerHTML = '';
descriptionPopup.textContent = article_data[Number(clickEvent.srcElement.id)].postDesc;
titlePopup.textContent = article_data[Number(clickEvent.srcElement.id)].postTitle;
titlePopup.appendChild(horizontaLine);
closePopup.textContent = closePopupText;
textArea.appendChild(titlePopup);
textArea.appendChild(closePopup);
textArea.setAttribute('id','titleandcross');
titlePopup.setAttribute('id','titlepopup');
descriptionPopup.setAttribute('id','descriptionpopup');
closePopup.setAttribute('id','closePopup');
popup.appendChild(textArea);
popup.appendChild(descriptionPopup);
fullContainer.style.opacity = '0.3';
} else if(clickEvent.srcElement.id === 'closePopup'){
popup.style.display = 'none';
fullContainer.style.opacity = '1';
}
}
}
Loading