HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
#container
header#header.grid.cols-6
section#proj-heading
h1 Wikipedia Viewer Application
details#proj-details
summary Project Info
section#details-body.grid.cols-2.rows-2
.details-column
.details-column
main#app
#app-con.flex-c
section#search.flex-c
h2
i.fa.fa-wikipedia-w.item-icon
| ikipedia Viewer
#search-bar
input#search-input(autocomplete='off' autofocus='' placeholder='Search The Wikipedia...' type='search')
button#search-btn(type='button')
i.fa.fa-search
a#random(href='https://en.wikipedia.org/wiki/Special:Random' target='_blank') Random Article
section#results-con.flex-c
footer#footer
p
| Last Updated:
time(datetime='2017-05-03') 03/05/2017
| &nbsp | &nbsp
a(href='https://codepen.io/U-ways/' target='_blank')
i.fa.fa-codepen(aria-hidden='true')
| U-ways
/* Color Scheme
================================================================================
Main Colors:
#c5dec2 - #95a893
#3e5050 - #3a4949
#263331 - #333
Matching R&G:
#549042 - #8e0000
*//* App
==============================================================================*/
#app-con {
margin-top: 10px;
justify-content: flex-start;
align-content: flex-start;
}
/* Search Section
==============================================================================*/
#search {
width: 90vw;
max-width: 1320px;
justify-content: flex-start;
align-content: flex-start;
align-items: flex-start;
margin: 25vh 0 1% 0;
} #search h2 {
color: #c5dec2;
margin: 0 0 2px -10px;
font-size: 1.6em;
} #search h2 i {
font-size: 1.4em;
font-style: italic;
}
.ceremony {
margin: 0 0 1% 0 !important;
transition: margin 1.5s ease;
}
/* Search-bar
============================================*/
#search-bar {
overflow: hidden;
width: 100%;
white-space: nowrap;
}
/* Input bar
============================================*/
#search-bar input[type=search] {
outline: none;
border: none;
width: 100%;
height: 50px;
background-color: #c5dec2;
color: #3b4c4c;
font-size: 1.5em;
padding-left: 15px;
border-radius: 5px;
float: left;
}
#search-bar input[type=search]:focus {
background: rgba(190, 214, 187, 0.87);
} #search-bar input[type=search]::-webkit-input-placeholder {
color: #405353;
} #search-bar input[type=search]:-ms-input-placeholder {
color: #405353;
}
/* Search button
============================================*/
#search-btn {
border-top-right-radius: 4.5px;
border-bottom-right-radius: 4.5px;
font-size: 1.5em;
height: 50px;
width: 55px;
margin-left: -55px;
transition: all .55s ease;
outline: none;
border: none;
background: #324141;
color: #c5dec2;
}
#search-btn:hover {
background: #293535;
}
/* Random Link
============================================*/
#random {
display: block;
padding-top: 5px;
padding-left: 3px;
color: #c5dec2;
}
#random:hover,
#random:focus {
color: #c5dec2;
text-decoration: none;
text-shadow: 0px 1px 8px #969696;
}
/* Results Container
==============================================================================*/
#results-con {
}
/* Random Heading
==============================================================================*/
#results-heading {
width: 90vw;
max-width: 1320px;
margin-bottom: .5%;
color: #bed6bb;
font-weight: 100;
animation: fadeIn 2s;
animation-timing-function: ease-out;
}
/* Result-list
==============================================================================*/
#result-list {
width: 85vw;
max-width: 1250px;
}
/* Result List Item
============================================*/
.result-list-item {
width: inherit;
max-width: inherit;
height: calc(2vh + 30px);
margin-top: .5%;
margin-bottom: .5%;
text-align: left;
border-radius: 3px;
border: 1px solid transparent;
animation: fadeIn 2s;
animation-timing-function: ease-out;
transition:background 1s ease;
}
.result-list-item:hover {
border: 1px solid #a8bda5;
}
.result-list-item:hover,
.result-list-item:focus {
background: #263331;
text-shadow: 0px 1px 8px #969696;
transition: all 1s ease;
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
/* Items Components
============================================*/
.item-link {
height: inherit;
color: #bed6bb;
text-decoration: none;
justify-content: flex-start;
padding: 0 25px 0 15px;
outline-color: #bed6bb;
}
.title-link:hover,
.item-link:focus {
text-decoration: none;
background: #263331;
text-shadow: 0px 1px 8px #969696;
transition: all 1.2s ease;
}
.item-icon {
font-size: 1em;
font-weight: bold;
}
.item-title {
margin: 0 0 0 15px;
font-weight: bold;
font-size: 1em;
width: auto;
white-space: nowrap;
}
.item-description {
color: #9eb9a6;
font-size: 1em;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
width: auto;
}
/* Network Error
==============================================================================*/
#NetworkErr {
position: absolute;
text-align: center;
top: 45%; bottom: 0;
text-transform: capitalize;
color: #273432;
animation: fadeIn 1s;
}
/* jshint esversion:6 */
const searchSection = document.querySelector('#search');
const searchBtn = document.querySelector('#search-btn');
const searchInput = document.querySelector('#search-input');
const resultsCon = document.querySelector('#results-con');
const keypressHandler = (key) => {
/** 13 === Enter Keycode **/
if (key.keyCode === 13) { ceremony(); }
};
/* Add listeners for initial search animation
==============================================================================*/
searchBtn.addEventListener("click", ceremony);
searchInput.addEventListener('keypress', keypressHandler);
/* Remove animation listeners & set normal eventListeners for getting results
==============================================================================*/
function ceremony() {
searchBtn.removeEventListener("click", ceremony);
searchInput.removeEventListener('keypress', keypressHandler);
searchSection.classList.add("ceremony");
function eventListeners() {
searchBtn.addEventListener("click", getResults);
searchInput.addEventListener('keypress', (key) => {
if (key.keyCode === 13) { getResults(); }}
);
getResults();
}
/** 1.8s delay to match my animation **/
window.setTimeout(eventListeners, 1800);
}
/* Get results as JSON using XHR.
==============================================================================*/
function getResults() {
let keyword = encodeURIComponent(searchInput.value.trim());
let url = `https://en.wikipedia.org/w/api.php?action=opensearch&limit=15&format=json&search=${keyword}&origin=*`;
xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.setRequestHeader('Api-User-Agent', 'Header_doest_work_._Update_your_MediaWiki_API_doc_.'); // Include this so Wiki developers can see it. https://www.mediawiki.org/wiki/API:Main_page#Identifying_your_client
xhr.onerror = () => getScriptJsonp(keyword);
xhr.onload = () => resultsHandler(JSON.parse(xhr.response));
xhr.send(null);
}
/* Display results.
==============================================================================*/
function resultsHandler(response) {
/** Clean up from previous queries **/
let results = '';
resultsCon.innerHTML = '';
searchInput.value = '';
if (response[1].length !== 0) {
resultsCon.innerHTML += `<h2 id="results-heading">Wikipedia Articles For: <i>${response[0]}</i></h2>`;
resultsCon.innerHTML += `<ul id="result-list"></ul>`;
let ul = document.querySelector('#result-list');
response[1].forEach(
(item, index) =>
/** Push all elements inside results first. (To load all at once) **/
results += component(item, index, response)
);
ul.innerHTML += results;
} else {
resultsCon.innerHTML =
`<h2 id="results-heading">No Resutls Found For: ${response[0]}</h2>`; // Add animation and style
}
}
function component(item, index, results) {
return `
<li class="result-list-item flex-r">
<a class="item-link flex-r" href="${results[3][index]}" target="_blank">
<i class="fa fa-wikipedia-w item-icon" aria-hidden="true"></i>
<h3 class="item-title">${results[1][index]}</h3>
<p class="item-description"><b>:</b> ${results[2][index]}</p>
</a>
</li>`;
}
/* JSONP script technique as a CROS error handler.
==============================================================================*/
function getScriptJsonp(keyword) {
let script = document.createElement('script');
let url = `https://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=${keyword}` + '&callback=wikiJsonpCb';
/**
* Create a window's proparty method with a simillar name to the requested function from
* the Wiki server (wikiJsonpCb) to be used as a callback. This method cleans up the
* JSONP mess and passes the data to cb.
*/
window.wikiJsonpCb = response => {
// Cleaning as we no longer need those elements.
delete window.wikiJsonpCb;
document.body.removeChild(script);
resultsHandler(response); // NOTE: MB try to make resultsHandler handle this one as well...
};
/**
* Set script src to the 'url' + Request a callback to 'wikiJsonpCb'. (JSONP technique)
* When script is set to the body, the server will return a call to 'wikiJsonpCb' with the API query result as a passed argument (JSONP technique)
* window.wikiJsonpCb will handle the rest afterwards.
*/
script.src = url;
script.onerror = connectionErr;
document.body.appendChild(script);
}
/* Connection error handler.
==============================================================================*/
function connectionErr() {
resultsCon.innerHTML = '<h2 id="NetworkErr">Unable to connect to the intrenet, Please check your network connection</h2>';
}
/* Adding project Details
==============================================================================*/
addProjDetails(0, 'Project Overview', 'This is a Wikipedia viewer application. Consider it something similar to the google search engine, it uses the Wikimedia API to search through the Wikipedia entries, then it displays a sum of the results with a brief description for each title.');
addProjDetails(0, 'Techniques/Technologies', 'This project had no complex components. AJAX was used for better client-side interactivity, and HTML and CSS was used for structure and presentation. I added some decent on search, hover, and display animation for a better UX.');
addProjDetails(1, 'Hurdles encountered', 'The Wikimedia API (the core for my search engine) had some outdated and misleading documentation. So I had a bit of trouble following the instruction provided, as they were incorrect.');
addProjDetails(1, 'Future implementations', 'I am interested into integrating caching functionality to the application. So if the user searched a keyword before, it should not request it again form the server. Instead, it should use the cached results for a faster and more efficient processing.');
Also see: Tab Triggers