Skip to content
This repository has been archived by the owner on Aug 23, 2019. It is now read-only.

Commit

Permalink
fix(example.js): remove test code from example
Browse files Browse the repository at this point in the history
  • Loading branch information
cmac1212 committed Feb 4, 2014
1 parent 0c4a910 commit 78753ce
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 27 deletions.
14 changes: 7 additions & 7 deletions examples/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html ng-app="ourCoolApp">
<html ng-app="app">
<head>
<title>GoInstant GoAngular Component Example</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Expand All @@ -19,7 +19,7 @@

<!-- jQuery & Bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet">
<script src="http://codeorigin.jquery.com/jquery-2.0.3.min.js"></script>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>

<!-- GoAngular -->
Expand All @@ -43,16 +43,16 @@
<div class="container" ng-controller="sweetController">
<!-- <button type="button" id="killTheGong">Kill Go-ng Binding</button> -->
<div class="col-md-6">
<h5>description: {{description.description}} | $value: {{name.$value}}</h5>
<h5>description: {{description}}</h5>
<div class="input-group">
<input ng-model="newTodo" type="text" class="form-control">
<input enter="addTodo()" ng-model="newTodo" type="text" class="form-control">
<span class="input-group-btn">
<button ng-click="addTodo()" class="btn btn-default" type="button">Add Todo</button>
<button enter="addTodo()" ng-click="addTodo()" class="btn btn-default" type="button">Add Todo</button>
</span>
</div><!-- /input-group -->
<br>
<ul class="list-group">
<li class="list-group-item" ng-repeat="todo in todos">{{todo.description}}&nbsp;<button ng-click="remove(todo.$name)" class="pull-right btn btn-xs btn-danger">x</button></li>
<li class="list-group-item" ng-repeat="(key, todo) in todos">{{todo.description}}<button ng-click="remove(key)" class="pull-right btn btn-xs btn-danger">x</button></li>
</ul>
</div><!-- /.col-lg-6 -->
<div class="col-md-6">
Expand All @@ -66,4 +66,4 @@ <h5>Current User: <input type="text" ng-model="currentUser.displayName"/></h5>
</div>
</div>
</body>
</html>
</html>
67 changes: 47 additions & 20 deletions examples/js/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,68 @@
require('goangular');

// Create an AngularJS application module
var ourCoolApp = angular.module('ourCoolApp', ['goangular']);
var app = angular.module('app', ['goangular']);

ourCoolApp.config(function($goConnectionProvider) {
$goConnectionProvider.$set(CONFIG.connectUrl, { user: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL2dvaW5zdGFudC5uZXQvbWF0dGNyZWFnZXIvRGluZ0RvbmciLCJzdWIiOiJuYSIsImRuIjoiZHVkZSIsImciOltdLCJhdWQiOiJnb2luc3RhbnQubmV0In0.LcvRSDmEj9LHonPhnXv1OWTQ5gjcBnk1QgxH4iYt6PM'});
app.config(function($goConnectionProvider) {
$goConnectionProvider.$set(CONFIG.connectUrl);
});

ourCoolApp.controller('sweetController', function($scope, $goKey) {
app.controller('sweetController', function($scope, $goKey, $goConnection) {

$scope.todos = $goKey('todos');
$scope.todos.$sync();
$scope.todos = $goKey('todos').$sync();

console.log('todos', $scope.todos);

// // reference nested key via todos
$scope.name = $scope.todos.$key('9edd3cf39e22da900707d9091f90eb52').$key('description').$sync();

// // reference nested key via .key
$scope.description = $goKey('todos/9edd3cf39e22da900707d9091f90eb52').$sync();

setTimeout(function() {
$scope.todos.$key('9edd3cf39e22da900707d9091f90eb52/description').$set('jygjygjguj');
}, 1000);
$goConnection.$ready().then(function(connection) {
var room = connection.room('lobby');
room.self().get().then(function(results) {
$scope.currentUser = results.value;
$scope.$apply();
});
});

$scope.addTodo = function() {
var desc = $scope.newTodo;
if (desc === undefined || desc === '') {
return;
}

$scope.todos.$add({
timestamp: new Date().getTime(),
description: $scope.newTodo,
complete: false
}, { expire: 500 }).then(function() {
console.log(arguments);
}).then(function() {
$scope.newTodo = '';
$scope.$apply();
});
};

var opts = {
local: true
};

$scope.todos.$on('add', opts, function(value) {
$scope.description = value.description;
});

$scope.remove = function(key) {
$scope.todos.$key(key).$remove();
};

});

app.directive('enter', function() {
var dir = {
restrict: 'A',
link: function(scope, element, attrs) {
element.bind('keydown', function(event) {
var key = (event.which) ? event.which : event.keyCode;

if (key !== 13) {
return;
}

scope.$eval(attrs.enter);
});
}
};

return dir;
});

0 comments on commit 78753ce

Please sign in to comment.