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

              
                  <div class=giar>
    <h1>Loading...</h1>
    <div class=votes>
      <span class=down>0</span><span class=up>0</span>
    </div>
    <div class="reading-list">
      <h2>Reading List</h2>
      <ul>
        <li>Items will be added here</li>
      </ul>
    </div>
    <a href="#" class="clear-list">clear</a>
  </div>

              
            
!

CSS

              
                 .giar {
	position: relative;
	width: 40%;
	margin: 0 auto;
	text-align: center;
	font-family: Helvetica Neue, Helvetica, sans-serif;
	color: #466;
 }
 .giar h1 {
	min-height: 1em;
 }
 .giar .votes {
	position: relative;

	margin: 2em auto;
	font-size: 2em;
 }
 .giar .votes span {
	border: 1px solid #eee;
	cursor: pointer;
	display: inline-block;
	padding: .5em;
 }
 .giar .votes span:hover {
	background: #eee;
 }
 .giar .votes .down {
	margin-right: .3em;
 }
 .giar .votes .down:before {
	content: "👎 ";
 }
 .giar .votes .up {
	margin-left: .3em;
 }
 .giar .votes .up:before {
	content: "👍 ";
 }
 .reading-list ul{
	list-style: none;
	padding: 0;
 }
 .reading-list ul li{
	padding-bottom: .5em;
	margin-bottom: .5em;
	border-bottom: 1px solid #eee;
 }
 a{
	text-decoration: none;
	color: #69c;
 }
 a:hover{
	color: #699;
 }
 .clear-list{
	color: #930;
 }
 .clear-list:hover{
	color: #600;
 }
              
            
!

JS

              
                var posts_mockup = [
	{ ID: 1, title: "First Post Title", permalink: 'http://example.com/1/', upvotes: 12, downvotes: 2 },
	{ ID: 22, title: "Second Post Title", permalink: 'http://example.com/2/', upvotes: 1, downvotes: 22 },
	{ ID: 33, title: "Third Post Title", permalink: 'http://example.com/3/', upvotes: 5, downvotes: 4 },
	{ ID: 44, title: "Fourth Post Title", permalink: 'http://example.com/4/', upvotes: 2, downvotes: 2 },
	{ ID: 55, title: "Fifth Post Title", permalink: 'http://example.com/5/', upvotes: 8, downvotes: 13 },
];

var $el;
var posts = {};
var votedOn = JSON.parse( localStorage.getItem( 'giar_votedOn' ) );

function getPostsFromServer( callback ) {
	// TODO: AJAX get posts from server
	
	posts = posts_mockup;
	if ( 'function' === typeof callback ) {
		callback.call();
	}
}
function getRandomPost() {
	var post = posts[ Math.floor( Math.random() * posts.length ) ];
	var current = $el.data( 'post' );
	if ( 'object' == typeof current && current.ID === post.ID ) {
		post = getRandomPost();
	}
	return post;
}
function showPost( post ) {
	$el.data( 'currentPost', post );
	$el.find( 'h1' ).text( post.title );
	$el.find( '.votes .up' ).text( post.upvotes );
	$el.find( '.votes .down' ).text( post.downvotes );
}

function getLS( key ) {
	var data = window.localStorage.getItem( key );
	try {
		return JSON.parse( data );
	} catch ( e ) {
		return data;
	}
}

function setLS( key, data ) {
	return window.localStorage.setItem( key, JSON.stringify( data ) );
}

function voteOnPost( post, updown ) {
	var readingList = getLS( 'readingList' ) || [];
	if ( 'up' === updown ) {
		if ( -1 === readingList.indexOf( post.ID ) ) {
			readingList.push ( post.ID );
			setLS( 'readingList', readingList );
			addReadingListElem( post );
		}
	}
	showPost( getRandomPost() );

	// TODO: AJAX send vote to server

}

function addReadingListElem( post ) {
	$el.find( '.reading-list ul' ).append( '<li data-id="' + post.ID + '"><a target=_blank href="' + post.permalink + '">' + post.title + '</a></li>' );
}

$( document ).ready( function() {
	$el = $( '.giar' );

	getPostsFromServer( initAfterAjax );

	function initAfterAjax() {
		showPost( getRandomPost() );

		// display saved reading list
		$el.find( '.reading-list ul' ).empty();
		var readingList = getLS( 'readingList' ) || [];
		$.each( readingList, function( i, ID ) {
			$.each( posts, function( i, post ) {
				if ( post.ID === ID ) {
					addReadingListElem( post );
				}
			} );
		} );
	}

	$el.on( 'click', '.votes span', function( e ) {
		voteOnPost( $el.data( 'currentPost' ), $( this ).attr( 'class' ) );
	} );

	$el.on( 'click', '.clear-list', function( e ) {
		e.preventDefault();
		setLS( 'readingList', [] );
		$el.find( '.reading-list ul' ).empty();
	} );

} );


              
            
!
999px

Console