Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save saske505/7a4f460e37ad12231efd to your computer and use it in GitHub Desktop.
Save saske505/7a4f460e37ad12231efd to your computer and use it in GitHub Desktop.
Material Design | Commenting | JavaScript
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--4-col"></div>
<div class="mdl-cell mdl-cell--4-col">
<div class="demo-card-wide mdl-card mdl-shadow--2dp">
<div class="mdl-card__title">
<h2 class="mdl-card__title-text">Material Design | Working Comments</h2>
</div>
<div class="mdl-card__supporting-text">
<form action="#">
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="status-box mdl-textfield__input" type="text">
<label class="mdl-textfield__label" for="sample3">Say something...please </label>
</div>
</form>
</div>
<div class="mdl-card__actions mdl-card--border">
<button id="update" disabled="disabled" class="mdl-button mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent">
<i class="material-icons">send</i> Post
</button>
<div class="counter material-icons mdl-badge mdl-badge--overlap" data-badge="140"></div>
<p><span class="commentCount"></span> <span class="people"></span></p>
<ul class="posts collection mdl-list">
</ul>
</div>
<div class="mdl-card__menu">
<button class="mdl-button mdl-button--icon mdl-js-button mdl-js-ripple-effect">
<i class="material-icons">share</i>
</button>
</div>
</div>
<div class="mdl-cell mdl-cell--4-col"></div>
</div>
</div>

Material Design | Commenting | JavaScript

The code is initially from the JavaScript Codecademy Series, I was just brushing up on some basics and decided to materialize it. Hope you enjoy it. Updated to use Material Design Lite - much smoother and looks better.

A Pen by stephan maree on CodePen.

License.

archive = [];
function updateCommentCount () {
var archiveCount = archive.length;
if(archiveCount === 1) {
$('span.people').text('peson has commented on this');
} else if(archiveCount > 1) {
$('span.people').text('people has commented on this');
} else if (archiveCount < 1) {
$('span.people').text('no comments so far');
}
$('span.commentCount').text(archiveCount);
}
var main = function() {
var index = $("ul.posts.collection.mdl-list").index(this);
var newVal = 1;
$('#update').click(function() {
updateCommentCount();
var post = $('input.status-box.mdl-textfield__input').val();
var template = '<li class="mdl-list__item collection-item"><i class="material-icons">textsms</i> ';
$('ul.posts.collection.mdl-list').append(template + post + ' ' + '<span class="dateStyle">' + d + '</span>');
$('input.status-box.mdl-textfield__input').val('');
$('.counter').attr('data-badge', 140);
$('#update').attr('disabled', true);
});
$('input.status-box.mdl-textfield__input').keyup(function() {
var postLength = $(this).val().length;
var charactersLeft = 140 - postLength;
$('.counter').attr('data-badge', charactersLeft);
if (charactersLeft < 0) {
$('#update').prop('disabled', true);
} else if (charactersLeft == 140) {
$('#update').prop('disabled', true);
} else {
$('#update').attr('disabled', false);
}
});
$('#update').attr('disabled', false);
};
$(document).ready(main);
function savePost() {
var post = $('input.status-box.mdl-textfield__input').val();
var action = document.querySelector('#update');
$(action).on('click', function() {
var post = $('input.status-box.mdl-textfield__input').val();
archive.push({
"CommentName": post,
"Time": d
});
for(var i = 0; i < archive.lenght; i++) {
localStorage.setItem(archive[i].CommentName, archive[i]);
}
});
}
savePost();
var d = new Date().toISOString().slice(0, 10);
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.96.1/js/materialize.min.js"></script>
<script src="https://code.getmdl.io/1.1.2/material.min.js"></script>
.demo-card-wide.mdl-card {
width: 512px;
}
.demo-card-wide > .mdl-card__title {
color: #fff;
height: 176px;
}
.demo-card-wide > .mdl-card__menu {
color: #fff;
}
html,
body {
color: #404040;
background-color: #eee;
background: url('http://www.wallpaperspeed.xyz/wp-content/uploads/2016/01/FLAT-WALLPAPER-WSP094.jpg');
background-size: cover;
background-repeat: no-repeat;
}
#header {
background: transparent;
}
.container {
background: white;
}
.z-depth-3 {
margin-bottom: 25px;
}
html {
font-family: Roboto;
}
p > a:hover {
text-decoration: none;
}
p > i {
position: relative;
top: 0px;
padding: 0px;
}
p > i:hover {}
.button-group {}
.counter {
display: inline;
margin-top: 0;
margin-bottom: 0;
margin-right: 10px;
}
.posts {
clear: both;
list-style: none;
padding-left: 0;
width: 100%;
overflow-y: scroll;
max-height: 390px;
}
.input-field.col.s12 {
margin-top: 30px;
position: relative;
}
.posts li {
background-color: #fff;
border: 1px solid #d8d8d8;
padding-top: 10px;
padding-left: 20px;
padding-right: 20px;
padding-bottom: 10px;
margin-bottom: 10px;
word-wrap: break-word;
min-height: 42px;
}
.mdl-card {
width: 512px;
}
.mdl-card__title {
color: #fff;
height: 176px;
background: url('../assets/demos/welcome_card.jpg') center / cover;
}
.mdl-card__title {
color: #fff;
height: 176px;
background: url('https://lh4.ggpht.com/nyp1JUkjVXcBTsEdWJxuNq_-h1-yqPvHJodynvQAySJsUqllkm1ZE9G5F5px2Vr1n7Tj=h900') center / cover;
}
.space {
padding: 15px;
}
.mdl-list__item collection-item > i {}
.posts > li > i {
color: #008080;
margin-right: 15px;
margin-top: 8px;
}
span.dateStyle {
font-size: xx-small;
float: right;
margin-left: 25px;
position: static;
color: #FF1493;
}
button.mdl-button.mdl-button.mdl-js-button.mdl-button--raised.mdl-js-ripple-effect.mdl-button--accent {
background: #008080;
}
<link href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.min.cs" rel="stylesheet" />
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" />
<link href="http://fonts.googleapis.com/css?family=Roboto:300,400,500,700" rel="stylesheet" />
<link href="https://code.getmdl.io/1.1.2/material.indigo-pink.min.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment