Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <body>
  <div class="container-fluid">    
    <h1>Pesquisar artigos na Wikipedia</h1>
    <div class="divSearch" >
     <button id="random" type="button" class="btn btn-info">
      <span class="glyphicon glyphicon-random"></span>
    </button> 
     <input type="text" id="searchBox" class="search" placeholder="Pesquisar Wikipedia ..." maxlength="50">
      <button id="searchBtn" type="button" class="btn btn-info">
      <span class="glyphicon glyphicon-search"></span> Pesquisa
    </button>
    </div>
      <div id="articles" class="articles">
      </div>
  
  <footer>
    <p>Made by <u><a href="https://www.freecodecamp.com/luisgonzaga"  target='_blank'>Luis Gonzaga</a></u> for
      <a href="https://www.freecodecamp.com/" target='_blank'><img src="https://s20.postimg.org/6cdgaf8l9/fcc.png" alt="freeCodeCamp" title="freeCodeCamp"></img>
      </a>
    </p>
</footer>
</div>
</body>
              
            
!

CSS

              
                a {
  color:#333300;
}

body {
  background-color:#1E6FBF;
  font-size: 1.7em;
  text-align:center;
}

footer {
  color: #fff;
  margin: 23px;
}

footer a{
  color: #fff;
}

h1 {
  color: #ececec;
  margin: 23px;
}

input[type=text] {
    background-color: #fff;
    background-image: url('https://s20.postimg.org/4pp9q8fzx/search.png');
    background-position: 1px 5px; 
    background-repeat: no-repeat;
    border: 2px solid #ccc;
    border-radius: 4px; 
    box-sizing: border-box;
    margin: 2px;
    padding: 8px 8px 8px 38px;
    -webkit-transition: width 0.4s ease-in-out;
    transition: width 0.4s ease-in-out;
    width: 30em;
}

.articles { 
  background-color: #fff;
  border: 2px double #ccc;
  border-radius: 6px; 
  box-sizing: border-box;
  color:#000033;
  display: none;
  margin:23px auto;
  max-width: 46em;
  min-width: 34em;
  padding: 6px;
  text-align:left;
}

              
            
!

JS

              
                $(document).ready(function() {
  
  $('#searchBox').keypress(function(event){
    if(event.keyCode == 13){
      $("#searchBtn").click();
    }
  });
  
  $("#random").click(function() {
    $.ajax({
      url: 'https://pt.wikipedia.org/w/api.php?action=query&list=random&rnlimit=1&utf8=',
      async: false,
      data: {
        format: 'json'
      },
      error: function(status) {
        console.log(status);
        alert("failed connection, please try again later")
      },
      dataType: 'jsonp'
    }).done(function(data, status) {
      var outWiki = data;

      $('#searchBox').val(outWiki.query.random[0].title.substr(0, 50));
    })
  });

  $("#searchBtn").click(function() {
    var searchURI = 'https://pt.wikipedia.org/w/api.php?action=query&list=search&srsearch=' + encodeURIComponent($('#searchBox').val()) + '&srlimit=20&utf8=';
    $.ajax({
      url: searchURI,
      async: false,
      data: {
        format: 'json'
      },
      error: function(status) {
        console.log(status);
        alert("failed connection, please try again later")
      },
      dataType: 'jsonp'
    }).done(function(data, status) {
      $('#articles').html('');
      var outWikiLinks = data;
      $('.articles').css('display', 'block')
      if (outWikiLinks.query) {
        $('#articles').append('Pesquisa para <b>"' + $('#searchBox').val() + '"</b>');
        if (outWikiLinks.query.searchinfo.totalhits > 20) {
          $('#articles').append('<br>Mostrando 20 resultados de um total de ' + outWikiLinks.query.searchinfo.totalhits + ' encontrados:<br><br>');
        } else {
          $('#articles').append('<br>Foram encontrados ' + outWikiLinks.query.searchinfo.totalhits + ' resultados:<br><br>');
        }
        for (n = 0; n < outWikiLinks.query.search.length; n++) {
          var uriEnc = encodeURIComponent(outWikiLinks.query.search[n].title);
          $('#articles').append('<p><a href="http://pt.wikipedia.org/wiki/' + uriEnc + '" target="_balnk"><b>' + outWikiLinks.query.search[n].title + '</b> -' + outWikiLinks.query.search[n].snippet + '</p></a><p>Nº palavras - ' + outWikiLinks.query.search[n].wordcount + '</p><br>')
        }
      } else {
        $('#articles').append('<p style="color:red; margin-left:33%;" class="glyphicon glyphicon-exclamation-sign"> Pesquisa inválida.</p><br>');
      }
    })
  });

});
              
            
!
999px

Console