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
gulp = require 'gulp' | |
gutil = require 'gulp-util' | |
sass = require 'gulp-sass' | |
prefix = require 'gulp-autoprefixer' | |
coffee = require 'gulp-coffee' | |
coffeelint = require 'gulp-coffeelint' | |
concat = require 'gulp-concat' | |
plumber = require 'gulp-plumber' | |
changed = require 'gulp-changed' | |
uglify = require 'gulp-uglify' |
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
pad = (num) -> | |
('0'+num).slice(-2) | |
console.log pad(8) | |
console.log pad(12) |
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
# http://viget.com/inspire/extending-paul-irishs-comprehensive-dom-ready-execution | |
SITENAME = | |
common: | |
init: -> | |
# application-wide code | |
users: | |
init: -> |
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
Module = (-> | |
_privateMethod = -> | |
console.log "Some text from the private method, called from the public method" | |
publicMethod = -> | |
console.log "something from the public method" | |
_privateMethod() | |
# métodos públicos que são expostos através do módulo |
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
# Creates a new object to be associated with the same prototype from the object | |
# passed in the constructor function | |
if typeof Object.create isnt 'function' | |
Object.create = (o) -> | |
F = -> | |
F:: = o | |
return new F() | |
newObject = Object.create(originalObject) |
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
#If you need to declare a self calling function in CoffeeScript, it's super easy, just do it: | |
message = "but stay safe" | |
do -> | |
message = "take chances" | |
alert message | |
alert message | |
# Outputs "takes chances" then "but stay safe" | |
# This gets super useful when you need to freeze a variable, like when in a for loop and using setTimeout, just pass in the variable: |
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
extend = (target) -> | |
return unless arguments[1] | |
for property in arguments | |
sourceProp = property | |
for prop of sourceProp | |
if not target[prop] and sourceProp.hasOwnProperty(prop) | |
target[prop] = sourceProp[prop] | |
return |
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
# MIXIN PATTERN IN COFFEESCRIPT | |
mixin = (target, source, methods...) -> | |
for method in methods | |
target[method] = source[method].bind(source) | |
return | |
# usage: | |
mixin toggle, toolbar.items[0], 'toggleActiveState' |
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) -> |
OlderNewer