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.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

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.

HTML

            
                  <body>
        <header>
            <h1>Wikipedia Search</h1>
        </header>
        <main>
          <label for="search">Enter search here</label>
          <input type="text" name="search">
          <button id="randBut" class="button" type="button" name="randomButton">Click here for a random article</button>
        </main>

        <ul id="output"></ul>
   
 
    </body>
            
          
!

CSS

            
              /*! HTML5 Boilerplate v5.0 | MIT License | http://h5bp.com/ */

html {
    color: #777;
    font-size: 1em;
    line-height: 1.4;
    background-color: rgb(191, 54, 12);
}

::-moz-selection {
    background: #b3d4fc;
    text-shadow: none;
}

::selection {
    background: #b3d4fc;
    text-shadow: none;
}

hr {
    display: block;
    height: 1px;
    border: 0;
    border-top: 1px solid #ccc;
    margin: 1em 0;
    padding: 0;
}

audio,
canvas,
iframe,
img,
svg,
video {
    vertical-align: middle;
}

fieldset {
    border: 0;
    margin: 0;
    padding: 0;
}

textarea {
    resize: vertical;
}

.browserupgrade {
    margin: 0.2em 0;
    background: #ccc;
    color: #000;
    padding: 0.2em 0;
}


/* ==========================================================================
   Author's custom styles
   ========================================================================== */

/* Fit to page - the standard way */
body{
    min-height: 100vh;
    position: relative;
    margin: 0;

    background-color: rgb(191, 54, 12);
    color: #FF5C2A;
    font-size: 1.3rem;
    font-family: arial;
}

header{
    padding-top: 10vh;
    padding-bottom: 8vh;
    display: flex;
    flex-direction: row;
    justify-content: center;
}


.hide {
    display: none;
}



header h1{
    
    font-size: 2rem;
}


main{
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding-top: 2vh;
}



.button{
    outline: 0;
    border:2px solid #ffad41;
    -webkit-border-radius: 10px;
    -moz-border-radius: 10px;
    border-radius: 10px;
    font-size:1rem;
    font-family:helvetica, sans-serif;
    padding: 10px 10px 10px 10px;
    text-decoration:none; 
    display:inline-block;
    text-shadow: 1px 1px 0 rgba(0,0,0,0.3);
    color: #FF5C2A;
    background-color: #ffc579; background-image: -webkit-gradient(linear, left top, left bottom, from(#ffc579), to(#fb9d23));
    background-image: -webkit-linear-gradient(top, #ffc579, #fb9d23);
    background-image: -moz-linear-gradient(top, #ffc579, #fb9d23);
    background-image: -ms-linear-gradient(top, #ffc579, #fb9d23);
    background-image: -o-linear-gradient(top, #ffc579, #fb9d23);
    background-image: linear-gradient(to bottom, #ffc579, #fb9d23);filter:progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr=#ffc579, endColorstr=#fb9d23);
    margin-bottom: 1rem;
    margin-top: 4rem;
}



.button:hover{
    border:1px solid #ff9913;
    background-color: #ffaf46; background-image: -webkit-gradient(linear, left top, left bottom, from(#ffaf46), to(#e78404));
    background-image: -webkit-linear-gradient(top, #ffaf46, #e78404);
    background-image: -moz-linear-gradient(top, #ffaf46, #e78404);
    background-image: -ms-linear-gradient(top, #ffaf46, #e78404);
    background-image: -o-linear-gradient(top, #ffaf46, #e78404);
    background-image: linear-gradient(to bottom, #ffaf46, #e78404);filter:progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr=#ffaf46, endColorstr=#e78404);
}


.button.withList{
    margin: 0;
    padding: 0;
}

main input{
  outline: none;
  border-style: solid;
  border-width: medium;
  border-color: #ff9913;
  border-radius: 2rem 2rem 2rem 2rem;
  margin-bottom: 1rem;
  margin-top: 1rem;
  background-color: rgb(114, 41, 19);
  text-align: center;
  height: 4rem;
  color: #ff9913;
}


main label{
    color: #ff9913;
}

ul{
    list-style-type: none;
    color: #ff9913;
    max-width: 80vw;
    display: flex;
    flex-direction: column;
    margin-left: 10vw;
    margin-right: 10vw;
}

li{
    background: rgb(114, 41, 19);
    padding: 1em 1em 1em 1em;
    margin-bottom: 1rem;
}


ul li a{
    color: #ff9913;
    text-decoration: none;
}



li:hover,
li:active,
li:focus{
    
    border-top:0px solid #ff9913;
    border-right:0px solid #ff9913;
    border-bottom:0px solid #ff9913;
    border-left:10px solid #ff9913;
}


/* ==========================================================================
   Media Queries
   ========================================================================== */

@media only screen and (min-width: 35em) {

}

@media print,
       (-o-min-device-pixel-ratio: 5/4),
       (-webkit-min-device-pixel-ratio: 1.25),
       (min-resolution: 120dpi) {

}

/* ==========================================================================
   Helper classes
   ========================================================================== */

.hidden {
    display: none !important;
    visibility: hidden;
}

.visuallyhidden {
    border: 0;
    clip: rect(0 0 0 0);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    width: 1px;
}

.visuallyhidden.focusable:active,
.visuallyhidden.focusable:focus {
    clip: auto;
    height: auto;
    margin: 0;
    overflow: visible;
    position: static;
    width: auto;
}

.invisible {
    visibility: hidden;
}

.clearfix:before,
.clearfix:after {
    content: " ";
    display: table;
}

.clearfix:after {
    clear: both;
}

.clearfix {
    *zoom: 1;
}

/* ==========================================================================
   Print styles
   ========================================================================== */

@media print {
    *,
    *:before,
    *:after {
        background: transparent !important;
        color: #000 !important;
        box-shadow: none !important;
        text-shadow: none !important;
    }

    a,
    a:visited {
        text-decoration: underline;
    }

    a[href]:after {
        content: " (" attr(href) ")";
    }

    abbr[title]:after {
        content: " (" attr(title) ")";
    }

    a[href^="#"]:after,
    a[href^="javascript:"]:after {
        content: "";
    }

    pre,
    blockquote {
        border: 1px solid #999;
        page-break-inside: avoid;
    }

    thead {
        display: table-header-group;
    }

    tr,
    img {
        page-break-inside: avoid;
    }

    img {
        max-width: 100% !important;
    }

    p,
    h2,
    h3 {
        orphans: 3;
        widows: 3;
    }

    h2,
    h3 {
        page-break-after: avoid;
    }
}

            
          
!

JS

            
              (function () {
"use strict";

    
     //  *************  Declare API elements   *************    
    
    var wikipediaAPi = "https://en.wikipedia.org/w/api.php?";
    
    
    var dataTypeList = {action: 'opensearch', format: 'json', namespace:'0', limit:'10'};
    var searchBBC = 'bbc';
    dataTypeList.search = searchBBC;
    // https://en.wikipedia.org/w/api.php?action=opensearch&format=json&namespace=0&limit=10&search=bbc
    console.log("bbc check ---> dataTypeList = " + JSON.stringify(dataTypeList));
    
    
    var dataTypeRand = {action: 'query', format: 'json', list:'random', rnnamespace:'0', rnlimit: '1'};
    // https://en.wikipedia.org/w/api.php?action=query&format=json&list=random&rnnamespace=0&rnlimit=1
    
    var newurl = 'https://en.wikipedia.org/w/index.php?curid=';
    
        
    
     //  *************  Random Api   *************

    function rndPageAjax(){
        
        rndAjax
        .done(function(dataR) {
            console.log('random Page is', dataR);
            console.log("dataR.query.random[0].id  " + dataR.query.random[0].id);
            //window.location = newurl + dataR.query.random[0].id;
            window.open(newurl + dataR.query.random[0].id,'_blank');
            // need to have taget=_blank so window.open not window.location
        })
        .fail(function(xhrR) {
          console.log('error callback for random page condition', xhrR);
        });
    }
    
    
    var rndAjax = $.ajax({
        type: 'GET',   // the URL to which the request is sent
        url: wikipediaAPi,  // need a single random wiki page
        dataType: 'jsonp',  // support cross-site requests domains (https://www.mediawiki.org/wiki/API:Cross-site_requests)
        data: dataTypeRand,
        traditional: true
    });
        

    
    //  *************  Search Api   *************
 
    function searchAjax(){
    
        var listAjax = $.ajax({
        type: 'GET',   // the URL to which the request is sent
        url: wikipediaAPi,  // need a single random wiki page
        dataType: 'jsonp',  // support cross-site requests domains (https://www.mediawiki.org/wiki/API:Cross-site_requests)
        data: dataTypeList,
        traditional: true
    });
        
        listAjax
        .done(function(dataS) {
          console.log('search list produced'+ JSON.stringify(dataS));
          
        //remove previous search
        $("#output").html("");
            
            console.log('dataS[1].length = ' + dataS[1].length);
            
        // reformat css
        $("header").addClass("hide");
        $(".button").addClass("withList");
            
        // 3 = link,  1 = title, 2 = description
            for (var i=0; i<dataS[1].length; i++ ){
                $("#output").append("<li> <a href="+dataS[3][i]+"><h3>"+dataS[1][i]+"</h3><p>"+dataS[2][i]+"</p></a></li>");
                // <li><a href="http....."><h3>Title</h3><p>description</p></a></li>
            }
            
        })
        .fail(function(xhrS) {
          console.log('error callback for seacrh list', xhrS);
        });
  
    }
    

    
     //  *************  Inputs   *************
    
    $( "#randBut" ).on( "click", function(event){
        /* set ajax request values for a random search */
        rndPageAjax();
        console.log("pressed random button");
    } );


    

    $("input").keyup(function(event){
            
        var searchVal = $("input").val(); 
            
        if(event.keyCode==13 && searchVal!==""){
        
            console.log("search dataTypeList value is currently = " + JSON.stringify(dataTypeList.search));
            console.log("search Value = " + searchVal);
            dataTypeList.search = searchVal;
            console.log("search input entry --> dataTypeList = " + JSON.stringify(dataTypeList));
            console.log("search dataTypeList value is now = " + JSON.stringify(dataTypeList.search));
            
            searchAjax();
        }
    });
    

})();



            
          
!
999px

Console