You can let Blaze solve your problem by listening to the "click, touchstart" (=tap) event (I am not sure if cordova automatically converts click to tap but I think you will get the point) and force a redraw based on a reactive variable:
First rewrite your ul
to not use any bootstrap based events but Blaze helpers:
<ul class="nav nav-tabs justify-content-center" id="myTab">
<li class="nav-item">
<a class="nav-link week-tab-link {{#if active 'currentWeek'}}active{{/if}}"
id="home-tab"
data-state="currentWeek"
href="#currentWeekTab"
aria-controls="home" aria-selected="{{active 'currentWeek'}}">
1
</a>
</li>
<li class="nav-item">
<a class="nav-link week-tab-link {{#if active 'nextWeek'}}active{{/if}}"
id="profile-tab"
data-state="nextWeek"
href="#nextWeekTab"
aria-controls="profile" aria-selected="{{active 'nextWeek'}}">
2
</a>
</li>
</ul>
{{#if active 'currentWeek'}}
<p>render current week</p>
{{/if}}
{{#if active 'nextWeek'}}
<p>render next week</p>
{{/if}}
As you can see the template relies on some state to determine a) which tab is active and b) which content to render.
To resolve this active
state a helper is required:
Template.myTemplate.helpers({
active (tabName) {
return Template.instance().state.get('active') === tabName
}
})
There also needs to be a default state to be set in order to determine what to render when the page is loaded:
Template.myTemplate.onCreated(function helloOnCreated () {
const instance = this
instance.state = new ReactiveDict(0)
instance.state.set('active', 'currentWeek')
})
In order to save lines of code (=less possible errors) you can create an event map for a common class selector .week-tab-link
which triggers an event callback if any of the tab is clicked. In this callback you can "read" the data-state
attribute from the tab in order to set the active
state:
Template.myTemplate.events({
'click, touchstart .week-tab-link' (event, templateInstance) {
// event.preventDefault() // uncomment this to prevent href update
const $target = templateInstance.$(event.currentTarget)
const activeState = $target.data('state')
templateInstance.state.set('active', activeState)
}
})
Note, that this uses ReactiveDict
but you can also implement this using ReactiveVar
.
Related:
Touch events in Meteor