menu update: model, angular logic;
This commit is contained in:
1 parent
0e67001b26
commit
8d2d889759
5 files changed
+34
-20
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(
|
api.gallery.album(
|
||||||
$routeParams.year,
|
$routeParams.year,
|
||||||
$routeParams.course,
|
$routeParams.course,
|
||||||
|
|||||||
+27
-12
@@ -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) {
|
module.exports = function (app) {
|
||||||
app.service("menu", function ($route) {
|
app.factory("menu", function ($route, $rootScope) {
|
||||||
menu.isActive = function (path) {
|
function Menu() {
|
||||||
if ($route.current && $route.current.regexp) {
|
this.items = require("../../models/menu.json");
|
||||||
return $route.current.regexp.test(path);
|
this.current = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
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
@@ -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"
|
|
||||||
}
|
|
||||||
@@ -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
@@ -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>
|
||||||
|
|||||||
Reference in new issue
Block a user