Skip to content

Instantly share code, notes, and snippets.

View Haraldson's full-sized avatar

Hein Haraldson Berg Haraldson

View GitHub Profile
@Haraldson
Haraldson / 7120.js
Created July 25, 2014 08:04
Lønns- og skattekalkulator – tabell 7120 – skatteklasse 1
(function(salary)
{
var tax7120 = {
0: 0,
100: 0,
200: 0,
300: 0,
400: 0,
500: 0,
600: 0,
@Haraldson
Haraldson / Gruntfile.js
Last active August 29, 2015 14:04
Grunt CSS processing
module.exports = function(grunt)
{
grunt.initConfig(
{
pkg: grunt.file.readJSON('package.json'),
watch: {
css: {
files: ['www/src/sass/**/*.scss'],
tasks: ['css']
// This is a view for rendering only! Handle click events and shit in its parent view
var IssueDetailCommonMenuItemsView = Marionette.ItemView.extend(
{
template: IssueDetailMenuItemsTemplate,
onRender: function()
{
this.listenTo(this.model, 'change:scheduled change:published change:live', this.render, this);
}
});
@Haraldson
Haraldson / filters.js
Created July 10, 2014 09:42
How to combine the three first filters, when { live: false } isn’t an option?
// Drafts
filter: {
scheduled: false,
published: false
}
// Scheduled
filter: {
scheduled: true,
published: false
@Haraldson
Haraldson / publication-base.js
Created July 3, 2014 19:22
Publication layout
define(
['marionette', 'model/publication', 'collection/issue/sections'],
function(Marionette, PublicationModel, SectionCollection)
{
var PublicationBaseLayout = Marionette.Layout.extend(
{
id: 'publication',
events: {
'click nav a': 'navigate'
@Haraldson
Haraldson / indexer.js
Created June 26, 2014 15:14
Cloudant indexing the WET way
function (doc) {
if (doc.docType === 'issue') {
index('default', doc.title);
if (doc.title) {
index('title', doc.title, {'store': 'yes'});
}
if (doc.publicationId) {
index('publicationId', doc.publicationId, {'store': 'yes'});
}
if (doc.liveStartDate) {
@Haraldson
Haraldson / indexer.js
Last active August 29, 2015 14:03
Cloudant indexing
function(doc)
{
if(doc.docType == 'issue')
{
var indexProperties = function(properties)
{
for(var i = 0; i < properties.length; i++)
{
var property = properties[i];
if(doc[property])
@Haraldson
Haraldson / 1-site.css
Created June 17, 2014 08:50
Easter override with @media queries (Grunt Combine Media Queries example)
body {
background: white;
}
@media (min-width: 800px) {
body {
background: black;
}
}
@Haraldson
Haraldson / model.js
Created May 26, 2014 10:08
Fetch using promises
fetch: function()
{
var deferred;
var data = this.cache();
if(data)
{
deferred = $.Deferred();
deferred.resolve(data);
}
function fetch(options)
{
var ongoingAjaxFetch = this.get('ongoingAjaxFetch');
if(ongoingAjaxFetch) return ongoingAjaxFetch;
var defaults = { includeDocs: true };
options = options ? $.extend({}, defaults, options) : defaults;
var deferred;
var data = this.cache();