-
-
Save iros/1267457 to your computer and use it in GitHub Desktop.
code for organization post
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
var chat = { | |
// Create this closure to contain the cached modules | |
module: function() { | |
// Internal module cache. | |
var modules = {}; | |
// Create a new module reference scaffold or load an | |
// existing module. | |
return function(name) { | |
// If this module has already been created, return it. | |
if (modules[name]) { | |
return modules[name]; | |
} | |
// Create a module and save it under this name | |
return modules[name] = { Views: {} }; | |
}; | |
}() | |
}; | |
// Using the jQuery ready event is excellent for ensuring all | |
// code has been downloaded and evaluated and is ready to be | |
// initialized. Treat this as your single entry point into the | |
// application. | |
jQuery(function($) { | |
// Initialize your application here. | |
}); |
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
var chat = { | |
// Create this closure to contain the cached modules | |
module: function() { | |
// Internal module cache. | |
var modules = {}; | |
// Create a new module reference scaffold or load an | |
// existing module. | |
return function(name) { | |
// If this module has already been created, return it. | |
if (modules[name]) { | |
return modules[name]; | |
} | |
// Create a module and save it under this name | |
return modules[name] = { Views: {} }; | |
}; | |
}() | |
}; |
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
// Using the jQuery ready event is excellent for ensuring all | |
// code has been downloaded and evaluated and is ready to be | |
// initialized. Treat this as your single entry point into the | |
// application. | |
jQuery(function($) { | |
// Initialize your application here. | |
}); |
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
// src/modules/friend.js | |
// Module reference argument, assigned at the bottom | |
(function(chat, Friend) { | |
// Dependencies | |
var Message = chat.module("message"); | |
// Define a friend | |
Friend.Model = Backbone.Model.extend({ | |
initialize: function() { | |
// Add a nested messages collection | |
this.set({ messages: new Message.List() }); | |
} | |
}); | |
// Define a friend list | |
Friend.List = Backbone.Collection.extend({ | |
model: Friend.Model | |
}); | |
})(chat, chat.module("friend")); |
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
// src/modules/friend.js | |
// Module reference argument, assigned at the bottom | |
(function(chat, Friend) { | |
//... | |
})(chat, chat.module("friend")); |
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
// src/modules/friend.js | |
// Module reference argument, assigned at the bottom | |
(function(chat, Friend) { | |
// Dependencies | |
var Message = chat.module("message"); | |
// Shorthands | |
// The application container | |
var app = chat.app; | |
})(chat, chat.module("friend")); |
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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> | |
<title>Example</title> | |
<link rel="stylesheet" href="/assets/css/main.css"> | |
</head> | |
<body> | |
<div id="content"> | |
<!-- ALL YOUR CONTENT HERE --> | |
</div> | |
<!-- Third-Party Libraries (Order matters) --> | |
<script src="/assets/js/libs/jquery.js"></script> | |
<script src="/assets/js/libs/underscore.js"></script> | |
<script src="/assets/js/libs/backbone.js"></script> | |
<!-- Application core (Order matters) --> | |
<script src="/src/application.js"></script> | |
<!-- Modules (Order does not matter) --> | |
<script src="/src/modules/friend.js"></script> | |
<script src="/src/modules/message.js"></script> | |
</body> | |
</html> |
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
// modules/message.js | |
// Module reference argument, assigned at the bottom | |
(function(chat, Message) { | |
Message.Model = Backbone.Model.extend({ | |
defaults: { | |
unread: true | |
} | |
}); | |
Message.List = Backbone.Collection.extend({ | |
model: Message.Model | |
}); | |
})(chat, chat.module("message")); |
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
var chat = { | |
friend: { Views: {} }, | |
message: { Views: {} } | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment