Skip to content

Instantly share code, notes, and snippets.

View brettjonesdev's full-sized avatar

Brett Jones brettjonesdev

View GitHub Profile
@brettjonesdev
brettjonesdev / app.js
Created March 24, 2014 16:25
Issue with onDomRefresh not being very reliable
var App = new Backbone.Marionette.Application();
App.addRegions({
main: '#main'
});
App.addInitializer(function() {
console.log('here');
App.main.show(new MainLayout())
});
@brettjonesdev
brettjonesdev / cors-post.js
Created April 16, 2014 13:52
Example of how to set up a CORS post to different domain.
$('#form').submit(function(e) {
e.preventDefault();
var data = {
subject: $('[name=body]).val(),
body: $('[name=body]).val()
};
$.ajax({
url: SALES_FORCE_URL,
method: 'POST',
<script type="text/javascript">
(function(){
function customScript() {
/* Your custom code */
}
if (window.addEventListener) {
window.addEventListener("load",customScript,false);
} else if (window.attachEvent) {
window.attachEvent("onload",customScript);
}
<script type="text/javascript">
(function() {
function customScript() {
/* Your custom code */
}
if (window.addEventListener) {
window.addEventListener("load",customScript,false);
} else if (window.attachEvent) {
window.attachEvent("onload",customScript);
}
<script type="text/javascript">
(function() {
function customScript() {
/* Your custom code */
}
if (window.addEventListener) {
window.addEventListener("load",customScript,false);
} else if (window.attachEvent) {
window.attachEvent("onload",customScript);
}
@brettjonesdev
brettjonesdev / SequentialSaveModel.js
Last active August 29, 2015 14:25
SequentialSaveModel
// Pass a Model class to modify. Will prevent concurrent ajax calls on model instances, instead queueing each call to `save`/`destroy`/`fetch` and running them sequentially.
// save/fetch/destroy still return jquery deferred promises so usage shoud not change.
function sequentialSyncModel(Model) {
function getWrappedMethod(method) {
return function() {
if (!this._steps) {
this._steps = [];
}
var currentArgs = arguments.length ? Array.prototype.slice.call(arguments, 0) : [];
const App = new Application();
App.selectedTodos = new Backbone.Collection();
// List Route
const collection = new TodoCollection();
collection.fetch().then(() => {
const listView = new ListView({collection}).render();
});
// ListView
it('should be able to select a TodoModel', () => {
const collection = new TodoCollection();
const listView = new ListView({collection});
const model = new TodoModel();
listView.select(model); // Throws exception - App is not defined!
});
const App = new Application();
App.selectedTodos = new Backbone.Collection();
// List Route
const collection = new TodoCollection();
collection.fetch().then(() => {
const listView = new ListView({
collection,
selectedTodos: App.selectedTodos
}).render();
it('should be able to select a TodoModel', () => {
const collection = new TodoCollection();
const selectedTodos = new TodoCollection();
const listView = new ListView({collection, selectedTodos});
const model = new TodoModel();
listView.select(model); // Works great!
expect(listView.isSelected(model)).toBe(true);
});