menu update: model, angular logic;

This commit is contained in:
tmshv committed 2015-07-08 23:08:26 +03:00
1 parent 0e67001b26
commit 8d2d889759
5 files changed
+35 -21

No files matched your search

+3 -1
View File
@@ -51,7 +51,9 @@ module.exports = function (app) {
} }
); );
app.controller("AlbumPageController", function ($scope, $http, $routeParams, api) { app.controller("AlbumPageController", function ($scope, $http, $routeParams, api, menu) {
menu.activate('/gallery');
api.gallery.album( api.gallery.album(
$routeParams.year, $routeParams.year,
$routeParams.course, $routeParams.course,
+28 -13
View File
@@ -2,30 +2,45 @@
* Created by tmshv on 05/11/14. * Created by tmshv on 05/11/14.
*/ */
var menu = require("../../models/menu.json"); module.exports = function (app) {
app.factory("menu", function ($route, $rootScope) {
function Menu() {
this.items = require("../../models/menu.json");
this.current = null;
}
module.exports = function(app) { Menu.prototype.activate = function (path) {
app.service("menu", function ($route) { var f = this.items.filter(function (i) {
menu.isActive = function (path) { return i.url === path;
if ($route.current && $route.current.regexp) { });
return $route.current.regexp.test(path);
if(f.length) {
this.current = f[0];
} }
return false;
}; };
var menu = new Menu();
$rootScope.$on('$routeChangeSuccess', function (event, current) {
var path = current['$$route'].originalPath;
menu.activate(path);
});
return menu; return menu;
}); });
app.controller("MenuController", function ($scope, menu) { app.controller("MenuController", function ($scope, menu) {
$scope.vkgroup = menu.vkgroup; $scope.menu = menu;
$scope.menu = menu.menu;
$scope.isCurrent = function(item) { $scope.isActive = function (item) {
return menu.isActive(item.url); if(menu.current) {
return item.url == menu.current.url;
}else{
return false;
}
}; };
$scope.isValid = function(item) { $scope.isValid = function (item) {
return Boolean(item.url); return 'url' in item;
}; };
}); });
}; };
+2 -5
View File
@@ -1,5 +1,4 @@
{ [
"menu": [
{ {
"text": "Школа", "text": "Школа",
"url": "/", "url": "/",
@@ -32,6 +31,4 @@
"url": "/docs", "url": "/docs",
"color": "yellow" "color": "yellow"
} }
], ]
"vkgroup": "https://vk.com/club10436104"
}
+1 -1
View File
@@ -33,7 +33,7 @@
<header> <header>
<nav role="navigation" ng-controller="MenuController"> <nav role="navigation" ng-controller="MenuController">
<ul> <ul>
<li ng-repeat="item in menu" class="{{item.color}}" ng-class="{selected:isCurrent(item)}"> <li ng-repeat="item in menu.items" class="{{item.color}}" ng-class="{selected: isActive(item)}">
<span ng-hide="isValid(item)">{{item.text}}</span> <span ng-hide="isValid(item)">{{item.text}}</span>
<a href="{{item.url}}" ng-show="isValid(item)">{{item.text}}</a> <a href="{{item.url}}" ng-show="isValid(item)">{{item.text}}</a>
</li> </li>
+1 -1
View File
@@ -50,7 +50,7 @@
<header> <header>
<nav role="navigation" ng-controller="MenuController"> <nav role="navigation" ng-controller="MenuController">
<ul> <ul>
<li ng-repeat="item in menu" class="{{item.color}}" ng-class="{selected:isCurrent(item)}"> <li ng-repeat="item in menu.items" class="{{item.color}}" ng-class="{selected: isActive(item)}">
<span ng-hide="isValid(item)">{{item.text}}</span> <span ng-hide="isValid(item)">{{item.text}}</span>
<a href="{{item.url}}" ng-show="isValid(item)">{{item.text}}</a> <a href="{{item.url}}" ng-show="isValid(item)">{{item.text}}</a>
</li> </li>