-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Matt Creaser
committed
Nov 18, 2013
1 parent
887a0a1
commit bf3a9a0
Showing
17 changed files
with
179 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
input, button { | ||
margin-bottom: 10px; | ||
} | ||
|
||
.delete { | ||
float: right; | ||
color: #888; | ||
margin-right: 20px; | ||
cursor: pointer; | ||
} | ||
|
||
li { | ||
list-style-position: inside; | ||
border-top: 1px solid #aaa; | ||
margin: 0; | ||
padding: 5px 0 5px 40px; | ||
} | ||
|
||
ul { | ||
padding: 0; | ||
border-bottom: 1px solid #aaa; | ||
} | ||
|
||
html, body, #items { | ||
height: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>Lists</title> | ||
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
|
||
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css"> | ||
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap-theme.min.css"> | ||
<link rel="stylesheet" href="css/lists.css"> | ||
|
||
<script src="//code.jquery.com/jquery-1.10.2.min.js"></script> | ||
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.2.1/lodash.min.js"></script> | ||
<script src="https://cdn.goinstant.net/v1/platform.min.js"></script> | ||
<script src="js/goinstant.list.js"></script> | ||
<script src="js/jquery.touchSwipe.min.js"></script> | ||
<script src="js/lists.js"></script> | ||
</head> | ||
<body> | ||
|
||
<section id="lists"> | ||
<input type="text" class="form-control" placeholder="New List..." /> | ||
</section> | ||
|
||
<section id="items" style="display:none"> | ||
<input type="text" class="form-control" placeholder="New Item..." /> | ||
</section> | ||
|
||
<script type="text/template" id="listTemplate"> | ||
<li><span class="name">${ name }</span> <a href="#" class="delete">X</a></li> | ||
</script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/*jshint browser:true*/ | ||
/*global _*/ | ||
|
||
var DEFAULT_TEMPLATE = '<li>${ name }</li>'; | ||
|
||
function DynamicList(opts) { | ||
this.key = opts.key; | ||
this.template = opts.template || DEFAULT_TEMPLATE; | ||
this.elem = document.createElement('ul'); | ||
|
||
var self = this; | ||
|
||
function add(item, id) { | ||
var html = _.template(self.template, item); | ||
var div = document.createElement('div'); | ||
div.innerHTML = html; | ||
var elem = div.querySelector('li'); | ||
elem.setAttribute('id', id); | ||
self.elem.appendChild(elem); | ||
} | ||
|
||
this.key.on('add', { local: true, listener: function(value, context) { | ||
var id = context.addedKey.substr(context.addedKey.lastIndexOf('/') + 1); | ||
add(value, id); | ||
}}); | ||
|
||
this.key.on('remove', { local: true, bubble: true, listener: function(value, context) { | ||
var id = context.key.substr(context.key.lastIndexOf('/') + 1); | ||
var elem = document.getElementById(id); | ||
if (elem) elem.parentNode.removeChild(elem); | ||
}}); | ||
|
||
this.key.get(function(err, items) { _.each(items, add); }); | ||
} | ||
|
||
DynamicList.prototype.destroy = function() { | ||
if (this.elem.parentNode) this.elem.parentNode.removeChild(this.elem); | ||
this.key.off(); | ||
}; | ||
|
||
DynamicList.prototype.add = function(item) { | ||
this.key.add(item); | ||
}; | ||
|
||
DynamicList.prototype.remove = function(id) { | ||
this.key.key(id).remove(); | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/*jshint browser:true*/ | ||
/*global DynamicList */ | ||
|
||
var goinstant = window.goinstant; | ||
var _ = window._; | ||
var $ = window.$; | ||
|
||
var room; | ||
|
||
var url = 'https://goinstant.net/mattcreaser/lists'; | ||
goinstant.connect(url, function(err, connection, lobby) { | ||
if (err) { | ||
console.error('Could not connect', err); | ||
return; | ||
} | ||
room = lobby; | ||
$(init); | ||
}); | ||
|
||
|
||
function init() { | ||
var listTmpl = $('#listTemplate').html(); | ||
|
||
var lists = new DynamicList({ key: room.key('lists'), template: listTmpl }); | ||
var items; | ||
|
||
$('#lists').on('click', 'li', function(e) { | ||
var id = $(this).attr('id'); | ||
items = new DynamicList({ key: room.key('items/' + id), template: listTmpl }); | ||
$('#items').append(items.elem); | ||
$('#items').show(); | ||
$('#lists').hide(); | ||
}); | ||
|
||
$('#lists').on('click', '.delete', function(e) { | ||
e.stopPropagation(); | ||
var li = $(this).closest('li'); | ||
var id = li.attr('id'); | ||
var name = li.find('.name').text(); | ||
if (window.confirm('Delete list ' + name + '?')) { | ||
lists.remove(id); | ||
room.key('items/' + id).remove(); | ||
} | ||
}); | ||
|
||
$('#items').on('click', '.delete', function(e) { | ||
e.stopPropagation(); | ||
var id = $(this).closest('li').attr('id'); | ||
items.remove(id); | ||
}); | ||
|
||
$('#items').swipe({ swipeRight: function() { | ||
items.destroy(); | ||
$('#lists').show(); | ||
$('#items').hide(); | ||
}}); | ||
|
||
$('#lists input').keyup(function(e) { | ||
if (e.keyCode !== 13) { return; } | ||
lists.add({ name: $(this).val() }); | ||
$(this).val(''); | ||
}); | ||
|
||
$('#items input').keyup(function(e) { | ||
if (e.keyCode !== 13) { return; } | ||
items.add({ name: $(this).val(), checked: false }); | ||
$(this).val(''); | ||
}); | ||
|
||
$('#lists').append(lists.elem); | ||
} |
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.