HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<div id="main" class="container clear-top text-center">
<div id="wrap">
<div id="main" class="container clear-top text-center">
<!-- TwitchTVChannels list -->
<div class="panel panel-info">
<!-- Default panel contents -->
<div class="panel-heading text-center panel-relative">
<h4>Twitch TV Channels</h4>
<!-- show all/online/offline dropdown -->
<div class="btn-group btn-right">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Show All <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="#">Show All</a></li>
<li><a href="#">Online</a></li>
<li><a href="#">Offline</a></li>
</ul>
</div>
<!-- END: show all/online/offline dropdown -->
</div>
<div class="panel-body">
<!-- /<p>...</p> -->
</div>
<!-- List group -->
<ul id="TwitchTVChannelsList" class="list-group">
</ul>
</div>
</div><!-- container -->
</div><!-- wrap -->
<!-- footer -->
<footer class="bg-footer footer-app-colophon text-gray-light text-sm text-center">
<p>Bootstrap theme designed and coded with <i class="fa fa-coffee fa-1" title="coffee" aria-hidden="true"></i> by
<a href="https://codepen.io/lorepirri/full/WpBJKO/" title="lorepirri" target="_blank">me</a> :)
</p>
</footer>
$body-bg-color: white;
$body-color: #435071;
.container {
padding: 70px 0px 70px 0px;
}
body {
background-color: $body-bg-color;
color: $body-color;
font-size: 14px;
font-weight: 300;
font-family: RobotoDraft, Roboto, sans-serif;
}
a {
text-decoration: none;
}
a.disabled {
pointer-events: none;
cursor: default;
}
a:hover {
text-decoration: none;
}
footer {
font-size: 14px;
font-weight: 300;
padding-top: 30px;
padding-bottom: 30px;
color: grey;
position: relative;
margin-top: -60px; /* negative value of footer height */
height: 60px;
clear:both;
padding-top:20px;
}
/* this makes the footer stays always down */
html, body {
height: 100%;
}
#wrap {
min-height: 100%;
}
#main {
overflow:auto;
padding-bottom:150px; /* this needs to be bigger than footer height*/
}
var myStreams = ["ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas", "brunofin", "comster404", "totallynotexistingname"];
function fixedEncodeURIComponent(str) {
return encodeURIComponent(str).replace(/[!'()*]/g, function(c) {
return '%' + c.charCodeAt(0).toString(16);
});
}
function updateUIaddChannel(UIParams) {
var newChannel = "";
// apply an HTML template to the channel/stream info
newChannel += '<li class="list-group-item '+ (UIParams.streamInfo.online?"online":"offline") +'">';
newChannel += '<div class="row align-items-center">';
// logo
// name
newChannel += '<div class="col col-xs-2">';
var imgSrc = UIParams.channelInfo.logo?UIParams.channelInfo.logo:"https://static-cdn.jtvnw.net/jtv_user_pictures/xarth/404_user_70x70.png";
newChannel += '<img class="img-responsive img-circle" src="' + imgSrc + '"title="' + UIParams.channelInfo.name + '" alt="' + UIParams.channelInfo.name + '">';
newChannel += '</div><!-- col -->';
newChannel += '<div class="col col-xs-10">';
// name
newChannel += '<div><h4>[';
if (UIParams.channelInfo.url) {
newChannel += '<a href="' + UIParams.channelInfo.url + '" target="_blank"> ';
}
newChannel += UIParams.channelInfo.name;
if (UIParams.channelInfo.url) {
newChannel += '</a>';
}
newChannel += ' ]</h4></div>';
// description
if (UIParams.streamInfo.online) {
newChannel += '<div><span class="itemSnippet"><b>' + UIParams.streamInfo.game + '</b> - ';
newChannel += '' + UIParams.channelInfo.status + ' ';
newChannel += ' <div><span class="label label-success" title="Viewers">' + UIParams.streamInfo.viewers + '</span>';
newChannel += ' <span class="label label-primary" title="Views">' + UIParams.channelInfo.views + '</span></div>';
newChannel += '</div>';
} else if (UIParams.channelInfo.notfound && UIParams.channelInfo.notfound === true) {
newChannel += '<div class="itemSnippet"><span class="label label-danger">not found</span></div>';
} else {
newChannel += '<div class="itemSnippet"><span class="label label-default">offline</span></div>';
}
newChannel += '</div><!-- col -->';
newChannel += '</div><!-- row -->';
newChannel += '</li>';
// append the new channel info to the list
$("#TwitchTVChannelsList").append(newChannel);
console.log("update UI");
console.log(UIParams);
}
function formatChannel(channel) {
return {
name: channel.name,
logo: channel.logo,
url: channel.url,
status: channel.status,
views: channel.views
};
}
function formatNotFoundData(channel) {
var streamInfo = { online: false };
var channelInfo = {
name: channel,
logo: null,//"https://www.twitch.tv/images/xarth/bg_glitch_pattern.png",
url: null,
status: "",
views: 0,
notfound: true
};
console.log("format not found data");
console.log(channel);
return {
streamInfo: streamInfo,
channelInfo: channelInfo
};
}
function formatData(response) {
// convert response into UIParams
var streamInfo = { online: false };
var channelInfo = {};
if (response.stream) {
// the channel is currently streaming
streamInfo.online = true;
// inside there is also the the channel info
if (response.stream.game) {
streamInfo.game = response.stream.game;
}
streamInfo.viewers = response.stream.viewers;
if (response.stream.links && response.stream.links.self) {
streamInfo.link = response.stream.links.self;
}
if (response.stream.channel) {
channelInfo = formatChannel(response.stream.channel);
}
} else {
// the channel is not streaming and
// this is only the channel info
channelInfo = formatChannel(response);
}
console.log("format data");
console.log(response);
return {
streamInfo: streamInfo,
channelInfo: channelInfo
};
}
function fetchChannel(channel) {
// api.twitch.tv requires now the Client-ID
// https://blog.twitch.tv/client-id-required-for-kraken-api-calls-afbb8e95f843
$.ajax({
type: 'GET',
url: 'https://api.twitch.tv/kraken/channels/' + channel,
headers: {
'Client-ID': '1l1xqs7sgng638sq5pfe0xu0rpum9m' // lorepirri's Client-ID, this can be public, no problem
},
success: function(response) {
console.log('channel success!');
updateUIaddChannel(formatData(response)); // update UI
},
error: function(err) {
console.error("channel error!");
if (err.status && err.status === 404) {
console.error("error channel not found");
updateUIaddChannel(formatNotFoundData(channel));
}
}
});
}
function fetchChannelsStream(channel) {
// api.twitch.tv requires now the Client-ID
// https://blog.twitch.tv/client-id-required-for-kraken-api-calls-afbb8e95f843
$.ajax({
type: 'GET',
url: 'https://api.twitch.tv/kraken/streams/' + channel,
headers: {
'Client-ID': '1l1xqs7sgng638sq5pfe0xu0rpum9m' // lorepirri's Client-ID, this can be public, no problem
},
success: function(response) {
console.log('stream success!');
if (response.stream) {
updateUIaddChannel(formatData(response)); // update UI
} else {
fetchChannel(channel);
}
},
error: function(err) {
console.error(err);
console.error("stream error!");
}
});
}
function fetchData() {
myStreams.forEach(fetchChannelsStream);
}
function filterChannelsByStatus(status) {
switch (status) {
case "Online":
$('.online').removeClass("hidden");
$('.offline').addClass("hidden");
break;
case "Offline":
$('.online').addClass("hidden");
$('.offline').removeClass("hidden");
break;
default:
$('.online').removeClass("hidden");
$('.offline').removeClass("hidden");
break;
}
}
$(document).ready(function() {
fetchData(); // first fetch on page ready
// on filter channel status change
$('.dropdown-menu li a').click(function (e) {
var newHeading = $(this).text();
var $heading = $('.dropdown-toggle');
var $caret = $('.caret', $heading);
$heading.html(newHeading + ' ').append($caret);
filterChannelsByStatus(newHeading);
});
});
Also see: Tab Triggers