Skip to content

Instantly share code, notes, and snippets.

@tvpmb
tvpmb / app.js
Created January 17, 2012 00:07
Require.js Init
define([
'backbone',
], function(Backbone){
Backbone.LayoutManager.configure({
// Override render to use Handlebars
render: function(template, context) {
return Handlebars.compile(template)(context);
},
@tvpmb
tvpmb / header.js
Created January 24, 2012 19:14
Moving Events from Module to separate file
(function() {
var Events = {
dropMenu: function(evt) {
alert("Handle the click");
},
events: {
"click .drop-menu": "dropMenu",
},
}
return Events;
@tvpmb
tvpmb / events.js
Created January 24, 2012 21:06
Separating Events/Event-Methods from the View (partial code, 2 examples, one is commented out)
//events
define([
"namespace",
// Libs
"use!backbone",
// Plugins
"use!plugins/backbone.layoutmanager",
],
@tvpmb
tvpmb / gist:1719905
Created February 1, 2012 22:37
template events
obj.Views.SubMenu = Backbone.LayoutManager.View.extend({
tagName: "ul",
template: "home/manage/menuSub1",
});
// Event Method:
subMenu: function(evt) {
$(evt.target).append(new obj.Views.SubMenu().render());
}
@tvpmb
tvpmb / gist:1879062
Created February 21, 2012 21:25
Nested View Array
UploadModal = new Module.Views.LogoModal;
DeleteModal = new Module.Views.DeleteModal;
AddModal = new Module.Views.AddModal;
layout.view("#content", new Module.Views.Main({
views: {
'#Modals' : [UploadModal, DeleteModal, AddModal]
}
@tvpmb
tvpmb / gist:1936598
Created February 29, 2012 00:43
ensure specific model data
initialize: function() {
if (!this.get("content")) {
this.set({"content": this.defaults.content});
}
},
@tvpmb
tvpmb / gist:1955761
Created March 2, 2012 04:47
fetch templates for bb layoutmanager
Backbone.LayoutManager.configure({
paths: {
layout: "//app/layouts/",
template: "//app/templates/"
},
fetch: function(path) {
path = path + ".html";
path = path.slice(1);
@tvpmb
tvpmb / gist:1961807
Created March 2, 2012 22:16
Rendering a model in Backbone??
render: function(layout) {
var view = layout(this);
var themeId = this.options.themeId;
/* THIS WORKS, BUT WHY DO I NEED TO LOOP THE COLLECTION?!?! */
this.collection.each(function(theme) {
if (theme.id == themeId) {
console.log('theme: ', theme);
view.insert(new ThemeEditor.Views.PreviewContent({
model: theme
@tvpmb
tvpmb / beforeunload.js
Created May 1, 2012 03:12
How to capture browser forward/back/refresh navigation
$(window).on('beforeunload', function(e) {
//confirm('UNLOAD', 'UNLOAD');
e.preventDefault();
//e.stopPropagation();
console.log('page navigation cancelled');
//debugger;
return false;
});
@tvpmb
tvpmb / HeaderView
Created June 12, 2012 17:42
pseudo code for running a complex bb "page"
// now that we have the initial interface built, lets run a search
HeaderView = Backbone.Views.extend({
template: 'template/path/here',
events: {
"click #searchButton": "search"
},
search: function(e) {