Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flow integration #221

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ To get a nice Ionic styled list item wrap your content in a `ionItem` block temp

#### Path and Link Examples

Meteor uses Iron:Router. Most are familiar with Iron:Router's [pathFor](https://github.com/EventedMind/iron-router/blob/devel/Guide.md#pathfor) and [urlFor](https://github.com/EventedMind/iron-router/blob/devel/Guide.md#urlfor) helpers. Meteoric lets you tap into those helpers from within `ionItem` or ignore them, the choice is yours.
Meteor uses Iron:FlowRouter. Most are familiar with Iron:FlowRouter's [pathFor](https://github.com/EventedMind/iron-router/blob/devel/Guide.md#pathfor) and [urlFor](https://github.com/EventedMind/iron-router/blob/devel/Guide.md#urlfor) helpers. Meteoric lets you tap into those helpers from within `ionItem` or ignore them, the choice is yours.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As flow-router doesn't provides these methods natively, the current option seems to be @arillo's meteor-flow-router-helpers.


To call IR's `pathFor` you would specify your route in the `path` attribute.

Expand Down Expand Up @@ -314,7 +314,7 @@ Lastly you can also pass a raw url by including the `href` attribute.
{{/ionList}}
```

**IronRouter's pathFor href**
**IronFlowRouter's pathFor href**

```
{{! href="/item/details/jkh34k234h?parentId=hkjh45j43k3#reviews" }}
Expand All @@ -329,7 +329,7 @@ Lastly you can also pass a raw url by including the `href` attribute.
{{/ionList}}
```

**IronRouter's urlFor href**
**IronFlowRouter's urlFor href**

```
{{! href="http://www.example.com/item/details?parentId=hkjh45j43k3" }}
Expand Down
25 changes: 24 additions & 1 deletion components/ionActionSheet/ionActionSheet.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
function transitionEndEventName () {
var i,
undefined,
el = document.createElement('div'),
transitions = {
'transition':'transitionend',
'OTransition':'otransitionend', // oTransitionEnd in very old Opera
'MozTransition':'transitionend',
'WebkitTransition':'webkitTransitionEnd'
};

for (i in transitions) {
if (transitions.hasOwnProperty(i) && el.style[i] !== undefined) {
return transitions[i];
}
}

//TODO: throw 'TransitionEnd event is not supported in this browser';
}

IonActionSheet = {
transitionEndEvent: 'transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd',
transitionEndEvent: transitionEndEventName(),

show: function (options) {
this.template = Template.ionActionSheet;
Expand Down Expand Up @@ -67,6 +87,9 @@ IonActionSheet = {

$wrapper.on(this.transitionEndEvent, function () {
$('body').removeClass('action-sheet-open');

// added this because of https://github.com/meteor/meteor/issues/3828
$('.action-sheet-backdrop').remove();
Blaze.remove(this.view);

if (typeof(callback) === 'function') {
Expand Down
2 changes: 1 addition & 1 deletion components/ionBody/ionBody.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template name="ionBody">
<div class="ionic-body {{platformClasses}}">
{{> UI.contentBlock}}
{{> Template.contentBlock}}
</div>
</template>
2 changes: 1 addition & 1 deletion components/ionContent/ionContent.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template name="ionContent">
<div class="scroll-content ionic-scroll">
<div class="{{classes}}">
{{> UI.contentBlock}}
{{> Template.contentBlock}}
</div>
</div>
</template>
2 changes: 1 addition & 1 deletion components/ionFooterBar/ionFooterBar.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template name="ionFooterBar">
<div class="{{classes}}">
{{> UI.contentBlock}}
{{> Template.contentBlock}}
</div>
</template>
2 changes: 1 addition & 1 deletion components/ionHeaderBar/ionHeaderBar.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template name="ionHeaderBar">
<div class="{{classes}}">
{{> UI.contentBlock}}
{{> Template.contentBlock}}
</div>
</template>
6 changes: 3 additions & 3 deletions components/ionItem/ionItem.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<template name="ionItem">
{{#if isAnchor}}
<a class="{{itemClasses}}" href="{{url}}" target="{{target}}">
{{> UI.contentBlock}}
{{> Template.contentBlock}}
</a>
{{else}}
<div class="{{itemClasses}}">
{{> UI.contentBlock}}
<div class="{{itemClasses}}" {{attrs}}>
{{> Template.contentBlock}}
</div>
{{/if}}
</template>
10 changes: 9 additions & 1 deletion components/ionItem/ionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,16 @@ Template.ionItem.helpers({
}

} else {
return Router.routes[path].path(Template.parentData(1));
return RouterLayer.getPath(path);
}
}
},

attrs: function() {
var ret = {};
if (this.id) {
ret.id = this.id;
}
return ret;
}
});
33 changes: 18 additions & 15 deletions components/ionNavBackButton/ionNavBackButton.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
IonScrollPositions = {};

Router.onStop(function () {
/*
RouterLayer.onStop(function () {
IonScrollPositions[this.route.path(this.params)] = $('.overflow-scroll').scrollTop();
});
});*/

Template.ionNavBackButton.events({
'click': function (event, template) {
$('[data-nav-container]').addClass('nav-view-direction-back');
$('[data-navbar-container]').addClass('nav-bar-direction-back');

//get most up-to-date url, if it exists
backUrl = template.getBackUrl()
if (backUrl) {
Router.go(backUrl);

if (template.backUrl) {
RouterLayer.go(template.backUrl);
} else {
window.history.back();
}
Expand All @@ -24,14 +22,19 @@ Template.ionNavBackButton.created = function () {
};

Template.ionNavBackButton.rendered = function () {
var self = this;
this.getBackUrl = function () {
var backUrl = null;
this.backUrl = null;

self.data = self.data || {};

if (self.data.href) {
backUrl = self.data.href;
this.data = this.data || {};

if (this.data.href) {
this.backUrl = this.data.href;
}

if (this.data.path) {
backRoute = RouterLayer.routes[this.data.path]
if (!backRoute) {
console.warn("back to nonexistent route: ", this.data.path);
return;
}

if (self.data.path) {
Expand Down
4 changes: 1 addition & 3 deletions components/ionNavBar/ionNavBar.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<template name="ionNavBar">
<div class="{{classes}} nav-bar-block nav-bar-transition-{{transition}} nav-bar-direction-forward" data-navbar-container>
{{> yield "headerButtonLeft"}}
{{> yield "headerTitle"}}
{{> yield "headerButtonRight"}}
{{> Template.contentBlock}}
</div>
</template>
4 changes: 2 additions & 2 deletions components/ionNavView/ionNavView.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Template.ionNavView.created = function () {
}
};

Template.ionNavView.rendered = function () {
Template.ionNavView.onRendered(function () {
var template = this;
var container = this.find('[data-nav-container]');

Expand Down Expand Up @@ -66,7 +66,7 @@ Template.ionNavView.rendered = function () {
}, template.transitionDuration);
}
};
};
});

Template.ionNavView.helpers({
transition: function () {
Expand Down
2 changes: 1 addition & 1 deletion components/ionSlideBox/ionSlideBox.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template name="ionSlideBox">
<div class="ion-slide-box">
{{> UI.contentBlock}}
{{> Template.contentBlock}}
</div>
</template>
2 changes: 1 addition & 1 deletion components/ionSubheaderBar/ionSubheaderBar.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template name="ionSubheaderBar">
<div class="{{classes}}">
{{> UI.contentBlock}}
{{> Template.contentBlock}}
</div>
</template>
25 changes: 7 additions & 18 deletions components/ionTab/ionTab.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
Template.ionTab.events({
'click': function (event, template) {
if (template.data.path) {
Session.set('ionTab.current', template.data.path);
}


// If the tab's content is being rendered inside of a ionNavView
// we don't want to slide it in when switching tabs
IonNavigation.skipTransitions = true;
Expand All @@ -26,24 +23,16 @@ Template.ionTab.helpers({
if (this.href) {
return this.href;
}

if (this.path && Router.routes[this.path]) {
return Router.routes[this.path].path(Template.currentData());

// kept for backwards compatibility
if (this.path) {
return this.path;
}
},

isActive: function () {
var ionTabCurrent = Session.get('ionTab.current');

if (this.path && this.path === ionTabCurrent) {
return 'active';
}

// The initial case where there is no localStorage value and
// no session variable has been set, this attempts to set the correct tab
// to active based on the router
var route = Router.routes[this.path];
if(route && route.path(Template.currentData()) === ionTabCurrent){
var route = RouterLayer.getPath(true);
if(route === this.path){
return 'active';
}
},
Expand Down
21 changes: 7 additions & 14 deletions components/ionTabs/ionTabs.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
Template.ionTabs.created = function () {
Template.ionTabs.onCreated(function () {
this.data = this.data || {};
};
});

Template.ionTabs.rendered = function () {
Template.ionTabs.onRendered(function () {
if ((this.data.class && this.data.class.indexOf('tabs-top') > -1) || this.data.style === 'android' || ( !this.data.style && Platform.isAndroid())) {
Session.set('hasTabsTop', true);
} else {
Session.set('hasTabs', true);
}
Session.set('ionTab.current', null);
});

this.$('.tabs').children().each(function() {
var href = $(this).attr('href');
var current = Router.current().location.get().path;
if(href === current){
Session.set('ionTab.current', href);
}
});
};

Template.ionTabs.destroyed = function () {
Template.ionTabs.onDestroyed(function () {
Session.set('hasTabs', false);
Session.set('hasTabsTop', false);
};
});

Template.ionTabs.helpers({
classes: function () {
Expand Down
9 changes: 4 additions & 5 deletions components/ionView/ionView.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<template name="ionView">
{{#if title}}
{{#contentFor "headerTitle"}}
<h1 class="title">{{title}}</h1>
{{/contentFor}}
<h1 class="title">{{title}}</h1>
{{! > headerTitle title=data.title}}
{{/if}}

<div class="{{classes}}">
{{> UI.contentBlock}}
{{> Template.contentBlock}}
</div>
</template>
</template>
12 changes: 4 additions & 8 deletions components/ionView/ionView.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
Template.ionView.rendered = function () {
Template.ionView.onRendered(function () {
// Reset our transition preference
IonNavigation.skipTransitions = false;

// Reset our scroll position
var routePath = Router.current().route.path(Router.current().params);
var routePath = RouterLayer.getPath();

if(IonScrollPositions[routePath]) {
$('.overflow-scroll').not('.nav-view-leaving .overflow-scroll').scrollTop(IonScrollPositions[routePath]);
delete IonScrollPositions[routePath];
}
};
});

Template.ionView.helpers({
classes: function () {
Expand All @@ -19,10 +20,5 @@ Template.ionView.helpers({
}

return classes.join(' ');
},
title: function () {
if ( Template.instance().data && Template.instance().data.title ) {
return Template.instance().data.title;
}
}
});
10 changes: 1 addition & 9 deletions package.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,7 @@ Cordova.depends({

Package.onUse(function(api) {
api.versionsFrom("1.0");
api.use([
"templating",
"underscore",
"fastclick",
"iron:[email protected]",
"tracker",
"session",
"jquery"
], "client");
api.use(["templating", "underscore", "fastclick", "nicolaslopezj:[email protected]", "tracker", "session", "jquery"], "client");

api.addFiles([
"vendor/snap.js",
Expand Down