-
Notifications
You must be signed in to change notification settings - Fork 1
fix #DH176 sidebar navigation on details page to match designs and re… #45
base: master
Are you sure you want to change the base?
Changes from 1 commit
55c65b7
cd0718b
8ed0735
2ea3e0c
e093748
f77d217
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// TODO move globally or into the config ? has to be the same as the media query for tablets | ||
const enableIfScreenSmallerThan = 641 | ||
const DOM_EL_WINDOW = '.tabbedwindow' | ||
const DOM_EL_TAB = '.tabbedwindow__tab' | ||
const DOM_EL_TAB_ICON = '.tabbedwindow__tab__icon' | ||
const DOM_EL_NAV = '.tabbedwindow__nav' | ||
const DOM_EL_PANE = '.tabbedwindow__pane' | ||
|
||
const CSS_CLASS_TAB = `${DOM_EL_TAB}`.replace('.', '') | ||
const CSS_CLASS_TAB_ACTIVE = `${CSS_CLASS_TAB}--active` | ||
|
||
let toggleEnabled = null | ||
|
||
function TabbedWindow () { | ||
this.toggleEnabled = null | ||
this.domEl = document.querySelector(DOM_EL_WINDOW) | ||
this.domElTabs = [].slice.call(document.querySelectorAll(DOM_EL_TAB)) | ||
this.domElNav = document.querySelector(DOM_EL_NAV) | ||
this.domElPane = document.querySelector(DOM_EL_PANE) | ||
} | ||
|
||
TabbedWindow.prototype = { | ||
onActiveItems: function () { | ||
return document.querySelectorAll(CSS_CLASS_TAB_ACTIVE) | ||
}, | ||
getNonActiveItems: function () { | ||
return this.domElTabs.filter(tab => tab.classList.contains(CSS_CLASS_TAB_ACTIVE) === false) | ||
}, | ||
disableActiveLink: function () { | ||
return document.querySelector('.' + CSS_CLASS_TAB_ACTIVE).setAttribute('onclick', 'return false') | ||
}, | ||
|
||
isItemCollapsed: function (item) { | ||
let chevron = item.querySelector(DOM_EL_TAB_ICON) | ||
return chevron.classList.contains('fa-chevron-down') | ||
}, | ||
|
||
getActiveItem: function () { | ||
return document.querySelector(`.${CSS_CLASS_TAB_ACTIVE}`) | ||
}, | ||
|
||
setChevronUp: function (item) { | ||
let chevron = item.querySelector(DOM_EL_TAB_ICON) | ||
chevron.classList.remove('fa-chevron-down') | ||
chevron.className += ' fa-chevron-up ' | ||
}, | ||
|
||
setChevronDown: function (item) { | ||
let chevron = item.querySelector(DOM_EL_TAB_ICON) | ||
chevron.classList.remove('fa-chevron-up') | ||
chevron.className += ' fa-chevron-down ' | ||
}, | ||
|
||
show: function (items) { | ||
[].forEach.call(items, function (a) { | ||
a.style.display = null | ||
}) | ||
}, | ||
|
||
hide: function (items) { | ||
[].forEach.call(items, function (a) { | ||
a.style.display = 'none' | ||
}) | ||
}, | ||
updateDisplay: function () { | ||
// @TODO stop calling updateDisplay resize | ||
// running dom queries on window resize is bad for performance | ||
// switch to event driven UI (JS Events) | ||
let screenIsSmall = document.documentElement.clientWidth <= enableIfScreenSmallerThan | ||
if (screenIsSmall) { | ||
this.hide(this.getNonActiveItems()) | ||
this.toggleEnabled = true | ||
this.disableActiveLink() | ||
} else { | ||
this.setChevronDown(this.getActiveItem()) | ||
this.show(this.domElTabs) | ||
this.toggleEnabled = false | ||
} | ||
}, | ||
onTabClick: function (e) { | ||
let el = e.target | ||
if (!el.classList.contains(CSS_CLASS_TAB)) { | ||
return | ||
} | ||
if (!this.toggleEnabled) { | ||
return | ||
} | ||
if (this.isItemCollapsed(el)) { | ||
this.setChevronUp(el) | ||
this.show(this.getNonActiveItems()) | ||
} else { | ||
this.setChevronDown(el) | ||
this.hide(this.getNonActiveItems()) | ||
} | ||
}, | ||
init: function () { | ||
// @TODO setinterval on resize callback being fired for performance reason | ||
window.addEventListener('resize', this.updateDisplay.bind(this)) | ||
window.addEventListener('load', this.updateDisplay.bind(this)) | ||
// expand/collapse logic | ||
|
||
this.domEl.addEventListener('click', this.onTabClick.bind(this)) | ||
console.log('TabWindow initialied!') | ||
console.log(this) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consoles must die There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. terminated |
||
} | ||
} | ||
|
||
module.exports = TabbedWindow |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const TabbedWindow = require('../../components/TabbedWindow') | ||
let oTabbedWindow = new TabbedWindow() | ||
|
||
oTabbedWindow.init() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
.tabbedwindow { | ||
@extend .clearfix; | ||
// layout | ||
&__nav, &__pane { | ||
float:left; | ||
} | ||
&__nav { | ||
width:25%; | ||
// @extend %site-width-container; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove commented out code if this is a finished file |
||
// @extend %contain-floats; | ||
// clear: both; | ||
|
||
} | ||
&__pane { | ||
margin-left:10%; | ||
width:65%; | ||
} | ||
&__tab { | ||
display:block; | ||
height:50px; | ||
padding-left:1rem; | ||
vertical-align:middle; | ||
line-height: 50px; | ||
text-decoration: underline; | ||
position:relative; | ||
&:hover, &:visited { | ||
color:$black; | ||
} | ||
&--active { | ||
background:$govuk-blue; | ||
color:$white; | ||
font-weight: bold; | ||
text-decoration: none; | ||
&:hover, &:visited { | ||
color:$white; | ||
} | ||
& .tabbedwindow__tab__icon { | ||
display: block; | ||
} | ||
@include media (tablet) { | ||
& .tabbedwindow__tab__icon { | ||
display: none; | ||
} | ||
} | ||
|
||
} | ||
&__icon { | ||
color:$white; | ||
position: absolute; | ||
right:1rem; | ||
top: 50%; | ||
transform:translate3d(0, -50%, 0); | ||
display: none; | ||
@include media(tablet) { | ||
display: none; | ||
} | ||
// &.fa { | ||
// display:none; | ||
// } | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,8 @@ | |
* Eventually variables can be split across multiple files | ||
* @type {[type]} | ||
*/ | ||
$mobile-break-point-max:320px; | ||
|
||
// $tablet-breakpoint: 641px !default; | ||
// $desktop-breakpoint: 769px !default; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delete There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gone |
||
$mobile-breakpoint-max:320px; | ||
$tablet-breakpoint-min:640px; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,6 @@ | |
{% import "macros/trade.html" as trade %} | ||
{% import "./investment_macros.html" as local %} | ||
|
||
|
||
|
||
<section class="projectheader"> | ||
<div class="projectoverview"> | ||
<h1 class="heading-large">{{ projectTitle | default('Project title goes here') }}</h1> | ||
|
@@ -19,7 +17,22 @@ <h1 class="heading-large">{{ projectTitle | default('Project title goes here') } | |
{% include "./partials/projectstatusbar.html" %} | ||
|
||
</section> | ||
<div class="left-nav-container"> | ||
<section class="tabbedwindow"> | ||
<nav class="tabbedwindow__nav"> | ||
{% for tab in navItems %} | ||
<a href="{{tab.url}}" class="tabbedwindow__tab{% if tab.tab == 'summary' %} tabbedwindow__tab--active{% endif %}"> | ||
{{tab.label}} | ||
<i class="tabbedwindow__tab__icon collapse-filter-js fa fa-chevron-down"></i> | ||
</a> | ||
{% endfor %} | ||
</nav> | ||
<div class="tabbedwindow__pane"> | ||
{% block tabmain%}{% endblock %} | ||
</div> | ||
</section> | ||
|
||
|
||
{# <div class="left-nav-container"> | ||
<div class="left-nav"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delete commented out code if not here for a good reason There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gone |
||
<nav> | ||
<div class="{% if tab == 'summary' %}active{% endif %}"> | ||
|
@@ -57,11 +70,12 @@ <h1 class="heading-large">{{ projectTitle | default('Project title goes here') } | |
{% block tabmain%}{% endblock %} | ||
|
||
|
||
</div> | ||
</div> #} | ||
</div> | ||
<script src="/javascripts/common.js"></script> | ||
|
||
<script src="/javascripts/leftnav.bundle.js"></script> | ||
{# <script src="/javascripts/leftnav.bundle.js"></script> #} | ||
<script src="/javascripts/investment_details.bundle.js"></script> | ||
|
||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah this is going to hurt - don't we have a debounce function lying around?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i could write one if we don't have one already?
I have just realised we are using lodash already in this project so can use the one included there