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

Router.changePage() supports data-transition and data-direction #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
27 changes: 24 additions & 3 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,43 @@ var AppRouter = Backbone.Router.extend({
},

changePage:function (page) {
var options = {
changeHash: false,
};

$(page.el).attr('data-role', 'page');
page.render();
$('body').append($(page.el));
var transition = $.mobile.defaultPageTransition;

// We don't want to slide the first page
if (this.firstPage) {
transition = 'none';
options.transition = 'none';
this.firstPage = false;
}
$.mobile.changePage($(page.el), {changeHash:false, transition: transition});

// Find the anchor that triggered this page change and mix-in the relevant data attributes
else if (this.clickedAnchor) {
_.extend({
reverse: (this.clickedAnchor.data().direction === 'reverse'),
transition: this.clickedAnchor.data().transition
}, options);

this.clickedAnchor = null;
}

$.mobile.changePage($(page.el), options);
}

});

$(document).ready(function () {
console.log('document ready');
app = new AppRouter();

// Bind to click events so we can store the anchor that triggered the page change.
$(document).bind("click", function(event) {
app.clickedAnchor = $(event.target).closest('a');
});

Backbone.history.start();
});