Change portal mode icon when in portal mode

This commit is contained in:
Joe Fiorini
2015-04-21 16:46:03 -04:00
parent 91fe2b5444
commit d760c96596
7 changed files with 111 additions and 5 deletions

View File

@@ -12,6 +12,7 @@ function link(scope, element, attrs) {
scope.$watch(function(scope) {
return scope.$eval(scope.style);
}, function(value) {
console.log('changed', scope.$eval(scope.style));
scope.menuStylePartialUrl = getMenuStylePartialUrl(value);
});
}

View File

@@ -1,7 +1,9 @@
import mainMenu from './main-menu.directive';
import menuItem from './menu-item.directive';
import portalModeLink from './portal-mode-link.directive';
export default
angular.module('mainMenu', [])
.directive('portalModeLink', portalModeLink)
.directive('menuItem', menuItem)
.directive('mainMenu', mainMenu);

View File

@@ -20,7 +20,7 @@
<a href="#/setup" class="MenuItem MenuItem--right MenuItem--fixed" title="Setup">
<img src="/static/img/Setup.svg" class="MenuItem-icon">
</a>
<a href="#portal" class="MenuItem MenuItem--fixed" title="Setup">
<a portal-mode-link class="MenuItem MenuItem--fixed" title="Portal Mode">
<img src="/static/img/PortalMode.svg" class="MenuItem-icon">
</a>
<a href="#/logout" title="Sign out" class="MenuItem MenuItem--fixed">

View File

@@ -4,9 +4,6 @@
<a href="#portal" title="Portal" class="MenuItem">
Portal
</a>
<a href="#portal" class="MenuItem MenuItem--right MenuItem--fixed" title="Setup">
<a portal-mode-link class="MenuItem MenuItem--right MenuItem--fixed" title="Portal Mode">
<img src="/static/img/PortalMode.svg" class="MenuItem-icon">
</a>
<a href="#logout" title="Sign out" class="MenuItem MenuItem--fixed">
<img src="/static/img/Signout.svg" class="MenuItem-icon">
</a>

View File

@@ -0,0 +1,26 @@
function wrapper(rootScope) {
return function compile(element, attrs) {
var href, title, icon;
if (rootScope.portalMode) {
href = '#';
title = 'Exit Portal Mode';
icon = 'PortalMode--exit.svg';
} else {
href = '#portal';
title = 'Portal Mode';
icon = 'PortalMode.svg';
}
element
.attr('href', href)
.attr('title', title)
.find('>img')
.attr('src', '/static/img/' + icon);
}
}
export default ['$rootScope', function($rootScope) {
return {
compile: wrapper($rootScope)
};
}]

View File

@@ -0,0 +1,64 @@
// Typically ng-include requires the use of an extra tag like:
//
// <div ng-include="my-partial.html"></div>
//
// This means that the content from `my-partial.html` will _always_
// be wrapped in that extra div.
//
// This directive works with ngInclude to replace its own contents with
// the contents of the included partial.
//
// The high-level strategy here is to find the comment
// inserted by ng-include, remove all children after
// the comment (this will be the children inserted by
// this directiv) then insert the included children
// after the comment.
//
// So say we have:
//
// <include-partial ng-include="'my-partial.html'"></include-partial>
//
// and "my-partial.html" contains:
//
// <p>Item 1</p>
// <p>Item 2</p>
// <p>Item 3</p>
//
// When the <include-partial> link function runs the
// DOM will look like:
//
// <!-- ngInclude: 'my-partial.html' -->
// <include-partial ng-include="'my-partial.html'">
// <p>Item 1</p>
// <p>Item 2</p>
// <p>Item 3</p>
// </include-partial>
//
// First we find the comment, then we get all the
// chilren of <include-partial> (the contents of 'my-partial.html').
//
// Then we remove the <include-partial> tag and
// insert the its contents after the comment.
//
// There is a potential bug here if the <include-partial>
// is followed by other siblings, they will get removed
// too. We can fix this probably by inserting another
// comment and removing everything between the two
// comments instead.
export default function() {
return {
restrict: 'E',
link: function(scope, linkElement) {
var contents = Array.prototype.slice.apply(linkElement.parent().contents());
var commentNode = contents.filter(function(node) {
// This selects a comment node
return node.nodeType === 8;
});
var children = linkElement.children();
$(commentNode[0]).nextAll().remove();
$(commentNode[0]).after(children);
}
};
}