Last active
December 16, 2015 05:38
-
-
Save JogoShugh/5385819 to your computer and use it in GitHub Desktop.
AngularJS Menu app examples
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
# Utilities | |
copy = (from, to, propertiesToCopy) -> | |
for property in propertiesToCopy | |
to[property] = from[property] | |
# Module setup | |
@Menu = angular.module 'Menu', [] | |
# Routing | |
@Menu.config ($routeProvider) -> | |
$routeProvider.when('/menu/:meal', { | |
templateUrl: 'partials/menu.html' | |
controller: 'RouteController' | |
}).otherwise({ | |
redirectTo: '/menu/breakfast' | |
}) | |
# Controllers | |
@MenuController = ($scope, $rootScope, $http) -> | |
$rootScope.navLinks = [ | |
text: 'Breakfast' | |
meal: 'breakfast' | |
, | |
text: 'Lunch' | |
meal: 'lunch' | |
, | |
text: 'Dinner' | |
meal: 'dinner' | |
] | |
$http.get('data/mealMenus.json').success (data) -> | |
$rootScope.mealMenus = data | |
$rootScope.getMenuFor = (meal) -> | |
if @mealMenus[meal]? | |
return @mealMenus[meal] | |
else | |
menu = @mealMenus.default | |
menu.name = meal | |
return menu | |
@RouteController = ($scope, $rootScope, $routeParams) -> | |
meal = $routeParams.meal | |
$scope.menu = meal | |
meal = $rootScope.getMenuFor(meal) | |
copy meal, $scope, ['name', 'headings', 'items'] |
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 lang="en" ng-app="Menu"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Let's Eat!</title> | |
<link rel="stylesheet" href="css/bootstrap.css"> | |
<link rel="stylesheet" href="css/bootstrap-responsive.css"> | |
<link rel="stylesheet" href="css/responsive-tables.css"> | |
<script src="lib/angular/angular.js"></script> | |
<script src="js/controllers.js"></script> | |
</head> | |
<body ng-controller="MenuController"> | |
<nav class="navbar navbar-fixed-top"> | |
<div class="navbar-inner"> | |
<div class="container-fluid"> | |
<ul class="nav"> | |
<li ng-repeat="navLink in navLinks"><a href="#/menu/{{navLink.meal}}">{{navLink.text}}</a></li> | |
</ul> | |
</div> | |
</div> | |
</nav> | |
<div class="container-fluid" style="margin-top:50px"> | |
<div class="row-fluid"> | |
<div class="span8"> | |
<ng-view></ng-view> | |
</div> | |
<div class="span4" style="background:#fcfcfc"> | |
Place ads or other things here! | |
</div> | |
</div> | |
</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
@media only screen and (max-width: 800px) { | |
/* Force table to not be like tables anymore */ | |
.responsive table, | |
.responsive thead, | |
.responsive tbody, | |
.responsive th, | |
.responsive td, | |
.responsive tr { | |
display: block; | |
} | |
/* Hide table headers (but not display: none;, for accessibility) */ | |
.responsive thead tr { | |
position: absolute; | |
top: -9999px; | |
left: -9999px; | |
} | |
.responsive tr { border: 1px solid #ccc; } | |
.responsive td { | |
/* Behave like a "row" */ | |
border: none; | |
border-bottom: 1px solid #eee; | |
position: relative; | |
padding-left: 50%; | |
white-space: normal; | |
text-align:left; | |
} | |
.responsive td:before { | |
/* Now like a table header */ | |
position: absolute; | |
/* Top/left values mimic padding */ | |
top: 6px; | |
left: 6px; | |
width: 45%; | |
padding-right: 10px; | |
white-space: nowrap; | |
text-align:left; | |
font-weight: bold; | |
} | |
/* | |
Label the data | |
*/ | |
.responsive td:before { content: attr(data-title); } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment