css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="container">
	<a href="https://github.com/TarekRaafat/autoComplete.js" class="github-corner" aria-label="View source on GitHub"><svg
                width="80" height="80" viewBox="0 0 250 250" style="fill:#64CEAA; color:#fff; position: absolute; top: 0; border: 0; right: 0;"
                aria-hidden="true">
                <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
                <path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
                    fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
                <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
                    fill="currentColor" class="octo-body"></path>
            </svg></a>
	<style>
		.github-corner:hover .octo-arm {
			animation: octocat-wave 560ms ease-in-out
		}

		@keyframes octocat-wave {
			0%,
			100% {
				transform: rotate(0)
			}
			20%,
			60% {
				transform: rotate(-25deg)
			}
			40%,
			80% {
				transform: rotate(10deg)
			}
		}

		@media (max-width:500px) {
			.github-corner:hover .octo-arm {
				animation: none
			}
			.github-corner .octo-arm {
				animation: octocat-wave 560ms ease-in-out
			}
		}
	</style>
	<header class="header">
		<h1><a href="https://github.com/TarekRaafat/autoComplete.js">autoComplete.js</a></h1>
	</header>
	<div class="body" align="center">
		<input id="autoComplete" type="text" tabindex="1">
		<div class="mode">
			<h4>mode</h4>
			<div class="toggele">
				<div class="toggeler">Strict</div>
			</div>
		</div>
		<div class="selection"></div>
	</div>
	<footer class="footer">
		<div class="copyrights">Copyright &copy; 2018 <a href="http://www.tarekraafat.com/">Tarek Raafat</a> All Rights Reserved</div>
	</footer>
</div>
            
          
!
            
              :root {
    --transition-1: all 0.3s ease-in-out;
    --transition-2: all 0.1s ease-in-out;
}

html {
    font-size: 1rem;
    font-family: "PT Sans", sans-serif;
}

body {
    margin: 0;
    padding: 0;
}

.contaier {
    width: 100vw;
    height: 100vh;
}

.header {
    text-align: center;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -webkit-touch-callout: none;
}

#autoComplete_results_list {
    display: none;
    height: 45vh;
    overflow: auto;
}

.in {
    padding: 0 2rem 0 3.5rem;
    color: rgba(255, 122, 122, 1);
    height: 3rem;
    width: 16.5rem;
    border: 0.05rem solid rgb(255, 122, 122);
    background: url("./images/magnifier.svg") no-repeat left/15% 1.5rem;
    box-shadow: rgba(255, 122, 122, 0.1) 0px 0px 20px 5px;
    position: relative;
    font-size: 1.2rem;
    outline: none;
    border-radius: 50rem;
    border: 0.05rem solid rgb(255, 122, 122);
    caret-color: rgb(255, 122, 122);
    transition: all 0.4s ease;
    -webkit-transition: all -webkit-transform 0.4s ease;
    text-overflow: ellipsis;
}

.out {
    position: relative;
    padding: 0 2rem 0 3.5rem;
    height: 2.1rem;
    width: 6rem;
    font-size: 1.2rem;
    outline: none;
    border-radius: 50rem;
    border: 0.05rem solid rgb(255, 122, 122);
    caret-color: rgb(255, 122, 122);
    color: rgba(255, 255, 255, 0);
    background: url("./images/magnifier.svg") no-repeat center/10% 1.5rem;
    transition: all 0.4s ease;
    -webkit-transition: all -webkit-transform 0.4s ease;
    text-overflow: ellipsis;
}

h1 {
    color: rgba(255, 122, 122, 1);
    transition: var(--transition-1);
}

h1>a {
    text-decoration: none;
    color: rgba(255, 122, 122, 1);
}

h1>a::selection {
    color: rgb(255, 122, 122);
}

h4 {
    margin-bottom: 5px;
    color: #ffc6c6;
}

h4::selection {
    color: #ffc6c6;
}

.github-corner {
    transition: var(--transition-1);
}

.mode {
    margin-top: 20px;
}

.toggele {
    display: flex;
    position: abolute;
    border: 1px solid #ffc6c6;
    height: 35px;
    width: 120px;
    border-radius: 50px;
    justify-content: flex-start;
    align-content: center;
    transition: var(--transition-1);
}

.toggeler {
    display: grid;
    cursor: pointer;
    background-color: rgba(255, 198, 198, 1);
    color: #fff;
    height: 25px;
    width: 60px;
    border-radius: 50px;
    margin: 5px;
    text-align: center;
    align-content: center;
    align-self: flex-start;
    transition: var(--transition-1);
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -webkit-touch-callout: none;
}

.toggeler:hover {
    width: 70px;
    background-color: rgba(255, 122, 122, 0.7);
}

.toggeler::selection {
    color: #fff;
}

.strict {
    display: inline;
}

.loose {
    display: inline;
}

.selection {
    margin-top: 25vh;
    font-size: 2rem;
    font-weight: bold;
    color: #ffc6c6;
    transition: var(--transition-1);
}

.selection::selection {
    color: #64ceaa;
}

.footer {
    display: flex;
    width: 100vw;
    position: absolute;
    bottom: 2rem;
    color: rgb(147, 147, 147);
    justify-content: center;
    transition: var(--transition-1);
}

.footer>div>a {
    text-decoration: none;
    color: rgb(147, 147, 147);
}

.footer>div>a::selection {
    color: rgba(255, 122, 122, 1);
}

.copyrights {
    font-size: 0.8rem;
}

.copyrights::selection {
    color: rgb(147, 147, 147);
}

.copyrights>a::selection {
    color: rgb(147, 147, 147);
}

@media only screen and (max-width: 600px) {
    .selection {
        margin-top: 15vh;
    }

    .footer {
        bottom: 1.5rem;
        transition: var(--transition-1);
    }
}

@media only screen and (max-height: 500px) {
    .footer {
        display: none;
    }
}
            
          
!
            
              // The autoComplete.js Engine instance creator
const autoCompletejs = new autoComplete({
	data: {
		src: async () => {
			// Loading placeholder text
			document.querySelector("#autoComplete").setAttribute("placeholder", "Loading...");
			// Fetch External Data Source
			const source = await fetch("https://tarekraafat.github.io/autoComplete.js/demo/db/generic.json");
			const data = await source.json();
			// Returns Fetched data
			return data;
		},
		key: "food"
	},
	placeHolder: "Food & Drinks",
	selector: "#autoComplete",
	threshold: 0,
	searchEngine: "strict",
	highlight: true,
	maxResults: Infinity,
	resultsList: {
		container: source => {
			resultsListID = "autoComplete_results_list";
			return resultsListID;
		},
		destination: document.querySelector("#autoComplete"),
		position: "afterend"
	},
	resultItem: (data, source) => {
		return `${data.match}`;
	},
	onSelection: feedback => {
		const selection = feedback.selection.food;
		// Render selected choice to selection div
		document.querySelector(".selection").innerHTML = selection;
		// Clear Input
		document.querySelector("#autoComplete").value = "";
		// Change placeholder with the selected value
		document.querySelector("#autoComplete").setAttribute("placeholder", selection);
		// Concole log autoComplete data feedback
		console.log(feedback);
	}
});

// On page load add class to input field
window.addEventListener("load", () => {
	document.querySelector("#autoComplete").classList.add("out");
	document.querySelector("#autoComplete_results_list").style.display = "none";
});

// Toggle Search Engine Type/Mode
document.querySelector(".toggeler").addEventListener("click", () => {
	// Holdes the toggle buttin alignment
	const toggele = document.querySelector(".toggele").style.justifyContent;

	if (toggele === "flex-start" || toggele === "") {
		// Set Search Engine mode to Loose
		document.querySelector(".toggele").style.justifyContent = "flex-end";
		document.querySelector(".toggeler").innerHTML = "Loose";
		autoCompletejs.searchEngine = "loose";
	} else {
		// Set Search Engine mode to Strict
		document.querySelector(".toggele").style.justifyContent = "flex-start";
		document.querySelector(".toggeler").innerHTML = "Strict";
		autoCompletejs.searchEngine = "strict";
	}
});

// Toggle results list and other elements
const action = action => {
	const github = document.querySelector(".github-corner");
	const title = document.querySelector("h1");
	const mode = document.querySelector(".mode");
	const selection = document.querySelector(".selection");
	const footer = document.querySelector(".footer");

	if (action === "dim") {
		github.style.opacity = 1;
		title.style.opacity = 1;
		mode.style.opacity = 1;
		selection.style.opacity = 1;
		footer.style.opacity = 1;
	} else if ("light") {
		github.style.opacity = 0.1;
		title.style.opacity = 0.3;
		mode.style.opacity = 0.2;
		selection.style.opacity = 0.1;
		footer.style.opacity = 0.1;
	}
};

// Toggle event for search input
// showing & hidding results list onfocus / blur
// ["focus", "blur"].forEach(eventType => {
["focus", "blur", "mousedown", "keydown"].forEach(eventType => {
	const input = document.querySelector("#autoComplete");
	const resultsList = document.querySelector("#autoComplete_results_list");

	document.querySelector("#autoComplete").addEventListener(eventType, event => {
		// Hide results list & show other elemennts
		if (eventType === "blur") {
			action("dim");
		} else if (eventType === "focus") {
			// Show results list & hide other elemennts
			action("light");
		}
	});

	// Hide Results list when not used
	document.addEventListener(eventType, event => {
		var current = event.target;
		if (
			current === input ||
			current === resultsList ||
			input.contains(current) ||
			resultsList.contains(current)
		) {
			resultsList.style.display = "block";
		} else {
			resultsList.style.display = "none";
		}
	});
});

// Toggle Input Classes on results list focus to keep style
["focusin", "focusout", "keydown"].forEach(eventType => {
	document.querySelector("#autoComplete_results_list").addEventListener(eventType, event => {
		if (eventType === "focusin") {
			if (event.target && event.target.nodeName === "LI") {
				action("light");
				document.querySelector("#autoComplete").classList.remove("out");
				document.querySelector("#autoComplete").classList.add("in");
			}
		} else if (eventType === "focusout" || event.keyCode === 13) {
			action("dim");
			document.querySelector("#autoComplete").classList.remove("in");
			document.querySelector("#autoComplete").classList.add("out");
		}
	});
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console