css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

            
              <div id="main">
  <div id="numResultsContainer" class="expandingWidth">
    <div id="numHexagonOuter" class="hexagonOuter">
      <div id="numHexagonOuterLeft" class="hexagonOuterLeft"></div>
      <div id="numHexagonOuterMiddle" class="hexagonOuterMiddle expandingWidth"></div>
      <div id="numHexagonOuterRight" class="hexagonOuterRight"></div>
      <div id="numHexagonInner" class="hexagonInner">
        <div id="numHexagonInnerLeft" class="hexagonInnerLeft"></div>
        <div id="numHexagonInnerMiddle" class="hexagonInnerMiddle expandingWidth">
          <p id="numText" class="topText expandingWidth">Results (1-20):</p>
          <input type="number" id="numResults" class="topText expandingWidth" min="1" max="20" value="5">
        </div>
        <div id="numHexagonInnerRight" class="hexagonInnerRight closeHexagon"></div>
      </div>
    </div>
  </div>
  <div id="randomArticle">
    <div id="randomHexagonOuter" class="hexagonOuter">
      <div id="randomHexagonOuterLeft" class="hexagonOuterLeft"></div>
      <div id="randomHexagonOuterMiddle" class="hexagonOuterMiddle"></div>
      <div id="randomHexagonOuterRight" class="hexagonOuterRight"></div>
      <div id="randomHexagonInner" class="hexagonInner">
        <div id="randomHexagonInnerLeft" class="hexagonInnerLeft"></div>
        <div id="randomHexagonInnerMiddle" class="hexagonInnerMiddle">
          <a id="randomLink" href="https://en.wikipedia.org/wiki/Special:Random" target="_blank" class="topText">Random</a>
        </div>
        <div id="randomHexagonInnerRight" class="hexagonInnerRight"></div>
      </div>
    </div>
  </div>
  <div id="searchForArticle" class="expandingWidth">
    <div id="searchHexagonOuter" class="hexagonOuter">
      <div id="searchHexagonOuterLeft" class="hexagonOuterLeft"></div>
      <div id="searchHexagonOuterMiddle" class="hexagonOuterMiddle expandingWidth"></div>
      <div id="searchHexagonOuterRight" class="hexagonOuterRight"></div>
      <div id="searchHexagonInner" class="hexagonInner">
        <div id="searchHexagonInnerLeft" class="hexagonInnerLeft"></div>
        <div id="searchHexagonInnerMiddle" class="hexagonInnerMiddle expandingWidth">
          <p id="searchString" class="topText expandingWidth">Search:</p>
          <form id="searchForm">
            <input id="searchField" class="topText expandingWidth" type="text">
            <!--Opted for a text field over a search field due to the "X" required to close the box.-->
            <a href="#" id="searchGo" class="topText expandingWidth">Go</a>
          </form>
        </div>
        <div id="searchHexagonInnerRight" class="hexagonInnerRight closeHexagon"></div>
      </div><!--searchHexagonInner-->
    </div><!--searchHexagonOuter-->
  </div><!--searchForArticle-->
  <div id="results">
    <div id="searchResultTitles"></div>
    <div id="searchResultExtracts"></div>
    <!-- At some point, I may choose to implement a "more" button that gets an additional set of results. -->
    <a href="#" id="moreResults"><span>More...</span></a>
  </div>
</div>

            
          
!
            
              body {
	background-color: #b3b3b3;
}

a {
	color: black;
  text-decoration: none;
}

a:hover,
a:active {
  text-decoration: underline;
}

#main {
	height: 55px;
	width: 600px;
	margin-top: 5%;
	margin-left: auto;
	margin-right: auto;
}

/* Styling for each of the different hexagon classes */
.hexagonLeft {
	height: 100px;
}

.hexagonOuter {
	float: left;
	height: 100px;
	overflow: hidden;
}

.hexagonInner {
	position: absolute;
	float: left;
	height: 100px;
	margin-top: 10px;
	overflow: hidden;
}

.hexagonOuterLeft {
	position: relative;
	float: left;
	width: 0px;
	height: 0px;
	border-top: 50px solid transparent;
	border-right: 25px solid #ff6600;
	border-bottom: 50px solid transparent;
}

.hexagonOuterMiddle {
	position: relative;
	float: left;
	height: 100px;
	overflow: hidden;
	background: #ff6600;
}

.hexagonOuterRight {
	position: relative;
	float: left;
	width: 0px;
	height: 0px;
	border-top: 50px solid transparent;
	border-left: 25px solid #ff6600;
	border-bottom: 50px solid transparent;
}

.hexagonInnerLeft {
	position: relative;
	float: left;
	left: 10px;
	width: 0px;
	height: 0px;
	border-top: 40px solid transparent;
	border-right: 20px solid gold;
	border-bottom: 40px solid transparent;
}

.hexagonInnerMiddle {
	position: relative;
	float: left;
	height: 80px;
	margin-left: 10px;
	overflow: hidden;
	background: gold;
}

.hexagonInnerRight {
	position: relative;
	float: left;
	right: 10px;
	width: 0px;
	height: 0px;
	margin-left: 10px;
	border-top: 40px solid transparent;
	border-left: 20px solid gold;
	border-bottom: 40px solid transparent;
}

.topText {
	float: left;
	margin-top: 18px;
	font-family: "Rubik";
	font-size: 28pt;
	white-space: nowrap; 
	overflow: hidden;
	text-overflow: clip;
}

.expandingWidth {
	-webkit-transition: width 2s, opacity 2s;
	transition: width 2s, opacity 2s;
}

/* Styling for the div that controls the number of results displayed */
#numResultsContainer {
	position: relative;
	float: left;
  width: 395px;
	top: 50px;
	left: 205px;
}

#numHexagonOuterMiddle {
	width: 145px;
}

#numHexagonInnerMiddle {
	/*width: 135px;*/
  width: 135px;
}

#numResults {
	width: 65px;
	background-color: gold;
	border: 0px solid;
  text-align: center;
}

#numResults:focus {
	outline: none;
}

/* Styling for the div that controls the random article link */
#randomArticle {
	height: 200px;
	margin-left: 0px;
}

#randomHexagonOuterMiddle {
	width: 180px;
}

#randomHexagonInnerMiddle {
	width: 170px;
}

#randomLink {
	float: left;
	width: 145px;
	margin-left: 13px;
}

/* Styling for the div that contains the search form */
#searchForArticle {
	position: relative;
	float: left;
	height: 100px;
	width: 195px;
	bottom: 50px;
	left: 205px;
}

#searchHexagonOuterMiddle {
	width: 145px;
}

#searchHexagonInnerMiddle {
	width: 135px;
}

#searchString {
	width: 120px;
	margin-left: 9px;
}

#searchField {
	float: left;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: clip;
	width: 0px;
	margin-top: 25px;
	margin-left: 5px;
	font-family: "Rubik";
	font-size: 18pt;
	opacity: 0;
}

/* Highlight the right part of the search box to close it. */
.closeHexagon:hover {
	border-left: 20px solid yellow;
}

#searchGo {
	width: 0px;
	margin-top: 29px;
  margin-left: 5px;
	opacity: 0;
	font-size: 16pt;
}

/* Styling for the results of the search */
#results {
	position: absolute;
	height: 400px;
	width: 740px;
}

.searchResultTitle {
	position: relative;
	float: right;
}

.titleLink p {
	height: 25px;
	white-space: nowrap;
	margin-top: 27px;
	font-family: "Rubik";
	font-size: 16pt;
	font-weight: bold;
}

.searchResult {
	position: relative;
	height: 100px;
	width: 510px;
	top: 50px;
	right: 25px;
}

.searchResult p {
	height: 60px;
	line-height: 20px;
	margin-top: 10px;
	overflow: hidden;
	text-overflow: ellipsis;
	font-family: "Rubik";
	font-size: 12pt;
}

.resultText {
	height: 52px;
	margin-top: 14px;
	font-family: "Rubik";
	font-size: 16pt;
	overflow: hidden;
	text-overflow: ellipsis;
}

#searchResultTitles {
	float: left;
	width: 230px;
}

#searchResultExtracts {
	float: left;
	width: 500px;
}

            
          
!
            
              var numResults = 10;
var extracts = [];
var titles = [];

