mirror of
https://github.com/amark/gun.git
synced 2026-03-12 19:48:37 +00:00
working realtime live push yay
This commit is contained in:
@@ -8,13 +8,11 @@ var gun = Gun({
|
||||
s3: (process.env.NODE_ENV === 'production')? null : require('../../test/shotgun') // replace this with your own keys!
|
||||
});
|
||||
|
||||
app.use(express.static(__dirname))
|
||||
.use(bodyParser.json())
|
||||
.use(gun.server);
|
||||
app.use(gun.server)
|
||||
.use(express.static(__dirname))
|
||||
app.listen(port);
|
||||
|
||||
console.log('Express started on port ' + port + ' with /gun');
|
||||
|
||||
gun.load('blob/data').blank(function(){
|
||||
gun.set({ hello: "world", from: "Mark Nadal" }).key('blob/data');
|
||||
gun.load('blob/data').blank(function(){ // in case there is no data on this key
|
||||
gun.set({ hello: "world", from: "Mark Nadal" }).key('blob/data'); // save some sample data
|
||||
});
|
||||
64
examples/admin/duel.html
Normal file
64
examples/admin/duel.html
Normal file
@@ -0,0 +1,64 @@
|
||||
<!DOCTYPE html>
|
||||
<html ng-app="admin">
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<script src="https://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js"></script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
|
||||
<script src="../../gun.js"></script>
|
||||
</head>
|
||||
<body ng-controller="editor">
|
||||
<style>
|
||||
html, body {
|
||||
font-family: Verdana, Geneva, sans-serif;
|
||||
}
|
||||
a {
|
||||
color: skyblue;
|
||||
text-decoration: none;
|
||||
cursor: poiner;
|
||||
}
|
||||
ul, li {
|
||||
list-style-type: none;
|
||||
}
|
||||
ul:hover, li:hover {
|
||||
list-style-type: inherit;
|
||||
}
|
||||
input {
|
||||
border: none;
|
||||
border-bottom: dashed 1px gainsboro;
|
||||
}
|
||||
.none {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
<form id="p1" class="assign-player" onsubmit="return false;">
|
||||
Player 1: <input type="text" name="p1" placeholder="nickname">
|
||||
<input type="submit" value="Join!">
|
||||
</form>
|
||||
<form id="p2" class="assign-player" onsubmit="return false;">
|
||||
Player 2: <input type="text" name="p2" placeholder="nickname">
|
||||
<input type="submit" value="Join!">
|
||||
</form>
|
||||
<script>
|
||||
(function(){
|
||||
var gun = Gun(['http://localhost:8888/' + 'gun'])
|
||||
.load('game/duel', function(game){
|
||||
console.log(game);
|
||||
$(document).on('submit', '.assign-player', function(e){
|
||||
e.preventDefault();
|
||||
console.log("Choosing player!");
|
||||
var nick = $(this).find('input').val();
|
||||
if(!nick){ return }
|
||||
gun.path(this.id).get(function(val){
|
||||
console.log(val, nick, 'oh?');
|
||||
if(val){ return }
|
||||
gun.path('p1').set(nick);
|
||||
});
|
||||
})
|
||||
Gun.on(game._[Gun.sym.id]).event(function(node){
|
||||
console.log("change!", node);
|
||||
});
|
||||
});
|
||||
}());
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -2,6 +2,9 @@
|
||||
<html ng-app="admin">
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<script src="https://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js"></script>
|
||||
<!--
|
||||
-->
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.js"></script>
|
||||
<script src="../../gun.js"></script>
|
||||
</head>
|
||||
@@ -13,6 +16,7 @@
|
||||
a {
|
||||
color: skyblue;
|
||||
text-decoration: none;
|
||||
cursor: poiner;
|
||||
}
|
||||
ul, li {
|
||||
list-style-type: none;
|
||||
@@ -30,6 +34,13 @@
|
||||
</style>
|
||||
<h3>Admin Data Editor</h3>
|
||||
This is a live view of your JSON data, you can edit it in realtime or add new key/values.
|
||||
<!--
|
||||
<form method="post" action="http://localhost:8888/gun">
|
||||
First name: <input type="text" name="firstname"><br>
|
||||
Last name: <input type="text" name="lastname">
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
-->
|
||||
<ul name="list">
|
||||
<li ng-repeat="(key, val) in data">
|
||||
<div ng-if="key != '_'">
|
||||
@@ -41,17 +52,26 @@
|
||||
<form ng-submit="add()">
|
||||
<label>
|
||||
<input ng-model="field" placeholder="key" ng-submit="add()">
|
||||
<a href="#" ng-click="add()">add</a>
|
||||
<a ng-click="add()">add</a>
|
||||
<input type="submit" class="none"/>
|
||||
</label>
|
||||
</form>
|
||||
</li>
|
||||
</ul>
|
||||
<div id="debug">SUP</div>
|
||||
<script>
|
||||
gun = Gun([location.origin + '/gun']);
|
||||
angular.module('admin', [
|
||||
|
||||
]).controller('editor', function($scope){
|
||||
function debug(s){
|
||||
document.getElementById('debug').innerHTML = s;
|
||||
}
|
||||
//var gun = Gun([location + 'gun']);
|
||||
var gun = Gun(['http://localhost:8888/' + 'gun']);
|
||||
/*
|
||||
(function(){
|
||||
debug('meow ');// + tab.com.toString());
|
||||
tab.com.jsonp();
|
||||
})();
|
||||
*/
|
||||
angular.module('admin', []).controller('editor', function($scope){
|
||||
$scope.data = {};
|
||||
$scope.$data = gun.load('blob/data', function(data){
|
||||
$scope.data = data;
|
||||
@@ -64,19 +84,13 @@
|
||||
});
|
||||
});
|
||||
$scope.add = function(a,b,c){
|
||||
$scope.$data.path($scope.field).set(
|
||||
$scope.data[$scope.field] = 'value'
|
||||
);
|
||||
$scope.$data.path($scope.field).set( $scope.data[$scope.field] = 'value' );
|
||||
$scope.field = '';
|
||||
};
|
||||
window.$data = $scope.$data;
|
||||
}).directive('gun', function(){
|
||||
return function(scope, elem){
|
||||
elem.on('keyup', function(){
|
||||
scope.$data.path(scope.key).set(
|
||||
scope.data[scope.key] = elem.text()
|
||||
);
|
||||
// scope.$apply();
|
||||
scope.$data.path(scope.key).set( scope.data[scope.key] = elem.text() );
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user