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
class Book | |
constructor: (@author, @title, @numCopies) -> | |
display: -> | |
console.log """Book | |
\t Author #{@author} | |
\t Title #{@title} | |
\t Copies #{@numCopies} | |
""" |
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
getClickPosition = (e) -> | |
parentPosition = getPosition e.currentTarget | |
xPos = e.clientX - parentPosition.x | |
yPos = e.clientY - parentPosition.y | |
# console.log "X:#{xPos} Y:#{yPos}" | |
getPosition = (element) -> | |
xPos = 0 | |
yPos = 0 | |
while (element) |
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
DOMTokenList::addClasses = (input) -> | |
classValues = input.split ' ' | |
for className in classValues | |
this.add className | |
return | |
# usage | |
# element.classList.addClasses 'xpto1 xpto2' | |
DOMTokenList::removeClasses = (input) -> |
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
# Based on: | |
# http://unscriptable.com/2009/03/20/debouncing-javascript-methods/ | |
debounce = (func, threshold, execAsap) -> | |
timeout = null | |
(args...) -> | |
obj = this | |
delayed = -> | |
func.apply(obj, args) unless execAsap | |
timeout = null |
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
# Reference: http://discontinuously.com/2012/05/iteration-in-coffeescript/ | |
for element in arr | |
console.log element | |
# code here | |
# Expose the index in an Array Comprehension | |
for element, index in arr | |
console.log element | |
# code 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
'use strict'; | |
var gulp = require('gulp'), | |
gutil = require('gulp-util'), | |
sass = require('gulp-sass'), | |
prefix = require('gulp-autoprefixer'), | |
coffee = require('gulp-coffee'), | |
coffeelint = require('gulp-coffeelint'), | |
component = require('gulp-component'), | |
componentcoffee = require('component-coffee'), |
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
# Swappable Mixins in CoffeeScript | |
# ================================ | |
# Many thanks to Hashmal, who wrote this to start. | |
# https://gist.github.com/803816/aceed8fc57188c3a19ce2eccdb25acb64f2be94e | |
# Usage | |
# ----- | |
# class Derp extends Mixin |
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
isInViewport = (el) -> | |
rect = el.getBoundingClientRect() | |
html = document.documentElement | |
return( | |
rect.top >= 0 and | |
rect.left >= 0 and | |
rect.bottom <= (window.innerHeight or html.clientHeight) and | |
rect.right <= (window.innerWidth or html.clientWidth) | |
) |
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
object = | |
init: -> | |
btnEl = document.querySelector 'button' | |
btnEl.addEventListener 'click', this | |
btnEl.addEventListener 'touchstart', this | |
handleEvent: (e) -> | |
switch e.type | |
when 'click' | |
@action(e.type) |
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
// Define a getElementsByAttribute function. It | |
// takes an attribute name string and an optional | |
// matching value. It calls walk_the_DOM, passing it a | |
// function that looks for an attribute name in the | |
// node. The matching nodes are accumulated in a | |
// results array. | |
var getElementsByAttribute = function (att, value) { | |
var results = []; | |
walkTheDom(document.body, function(node){ |