mirror of
https://github.com/openstf/stf
synced 2025-10-05 10:39:25 +02:00
- New nav menu active links work.
This commit is contained in:
parent
593e14a80a
commit
533ce2d967
4 changed files with 27 additions and 26 deletions
|
@ -1,31 +1,42 @@
|
||||||
|
// Based from https://ryankaskel.com/blog/2013/05/27/a-different-approach-to-angularjs-navigation-menus
|
||||||
|
|
||||||
|
|
||||||
module.exports = function ($location) {
|
module.exports = function ($location) {
|
||||||
return function (scope, element, attrs) {
|
return function (scope, element, attrs) {
|
||||||
var links = element.find('a')
|
var links = element.find('a')
|
||||||
var onClass = attrs.navMenu || 'current'
|
var onClass = attrs.navMenu || 'current'
|
||||||
var routePattern
|
var routePattern
|
||||||
|
var routeBasePattern = /\/#[^/]*/ // TODO: add regex to remove last part of the url
|
||||||
var link
|
var link
|
||||||
var url
|
var url
|
||||||
var currentLink
|
var currentLink
|
||||||
var urlMap = {}
|
var urlMap = []
|
||||||
var i
|
var i
|
||||||
|
|
||||||
if (!$location.$$html5) {
|
if (!$location.$$html5) {
|
||||||
routePattern = /^#[^/]*/
|
routePattern = /\/#[^/]*/
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < links.length; i++) {
|
for (i = 0; i < links.length; i++) {
|
||||||
link = angular.element(links[i])
|
link = angular.element(links[i])
|
||||||
url = link.attr('href')
|
url = link.attr('ng-href')
|
||||||
|
|
||||||
if ($location.$$html5) {
|
if ($location.$$html5) {
|
||||||
urlMap[url] = link
|
urlMap.push({url: url, link: link})
|
||||||
} else {
|
} else {
|
||||||
urlMap[url.replace(routePattern, '')] = link
|
urlMap.push({url: url.replace(routePattern, ''), link: link})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
scope.$on('$routeChangeStart', function () {
|
function activateLink() {
|
||||||
var pathLink = urlMap[$location.path()]
|
var location = $location.path()
|
||||||
|
var pathLink = ''
|
||||||
|
|
||||||
|
for (i = 0; i < urlMap.length; ++i) {
|
||||||
|
if (urlMap[i].url == location) {
|
||||||
|
pathLink = urlMap[i].link
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (pathLink) {
|
if (pathLink) {
|
||||||
if (currentLink) {
|
if (currentLink) {
|
||||||
|
@ -34,6 +45,9 @@ module.exports = function ($location) {
|
||||||
currentLink = pathLink;
|
currentLink = pathLink;
|
||||||
currentLink.addClass(onClass);
|
currentLink.addClass(onClass);
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
|
activateLink()
|
||||||
|
scope.$on('$routeChangeStart', activateLink)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,7 +6,7 @@ module.exports = angular.module('device-control', [
|
||||||
require('stf/screen').name
|
require('stf/screen').name
|
||||||
])
|
])
|
||||||
.config(['$routeProvider', function ($routeProvider) {
|
.config(['$routeProvider', function ($routeProvider) {
|
||||||
$routeProvider.when('/devices/:serial', {
|
$routeProvider.when('/control/:serial', {
|
||||||
template: require('./device-control.jade'),
|
template: require('./device-control.jade'),
|
||||||
controller: 'DeviceControlCtrl'
|
controller: 'DeviceControlCtrl'
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,16 +1,3 @@
|
||||||
module.exports = function MenuCtrl($scope) {
|
module.exports = function MenuCtrl($scope) {
|
||||||
|
|
||||||
$scope.isActive = function (viewLocation) {
|
|
||||||
var pattern = '/' + viewLocation,
|
|
||||||
re = new RegExp(pattern);
|
|
||||||
return re.test($location.path());
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.isActive = function (path) {
|
|
||||||
console.log($location.path())
|
|
||||||
console.log($location.path().substr(0, path.length))
|
|
||||||
|
|
||||||
return $location.path().substr(0, path.length) == path;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
.navbar.stf-menu
|
.navbar.stf-menu
|
||||||
.container-fluid.stf-top-bar
|
.container-fluid.stf-top-bar
|
||||||
a.stf-logo(href="/") STF 2
|
a.stf-logo(href="/") STF 2
|
||||||
ul.nav.stf-nav(nav-menu)
|
ul.nav.stf-nav(nav-menu='current')
|
||||||
li(ng-cloak)
|
li(ng-cloak)
|
||||||
a(href='/#!/control')
|
a(ng-href='/#!/control')
|
||||||
span.fa.fa-mobile
|
span.fa.fa-mobile
|
||||||
| {{"Control"|translate}}
|
| {{"Control"|translate}}
|
||||||
a(href='/#!/devices')
|
a(ng-href='/#!/devices')
|
||||||
span.fa.fa-sitemap
|
span.fa.fa-sitemap
|
||||||
| {{"Devices"|translate}}
|
| {{"Devices"|translate}}
|
||||||
a(href='/#!/settings')
|
a(ng-href='/#!/settings')
|
||||||
span.fa.fa-gears
|
span.fa.fa-gears
|
||||||
| {{"Settings"|translate}}
|
| {{"Settings"|translate}}
|
||||||
ul.nav.stf-nav.stf-feedback.pull-right(ng-cloak)
|
ul.nav.stf-nav.stf-feedback.pull-right(ng-cloak)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue