diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..59fa75a --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,19 @@ +module.exports = function(grunt) { + + // Project configuration. + grunt.initConfig({ + uglify: { + build: { + src: 'eventSky.js', + dest: 'src/eventSky.min.js' + } + } + }); + + // Load the plugin that provides the "uglify" task. + grunt.loadNpmTasks('grunt-contrib-uglify'); + + // Default task(s). + grunt.registerTask('default', ['uglify']); + +}; diff --git a/eventSky.js b/eventSky.js index 83b55b3..be6dfc2 100644 --- a/eventSky.js +++ b/eventSky.js @@ -6,6 +6,7 @@ /* -readme about window.eventSky -write readme info for init() & firehose + -add firehose to each method */ diff --git a/package.json b/package.json new file mode 100644 index 0000000..235d5e8 --- /dev/null +++ b/package.json @@ -0,0 +1,27 @@ +{ + "name": "event-sky", + "version": "0.1.0", + "description": "front-end event pub/sub utility", + "main": "eventSky.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "https://github.com/crobinson42/event-sky.git" + }, + "keywords": [ + "event", + "pub/sub" + ], + "author": "cory robinson", + "license": "MIT", + "bugs": { + "url": "https://github.com/crobinson42/event-sky/issues" + }, + "homepage": "https://github.com/crobinson42/event-sky", + "dependencies": { + "grunt": "^0.4.5", + "grunt-contrib-uglify": "^0.9.1" + } +} diff --git a/src/eventSky.min.js b/src/eventSky.min.js new file mode 100644 index 0000000..7597d56 --- /dev/null +++ b/src/eventSky.min.js @@ -0,0 +1 @@ +!function(){var a=function(a,b){throw new Error("eventSky.js: "+a,b||null)},b=function(a,c){b.active&&console.log(a,c)};b.active=!1;var c=function(a){a&&(b.active=a.firehose?!0:!1)},d={},e={},f=function(a,b){return this.event=b,this.when=a,this},g=function(){return this.before={},this.on={},this.after={},this},h=function(){return(new Date).getTime()+Math.floor(100*Math.random())},i=function(b){return b?d&&d[b]?!0:(d[b]=new g,!0):(a("ensureEventExists was not passed an event."),!1)};addEventListenerAction=function(b,c,g,j){console.log(b,c,g,j);var k,l,m,n=h();return k=c?c:a("No event specified."),l=g&&"function"!=typeof g?g:null,m=l?l:j?null:g,console.log(b,k,l,m),b&&k&&m?(i(k),d[k][b][n]=m,e[n]=new f(b,k),n):a(b+"() cannot be set due to invalid arguments.")};var j=function(a,b,c){return addEventListenerAction("on",a,b,c)},k=function(a,b,c){return addEventListenerAction("before",a,b,c)},l=function(a,b,c){return addEventListenerAction("after",a,b,c)},m=function(b,c){if(b&&d[b])d[b]=new g;else{var f=e[b];if(!f)return a("off() cannot map event ID.");delete e[b],delete d[f.event][f.when][b]}},n=function(a,c){var f=e[a];"object"==typeof f?(b("Trigger:"+f.event+":"+f.when+":"+a),d[f.event][f.when][a](c)):d[a]&&(Object.keys(d[a].before).forEach(function(e){b("Trigger:"+a+":before:*"),d[a].before[e](c)}),Object.keys(d[a].on).forEach(function(e){b("Trigger:"+a+":on:*"),d[a].on[e](c)}),Object.keys(d[a].after).forEach(function(e){b("Trigger:"+a+":after:*"),d[a].after[e](c)}))},o=function(){return Object.keys(d)};window.eventSky={init:c,on:j,before:k,after:l,off:m,trigger:n,events:o,dev:{eventStack:d,eventMap:e}}}(); \ No newline at end of file