Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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 ng-app="wikiSearch">

  <form ng-submit="search()" ng-controller="searchCtrl">
    <div id="search" ng-class="{'wholeScreen': noEntries}">
      <input id="input" placeholder="Search..." type="text" ng-model="searchInput" ng-focus="focus()"/>
      <button id="button" type="submit" ng-show="!isFocused"><span class="screen-reader-text">Search</span><i class="fa fa-search"></i></button>
      <button id="button" type="button" ng-show="isFocused" ng-click="unFocus()"><span class="screen-reader-text">Exit</span><i class="fa fa-close"></i></button>
      <div class="spinner"><i class="fa fa-spinner"></i></div>

      <a class="randomButton" ng-href="https://en.wikipedia.org/wiki/Special:Random" target="_blank"><i class="fa fa-random"></i></a>
    </div>
  </form>


  <articles></articles>

  <script type="text/ng-template" id="articles.html">
    <div class="wiki-article animate-enter" ng-repeat="article in articles">
      <a ng-href="https://en.wikipedia.org/wiki/{{article.title | encodeURIComponent}}" target="_blank">
        <h1 ng-bind-html="article.title | renderHTMLCorrectly" class="article-title">
        </h1>
        <p ng-bind-html="article.snippet | renderHTMLCorrectly">
        </p>
      </a>
    </div>
  </script>
</div>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

body {
  background: #0E8FB1;
  color: #fff;
  font-family: 'Lato', sans-serif;
  -webkit-box-align: center;
  -webkit-align-items: center;
      -ms-flex-align: center;
          align-items: center;
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  -webkit-flex-flow: column nowrap;
      -ms-flex-flow: column nowrap;
          flex-flow: column nowrap;
  height: 100%;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
      -ms-flex-pack: center;
          justify-content: center;
  width: 100%;
}

/* Search Form */

form, #search {
  -webkit-box-align: center;
  -webkit-align-items: center;
      -ms-flex-align: center;
          align-items: center;
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
}

form {
  -webkit-flex-flow: column nowrap;
      -ms-flex-flow: column nowrap;
          flex-flow: column nowrap;
}

#search {
  -webkit-box-pack: justify;
  -webkit-justify-content: space-between;
      -ms-flex-pack: justify;
          justify-content: space-between;
  margin: 0.5em 0;
  padding: 1em 0.5em 0.5em 1em;
  -webkit-transition: all 0.5s;
  transition: all 0.5s;
  max-width: 400px;
}

.wholeScreen {
  height: 100vh;
}

#search button, #search input {
  -webkit-appearance: none;
     -moz-appearance: none;
          appearance: none;
  background: transparent;
  
  color: inherit;
  font: inherit;
  outline: 0;
}

#button {
  border: 0;
  cursor: pointer;
  padding: 0 0.25em;
}

#search input {
  -webkit-box-flex: 1;
  -webkit-flex: 1;
      -ms-flex: 1;
          flex: 1;
  border: 0;
	border-bottom: 3px solid white;
  background: transparent;
  height: 30px;
  color: white;
  font-family: 'Lato', sans-serif;
  font-size: 1.3em;
}

#search .spinner {
  -webkit-animation: spinner 1s infinite linear;
          animation: spinner 1s infinite linear;
  display: none;
  padding: 0 0.25em;
}

/* Spinner Animations */

#search.loading button {
  display: none;
}
#search.loading .spinner {
  display: block;
}

@-webkit-keyframes spinner {
  0% {
    -webkit-transform: rotate(0deg);
            transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(360deg);
            transform: rotate(360deg);
  }
}

@keyframes spinner {
  0% {
    -webkit-transform: rotate(0deg);
            transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(360deg);
            transform: rotate(360deg);
  }
}

/* Placeholder Text */

::-webkit-input-placeholder {
  color: #fff;
  font-size: 1.2em;
}
:-moz-placeholder {
  color: #fff;
  font-size: 1.2em;
}
::-moz-placeholder {
  color: #fff;
  font-size: 1.2em;
}
:-ms-input-placeholder {
  color: #fff;
  font-size: 1.2em;
}

/* Alter autofill styles */

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
  transition: background-color 5000s ease-in-out 0s;
  -webkit-text-fill-color: #fff;
  -webkit-text-size: 1.5em;
}

/* Random Article Buttons */
.randomButton {
  background: transparent;
  border: none;
}

