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.

            
              <body>
  <!--navigation bar-->
  <div class="header">
  <nav>
    <!--container is a default class name-->
    <div class="container1">
      <div class="heading">
        <h4><a target="_blank" href="#" id="banner"><span class="highlight">WikiPedia</span> Viewer</a></h4>
      </div>
      <div class="search-bar">
        <input placeholder="Search" id="input"></input>
        <span><button id="search-button"><i class="fa fa-search"></i></button></span>
      </div>
    </div>
  </nav>
  </div>

  <!--section for wikipedia results-->
  <div class="section1">
    <div class="container1" id="wikipedia-content">      
      
    </div>    
  </div>
  <div class="footer">
    <ul>
      <li>site by Prakash Chandra</li>
    </ul>    
  </div>
</body>
            
          
!
            
              body{
  margin:0;
  padding:0;
  font-family:Rockwell;
  background-color:rgb(44, 107, 84);
}

.default-class{
  padding:0;
  margin:0;
  text-decoration:none;
}

h4{
  font-weight:bold;
  font-family:Rockwell;
}

/*banner*/
#banner{
  cursor:pointer;
  text-decoration:none;
  color:black;
}


/*todo - header tag usage - when padding changed causes height to change
->box-sizing tag-?
*/
.header{
  /*background-color:blue;*/
  box-sizing:border-box;
  padding-top:10px;
  height:50px;
  border-bottom:2px solid black;
  }

nav{
  /*background-color:orange;*/
  height:100%;
}

.container1{
  /*background-color:purple;*/
  width:80%;
  height:100%;
  margin:auto;
   /*removing this causes the backgorund-color to become invisible*/
  overflow:hidden;
}

.heading{
  float:left;  
}

.highlight{
  color:#2EBA50;
}

.search-bar{
  float:right;
  border:2px solid black;
  border-radius:2px;
  height:30px;
  width:240px;
}

.search-bar input{
  float:left;
  #background-color:blue; 
  #box-sizing:border-box;  /*effects the width or not ? */
  font-family:Rockwell;
  height:100%;
  padding-left:10px;
  width:86%;
  border:none;
  outline:none;
  /*transition:all 0.5s ease-in-out 0.1s;*/
}

/*
.search-bar input:focus {
  width:100%;
  padding-left:50px;
}*/

.search-bar input::placeholder{
  color:black;
  font-weight:bold;
  font-family:Rockwell;
}


.search-bar span{
  float:right;
  border-left:2px solid black;
  height:26px;
  /*background-color:orange;*/
  background-color:#2EBA50;
  }

.search-bar button{
  background:none;
  cursor:pointer;
  border:none;
  outline:none;
}

.section1{
  margin-top:10px;
  margin-bottom:10px;
  height:100%;
  /*background-color:blue;*/
}
.section1 .container1{
  /*background-color:#2EBA50;*/
  height:100%;
}

/*footer*/
.footer{
  text-align:center;
  color:black;
  /*border-top:2px solid black;*/
}

.footer ul{
  text-decoration:none;
  display:inline;
}

/*todo*/

.wikipedia-result{
  color:black;
}

.wiki-link{
  text-decoration:none;
  transition:all 1.3s;
  color:rgb(0,96,252);
}

.wiki-link:hover{
  text-decoration:none;
  color:rgb(0,96,252);
  transform:scale(2.4);
}




/*media query*/
@media(max-width:700px){
  .header{
    height:80px;
  }
  
  .header nav{
    text-align:center;
  }

  .header nav .container1 .heading{
    float:none;
  }
  .header nav .container1 .search-bar{
    float:none;
    margin:auto;
    width:240px;
  }
  .header nav .container1 .search-bar input:focus{
    padding-right:0;
  }
}
            
          
!
            
              /*
"https://en.wikipedia.org/w/api.php?action=opensearch&search=" + searchTerm + "&format=json&callback=?";
*/
/*
$(document).ready(function(){    
  
  
  var link = 'https://en.wikipedia.org/w/api.php?action=opensearch&search=" + searchTerm + "&format=json&callback=?';
  var link = "https://en.wikipedia.org/w/api.php?action=query&titles=India&prop=revisions&rvprop=content&format=json&callback=?";
});
*/

/*even handler for when user gives an input*/
$("#input").on("focusin",function(){  
  
  var input_val;
  $("#input").keyup(function(event){
    input_val = $("#input").val();
    if(event.which === 8){
      if(input_val == ''){
        $("#input").css("background-color","white");  
      }  
    }else{
       $("#input").css("background-color","rgb(164, 168, 173)");  
    }    
  });
  
  $("#input").keydown(function(event){
    input_val = $("#input").val();
    if(event.which === 8){
      if(input_val == ''){
        $("#input").css("background-color","white");  
      }  
    }else{
      $("#input").css("background-color","rgb(164, 168, 173)");  
    }    
    
  });  
});

/*even handler for when user gives focuses out of search bar*/
$("#input").on("focusout",function(){
  var input_val = $("#input").val();
  //alert(input_val);
  if(input_val == ''){
    $("#input").css("background-color","white");  
  }
  });

/*event handler if user presses enter key for search or backspace*/
$("#input").keyup(function(event){
  var input_val;
  if(event.which === 13){
    $("#search-button").click();
  }/*else if(event.which === 8){
      input_val = $("#input").val();
      if(input_val == ''){
        
        $("#input").css("background-color","white");
      }
  }*/
});


$("#search-button").on("click",function(){
  
  $("#wikipedia-content").html('');
  //$("#wikipedia-content").empty();
  var searchTerm = $("#input").val();
  var link = 'https://en.wikipedia.org/w/api.php?action=opensearch&search='+ searchTerm +'&format=json&callback=?'; 
    $.getJSON(link,function(data){
     console.log(data);
     var html;
     //loop over the results
     for(var i=0;i<data[1].length;i++){
       html = '<div class="wikipedia-result"><h4>'+data[1][i]+'</h4>\
                    <p>'+data[2][i]+'</p>\
                    <a  target="_blank" class="wiki-link" href='+data[3][i]+'>'+data[3][i]+'</a>\
                    </div>';     
       $("#wikipedia-content").append(html);
       
       //assign border to all but last result
       /*$(".wikipedia-result").css({"color":"black"});
       $(".wiki-link").css({"text-decoration":"none","transition-property":"all","transition-duration":"1.3s","color":"rgb(40, 105, 255)"}); */
       
       if(i !== data[i].length-1){
        $(".wikipedia-result").css({"border-bottom-color":"black","border-bottom-width":"2px","border-bottom-style":"solid"});  
       }else{
         $(".wikipedia-result").css({"border-bottom":"none"});
       }       
       
       
       $(".section1").css({"border-bottom-width":"2px","border-bottom-color":"black","border-bottom-style":"solid"});
     }           
  });  
});



            
          
!
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