mirror of
https://github.com/amark/gun.git
synced 2025-06-07 22:56:42 +00:00
added Forrest's Todo Example and made example directory
This commit is contained in:
parent
8721ff345c
commit
64709bd9b4
@ -53,7 +53,7 @@
|
|||||||
var gun = Gun(location.origin + '/gun');
|
var gun = Gun(location.origin + '/gun');
|
||||||
angular.module('admin', []).controller('editor', function($scope){
|
angular.module('admin', []).controller('editor', function($scope){
|
||||||
$scope.data = {};
|
$scope.data = {};
|
||||||
$scope.$data = gun.load('example/angular/todo').blank(function(){
|
$scope.$data = gun.load('example/angular/data').blank(function(){
|
||||||
console.log("Initializing Data!");
|
console.log("Initializing Data!");
|
||||||
this.set({});
|
this.set({});
|
||||||
}).on(function(data){
|
}).on(function(data){
|
||||||
@ -63,7 +63,7 @@
|
|||||||
});
|
});
|
||||||
$scope.$apply();
|
$scope.$apply();
|
||||||
});
|
});
|
||||||
$scope.add = function(a,b,c){
|
$scope.add = function(){
|
||||||
$scope.$data.path($scope.field).set( $scope.data[$scope.field] = 'value' );
|
$scope.$data.path($scope.field).set( $scope.data[$scope.field] = 'value' );
|
||||||
$scope.field = '';
|
$scope.field = '';
|
||||||
};
|
};
|
||||||
|
15
examples/index.html
Normal file
15
examples/index.html
Normal 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>
|
@ -1,15 +1,39 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<body onload="ready()">
|
||||||
<title>ToDo</title>
|
<h2>ToDo List</h2>
|
||||||
</head>
|
|
||||||
<body>
|
<form id="addToDo"><input id="todoItem" /><button>Add</button></form>
|
||||||
<h1>
|
<ul id="todos"></ul>
|
||||||
Todo List
|
|
||||||
</h1>
|
<script src="../../gun.js"></script>
|
||||||
<form name="sign" action="http://localhost:8888/gun">
|
<script>
|
||||||
<input name="email" placeholder="email">
|
// by Forrest Tait! Edited by Mark Nadal.
|
||||||
<input name="password" type="password" placeholder="password">
|
function ready(){
|
||||||
<input type="submit" name="it" value="sign in or up">
|
var $ = document.querySelector.bind(document);
|
||||||
</form>
|
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>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
x
Reference in New Issue
Block a user