123

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.

            
              <header>
  <link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Raleway" />
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</header>

<h1 class = "text-center" style="margin-top:40px; color:#D86E31;">ALORA Wikipedia Viewer</h1>

<div id = "section-input" class="container-fluid">
  <input id = "searchTxt" type="text" placeholder="Search..."/>
  <div id = "section-close"><button id ="clearTxt"></button>X</div>
  </div>
<div id="randomArticle">
  <a href = "https://en.wikipedia.org/wiki/Special:Random" target="_blank"><h4 class="text-center">Not sure what to look for?<br> Click here to read a random article...</h4></a>
    
  </div>
<div id = "search-result-div">
  <div id = "dynamicDiv">
    
  </div>
  
            
          
!
            
              @col-orange: #D86E31;
h1{
  font-family: Raleway;
  font-size: 30px;  
  text-shadow: .5px -1px black;  
}
h4{
  font-family: Raleway;
  font-size:12px;
  color: #D86E31;
    
}
body{
  background: #092B40;
}
#randomArticle{
  position:absolute;
  top:140px;
  left:50%;
  transform: translate(-50%,-50%);
}
#section-input{
  position:absolute;
  width: 350px;
  top:180px;
  left:50%;
  transform: translate(-50%,-50%);
}
#searchTxt{
  width: 100%;
  height: 40px;
  border: 4px solid #D86E31;
  border-radius: 25px;
  outline: none;
  background: transparent;
  text-indent: 10px;
  color: white;
}
#section-close{
  color: #D86E31;
  position:absolute;
  top:30%;
  right:9%;
  cursor: pointer;
  }
#clearTxt{
  position:absolute;
  z-index: 1;
  height:17px;
  opacity:0;
}
p{
  color: white;
}
#search-result-div{
  position:relative;
  top: 130px;
  left:20px;
  margin-right:40px;
  
}
.resultBlock{
  position:relative;
  left:5px;
  transition: all .5s ease-in-out;
  
  }
#dynamicDiv{
  position:relative;
  max-width: 800px;
  left: 50%;
  transform: translate(-50%);  
}
.resultBlock:hover {
  background: #D86E31;
  color: white;
  transform: rotateY(7deg);.
  transition: 0.3s;
}
a{
  color: inherit;
  text-decoration: none;
  font: inherit;
}
a:hover{
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}
a:focus{
  color: inherit;
  text-decoration: none;
}
            
          
!
            
              $(document).ready(function(){
    
  $("#clearTxt").on("click",clearText);
  
  $("#searchTxt").keyup(showResult);
    
});

//Obtaining data on Enter key press.

function showResult(enteredTxt){
  if (enteredTxt.keyCode === 13){
    
    //Take the search term entered to the input field.
    var search = $("#searchTxt").val();
 
      
     // making cache false.
     $.ajaxSetup({ cache: false });
    
     //obtaining data using getJSON.
     $.getJSON("https://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=" + search + "&callback=?", function(result){
     

     //remove previous data filled div elements.
     $("#dynamicDiv div").remove();
     
     //Filter out garbage search terms.  
     if ((result[1][0]) == undefined){
      var errorMsg = "<div class='well resultBlock' id='1'><span><b>Error!</b></span><br>No Results Found. Please try a different search term.<div>"      
      $("#dynamicDiv").html(errorMsg);  
     }else{
     //Creating div elements and pushing data into them. 
     var n = 0; 
     while (n < 10){ 
     
     var searchContent = "<a target = '_blank' href='"+ result[3][n] +"'><div class='well resultBlock' id='"+ n + "'><span><b>" + result[1][n] +"</b></span><br>" + result[2][n] + "</div></a>" 
    
    $("#dynamicDiv").css("opacity","0");
    $("#dynamicDiv").append(searchContent);
     
     n += 1;
     }
    $("#dynamicDiv").animate({opacity: 1},500,);
     }  
     });
     
}}

//Clear button function.
function clearText(){
  $("input:text").val("");
  $("#dynamicDiv div").remove();
 // $("#search-result-div").remove();
};
//Assigning search text to the API URL
/*  var searchStr = $("#searchTxt").val();
  var apiUrl = "https://en.wikipedia.org/w/api.php?format=json&action=query&generator=search&gsrnamespace=0&gsrlimit=10&prop=pageimages|extracts&pilimit=max&exintro&explaintext&exsentences=1&exlimit=max&gsrsearch=" + searchStr + "&callback="

//Using ajax to get data  
$.ajax({
        url: apiUrl,
        dataType: "jsonp",
        success: function (data) {
            var n = 0;
            while (n < 10){
            var pageData = (data.query.pages);
            var x = pageData[Object.keys(pageData)[n]];
            var pageId = Object.keys(pageData)[n];
            var idh = '#h' + (n + 1);
            var idc = '#c' + (n + 1);
            var idd = '#' + (n + 1);
            var ida = '#a' + (n + 1); 
            var pageIdLink = "https://en.wikipedia.org/?curid=" + pageId;
            $(idd).animate({
            opacity: 1
            }, 700);
            $(idc).html(x.extract);
            $(idh).html(x.title);
            $(ida).attr("href",pageIdLink);
            //setTimeout(function(){
             //var x = 0;
            //},5000);
            n += 1;
            }
            
        },
        error: function (errorMessage) {
          $("h4").html(JSON.stringify(errorMessage));
        }
    })} */



















//Using getJSON with jsonp type to get data
/*$.getJSON("https://en.wikipedia.org/w/api.php?format=json&action=query&generator=search&gsrnamespace=0&gsrlimit=10&prop=pageimages|extracts&pilimit=max&exintro&explaintext&exsentences=1&exlimit=max&gsrsearch=hi&callback=?",function(errorMessage){
   $("h4").html(JSON.stringify(errorMessage));
  
})}; */
 
    


            
          
!
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.

Console