Created
May 8, 2012 06:35
-
-
Save pedromtavares/2633063 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require([ | |
"app/namespace", | |
// Libs | |
"jquery", | |
"use!backbone", | |
// Plugins | |
"use!jqueryCookie", | |
"use!jqueryValidate", | |
"use!jqueryGritter", | |
"use!jqueryIframe", | |
"use!bootstrapDropdown" | |
], | |
function(namespace, $, Backbone) { | |
// Defining the application router, you can attach sub routers here. | |
var Router = Backbone.Router.extend({ | |
, | |
routes: { | |
"": "index" | |
}, | |
index: function(hash) { | |
} | |
}); | |
// Shorthand the application namespace | |
var app = namespace.app; | |
// Treat the jQuery ready function as the entry point to the application. | |
// Inside this function, kick-off all initialization, everything up to this | |
// point should be definitions. | |
$(function() { | |
$("#loading").ajaxStart(function() { | |
$(this).show(); | |
}).ajaxComplete(function() { | |
$(this).hide(); | |
}); | |
// Define your master router on the application namespace and trigger all | |
// navigation from this instance. | |
app.router = new Router(); | |
// Trigger the initial route | |
Backbone.history.start({ | |
pushState: false | |
}); | |
}); | |
// All navigation that is relative should be passed through the navigate | |
// method, to be processed by the router. If the link has a data-bypass | |
// attribute, bypass the delegation completely. | |
$(document).on("click", "a:not([data-bypass])", function(evt) { | |
// Get the anchor href and protcol | |
var href = $(this).attr("href"); | |
var protocol = this.protocol + "//"; | |
// Ensure the protocol is not part of URL, meaning its relative. | |
if (href && href.slice(0, protocol.length) !== protocol && href.indexOf("javascript:") !== 0) { | |
// Stop the default event to ensure the link will not cause a page | |
// refresh. | |
evt.preventDefault(); | |
// `Backbone.history.navigate` is sufficient for all Routers and will | |
// trigger the correct events. The Router's internal `navigate` method | |
// calls this anyways. | |
Backbone.history.navigate(href, true); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment