menu update: model, angular logic;
This commit is contained in:
1 parent
0e67001b26
commit
8d2d889759
5 files changed
+67
-53
No files matched your search
@@ -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,
|
||||
|
||||
+28
-13
@@ -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;
|
||||
};
|
||||
});
|
||||
};
|
||||
+34
-37
@@ -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"
|
||||
}
|
||||
]
|
||||
@@ -33,7 +33,7 @@
|
||||
<header>
|
||||
<nav role="navigation" ng-controller="MenuController">
|
||||
<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>
|
||||
<a href="{{item.url}}" ng-show="isValid(item)">{{item.text}}</a>
|
||||
</li>
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@
|
||||
<header>
|
||||
<nav role="navigation" ng-controller="MenuController">
|
||||
<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>
|
||||
<a href="{{item.url}}" ng-show="isValid(item)">{{item.text}}</a>
|
||||
</li>
|
||||
|
||||
Reference in new issue
Block a user