cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              <div class="container">
	<h1><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/331813/treehouse.svg" />Treehouse Performance Profile<br /><small>with AJAX</small></h1>
	<p><button id="updateMetrics">Update</button> <span  id="status">Updating...</span></p>
</div>
<div class="container">
	<div id="aboutUser" class="well">
		<div class="row">
			<div id="gravatar" class="col-sm-3">
				
			</div>
			<div class="col-sm-9">
				<p id="userName"></p>
				<p id="totalPoints"></p>
				<div id="colorLine"></div>
			</div>
		</div>
	</div>
</div>
<div class="container">
	<div id="pointsContainer" class="well">
		
	</div>
</div>
<div class="container">
	<div id="badgeTimeline" class="well">

	</div>
</div>
            
          
!
            
              *, *:before, *:after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  width: 100%;
  height: 100%;
}

body {
  position: relative;
  width: 100%;
  height: 100%;
  background: #F5F5F5;
  font-family: Muli, sans-serif;
  font-size: 16px;
	color: #333;
}

h1 {
	overflow: hidden;
}

h1 img {
	width: 42px;
	height: auto;
	padding-right: 8px;
}

h1 small {
	padding-left: 50px;
}

button, a, #badgeTimeline p {
	-webkit-transition: all .15s linear;
	 -moz-transition: all .15s linear;
	-o-transition: all .15s linear;
	transition: all .15s linear;
}

.well {
	border: 2px solid #ccc;
	background: #FBFBFB;
}

#colorLine {
	width: 100%;
	height: 20px;
	text-align: center;
}

@media (min-width: 768px) {
	#colorLine {
		width: 50%;
		text-align: left;
	}
}

.colorPiece {
	display: inline-block;
	height: 100%;
}

@media (min-width: 768px) {
	colorPiece {
		display: block;
		float: left;
	}
}

.points {
	font-weight: 700;
	color: #006C21;
}

#status {
	font-size: 0.8em;
	color: #ccc;
}

#gravatar {
	text-align: center;
}

#gravatar img {
	padding: 2px;
	width: 140px;
	max-width: 70%;
	height: auto;
	border-radius: 50%;
	border: 2px solid #20A749;
}

#userName {
	font-size: 1.5em;
	overflow: hidden;
}

#aboutUser p {
	text-align: center;
}

@media (min-width: 768px) {
	#aboutUser p {
		text-align: left;
	}
}

#updateMetrics {
	font-size: 0.8em;
	padding: 1px 4px;
	background: none;
	border: 2px solid #ccc;
	outline: none;
	border-radius: 3px;
}

#updateMetrics:hover {
	border-color: #20A749;
}

.pointBox {
	text-align: center;
	text-overflow: ellipsis;
	overflow: hidden;
	padding: 10px 20px 20px 20px;
	position: relative;
}

.pointBox .colorBar {
	position: absolute;
	width: 50%;
	max-width: 100px;
	height:8px;
	top: 0;
	left: 50%;
	-webkit-transform: translateX(-50%);
	-moz-transform: translateX(-50%);
	-ms-transform: translateX(-50%);
	-o-transform: translateX(-50%);
	transform: translateX(-50%);
	content: '';
	border-radius: 3px;
}

#badgeTimeline {
	overflow: auto;
}

#badgeTimeline img {
	display: block;
	width: 50px;
	height: auto;
	float: left;
	margin-right: 8px;
}

#badgeTimeline p {
	position: relative;
	float: left;
	overflow: hidden;
	width: 100%;
	height: 100px;
	padding: 15px 46px 0 0;
	margin: 0;
	text-overflow: ellipsis;
}

#badgeTimeline p:hover {
	background-color: #eee;
}

@media (min-width: 768px) {
	#badgeTimeline p {
		width: 50%;
	}
}
            
          
!
            
              var user = 'daev',
urlJSON = "https://teamtreehouse.com/" + user + ".json",
langColors = {
			"JavaScript": "#c25975",
			"CSS": "#317aab",
			"HTML": "#39add1",
			"Development Tools": "#637a91",
			"PHP": "#7d669e",
			"WordPress": "#838cc7",
			"Databases": "#eb7728",
			"C#": "#9e4d83",
			"Game Development": "#228a8d",
			"Digital Literacy": "#c38cd4",
			"Java": "#2c9676",
			"Python": "#f095b2",
			"Business": "#f9845b",
			"Android": "#5cb860",
			"iOS": "#53bbb4",
			"Ruby": "#e15258",
			"Design": "#e59a13"
		},

colorLine = {};

//On a successful request, show the updated time
$(document).ajaxSuccess(function( event, xhr, settings ) {
  if ( settings.url == urlJSON ) {
		var dt = new Date();
		var time = dt.getHours() + ":" + dt.getMinutes() + ":" + dt.getSeconds();
    $('#status').text('Updated at ' + time);
  }
});

//On an unsuccessful request, show an error
$(document).ajaxError(function( event, xhr, settings ) {
  if ( settings.url == urlJSON ) {
    $('#status').text('Data not found!');
  }
});

$(document).ready(function() {
	
	//Make the request
	function refreshMetrics(){
    $('#status').text('Updating...');
    $.get(urlJSON, function(data, status){
			
			//To count the number of 'col-sm-3' elements in a row
			var rowCounter = 0;
			
			//Create the Profile area
			$('#gravatar').html("<img src='" + data['gravatar_url'] + "' />");
			$('#userName').html(data['name']+" <small>("+data['profile_name']+")</small>");
			
			//Create the Points area
			var totalPoints = 0;
			var pointsHTML = "<div class='row'>";
			
			//For each skill...
			$.each(data.points, function (skill, points) {
        if(points > 0) {
					//Leave out 'Total', put it in the profile area
					if(skill == "total") {
						totalPoints += points;
						$('#totalPoints').html('Total Points: <span class="points">' + points + '</span>');
					} else {
						//Add a color to the color line array
						colorLine[skill] = Math.round(100*(points/totalPoints));
						//Create a points box
						pointsHTML += "<div class='col-sm-3 pointBox'>";
						pointsHTML += "<div class='colorBar' style='background-color: " + langColors[skill] + "'></div>"
						pointsHTML += skill + "<br /><span class='points'>" + points + "</span>";
						pointsHTML += "</div>";
						//Check how many 'col-sm-3' elements in a row (Bootstrap row)
						rowCounter++;
						if (rowCounter > 3) {
							rowCounter = 0;
							pointsHTML += "</div>";
							pointsHTML += "<div class='row'>";
						}
					}
				}
    	});
			pointsHTML += "</div>";
			$('#pointsContainer').html(pointsHTML);
			
			//Create the Color Line
			var colorLineHTML = "";
			$.each(colorLine, function(skill, percent) {
				colorLineHTML += "<div class='colorPiece' style='background:" + langColors[skill] + ";width:" + percent + "%;'></div>";
			});
			$("#colorLine").html(colorLineHTML);
			
			//Create the Badges area
			var badgesHTML = "";
			$.each(data.badges, function (i, badge) {
				badgesHTML += "<p><img src='" + badge.icon_url + "' /> " + badge.name + "<br /><span class='small'>" + badge.earned_date.substring(0,10) + "</span></p>";
    	});
			$("#badgeTimeline").html(badgesHTML);
		});
	}
	
	//Do all the things
	refreshMetrics();
	
	//Do all the things every so often
	setInterval(function(){refreshMetrics();}, 300000);
	
	//Do all the things when 'Update' is clicked
	$('#updateMetrics').on('click', function() {
		refreshMetrics();
	});
	
});
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console