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

              
                <!-- TODO: style filter buttons -->
<!-- TODO: display # of users watching in real time -->

<link href="https://fonts.googleapis.com/css?family=Open+Sans|Raleway" rel="stylesheet">

<br>
<div class="container">
  <h1>twitch.tv</h1>
  <br>
  <div class="channel-filters">
      <input class="filter-positive" value ="all" type="radio" id="all" name="filter" checked="checked"/>
      <label for="all">all</label>

      <input class="filter-positive" value ="online" type="radio" id="online" name="filter" />
      <label for="online">online</label>

      <input class="filter-negative" value ="online" type="radio" id="offline" name="filter"/>
      <label for="offline">offline</label>

      <input class="filter-positive" value="active" type="radio" id="active" name="filter" />
      <label for="active">active</label>
  </div>
  <div class="channels">
    <input type="text" class="live-search-box" placeholder="search here" /><br><br>
  </div>
  <br>
  <h2>created by scamargo</h2>
  <br>
</div>
              
            
!

CSS

              
                body{
  background-color:#39A0ED;
  color:#F6E8EA;
  font-family: 'Raleway', sans-serif;
}

h1{
  text-align: center;
  font-size: 3em;
  color:#F6E8EA;
}

h2 {
  text-align:center;
}

.container {
  width: 95%;
  max-width: 500px;
  margin: auto;
}

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

.channels{
  width: 100%;
  margin: auto;
  min-height: 44vh; /* ensure name appears at bottom */
}

.live-search-box{
  width: 100%;
  max-width: inherit;
  margin: inherit;
  font-size: 2em;
  color: black;
  box-sizing: border-box;
  border: 2px solid #ccc;
  border-radius: 4px;
  background-image: url('https://cdn1.iconfinder.com/data/icons/hawcons/32/698627-icon-111-search-128.png');
  background-repeat: no-repeat;
  background-size: contain;
  padding: 10px 30px 12px 70px;
}

.channel {
  padding: 1em 1em 1em 5em;
  margin: .2rem 0 0 0;
  font-family: 'Open Sans', sans-serif;
  font-weight:bold;
  background-repeat: no-repeat;
  background-size: 3.4rem; /*fix size to match div */
}

.online {
  background-color: #EE4266;
}

.offline {
  background-color: #F6E8EA;
  color:#22181C;
}

.offline .detail {
  font-style: italic;
}

.inactive {
  padding: 1em;
}

.detail {
  display: none;
  font-style: normal;
}

.channel-filters {
  width: 100%;
  margin: 5px auto;
  font-size: 1em;
  color: black;
  box-sizing: border-box;
  text-align: center;
}

.channel-filters label, .channel-filters input {
    line-height:1em;
    color: #F6E8EA;
}

.channel-filters input[type="radio"] {
    opacity:.01;
    height: 1em;
    display: inline;
    z-index: 90;
    position: absolute; /* fixed input so it can't be clicked */
}

.channel-filters input[type="radio"]:checked + label {
    background:#205882;
}

.channel-filters label {
    width: 24.3%; 
    padding:5px;
    border:1px solid #F6E8EA; 
    cursor:pointer;
    display: inline-block;
    box-sizing: border-box;
    position: relative;
    z-index: 100;
}

/* Default styles first then media queries */
@media screen and (min-width: 400px)  {
  
  .detail {
    display: inline;
    float:right;
  }
}
@media screen and (min-width: 600px)  {...}
@media screen and (min-width: 1000px) {...}
@media screen and (min-width: 1400px) {...}

              
            
!

JS

              
                var channels = ["ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas","comster404","360chrism"];

var twitchApi = "https://wind-bow.gomix.me/twitch-api/";

var Channel = function(name,url,game,logo,status) {  
  this.active = (status != "404");
  this.name = name;
  this.url = url;
  this.game = game;
  this.logo = logo;
  this.online = (game != null);
};

var channelMap = {};
var channelArr = [];

$(document).ready(function() {
  var html = $(".channels").html();
  
  for(var i = 0;i< channels.length;i++) {
    var channelUrl = twitchApi + "channels/" + channels[i];    
    (function(i) { 
      // get channel data
      $.getJSON(channelUrl, function(json) {
        var channelObj = parseChannelData(json,channels[i]);
        channelArr.push(channelObj);    
        sortArray();   
        // build channels div
        if (channelArr.length == channels.length) { // after adding all channels
          for(var j = 0; j < channelArr.length;j++) {
            $(".channels").append(buildChannelElement(channelArr[j]));
          }
        }
      });
    })(i) //protect i w/in getJSON    
  } //for loop 
  
  function parseChannelData(data,chName) {
    var newChannel = new Channel(chName,data.url, data.game,data.logo,data.status);     
    channelMap[newChannel.name] = newChannel;
    return newChannel;
  }
  
  function sortArray() {
    channelArr.sort(function(a,b) {
      if((!a.online && b.online) || 
         (!a.active && b.active)){
        return 1;
      } 
      else if((a.online && !b.online) || 
              (a.active && !b.active)) {
        return -1;
      } 
      return 0;
    });
    
    channelArr.sort(function(a,b) {
      if(!a.active && b.active) {
        return 1;
      } 
      else if(a.active && !b.active){
        return -1;
      }
      return 0;
    });
  }
  
  function buildChannelElement(chObj) {

    var link = document.createElement('a');
    var item = document.createElement('div');
    item.appendChild(document.createTextNode(chObj.name));   
    var detail = document.createElement('div');
    detail.setAttribute("class","detail");
 
    // Create custom attributes
    var att = document.createAttribute("data-search-term"); 
    att.value = chObj.name.toLowerCase();
    item.setAttributeNode(att);
    att = document.createAttribute("online");
    att.value = chObj.online;
    item.setAttributeNode(att);
    att = document.createAttribute("active");
    att.value = chObj.active;
    item.setAttributeNode(att);

    if(!chObj.active) {
      item.setAttribute("class","channel offline inactive");
      detail.appendChild(document.createTextNode("inactive"));
    }
    else { //channel is active
      item.setAttribute("style","background-image:url("+chObj.logo+")");
      link.setAttribute("href",chObj.url);
      link.setAttribute("target","_blank");

      if (!chObj.online) {
        item.setAttribute("class","channel offline");
        detail.appendChild(document.createTextNode("offline"));
      }
      else { //channel is online
        item.setAttribute("class","channel online");
        var detailText = truncate(chObj.game,18);
        detail.appendChild(document.createTextNode(detailText));
      }
    }
    
    item.appendChild(detail);
    link.appendChild(item);
    return link;
  } //buildChannelElement
  
  function truncate(str, maxLength) {
    if(str.length < maxLength) {
      return str;
    }
    return str.substring(0,maxLength-3) + "...";
  }
  
  function sortChannels() {
    $('.channels div').each(function(){
        if ($(this).filter('[data-search-term *= ' + searchTerm + ']').length > 0 || searchTerm.length < 1) {
            $(this).show();
        } else {
            $(this).hide();
        }
    });
  }
  
  $('.live-search-box').on('keyup', function(){ //TODO: make search work with filters
    var searchTerm = $(this).val().toLowerCase();
    $('.channels div').each(function(){
        if ($(this).filter('[data-search-term *= ' + searchTerm + ']').length > 0 || searchTerm.length < 1) {
            $(this).show();
        } else {
            $(this).hide();
        }
    });
  }); //.on keyup
  
  $('.filter-positive').click(function(){ 
    var filterType = $(this).val();
    $('.channels div').each(function(){
        if ($(this).filter('[' + filterType + ' *= true]').length > 0 || filterType == "all" || $(this).attr('class') == "detail") {
            $(this).show();
        } else {
            $(this).hide();
        }
    });
  }); // filter-positve btn clicked
  
  $('.filter-negative').click(function(){ 
    var filterType = $(this).val();
    $('.channels div').each(function(){
        if ($(this).filter('[' + filterType + ' *= false]').length > 0 
            || $(this).attr('class') == "detail") {
            $(this).show();
        } else {
            $(this).hide();
        }
    });
  }); // filter-negative btn clicked
  
}); // document.ready
              
            
!
999px

Console