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 includes JSX processing.

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

Packages

Add Packages

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.

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

              
                <div class="container-fluid">
  <div class="row">
    <div class="col-flex-container col-xs-12 col-sm-offset-1 col-sm-10 col-md-offset-2 col-md-8 col-lg-offset-3 col-lg-6">
      <div class="header">
        <div class="row-flex-container">
          <div class="header-left">
            Wikipedia Viewer
          </div>
          
          <div class="header-right">
            <button class="btn search-btn">
              <i class="fa fa-search fa-3x"></i>
            </button>
            
            <a class="btn" target="_blank"
               href="https://en.wikipedia.org/wiki/Special:Random">
              <i class="fa fa-random fa-3x"></i>
            </a>
          </div>
        </div>
      </div>
      
      <div class="content">
        <i class="fa fa-spinner fa-pulse fa-5x fa-fw load-icon"></i>
        
        <div class="result-list">
          <div class="helper">
            <i class="fa fa-search fa-lg"></i> To Search <br>
            <i class="fa fa-random fa-lg"></i> To View a Random Page
          </div>
        </div>
        <div class="page-btns btn-group btn-group-justified" role="group">
          <div class="btn-group btn-group-justified" role="group">
            <button class="btn prev-btn">
              <i class="fa fa-arrow-left fa-3x"></i>
            </button>
          </div>
          <div class="btn-group btn-group-justified" role="group">
            <button class="btn next-btn">
              <i class="fa fa-arrow-right fa-3x"></i>
            </button>
          </div>
        </div>
      </div>
      
      <div class="footer">
        by <cite><a href="//codepen.io/ksmai" target="_blank">ksmai</a></cite>
      </div>
    </div>
  </div>
  
  
 
  <div class="search-modal">
    <div class="row">
      <div class="col-xs-offset-2 col-xs-10 col-sm-offset-3 col-sm-8 col-md-offset-4 col-md-6 col-lg-offset-5 col-lg-4">
        <div class="search-modal-box">
                
            <input type="text" placeholder="Search Wikipedia..."
                   class="search-input">
            <button class="btn submit-search-btn">
              <i class="fa fa-search"></i>
            </button>            
          
        </div>
        <div class="search-modal-hints col-xs-offset-1">
          <ul class="hint-list">
            <li class="hint">hint1</li>
            <li class="hint">hint2</li>
          </ul>
        </div>
      </div>
    </div>
  </div>



  
</div>



              
            
!

CSS

              
                html,
body {
  background-color: #222;
  color: #ccc;
  margin: 0;
  padding: 0; 
}

.col-flex-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.row-flex-container {
  display: flex;
  flex-direction: row;
}

.header {
  padding: 20px 0;
  font: bold small-caps 3em 'Atomic Age', sans-serif;
  border-bottom: #666 solid 1px;
}

.content {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
}

.footer {
  font-size: .8em;
  text-align: right;
  border-top: #666 solid 1px;
}

.header-left {
  flex: 1;
}

.btn,
.btn:focus {
  background-color: transparent;
  color: #ccc;
  height: 100%;
}

.btn:hover {
  background-color: #ccc;
  color: #222;
}

.search-modal {
  display: none;
  position: fixed;
  z-index: 1;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
/*  overflow: auto; */
  background-color: #000;
  background-color: rgba(0, 0, 0, 0.7);
  margin: 0;
  padding-top: 15vh;
}

.search-modal-box {
  display: none;
  padding: 20px;
  border: #ccc solid 1px;
  border-radius: 5px;
  background-color: #222;
}

.search-input {
  background-color: transparent;
  padding-right: 50px;
  height: 100%;
  border: 0;
  width: 90%;
}

.submit-search-btn {
  margin: -50px;
  height: 100%;
}

.load-icon {
  display: none;
}

.helper {
  font: normal small-caps bold 3em 'Atomic Age', sans-serif;
}

.page-btns {
  display: none;
}

p.error {
  font-weight: bold;
  font-size: 3em;
  font-family: 'Atomic Age', sans-serif;
  word-wrap: break-word;
}

.result-container,
.result-container:focus {
  border: 3px #ccc outset;
  border-radius: 5px;
  padding: 5px 10px;
  margin: 20px 0;
  text-decoration: none;
  background-color: #333;
  color: #ccc;
}

.result-container:hover {
  text-decoration: none;
  background-color: #ccc;
  color: #333;
}

.result-title {
  font-size: 1.5em;
  font-variant: small-caps;
  font-weight: bold;
  font-style: italic;
  font-family: serif;
}

.search-modal-hints {
  background-color: #999;
  padding: 10px;
  border: 0;
  border-radius: 0 0 30px 10px;
  display: none;
  font-size: .9em;
}

.hint-list {
  list-style: none;
}

.hint,
.hint:focus {
  color: #666;
  border-bottom: 1px solid #666;
  padding: 5px 0;
}

.hint:hover {
  background-color: #222;
  color: #ccc;
  border: 0;
}

.hint:last-child {
  border: none;
}
              
            
!

JS

              
                var currentPage = 0;
var totalPage = 0;
var resultPerPage = 10;

function createDiv(title, extract, url) {
  var $div = $('<a href="' + url + 
             '" target="_blank"><div class="result-container">' +
             '<div class="result-title">' + title + '</div>' +
             '<div class="result-extract">' + extract + '</div>' +
             '</div></a>');
  
  return $div;
}

function createPage(i) {
  var $page = $('<div class="result-page" id="result-page-' + (i + 1) +  '"></div>');
  
  return $page;
}

function nextPage() {
  if(currentPage < totalPage) {
    $('#result-page-' + currentPage).hide();
    currentPage++;
    $('#result-page-' + currentPage).show().fadeOut().fadeIn();
    $("html, body").animate({ scrollTop: 0 }, "slow");
    $('.prev-btn').prop('disabled', false);
    $('.prev-btn').show();
    if(currentPage == totalPage) {
      $('.next-btn').prop('disabled', true);
      $('.next-btn').hide();
    }
  }
}

function prevPage() {
  if(currentPage > 1) {
    $('#result-page-' + currentPage).hide();
    currentPage--;
    $('#result-page-' + currentPage).show().fadeOut().fadeIn();
    $("html, body").animate({ scrollTop: 0 }, "slow");
    $('.next-btn').prop('disabled', false);
    $('.next-btn').show();
    if(currentPage == 1) {
      $('.prev-btn').prop('disabled', true);
      $('.prev-btn').hide();
    }
  }
}

$(document).ready(function() {
  $('.prev-btn').on('click', prevPage);
  $('.next-btn').on('click', nextPage);
  $('.search-btn').on('click', function() {
    $('.search-modal').css('display', 'block');
    $('.search-modal-box').slideToggle("fast");
  });
  
  $('.search-input').on('keyup', function(e) {
    var key = typeof e.which === "number" ? e.which : e.keyCode;
    if(key === 13) {
      $('.submit-search-btn').trigger('click');
    } else if($.trim($('.search-input').val()) !== "") {
      $('.search-modal-hints').hide();
      $('.hint-list').empty();
      $.ajax({
        'url': '//en.wikipedia.org/w/api.php',
        'data': {
          'action': 'query',
          'list': 'prefixsearch',
          'pssearch': $('.search-input').val(),
          'format': 'json',
          'pslimit': '5'
        },
        'dataType': 'jsonp',
        'success': function(data) {
          console.log(data);
          $('.hint-list').empty();
          if(data.query.prefixsearch.length > 0) {
            for(var i = 0; i < data.query.prefixsearch.length; i++) {
              $('<li class="hint">' + data.query.prefixsearch[i].title +
                '</li>').appendTo('.hint-list');              
            }
            $('.hint').on('click', function() {
              $('.search-input').val($(this).text());
              $('.search-modal-hints').hide();
              $('.search-input').focus();
              $('.submit-search-btn').trigger('click');
            });
            $('.search-modal-hints').show();
          }
        }
        
        
      });
    }
    else {
      $('.search-modal-hints').hide();
    }
  });
  
  $('.search-modal').on('click', function(evt) {
    if(evt.target === this) {
      $('.search-modal-hints').hide();
      $('.search-modal-box').slideToggle("fast", function() {
        $('.search-modal').hide();
      });      
    }
  });
  
  $('.helper').on('click', function() {
    $('.header-right').fadeOut('fast')
      .fadeIn('fast').fadeOut('fast').fadeIn('fast')
      .fadeOut('fast').fadeIn('fast'); 
  });
  
  
  $('.submit-search-btn').on('click', function() {
    console.log(encodeURIComponent($('.search-input').val()));
    $('.search-modal-hints').hide();
    $('.result-list').empty();
    $('.page-btns').hide();
    $('.content').css('display', 'flex');
    $('.load-icon').show();
    if($('.helper')) {
      $('.helper').remove();   
    }    
    $('.search-modal').trigger('click');
    $.ajax({
      'url': '//en.wikipedia.org/w/api.php',
      'dataType': 'jsonp',
      'data': {
        'action': 'opensearch',
        'search': $('.search-input').val(),
        'limit': 'max',
        'namespace' : '0',
        'format': 'json'
      },
        'success': function(data) {
          console.log(data);
          $('.load-icon').hide();
          
          $('.content').css('display', 'block');
          
          totalPage = Math.ceil((data[1].length - 0.1) / resultPerPage);
          currentPage = 1;
          
          if(totalPage > 0) {
            for(var i = 0; i < totalPage; i++) {
              createPage(i).appendTo('.result-list');
              if(i > 0) {
                $('#result-page-' + (i + 1)).hide();
              }
            }
            
            for(var i = 0; i < data[1].length; i++) {
              createDiv(data[1][i], data[2][i], data[3][i]).appendTo('#result-page-' +
                                                  Math.ceil((i + 0.1) / resultPerPage));
            }
          
            $('.prev-btn').prop('disabled', true);
            $('.prev-btn').hide();
            
            if(totalPage < 2) {
              $('.next-btn').prop('disabled', true);
              $('.next-btn').hide();
            } else {
              $('.next-btn').prop('disabled', false);
              $('.next-btn').show();
            }
            
            $('.page-btns').show();
          } else {
  //          $('.content').css('display', 'flex');
  // "word-wrap: break-word; doesnt work in flexbox for some reasons
            $('<p class="error">No results found for "' + data[0] + 
              '"</p>').appendTo('.result-list');
          }
          
        },
      'error': function() {
        $('<p class="error">An error has occurred.</p>').appendTo('.result-list');
      }
    });
  });
  

});
              
            
!
999px

Console