added Forrest's Todo Example and made example directory

This commit is contained in:
Mark Nadal 2015-01-22 18:08:48 -07:00
parent 8721ff345c
commit 64709bd9b4
3 changed files with 54 additions and 15 deletions

View File

@ -53,7 +53,7 @@
var gun = Gun(location.origin + '/gun');
angular.module('admin', []).controller('editor', function($scope){
$scope.data = {};
$scope.$data = gun.load('example/angular/todo').blank(function(){
$scope.$data = gun.load('example/angular/data').blank(function(){
console.log("Initializing Data!");
this.set({});
}).on(function(data){
@ -63,7 +63,7 @@
});
$scope.$apply();
});
$scope.add = function(a,b,c){
$scope.add = function(){
$scope.$data.path($scope.field).set( $scope.data[$scope.field] = 'value' );
$scope.field = '';
};

15
examples/index.html Normal file
View File

@ -0,0 +1,15 @@
<html>
<body>
<h1>Examples Directory</h1>
<style>
iframe {
width: 100%;
height: 50%;
border: none;
border-top: ridge 2em skyblue;
}
</style>
<a href="todo/index.html"><iframe src="todo/index.html"></iframe></a>
<a href="angular/index.html"><iframe src="angular/index.html"></iframe></a>
</body>
</html>

View File

@ -1,15 +1,39 @@
<html>
<head>
<title>ToDo</title>
</head>
<body>
<h1>
Todo List
</h1>
<form name="sign" action="http://localhost:8888/gun">
<input name="email" placeholder="email">
<input name="password" type="password" placeholder="password">
<input type="submit" name="it" value="sign in or up">
</form>
<body onload="ready()">
<h2>ToDo List</h2>
<form id="addToDo"><input id="todoItem" /><button>Add</button></form>
<ul id="todos"></ul>
<script src="../../gun.js"></script>
<script>
// by Forrest Tait! Edited by Mark Nadal.
function ready(){
var $ = document.querySelector.bind(document);
var gun = Gun(location.origin + '/gun').load('example/todo/data').set({});
gun.on(function renderToDo(val){
var todoHTML = '';
for(key in val) {
if(!val[key] || key == '_') continue;
todoHTML += '<li style="width:400px;height:2em;">' + val[key] +
'<button style="float:right;" onclick=removeToDo("'+key+'")>X</button></li>';
}
$("#todos").innerHTML = todoHTML;
});
$("#addToDo").onsubmit = function(){
var id = randomId();
gun.path(id).set($("#todoItem").value);
$("#todos").innerHTML += "<li>"+$("#todoItem").value+"</li>";
$("#todoItem").value = "";
return false;
};
window.removeToDo = function(id){
gun.path(id).set(null);
}
}
function randomId(){
return ''+(new Date()).getTime()+Math.round((Math.random()*1000));
}
</script>
</body>
</html>