diff --git a/client/pages/gallery.js b/client/pages/gallery.js index 1221da84..85a50614 100644 --- a/client/pages/gallery.js +++ b/client/pages/gallery.js @@ -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( $routeParams.year, $routeParams.course, diff --git a/client/ui/menu.js b/client/ui/menu.js index ee723ec7..2ea9e055 100644 --- a/client/ui/menu.js +++ b/client/ui/menu.js @@ -2,30 +2,45 @@ * 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) { - app.service("menu", function ($route) { - menu.isActive = function (path) { - if ($route.current && $route.current.regexp) { - return $route.current.regexp.test(path); + Menu.prototype.activate = function (path) { + var f = this.items.filter(function (i) { + return i.url === 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; }); app.controller("MenuController", function ($scope, menu) { - $scope.vkgroup = menu.vkgroup; - $scope.menu = menu.menu; + $scope.menu = menu; - $scope.isCurrent = function(item) { - return menu.isActive(item.url); + $scope.isActive = function (item) { + if(menu.current) { + return item.url == menu.current.url; + }else{ + return false; + } }; - $scope.isValid = function(item) { - return Boolean(item.url); + $scope.isValid = function (item) { + return 'url' in item; }; }); }; \ No newline at end of file diff --git a/models/menu.json b/models/menu.json index 9b9beac2..45340eed 100644 --- a/models/menu.json +++ b/models/menu.json @@ -1,37 +1,34 @@ -{ - "menu": [ - { - "text": "Школа", - "url": "/", - "color": "blue" - }, - { - "text": "События" - }, - { - "text": "Расписание", - "url": "/schedule", - "color": "green" - }, - { - "text": "Занятия", - "color": "" - }, - { - "text": "Коллектив", - "url": "/team", - "color": "pink" - }, - { - "text": "Галерея", - "url": "/gallery", - "color": "red" - }, - { - "text": "Документы", - "url": "/docs", - "color": "yellow" - } - ], - "vkgroup": "https://vk.com/club10436104" -} +[ + { + "text": "Школа", + "url": "/", + "color": "blue" + }, + { + "text": "События" + }, + { + "text": "Расписание", + "url": "/schedule", + "color": "green" + }, + { + "text": "Занятия", + "color": "" + }, + { + "text": "Коллектив", + "url": "/team", + "color": "pink" + }, + { + "text": "Галерея", + "url": "/gallery", + "color": "red" + }, + { + "text": "Документы", + "url": "/docs", + "color": "yellow" + } +] \ No newline at end of file diff --git a/templates/main-dev.html b/templates/main-dev.html index a2aa7a3e..502d6ba4 100644 --- a/templates/main-dev.html +++ b/templates/main-dev.html @@ -33,7 +33,7 @@