View difference between Paste ID: 1p3XfGtT and A7bFDq4i
SHOW: | | - or go back to the newest paste.
1
<div id="console" class="panel" ng-app ng-controller="ConsoleController">
2
	<div id="consoleWrap">
3
		<div id="history">
4
			
5
			<div class="consoleLine" ng-repeat="line in consoleLines">
6
				<span class="consoleID">{{line.username}}</span>
7
				<span class="consoleText">{{line.message}}</span>
8
				<span class="consoleTime">{{line.timestamp | date:'mediumTime'}}</span>
9
			</div>
10
			
11
		</div>
12
		<div id="consoleInputWrap">
13
			<form ng-submit="addConsoleMessage()">
14
				<input type=text id="consoleInput" ng-model="consoleInput">
15
			</form>
16
		</div>
17
	</div>
18
</div>
19
20
21
<script>
22
$username = "me";
23
24
function ConsoleController($scope)
25
{
26
	$scope.consoleLines = [ {username:'System', message:'Welcome', timestamp:new Date()} ];
27
	
28
	$scope.addConsoleMessage = function()
29
	{
30
		// Execute javascript on request
31
		if($scope.consoleInput.toLowerCase().indexOf("/js ") == 0)
32
		{
33
			eval($scope.consoleInput.substr(4));
34
		}
35
		
36
		$scope.consoleLines.push({username:$username, message:$scope.consoleInput, timestamp:new Date() });
37
		$scope.consoleInput = "";
38
		
39
		// A delay is needed before we can scroll to the bottom to allow Angular to update the DOM
40
		setTimeout($("#history").scrollTop($("#history").prop("scrollHeight")), 100);
41-
// All of this is to watch for new items in the console and scroll to the bottom
41+
42-
$(document).ready(function()
42+
43
</script>