JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
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.
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.
<body>
<div class="image">
<img src="http://vignette3.wikia.nocookie.net/simpsons/images/d/dd/Wikipedia-logo.svg.png/revision/latest?cb=20100610161747"></div>
<div class="main">
<h1>Wikipedia Viewer</h1>
<div class="search">
<input type="text" name="search" placeholder="Enter your query" id="text">
<i class="material-icons">search</i>
<i class="fa fa-random" aria-hidden="true"></i>
</div>
<section class='wiki-articles'></section>
</div>
</body>
*{
font-family: 'Raleway', sans-serif; font-weight: 300;
}
body{
width: 100vw;
height: 1300px;
background:linear-gradient(to right, #00c6ff, #0072ff) ;
margin: 0 0;
}
.image{
display: block;
text-align: center;
position: relative;
top: 100px;
}
img{
height:150px;
width: 150px;
object-fit: contain;
overflow: hidden;
}
h1{
color: white;
font-weight: 300;
font-size: 40px;
text-align: center;
text-shadow: 2px 1px #444;
}
.main{
width: 80%;
min-height: 200px;
max-height: 100%;
margin-left: 10%;
margin-top: 110px;
}
.search{
position: relative;
}
input{
width:60%;
margin-left: 20%;
height: 35px;
font-size: 25px;
padding-left: 10px;
border: none;
box-shadow: 2px 10px 20px #444;
}
.material-icons{
color: white;
font-size: 35px;
line-height: 35px;
position: absolute;
margin-left: 5px;
cursor: pointer;
text-shadow: 2px 2px #444
}
.fa{
color: white;
font-size: 25px;
line-height: 35px;
position: absolute;
margin-left: 50px;
cursor: pointer;
font-weight: 100;
text-shadow: 2px 2px #444;
}
.wiki-articles{
width: 60%;
min-height: 300px;
max-height: 100%;
background: #efefef;
margin-left: 20%;
margin-bottom: 20px;
padding-left: 10px;
margin-top: 40px;
box-shadow: 2px 10px 20px #444;
}
.title{
font-size: 34px;
color: #0072ff;
text-align: center;
padding: 10px 0;
}
.extract{
font-size: 20px;
padding: 5px 20px;
}
.thumbnail{
float: left;
padding: 0 20px;
width: 150px;
height: 150px;
}
.thumbnail img{
background-size: cover;
}
.description {
padding: 0 20px;
font-size: 17px;
span{
color: #0072ff;
font-weight: 600;
}
}
.fullurl{
padding: 0 20px 20px 20px;
a{
text-decoration: none;
color: red;
}
}
var query, title, article;
$(document).ready(function() {
function wikipedia() {
$('.wiki-articles').empty();
$.ajax({
url: 'https://en.wikipedia.org/w/api.php?action=query&format=json&prop=pageimages%7Cpageterms%7Cinfo%7Cextracts&generator=prefixsearch&redirects=1&formatversion=2&piprop=thumbnail&pithumbsize=300&pilimit=10&wbptterms=description&inprop=url&exsentences=3&exlimit=20&exintro=1&explaintext=1&exsectionformat=wiki&gpslimit=10&callback=?&gpssearch=' + query + '',
dataType: "jsonp",
success: function(data) {
//gives a number of query results
var articleNum = data.query.pages.length;
for (var i = 0; i < articleNum; i++) {
title = data.query.pages[i].title; //assign values to variables
if(!data.query.pages[i].thumbnail) {
thumbnail = 'https://www.google.rs/logos/doodles/2017/carmen-mirandas-108th-birthday-6367640367923200-hp.jpg';
}else{
thumbnail = data.query.pages[i].thumbnail.source;
};
if(!data.query.pages[i].terms){
description = 'No description avaliable for this article';
}else{
description = data.query.pages[i].terms.description;
};
extract = data.query.pages[i].extract;
fullurl = data.query.pages[i].fullurl;
//constructor of wiki articles
var Article = function(title, thumbnail, description, extract, fullurl) {
this.title = title;
this.thumbnail = thumbnail;
this.description = description;
this.extract = extract;
this.fullurl = fullurl;
}
console.log(fullurl);
article = new Article(title, thumbnail, description,extract, fullurl); //make object with variables declared
console.log(article);
function appendArticles(){ //make divs and populate them with with content of object
$('.wiki-articles').append('<div class=\'title\'>'+article['title']+'</div>');
$('.wiki-articles').append('<div class=\'thumbnail\'><img src=\''+article['thumbnail']+'\'</div>');
$('.wiki-articles').append('<div class=\'extract\'>'+article['extract']+'</div>');
$('.wiki-articles').append('<div class=\'description\'><span>Description </span>'+article['description']+'</div>');
$('.wiki-articles').append('<div class=\'fullurl\'> If you want to read whole article <a href=\''+article['fullurl']+'\'> click here</a></div>');
}
appendArticles();
}
}
})
console.log("success");
}
//take input and assign it to query variable which gets asigned to api call
$('.material-icons').on('click', function() {
query = document.getElementById('text').value;
console.log(query);
wikipedia();
});
$.fn.pressEnter = function(fn) {
return this.each(function() {
$(this).off('enterPress');
$(this).on('enterPress', fn);
$(this).keypress(function(e) {
if (e.keyCode == 13) {
$(this).trigger("enterPress");
}
});
});
};
$('#text').pressEnter(function () {
query = document.getElementById('text').value;
wikipedia();
});
console.log(article);
});
Also see: Tab Triggers