-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
29,100 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
dist/ | ||
npm-debug.log | ||
.lock-wscript | ||
build/node_modules/grunt/node_modules/glob/build |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Set the require.js configuration for your application. | ||
require.config({ | ||
// Initialize the application with the main application file | ||
deps: ["main"], | ||
|
||
paths: { | ||
// JavaScript folders | ||
libs: "../assets/js/libs", | ||
plugins: "../assets/js/plugins", | ||
|
||
// Libraries | ||
jquery: "../assets/js/libs/jquery", | ||
underscore: "../assets/js/libs/underscore", | ||
backbone: "../assets/js/libs/backbone", | ||
|
||
// Shim Plugin | ||
use: "../assets/js/plugins/use" | ||
}, | ||
|
||
use: { | ||
backbone: { | ||
deps: ["use!underscore", "jquery"], | ||
attach: "Backbone" | ||
}, | ||
|
||
underscore: { | ||
attach: "_" | ||
} | ||
} | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
require([ | ||
"namespace", | ||
|
||
// Libs | ||
"jquery", | ||
"use!backbone", | ||
|
||
// Modules | ||
"modules/example" | ||
], | ||
|
||
function(namespace, $, Backbone, Example) { | ||
|
||
// Defining the application router, you can attach sub routers here. | ||
var Router = Backbone.Router.extend({ | ||
routes: { | ||
"": "index", | ||
":hash": "index" | ||
}, | ||
|
||
index: function(hash) { | ||
var route = this; | ||
var tutorial = new Example.Views.Tutorial(); | ||
|
||
// Attach the tutorial to the DOM | ||
tutorial.render(function(el) { | ||
$("#main").html(el); | ||
|
||
// Fix for hashes in pushState and hash fragment | ||
if (hash && !route._alreadyTriggered) { | ||
// Reset to home, pushState support automatically converts hashes | ||
Backbone.history.navigate("", false); | ||
|
||
// Trigger the default browser behavior | ||
location.hash = hash; | ||
|
||
// Set an internal flag to stop recursive looping | ||
route._alreadyTriggered = true; | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
// 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() { | ||
// Define your master router on the application namespace and trigger all | ||
// navigation from this instance. | ||
app.router = new Router(); | ||
|
||
// Trigger the initial route and enable HTML5 History API support | ||
Backbone.history.start({ pushState: true }); | ||
}); | ||
|
||
// 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); | ||
} | ||
}); | ||
|
||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
define([ | ||
"namespace", | ||
|
||
// Libs | ||
"use!backbone" | ||
|
||
// Modules | ||
|
||
// Plugins | ||
], | ||
|
||
function(namespace, Backbone) { | ||
|
||
// Create a new module | ||
var Example = namespace.module(); | ||
|
||
// Example extendings | ||
Example.Model = Backbone.Model.extend({ /* ... */ }); | ||
Example.Collection = Backbone.Collection.extend({ /* ... */ }); | ||
Example.Router = Backbone.Router.extend({ /* ... */ }); | ||
|
||
// This will fetch the tutorial template and render it. | ||
Example.Views.Tutorial = Backbone.View.extend({ | ||
template: "app/templates/example.html", | ||
|
||
render: function(done) { | ||
var view = this; | ||
|
||
// Fetch the template, render it to the View element and call done. | ||
namespace.fetchTemplate(this.template, function(tmpl) { | ||
view.el.innerHTML = tmpl(); | ||
|
||
// If a done function is passed, call it with the element | ||
if (_.isFunction(done)) { | ||
done(view.el); | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
// Required, return the module for AMD compliance | ||
return Example; | ||
|
||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
define([ | ||
// Libs | ||
"jquery", | ||
"use!underscore", | ||
"use!backbone" | ||
], | ||
|
||
function($, _, Backbone) { | ||
// Put application wide code here | ||
|
||
return { | ||
// This is useful when developing if you don't want to use a | ||
// build process every time you change a template. | ||
// | ||
// Delete if you are using a different template loading method. | ||
fetchTemplate: function(path, done) { | ||
var JST = window.JST = window.JST || {}; | ||
var def = new $.Deferred(); | ||
|
||
// Should be an instant synchronous way of getting the template, if it | ||
// exists in the JST object. | ||
if (JST[path]) { | ||
if (_.isFunction(done)) { | ||
done(JST[path]); | ||
} | ||
|
||
return def.resolve(JST[path]); | ||
} | ||
|
||
// Fetch it asynchronously if not available from JST, ensure that | ||
// template requests are never cached and prevent global ajax event | ||
// handlers from firing. | ||
$.ajax({ | ||
url: path, | ||
type: "get", | ||
dataType: "text", | ||
cache: false, | ||
global: false, | ||
|
||
success: function(contents) { | ||
JST[path] = _.template(contents); | ||
|
||
// Set the global JST cache and return the template | ||
if (_.isFunction(done)) { | ||
done(JST[path]); | ||
} | ||
|
||
// Resolve the template deferred | ||
def.resolve(JST[path]); | ||
} | ||
}); | ||
|
||
// Ensure a normalized return value (Promise) | ||
return def.promise(); | ||
}, | ||
|
||
// Create a custom object with a nested Views object | ||
module: function(additionalProps) { | ||
return _.extend({ Views: {} }, additionalProps); | ||
}, | ||
|
||
// Keep active application instances namespaced under an app object. | ||
app: _.extend({}, Backbone.Events) | ||
}; | ||
}); |
Oops, something went wrong.