.fa-search, .fa-random , .fa-spinner, .fa-close {
  color: white;
  font-size: 2em;
}

/* Button Screen Reader Text */

.screen-reader-text {
  height: auto;
  width: 1px;
  clip: rect(1px, 1px, 1px, 1px);
  height: 1px;
  overflow: hidden;
  position: absolute !important;
}
.screen-reader-text:hover, .screen-reader-text:active, .screen-reader-text:focus {
  height: auto;
  width: auto;
  background-color: #000000;
  border-radius: 2px;
  box-shadow: 0 0 2px 2px rgba(0, 0, 0, 0.6);
  clip: auto !important;
  color: #FFFFFF;
  display: block;
  font-size: 0.875rem;
  font-weight: 700;
  left: 0.3125rem;
  line-height: normal;
  padding: 0.9375rem 1.4375rem 0.875rem;
  text-decoration: none;
  top: 0.3125rem;
  z-index: 100000;
}

/* Results Styles*/
.wiki-article {
  background: #EDE8E8;
  padding: 10px 10px 20px 14px;
  margin-bottom: 10px;
  border-left: 6px #EDE8E8 solid; /* Cheat to stop the div from moving on hover */
}

.wiki-article a {
  text-decoration: none;
  color: black;
}

.wiki-article:hover {
  border-left: 6px #5C2A6F solid;
}

/* Animations */
.animate-enter
{ 
    -webkit-animation: fadeInUp 1.5s;
    animation: fadeInUp 1.5s;
} 

              
            
!

JS

              
                // on submit, take in query from input
// build search string
// https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=meaning
// 
//submit xhr request
//receive JSON
//output to a div in the html
'use strict';
var app = angular.module('wikiSearch', []);

//A filter allows us to render the HTML correctly
//See here: http://www.saintsatplay.com/blog/2015/02/parsing-html-data-from-an-array-inside-an-angularjs-view#.VyaRbaODGko
app.filter('renderHTMLCorrectly', function($sce)
{
	return function(stringToParse)
	{
		return $sce.trustAsHtml(stringToParse);
	}
});

/*A filter to encode title properly*/
app.filter('encodeURIComponent', function() {
    return window.encodeURIComponent;
});

app.controller('searchCtrl', function($scope, $http, $rootScope, dataService){
  function constructQuery (searchTerm) {
    var query = 'https://en.wikipedia.org/w/api.php?format=json&action=query&prop=info&list=search&srsearch=';
    query += searchTerm;
    return query;
  }
  var self = this;
  
  var search = document.getElementById('search');
  var button = document.getElementById('button');
  var input = document.getElementById('input');
  
  // Activates spinner animation
  $scope.loading = function() {
	  search.classList.add('loading');
	
	  setTimeout(function() {
		  search.classList.remove('loading');
	  }, 1500);
  }
  
  // Use isFocused to show or hide the exit button
  $scope.isFocused = false;
  // Use noEntries to either move search to middle of screen or not
  $scope.noEntries = true;
  
  // Called on input focus
  $scope.focus = function() {
    $scope.isFocused = true;
  };
  
  // Called when exit button is clicked
  // Removes entries and resets search box
  $scope.unFocus = function() {
    $scope.isFocused = false;
    $scope.searchInput = "";
    $rootScope.articles = null;
    $scope.noEntries = true;
  };
  
  
  $scope.search = function() {
    /*loadRemoteData();*/
    $scope.loading();
   var query = constructQuery($scope.searchInput);
 /*Couldnt figure out how to share without rootscope*/      dataService.getWikiResults(query).then(function(response){
     $rootScope.articles = response;
     console.log($rootScope.articles);
  });
    $scope.noEntries = false;
  };
  
});

app.service('dataService', function($http){
    return({
      getWikiResults: function (query) {
    return $http.jsonp(query + "&callback=JSON_CALLBACK").then(function(response){
      return response.data.query.search;
    });
  }
    });
  
  //Took forever to arrive here!
  //jsonp necessary to circumvent cross origin issue
  //necessitates adding JSON CALLBACK to get the data, otherwise, expects more than plain JSON
  
});

app.directive('articles', function(){
  return {
    restrict: 'E',
    templateUrl: 'articles.html',
    controller: 'searchCtrl',
    replace: true,
    
  }
});
              
            
!
999px

Console