Created
October 22, 2013 11:26
-
-
Save Gwash3189/7098987 to your computer and use it in GitHub Desktop.
Header bar directive for angular js 1.0.7. Takes the route and uses it as a heading. Also takes a persons name, separated by commas and then uses that as the header if available
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function clean (array,deleteValue) { | |
for (var i = 0; i < array.length; i++) { | |
if (array[i] == deleteValue) { | |
array.splice(i, 1); | |
i--; | |
} | |
} | |
return array; | |
} | |
var app = angular.module('app',[]); | |
app.config(function($routeProvider){ | |
$routeProvider.when('/Approvals', { | |
controller: 'ctrl', | |
templateUrl: './home.html' | |
}); | |
$routeProvider.when('/Steve,Test', { | |
controller: 'ctrl', | |
templateUrl: './home.html' | |
}); | |
$routeProvider.when('/Steve,', { | |
controller: 'ctrl', | |
templateUrl: './home.html' | |
}); | |
$routeProvider.when('/', { | |
template: '<a href="#/Steve,Test">Steve,Test </a> <br> <a href="#/Approvals">Approvals</a><br> <a href="#/Steve,">Steve,</a>' | |
}) | |
}) | |
app.controller('ctrl', function($scope, $location){ | |
$scope.vm = {}; | |
$scope.vm.message = $location.path(); | |
}); | |
app.directive('headerBar', function(){ | |
return { | |
restrict: 'E', | |
controller: function($scope, $location){ | |
$scope.vm = {}; | |
$scope.vm.message = getName(getRoute($location.path())); | |
$scope.vm.back = function(){ | |
$location.path('/'); | |
} | |
function getRoute(route){ | |
var result = clean(route.split('/'), ''); | |
if(result.length >= 2) { | |
var length = result.length - 1; | |
return result[length]; | |
} | |
return result[0]; | |
} | |
function getName(name){ | |
if(name.indexOf(',') > -1){ | |
return name.split(',')[0] + ' ' + name.split(',')[1]; | |
} else { | |
return name; | |
} | |
} | |
}, | |
template: '<div class="header-bar">' + | |
'<span class="col-xs-2" ><button ng-click="vm.back()" class="btn route-button">back</button></span>'+ | |
'<h3 style="" class="col-xs-8 center">{{ vm.message }}</h3>' + | |
'<span class="col-xs-2 pull-right"><button class="btn route-button">logout</button></span>'+ | |
'</div>' | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="container"> | |
<div class="row"> | |
<header-bar></header-bar> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<link data-require="bootstrap-css@3.0.0" data-semver="3.0.0" rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" /> | |
<script data-require="angular.js@1.0.7" data-semver="1.0.7" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js"></script> | |
<link rel="stylesheet" href="style.css" /> | |
<script src="script.js"></script> | |
</head> | |
<body ng-app="app"> | |
<div ng-view> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.center{ | |
text-align:center; | |
} | |
.route{ | |
display: inline; | |
} | |
.route-button{ | |
margin-top: 1.2em; | |
} | |
.header-bar{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment