Skip to content

Commit

Permalink
Multilevel offcanvas menu
Browse files Browse the repository at this point in the history
  • Loading branch information
socketz committed Jun 20, 2014
1 parent 7ddd42f commit b6d3c62
Show file tree
Hide file tree
Showing 5 changed files with 274 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{{#markdown}}
```html
<div class="off-canvas-wrap">
<div class="inner-wrap">
<nav class="tab-bar">
<section class="left-small">
<a class="left-off-canvas-toggle menu-icon" ><span></span></a>
</section>

<section class="middle tab-bar-section">
<h1 class="title">Foundation</h1>
</section>

<section class="right-small">
<a class="right-off-canvas-toggle menu-icon" ><span></span></a>
</section>
</nav>

<aside class="left-off-canvas-menu">
<ul class="off-canvas-list">
<li><label>Foundation</label></li>
<li class="has-submenu"><a href="#" class="icon-left">The Psychohistorians</a>
<ul class="left-off-canvas-submenu">
<li class="back"><a href="#">Back &raquo;</a></li>
<li><label>Level 1</label></li>
<li><a href="#">Link 1</a></li>
<li class="has-submenu"><a href="#" class="icon-left">Link 2 w/ submenu</a>
<ul class="left-off-canvas-submenu">
<li class="back"><a href="#">Back &raquo;</a></li>
<li><label>Level 2</label></li>
<li><a href="#">...</a></li>
</ul>
</li>
<li><a href="#">...</a></li>
</ul>
</li>
<li><a href="#">The Encyclopedists</a></li>
<li><a href="#">The Mayors</a></li>
<li><a href="#">The Traders</a></li>
<li><a href="#">The Merchant Princes</a></li>
</ul>
</aside>

<aside class="right-off-canvas-menu">
<ul class="off-canvas-list">
<li><label>Users</label></li>
<li><a href="#">Hari Seldon</a></li>
<li><a href="#">...</a></li>
</ul>
</aside>

<section class="main-section">
<!-- content goes here -->
</section>

<a class="exit-off-canvas"></a>

</div>
</div>
```
{{/markdown}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<div class="off-canvas-wrap docs-wrap">
<div class="inner-wrap">
<nav class="tab-bar">
<section class="left-small">
<a class="left-off-canvas-toggle menu-icon" ><span></span></a>
</section>

<section class="middle tab-bar-section">
<h1 class="title">Foundation</h1>
</section>

<section class="right-small">
<a class="right-off-canvas-toggle menu-icon" ><span></span></a>
</section>
</nav>

<aside class="left-off-canvas-menu">
<ul class="off-canvas-list">
<li><label>Foundation</label></li>
<li class="has-submenu"><a href="#" class="icon-left">The Psychohistorians</a>
<ul class="left-off-canvas-submenu">
<li class="back"><a href="#">Back &raquo;</a></li>
<li><label>Level 1</label></li>
<li><a href="#">Link 1</a></li>
<li class="has-submenu"><a href="#" class="icon-left">Link 2 w/ submenu</a>
<ul class="left-off-canvas-submenu">
<li class="back"><a href="#">Back &raquo;</a></li>
<li><label>Level 2</label></li>
<li><a href="#">Link 1</a></li>
<li><a href="#">Link 2</a></li>
<li><a href="#">Link 3</a></li>
<li><a href="#">Link 4</a></li>
</ul>
</li>
<li><a href="#">Link 3</a></li>
<li><a href="#">Link 4</a></li>
</ul>
</li>
<li><a href="#">The Encyclopedists</a></li>
<li><a href="#">The Mayors</a></li>
<li><a href="#">The Traders</a></li>
<li><a href="#">The Merchant Princes</a></li>
</ul>
</aside>

<aside class="right-off-canvas-menu">
<ul class="off-canvas-list">
<li><label>Users</label></li>
<li><a href="#">Hari Seldon</a></li>
<li><a href="#">R. Giskard Reventlov</a></li>
<li><a href="#">R. Daneel Olivaw</a></li>
<li><a href="#">The Mule</a></li>
<li><a href="#">Dors Venabili</a></li>
<li><a href="#">Yugo Amaryl</a></li>
<li><a href="#">The Mule</a></li>
<li><a href="#">Emperor Cleon I</a></li>
<li><a href="#">Gaal Dornick</a></li>
<li><a href="#">Bel Riose</a></li>
<li><a href="#">Salvor Hardin</a></li>
<li><a href="#">Bel Riose</a></li>
</ul>
</aside>

<section class="main-section">
<div class="row">
<div class="large-12 columns">
<br/>
<h4 class="">The Psychohistorians</h4>

<p>Set in the year 0 F.E. ("Foundation Era"), The Psychohistorians opens on Trantor, the capital of the 12,000-year-old Galactic Empire. Though the empire appears stable and powerful, it is slowly decaying in ways that parallel the decline of the Western Roman Empire. Hari Seldon, a mathematician and psychologist, has developed psychohistory, a new field of science and psychology that equates all possibilities in large societies to mathematics, allowing for the prediction of future events.</p>

<p>Using psychohistory, Seldon has discovered the declining nature of the Empire, angering the aristocratic members of the Committee of Public Safety, the de facto rulers of the Empire. The Committee considers Seldon's views and statements treasonous, and he is arrested along with young mathematician Gaal Dornick, who has arrived on Trantor to meet Seldon. Seldon is tried by the Committee and defends his beliefs, explaining his theories and predictions, including his belief that the Empire will collapse in 500 years and enter a 30,000-year dark age, to the Committee's members.</p>

</div>
</div>
</section>

<a class="exit-off-canvas"></a>

</div>
</div>
18 changes: 18 additions & 0 deletions doc/pages/components/offcanvas.html
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ <h4>HTML</h4>
<section class="left tab-bar-section"><h1>Right Section</h1></section>
<section class="right-small"><a class=" menu-icon" ><span></span></a></section>
</nav>

&nbsp;

### Off-Canvas List
Expand Down Expand Up @@ -257,6 +258,23 @@ <h4>Rendered HTML</h4>
</div>
</div>

&nbsp;

### Off-Canvas Multilevel Menu

We've included a nice multilevel pattern for list in the off-canvas menu. Add a `li.has-submenu` and include `ul.left-off-canvas-submenu` inside your to define a submenu, later add `li.back` element inside this new list. This supports multiple level of submenus

<div class="row">
<div class="large-6 columns">
<h4>HTML</h4>
{{> examples_offcanvas_multiple_level_markup}}
</div>
<div class="large-6 columns">
<h4>Rendered HTML</h4>
{{> examples_offcanvas_multiple_level_rendered}}
</div>
</div>

***

## Customize With Sass
Expand Down
37 changes: 30 additions & 7 deletions js/foundation/foundation.offcanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
Foundation.libs.offcanvas = {
name : 'offcanvas',

version : '5.2.1',
version : '5.2.2',

settings : {},
settings : {
close_on_click: true
},

init : function (scope, method, options) {
this.events();
Expand All @@ -18,23 +20,44 @@

S(this.scope).off('.offcanvas')
.on('click.fndtn.offcanvas', '.left-off-canvas-toggle', function (e) {
self.click_toggle_class(e, 'move-right');
self.click_toggle_class(e, 'move-right');
S(".left-off-canvas-submenu").removeClass('move-right');
})
.on('click.fndtn.offcanvas', '.left-off-canvas-menu a', function (e) {
S(".off-canvas-wrap").removeClass("move-right");
if(self.settings.close_on_click && !S(this).parent().hasClass("has-submenu") && !S(this).parent().hasClass("back")){
S(".off-canvas-wrap").removeClass("move-right");
S(this).parent().parent().removeClass('move-right');
}else if(S(this).parent().hasClass("has-submenu")){
e.preventDefault();
S(this).siblings(".left-off-canvas-submenu").toggleClass('move-right');
}else if(S(this).parent().hasClass("back")){
e.preventDefault();
S(this).parent().parent().removeClass('move-right');
}
})
.on('click.fndtn.offcanvas', '.right-off-canvas-toggle', function (e) {
self.click_toggle_class(e, 'move-left');
S(".right-off-canvas-submenu").removeClass('move-left');
})
.on('click.fndtn.offcanvas', '.right-off-canvas-menu a', function (e) {
S(".off-canvas-wrap").removeClass("move-left");
if(self.settings.close_on_click && !S(this).parent().hasClass("has-submenu") && !S(this).parent().hasClass("back")){
S(".off-canvas-wrap").removeClass("move-left");
S(this).parent().parent().removeClass('move-left');
}else if(S(this).parent().hasClass("has-submenu")){
e.preventDefault();
S(this).siblings(".right-off-canvas-submenu").toggleClass('move-left');
}else if(S(this).parent().hasClass("back")){
e.preventDefault();
S(this).parent().parent().removeClass('move-left');
}
})
.on('click.fndtn.offcanvas', '.exit-off-canvas', function (e) {
self.click_remove_class(e, 'move-left');
self.click_remove_class(e, 'move-right');
S(".left-off-canvas-submenu").removeClass('move-right');
S(".right-off-canvas-submenu").removeClass('move-left');
})
},

click_toggle_class: function(e, class_name) {
e.preventDefault();
this.S(e.target).closest('.off-canvas-wrap').toggleClass(class_name);
Expand All @@ -47,4 +70,4 @@

reflow : function () {}
};
}(jQuery, this, this.document));
}(jQuery, this, this.document));
84 changes: 84 additions & 0 deletions scss/foundation/components/_offcanvas.scss
Original file line number Diff line number Diff line change
Expand Up @@ -379,3 +379,87 @@ $menu-slide: "transform 500ms ease" !default;

}
}

//
// Off-Canvas Submenu Classes
//
@mixin off-canvas-submenu($position) {
@include kill-flicker;
* { @include kill-flicker; }
width: $off-canvas-width;
top: 0;
bottom: 0;
position: absolute;
margin: 0;
overflow-y: auto;
background: $off-canvas-bg;
z-index: 1002;
box-sizing: content-box;
-webkit-overflow-scrolling: touch;
@if $position == left {
@include translate3d(-100%,0,0);
left: 0;
}
@if $position == right {
@include translate3d(100%,0,0);
right: 0;
}
-webkit-transition: -webkit-#{$menu-slide};
-moz-transition: -moz-#{$menu-slide};
-ms-transition: -ms-#{$menu-slide};
-o-transition: -o-#{$menu-slide};
transition: #{$menu-slide};

//back button style like label
.back > a {
padding: $off-canvas-label-padding;
color: $off-canvas-label-color;
text-transform: $off-canvas-label-text-transform;
font-weight: $off-canvas-label-font-weight;
background: $off-canvas-label-bg;
border-top: $off-canvas-label-border-top;
border-bottom: $off-canvas-label-border-bottom;
margin: $off-canvas-label-margin;
}
}
//Left double angle quote or Right double angle quote chars
@mixin icon-double-arrows ($position){
@if $position == left {
content: "\AB";
margin-right: 0.5rem;
}
@if $position == right {
content: "\BB";
margin-left: 0.5rem;
}
}

@if $include-html-off-canvas-classes {
.left-off-canvas-submenu { @include off-canvas-submenu($position: left);
&.move-right {
@include translate3d(0%,0,0);
}
}

.right-off-canvas-submenu { @include off-canvas-submenu($position: right);
&.move-left {
@include translate3d(0%,0,0);
}
}
ul.off-canvas-list {
li {
a.icon-left:before {
@include icon-double-arrows($position: left);
display: inline;
position: relative;
}
a.icon-right:after {
@include icon-double-arrows($position: right);
display: inline;
position: relative;
}

}
}

}

0 comments on commit b6d3c62

Please sign in to comment.