Skip to content

Commit

Permalink
initial sidemenu implementation using snap.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Wientge committed Dec 17, 2014
1 parent b8feae6 commit 38a385f
Show file tree
Hide file tree
Showing 12 changed files with 793 additions and 12 deletions.
5 changes: 5 additions & 0 deletions components/ionSideMenu/ionSideMenu.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template name="ionSideMenu">
<div class="{{classes}}">
{{> UI.contentBlock}}
</div>
</template>
15 changes: 15 additions & 0 deletions components/ionSideMenu/ionSideMenu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Template.ionSideMenu.helpers({
classes: function () {
var classes = ['snap-drawer'];

if (this.side) {
classes.push('menu-' + this.side);
classes.push('snap-drawer-' + this.side);
} else {
classes.push('menu-left');
classes.push('snap-drawer-left');
}

return classes.join(' ');
}
});
3 changes: 3 additions & 0 deletions components/ionSideMenuContainer/ionSideMenuContainer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template name="ionSideMenuContainer">
{{> UI.contentBlock}}
</template>
40 changes: 40 additions & 0 deletions components/ionSideMenuContainer/ionSideMenuContainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Template.ionSideMenuContainer.rendered = function () {
$snapperEl = this.$('.snap-content');
if (!$snapperEl) {
return;
}

this.snapper = new Snap({
element: $snapperEl.get(0)
});
};

Template.ionSideMenuContainer.events({
'click [data-ion-menu-toggle]': function (event, template) {
if (!template.snapper) {
return;
}

var direction;
var $el = $(event.target);

if ($el.data('ion-menu-toggle') !== '') {
direction = $el.data('ion-menu-toggle');
} else {
direction = 'left';
}

if(template.snapper.state().state === direction){
template.snapper.close();
} else {
template.snapper.open(direction);
}
},

'click [data-ion-menu-close]': function (event, template) {
if (!template.snapper) {
return;
}
template.snapper.close();
}
});
5 changes: 5 additions & 0 deletions components/ionSideMenuContent/ionSideMenuContent.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template name="ionSideMenuContent">
<div class="{{classes}}">
{{> UI.contentBlock}}
</div>
</template>
6 changes: 6 additions & 0 deletions components/ionSideMenuContent/ionSideMenuContent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Template.ionSideMenuContent.helpers({
classes: function () {
var classes = ['menu-content', 'snap-content', 'pane'];
return classes.join(' ');
}
});
5 changes: 5 additions & 0 deletions components/ionSideMenus/ionSideMenus.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template name="ionSideMenus">
<div class="{{classes}}">
{{> UI.contentBlock}}
</div>
</template>
6 changes: 6 additions & 0 deletions components/ionSideMenus/ionSideMenus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Template.ionSideMenus.helpers({
classes: function () {
var classes = ['view', 'snap-drawers'];
return classes.join(' ');
}
});
18 changes: 18 additions & 0 deletions package.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ Package.describe({
Package.onUse(function(api) {
api.versionsFrom("1.0");
api.use(["templating", "underscore"], "client");

api.addFiles([
"vendor/snap.js",
"vendor/snap.css"
], "client");

api.addFiles([
"components/ionBody/ionBody.html",
"components/ionBody/ionBody.js",
Expand Down Expand Up @@ -42,6 +48,18 @@ Package.onUse(function(api) {
"components/ionRadio/ionRadio.html",
"components/ionRadio/ionRadio.js",

"components/ionSideMenu/ionSideMenu.html",
"components/ionSideMenu/ionSideMenu.js",

"components/ionSideMenuContainer/ionSideMenuContainer.html",
"components/ionSideMenuContainer/ionSideMenuContainer.js",

"components/ionSideMenuContent/ionSideMenuContent.html",
"components/ionSideMenuContent/ionSideMenuContent.js",

"components/ionSideMenus/ionSideMenus.html",
"components/ionSideMenus/ionSideMenus.js",

"components/ionSubheaderBar/ionSubheaderBar.html",
"components/ionSubheaderBar/ionSubheaderBar.js",

Expand Down
70 changes: 58 additions & 12 deletions showcase/client/templates/sideMenu/sideMenu.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,60 @@
<template name="sideMenu">
{{#ionHeaderBar class="bar-positive"}}
<a href="{{pathFor 'index'}}" class="button button-clear pull-left">
{{> ionIcon icon='ios-arrow-back'}}
</a>
<h1 class="title">Side Menu</h1>
{{/ionHeaderBar}}

{{#ionContent}}
<div class="padding">
Content goes here
</div>
{{/ionContent}}

{{#ionSideMenuContainer}}

{{#ionSideMenus}}

{{#ionSideMenu}}
<div class="bar bar-header bar-dark">
<h1 class="title">Left Menu</h1>
</div>
<div class="content has-header">
<div class="list">
<div class="item item-icon-right" data-ion-menu-close>
Close Me {{> ionIcon icon="ios-arrow-right"}}
</div>
</div>
</div>
{{/ionSideMenu}}

{{#ionSideMenu side="right"}}
<div class="bar bar-header bar-dark">
<h1 class="title">Right Menu</h1>
</div>
<div class="content has-header">
<div class="list">
<div class="item item-icon-left" data-ion-menu-close>
{{> ionIcon icon="ios-arrow-left"}} Close Me
</div>
</div>
</div>
{{/ionSideMenu}}

{{/ionSideMenus}}

{{#ionSideMenuContent}}

{{#ionHeaderBar class="bar-positive"}}
<button class="button button-clear pull-left" data-ion-menu-toggle="left">
{{> ionIcon icon='navicon'}}
</button>
<h1 class="title">Side Menu</h1>
<button class="button button-clear pull-right" data-ion-menu-toggle="right">
{{> ionIcon icon='navicon'}}
</button>
{{/ionHeaderBar}}

{{#ionContent}}
<div class="padding">
<a href="{{pathFor 'index'}}" class="button button-large button-stable">
{{> ionIcon icon='ios-arrow-back'}}
Back to Showcase
</a>
</div>
{{/ionContent}}

{{/ionSideMenuContent}}

{{/ionSideMenuContainer}}

</template>
64 changes: 64 additions & 0 deletions vendor/snap.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
.snap-content {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
width: auto;
height: auto;
z-index: 2;
overflow: auto;
-webkit-overflow-scrolling: touch;
-webkit-transform: translate3d(0, 0, 0);
-moz-transform: translate3d(0, 0, 0);
-ms-transform: translate3d(0, 0, 0);
-o-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}

.snap-drawers {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
width: auto;
height: auto;
}

.snap-drawer {
position: absolute;
top: 0;
right: auto;
bottom: 0;
left: auto;
width: 265px;
height: auto;
overflow: auto;
-webkit-overflow-scrolling: touch;
-webkit-transition: width 0.3s ease;
-moz-transition: width 0.3s ease;
-ms-transition: width 0.3s ease;
-o-transition: width 0.3s ease;
transition: width 0.3s ease;
}

.snap-drawer-left {
left: 0;
z-index: 1;
}

.snap-drawer-right {
right: 0;
z-index: 1;
}

.snapjs-left .snap-drawer-right,
.snapjs-right .snap-drawer-left {
display: none;
}

.snapjs-expand-left .snap-drawer-left,
.snapjs-expand-right .snap-drawer-right {
width: 100%;
}
Loading

0 comments on commit 38a385f

Please sign in to comment.