AO Console After Angular

by jcpmcdonald

HTML

<div id="console" class="panel" ng-app ng-controller="ConsoleController">
	<div id="consoleWrap">
		<div id="consoleHistory">			   
			<div class="consoleLine" ng-repeat="line in consoleLines">
				<span class="consoleID">{{line.username}}</span>
				<span class="consoleText">{{line.message}}</span>
				<span class="consoleTime">{{line.timestamp | date:'mediumTime'}}</span>
			</div>
		</div>
		<div id="consoleInputWrap">
			<form ng-submit="addConsoleMessage()">
				<input type="text" id="consoleInput" ng-model="consoleInput" />
			</form>
		</div>
	</div>
</div>

CSS

</style> <!-- Ugly Hack due to jsFiddle issue: http://goo.gl/BUfGZ --> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js"></script>
<style>

body
{
	background-color: rgba(0, 0, 0, 0);
	color: #FFFFFF;
	
	-moz-user-select: none;
	-webkit-user-select: none;
}

.panel
{
	position: absolute;
	background-color: rgba(100, 100, 100, 0.7);
	border-color: #bbbbbb;
	border-width: 1px;
}


#console
{
	bottom: 0px;
	right: 10px;
	
	font-size: small;
	text-shadow:0 1px 0 rgba(255,255,255,0.3);
	
	padding: 10px;
	border-radius: 15px 15px 0px 0px;
	border-style: solid solid none solid;
	-moz-user-select: text;
	-webkit-user-select: text;
}

#consoleWrap
{
	position: relative;
	width: 350px;
    
	display: table-cell;
	vertical-align: bottom;
}

#consoleHistory
{
    overflow: auto;
	
	height: 150px;
	max-height: 150px;
	
	background-color: rgba(70, 70, 70, 0.5);
}

.consoleID
{
	width: 50%;
	color: rgba(230, 230, 230, 0.6);
	font-weight: lighter;
}

.consoleID:after
{
	content: ": ";
}

.consoleLine:hover
{
	background-color: rgba(70, 70, 70, 0.6);
}

.consoleTime
{
	color: rgba(220, 220, 220, 0.6);
	float: right;
	margin-right: 5px;
	
	-moz-user-select: none;
	-webkit-user-select: none;
}

#consoleInputWrap
{
	height: 20px;
	padding-top: 5px;
}

#consoleInput
{
	width: 100%;
	padding: 0px;
}

JavaScript

// AFTER

$username = "me";
 
function ConsoleController($scope)
{
    $scope.consoleLines = [ {username:'System', message:'Welcome', timestamp:new Date()} ];
    
    $scope.addConsoleMessage = function()
    {
        // Execute javascript on request
        if($scope.consoleInput.toLowerCase().indexOf("/js ") == 0)
        {
            eval($scope.consoleInput.substr(4));
        }
        
        $scope.consoleLines.push({username:$username, message:$scope.consoleInput, timestamp:new Date() });
        $scope.consoleInput = "";
        
        // A delay is needed before we can scroll to the bottom to allow Angular to update the DOM
        setTimeout(function() { $("#consoleHistory").scrollTop($("#consoleHistory").prop("scrollHeight")); }, 10);
    }
}