$(document).ready(function() {
  // Hide the "more results" link until a search result is entered.
  $("#moreResults").hide();
  
  // Function to expand/contract the results box to the right on hover.
  $("#numResultsContainer").hover(function() {
    $("#numHexagonOuterMiddle").width(335);
    $("#numHexagonInnerMiddle").width(325);
    $("#numResults").width(65);
    $("#numResults").css("opacity", "1");
  }, function() {
    // This logic will go in the on-click event for the searchClose button.
  });
  
  $("#numHexagonInnerRight").on("click", function() {
    $("#numHexagonOuterMiddle").width(145);
    $("#numHexagonInnerMiddle").width(135);
    $("#numResults").width(0);
    $("#numResults").css("opacity", "0");
  });
  
  // Function to expand/contract the search box to the right on hover.
  $("#searchForArticle").hover(function() {
    $("#searchForArticle").width(395);
    $("#searchHexagonOuterMiddle").width(335);
    $("#searchHexagonInnerMiddle").width(325);
    $("#searchString").width(130);
    $("#searchField").width(140);
    $("#searchField").css("opacity", "1");
    $("#searchGo").width(30);
    $("#searchGo").css("opacity", "1");
  }, function() {
    // This logic will go in the on-click event for the searchClose button.
  });
  
  $("#searchHexagonInnerRight").on("click", function() {
    $("#searchForArticle").width(195);
    $("#searchHexagonOuterMiddle").width(145);
    $("#searchHexagonInnerMiddle").width(135);
    $("#searchString").width(120);
    $("#searchField").width(0);
    $("#searchField").css("opacity", "0");
    $("#searchGo").width(0);
    $("#searchGo").css("opacity", "0");
  });
  
  $("#searchGo").on("click", function() {
    $("#searchForm").submit();
  })
});

$("#searchForm").submit(function(e) {
  // Prevent the form from executing its default action that would reload the page and get rid of the result data.
  e.preventDefault();
  
  $.ajax({
    url: "https://en.wikipedia.org/w/api.php",
    type: "GET",
    data: { 
      action: "query",
	    format: "json",
	    list: "search",
	    utf8: 1,
	    srsearch: $("#searchField").val(),
      origin: "*",
      srlimit: $("#numResults").val()
    },
    success: function (searchData) {
      // Clear out any old data from the arrays of titles and extracts.
      titles = [];
      extracts = [];
      pageInfo = [];
      
      // Build an array of titles to be used after all of the AJAX calls are done.
      for (var i = 0; i < searchData.query.search.length; i++) {
        titles.push(searchData.query.search[i].title);
        // Make another API call to get the first sentence of the page for the given title.
        $.ajax({
          url: "https://en.wikipedia.org/w/api.php",
          type: "GET",
          data: {
            action: "query",
            format: "json",
            prop: "extracts",
            titles: searchData.query.search[i].title,
            formatversion: 2,
            origin: "*",
            exsentences: 1,
            exintro: 1
          },
          success: function(extractData) {
            // Find the matching title in that array and put the extract in the same place.
            var k = titles.findIndex(function(str) {
              return str === extractData.query.pages[0].title;
            });
            
            extracts[k] = extractData.query.pages[0].extract;
          },
          error: function(extractError) {
            console.log("EXTRACT ERROR");
            console.log(extractError);
          }
        });
      } //end of for loop
      
      // Turn on the More Results link.
      //$("#moreResults").show();
    },
    error: function (searchError) {
      console.log("SEARCH ERROR");
      console.log(searchError);
    }
  });
  
  $("#moreResults").on("click", function() {
    
  });
});

// This function executes after all of the AJAX calls have finished.
// The function builds all of the titles and page extracts into their respective hexagons.
$(document).ajaxStop(function () {
  // Start by removing all of the old results.
  $("#searchResultTitles").empty();
  $("#searchResultExtracts").empty();
  
  // Loop through all of the results.
  for (var i = 0; i < titles.length; i++) {
    // Make a smaller hexagonal shape for the title.
    // Start with the outer hexagon.
    $("#searchResultTitles").append("<div id=\"title" + i + "\" class=\"hexagonLeft expandingWidth searchResultTitle\"></div>");
    
    $("#title" + i).append("<div id=\"hexagonOuterTitle" + i + "\" class=\"hexagonOuter expandingWidth\"></div>");
    $("#hexagonOuterTitle" + i).append("<div id=\"hexagonOuterLeftTitle" + i + "\" class=\"hexagonOuterLeft\"</div>");
    $("#hexagonOuterTitle" + i).append("<div id=\"hexagonOuterMiddleTitle" + i + "\"class=\"hexagonOuterMiddle expandingWidth\"</div>");
    $("#hexagonOuterTitle" + i).append("<div id=\"hexagonOuterRightTitle" + i + "\"class=\"hexagonOuterRight\"</div>");
    
    // Next, make the inner hexagon.
    $("#hexagonOuterTitle" + i).append("<div id=\"hexagonInnerTitle" + i + "\" class=\"hexagonInner expandingWidth\"></div>");
    $("#hexagonInnerTitle" + i).append("<div id=\"hexagonInnerLeftTitle" + i + "\" class=\"hexagonInnerLeft\"></div>");
    $("#hexagonInnerTitle" + i).append("<div id=\"hexagonInnerMiddleTitle" + i + "\" class=\"hexagonInnerMiddle expandingWidth\"></div>");
    $("#hexagonInnerTitle" + i).append("<div id=\"hexagonInnerRightTitle" + i + "\" class=\"hexagonInnerRight\"></div>");
    
    // Add the title from the JSON as a link to the actual wiki page.
    $("#hexagonInnerMiddleTitle" + i).append("<a href=\"https://en.wikipedia.org/wiki/" + titles[i] + "\" class=\"titleLink\" target=\"_blank\"><p id=\"title" + i + "text\">" + titles[i] + "</p></a>");
    
    // Set the widths of all the divs in the hexagon based on the width of the text field.
    var textWidth = $("#title" + i + "text").width();
    
    $("#title" + i).width(textWidth + 60);
    $("#hexagonOuterTitle" + i).width(textWidth + 60);
    $("#hexagonOuterMiddleTitle" + i).width(textWidth + 10);
    $("#hexagonInnerTitle" + i).width(textWidth + 60);
    $("#hexagonInnerMiddleTitle" + i).width(textWidth + 0);
    
    // Make an expanded hexagonal shape for the description.
    // Start with the outer hexagon.
    $("#searchResultExtracts").append("<div id=\"result" + i + "\" class=\"searchResult\"</div>");
    $("#result" + i).append("<div id=\"hexagonOuterResult" + i + "\" class=\"hexagonOuter\"></div>");
    $("#hexagonOuterResult" + i).append("<div id=\"hexagonOuterLeftResult" + i + "\" class=\"hexagonOuterLeft\"</div>");
    $("#hexagonOuterResult" + i).append("<div id=\"hexagonOuterMiddleResult" + i + "\"class=\"hexagonOuterMiddle\"</div>");
    $("#hexagonOuterResult" + i).append("<div id=\"hexagonOuterRightResult" + i + "\"class=\"hexagonOuterRight\"</div>");
    
    // Expand the outer hexagons to the proper width.
    $("#hexagonOuterResult" + i).width(385);
    $("#hexagonOuterMiddleResult" + i).width(335);
    
    // Next, make the inner hexagon.
    $("#hexagonOuterResult" + i).append("<div id=\"hexagonInnerResult" + i + "\" class=\"hexagonInner\"></div>");
    $("#hexagonInnerResult" + i).append("<div id=\"hexagonInnerLeftResult" + i + "\" class=\"hexagonInnerLeft\"</div>");
    $("#hexagonInnerResult" + i).append("<div id=\"hexagonInnerMiddleResult" + i + "\" class=\"hexagonInnerMiddle\"</div>");
    $("#hexagonInnerResult" + i).append("<div id=\"hexagonInnerRightResult" + i + "\" class=\"hexagonInnerRight\"</div>");
    
    // Expand the inner hexagons to the proper width.
    $("#hexagonInnerResult" + i).width(385);
    $("#hexagonInnerMiddleResult" + i).width(325);
    
    $("#hexagonInnerMiddleResult" + i).append(extracts[i]);
    //$("#hexagonInnerMiddleResult" + i).append("<p class=\"resultText\">" + extracts[i] + "</p>");
  }
});

            
          
!
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.
Loading ..................

Console