Skip to content

Instantly share code, notes, and snippets.

@thomsbg
thomsbg / main.js
Created September 11, 2013 17:39
Global settings object
defaults: {
ajaxTimeout: 15000,
autoUpdateAlertTimeShown: 6500,
editTimeWindow: 90,
maxIndentationDepth: 30,
showAutoUpdateAlert: true,
showAvatars: true,
showSignatures: true,
showImages: true,
sortMethod: 'ancestry'
@thomsbg
thomsbg / main.js
Created September 11, 2013 17:18
App object extends Backbone.Events
// main.js
App = _.extend({}, Backbone.Events, {
...
});
@thomsbg
thomsbg / app.js
Last active December 22, 2015 20:29
App initialization with namespaces
// main.js
App = {
// Namespaces
Collections: {},
Models: {},
Views: {},
Mixins: {},
initialize: function() {
this.comments = new App.Collections.Comments({ model: App.Models.Comment });
@thomsbg
thomsbg / compile_templates.js
Last active December 22, 2015 20:29
Loop through all the view prototype objects in a namespace, transforming their templateId into a template function.
var compileTemplates = function() {
_.each(App.Views, function(View) {
if (View.prototype.templateId) {
// The templateId references the id of a DOM element containing
// the content of the template
var html = jQuery('#' + View.prototype.templateId).html() || '';
View.prototype.template = _.template(html);
}
});
}
function countCSSRules() {
var results = '',
log = '';
if (!document.styleSheets) {
return;
}
for (var i = 0; i < document.styleSheets.length; i++) {
countSheet(document.styleSheets[i]);
}
function countSheet(sheet) {