Skip to content

Commit

Permalink
First code base
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobmattsson committed Jun 29, 2012
1 parent 5b6b57f commit 0e3b3eb
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -11,5 +11,6 @@ pids
logs
results

lib
node_modules
npm-debug.log
npm-debug.log
1 change: 1 addition & 0 deletions .npmignore
@@ -0,0 +1 @@
src
20 changes: 20 additions & 0 deletions package.json
@@ -0,0 +1,20 @@
{
"name": "piescore",
"description": "Utility functions",
"main": "./lib/piescore.js",
"version": "0.1.0",
"author": "Jakob Mattsson <jakob.mattsson@gmail.com> (jakobmattsson.se)",
"repository": {
"type": "git",
"url": "git@github.com:jakobmattsson/piescore.git"
},
"engines": {
"node": ">=0.6.0"
},
"devDependencies": {
"coffee-script": "1.3.x"
},
"scripts": {
"prepublish": "coffee -c -o lib src"
}
}
38 changes: 38 additions & 0 deletions src/piescore.coffee
@@ -0,0 +1,38 @@
exports.makeObject = ->
obj = {}
for i in [0..arguments.length/2]
obj[arguments[i*2]] = arguments[i*2+1]
obj

exports.argsToArray = ->
x for x in arguments

exports.block = (f) -> f()

exports.toKeyValues = (source) ->
Object.keys(source).map (key) ->
key: key
value: source[key]

exports.attachEvent = (obj, eventName, callback) ->
onEventName = "on" + eventName
if obj.addEventListener
obj.addEventListener(eventName, callback, false)
else if obj.attachEvent
obj.attachEvent(onEventName, callback)
else
currentEventHandler = obj[onEventName]
obj[onEventName] = () ->
if typeof currentEventHandler == 'function'
currentEventHandler.apply(this, arguments)
callback.apply(this, arguments)

exports.removeChildren = (element) ->
argsToArray(element.children).forEach (x) ->
element.removeChild(x)

exports.replaceChildren = (id, node) ->
parent = window.document.getElementById id
underline.removeChildren parent
parent.appendChild node

0 comments on commit 0e3b3eb

Please sign in to comment.