Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <body>

 	<div class="container cont-left">
	    <h1>Danny's Movie List</h1>
	    <div class='inputBtnContainer'>
		    <div class="inputContainer cont-left">
		     	<input id="inputDanny" class="input" type="text" placeholder="Enter a movie">
		    </div>
		    <div class="btnContainer">
		     	<button id="btnDanny">Add</button>
		    </div> 
	    </div> 
	    <ul id="listDanny" class="list">      
	    	<!--JS Li elements here-->
	    </ul>  
  	</div>
  	<div class='submitContainer'>
  		<button id="submitBtn" type="submit">Save</button>
  	</div>
  	<div class="container cont-right">
	    <h1>Lola's Movie List</h1>
	    <div class='inputBtnContainer'>
		    <div class="inputContainer cont-right">
		     	<input id="inputLola" class="input" type="text" placeholder="Enter a movie">
		    </div>
		    <div class="btnContainer">
		     	<button id="btnLola">Add</button>
		    </div> 
	    </div> 
	    <ul id="listLola" class="list">
	    	<!--JS Li elements here-->      
	    </ul>  
 	</div>
</body>
              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Montserrat', sans-serif;
  display: flex;
  flex-direction: row;
  justify-content: space-around;
  height: 100vh;
  width: 100%;
  background-image: linear-gradient(to right, #67f6e5, #8981c4);
  padding: 0.5em;
}

h1 {
  font-family: 'Karla', sans-serif;
}

/*****Individual containers*****/
.container {
  width: 40%;
  height: 100vh;
  max-height: 800px;
  padding: 0.5em;
 /* outline: solid blue;*/
}

.container h1 {
  text-align: center;
  margin-bottom: 0.5em;
}

/*****InputBtnContainer*****/
.inputBtnContainer {
  width: 100%;
  margin-bottom: 0.5em;
  text-align: center;
  /*outline: solid black;*/
}

/*****Input*****/
.inputContainer {
  display: inline-block;
  width: 50%;
  margin-right: 20px;
  /*outline: solid 1px red;  */
}

.input {
  width: 100%;
  border: none;
}

/*****Buttons*****/
.btnContainer {
  display: inline-block;
  margin: auto;
  width: 10%;
  /*outline: solid red;*/
}

button {
  width: 100%;
  height: 100%;
  padding: 0.5em;
  border: none;
  border-radius: 10px;
  transition: all 0.5s;
  cursor: pointer;
}

button:hover {
  transform: scale(1.1);
  color: green;
}

/*****Submit(save) button*****/
.submitContainer {
  position: relative;
  height: 30px;
  margin-top: 2em;
}

.submitContainer button {
  height: 100%;
  width: 100%;
  padding: 0.3em;
}

.submitContainer button:hover {
  color: green;
  box-shadow: 0px 0px 10px 0px green;  
}

/*.saveMe {   JS Add
  color: green;
  box-shadow: 0px 0px 5px 1px #00ff00;
}*/

/*****Lists*****/
ul {
  max-height: 90%;
  padding: 1em;
  /*outline: solid green;*/
}

/*****JS added classes*****/
.itemClass {
  position: relative;
  height: 100%; 
  list-style: none;
  margin: 0 auto;
  margin-bottom: 1em;
  padding: 0.2em;
  border-bottom: solid 1px black;
  /*outline: dotted red;*/
}

.btnClass {
  position: absolute;
  right: 0.5em;
  top: 0;   
  width: 6%;
  height: 90%;
  background: white;
  color: black;
  border: none;
  border-radius: 20px;
  padding: 0;
}

.btnClass:hover {
  color: red;
  box-shadow: 0px 0px 5px 1px red;
}

.approvedHidden {
  opacity: 0;
  position: absolute;
  left: 175px;
  top: -10px;
  font-size: 20px;
  color: green;
  transform: skew(0deg, 170deg);
}

.approvedVisible {
  opacity: 1;
}
              
            
!

JS

              
                const inputDanny = document.getElementById('inputDanny');
const inputLola =  document.getElementById('inputLola');
const listDanny = document.getElementById('listDanny');
const listLola = document.getElementById('listLola');
const buttons = document.querySelectorAll('button');
const inputs = Array.from(document.getElementsByClassName('input'));
const submit = document.getElementById('submitBtn');
const clear = document.getElementById('clearBtn');

let dannyArray = [];
let lolaArray = [];


function approveMovie() {	
	if(this.parentElement.id === "listDanny") {
		this.children[1].innerText = "Lola approved!";
		this.children[1].classList.toggle('approvedVisible');
	}

	if(this.parentElement.id === "listLola") {
		this.children[1].innerText = "Danny approved!";
		this.children[1].classList.toggle('approvedVisible');
	}
}

//Fix - Movies of the same name don't get deleted unless they are all deleted together
function removeMovie(list, arr) {
	let textContentArray = Array.from(list.children).map(node => node.firstChild.textContent);

	for(let i=0; i < arr.length; i++) {
		if(textContentArray.indexOf(arr[i]) === -1) { 
			arr.splice(i, 1);
			removeMovie(list, arr);
		}
	} return arr;
}

function deleteItem(e) {	// Delete item from list and remove it from array
	this.parentNode.remove();
	removeMovie(listDanny, dannyArray);
	removeMovie(listLola, lolaArray);
}

function createStamp() {
	let stamp = document.createElement('div');
	stamp.className = 'approvedHidden';
	return stamp;
}

function createItem() {
	let item = document.createElement('li');
 	item.className = 'itemClass';
 	return item;
}

function createBtn() {
	let btn = document.createElement('button');
	btn.className = 'btnClass';
	btn.appendChild(document.createTextNode('X'));
	return btn;
}

function addItem(user, value) {

 	let item = createItem();

 	let btn = createBtn();	

 	let stamp = createStamp();
	
	if (user === "Danny" && !value) {
		item.appendChild(document.createTextNode(inputDanny.value));
		listDanny.appendChild(item);
		item.appendChild(btn);
		item.appendChild(stamp);
		inputDanny.value = "";		
		dannyArray.push(item.childNodes[0].nodeValue);

	}  	else if (user === "Danny" && value) {
			item.appendChild(document.createTextNode(value));
			listDanny.appendChild(item);
			item.appendChild(btn);
			item.appendChild(stamp);
				
	}  	else if (user === "Lola" && !value) {
			item.appendChild(document.createTextNode(inputLola.value));
			listLola.appendChild(item);
			item.appendChild(btn);
			item.appendChild(stamp);
			inputLola.value = "";
			lolaArray.push(item.childNodes[0].nodeValue);

	}	else if (user === "Lola" && value) {
			item.appendChild(document.createTextNode(value));
			listLola.appendChild(item);
			item.appendChild(btn);
			item.appendChild(stamp);
		}

	btn.addEventListener('click', deleteItem);
	item.addEventListener('click', approveMovie);				
}

function hasContent(user) {

	if(user === "Danny" && inputDanny.value === "") {
		return inputDanny.placeholder = "Please enter a movie";
	
	} else if(user === "Danny" && inputDanny.value !== "") {
		addItem("Danny", null);
	
	} else if(user === "Lola" && inputLola.value === "") {
		return inputLola.placeholder = "Please enter a movie";
	
	} else {addItem("Lola", null);}
}

function clickFunk(e) {
	e.target.id === "btnDanny" ? hasContent("Danny") 
	: e.target.id === "btnLola" ? hasContent("Lola")
	: "";
}

function enterFunk(e) {
	e.keyCode === 13 && e.target.id === "inputDanny" ? hasContent("Danny") 
	: e.keyCode === 13 && e.target.id === "inputLola" ? hasContent("Lola")
	: ""; 
}

function saveFunk(state1, state2) {
		localStorage.setItem('dannyMovies', JSON.stringify(dannyArray));
		localStorage.setItem('lolaMovies', JSON.stringify(lolaArray));
		localStorage.setItem('dannyStates', JSON.stringify(state1));
		localStorage.setItem('lolaStates', JSON.stringify(state2));
		console.log('save: ', state1, state2);
	}

function isStampVisible() {
	const dannyStampStates = Array.from(listDanny.getElementsByTagName("div"))
						.map(node => node.classList)
						.map(node => node.value)
						.map(item => item.includes('approvedVisible'));

	const lolaStampStates = Array.from(listLola.getElementsByTagName("div"))
						.map(node => node.classList)
						.map(node => node.value)
						.map(item => item.includes('approvedVisible'));

	saveFunk(dannyStampStates, lolaStampStates);
}

function assignStamps(list, stamps) {
	const items = Array.from(list.getElementsByTagName("div"))
	for(let i=0;i<items.length;i++) {
		if(stamps[i] === true) {
			items[i].classList.add('approvedVisible');
		}
	}
}

window.onload = function() {
	dannyArray = Array.from(JSON.parse(localStorage.getItem('dannyMovies')));
	lolaArray = Array.from(JSON.parse(localStorage.getItem('lolaMovies')));
	dannyArray.forEach(movie => addItem("Danny", movie));
	lolaArray.forEach(movie => addItem("Lola", movie));

	dannyStampStates = Array.from(JSON.parse(localStorage.getItem('dannyStates')));
	lolaStampStates = Array.from(JSON.parse(localStorage.getItem('lolaStates')));

	assignStamps(listDanny, dannyStampStates);	
	assignStamps(listLola, lolaStampStates);

	console.log('load: ', dannyStampStates, lolaStampStates);
}

buttons.forEach(btn => btn.addEventListener('click', clickFunk));
inputs.forEach(input => input.addEventListener('keypress', enterFunk));
submit.addEventListener('click', isStampVisible);

              
            
!
999px

Console