diff --git a/Makefile b/Makefile index 2afb2c0..a05965e 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,6 @@ -all:build +project=humane + +all: tmux watch: @echo "Notice: Stylus + Nib + Canvas Required: npm install -g stylus nib canvas" @@ -8,3 +10,20 @@ build: @echo "Notice: UglifyJS Required: npm install -g uglify-js" @uglifyjs humane.js > humane.min.js @echo "Built uglified JS - humane.min.js" + +tmux_setup: + @tmux new-session -s ${project} -d -n workspace + @tmux split-window -t ${project} -h + @tmux split-window -t ${project} -v + @tmux select-pane -t ${project}:1.0 + @tmux select-pane -t ${project}:1.1 + @tmux resize-pane -t ${project} -D 2 + @tmux select-layout -t ${project} main-vertical + @tmux send-keys -t ${project}:1.0 'vim' C-m + @tmux send-keys -t ${project}:1.1 'make watch' C-m + @tmux select-pane -t ${project}:1.0 + @tmux resize-pane -t ${project} -R 40 + +tmux: + @if ! tmux has-session -t ${project}; then exec make tmux_setup; fi + @tmux attach -t ${project} diff --git a/humane.js b/humane.js index b21bfb6..cbfc5e7 100644 --- a/humane.js +++ b/humane.js @@ -1,217 +1,205 @@ -/** - * humane.js - * Humanized Messages for Notifications - * @author Marc Harter (@wavded) - * @example - * humane('hello world'); - * See more usage examples at: http://wavded.github.com/humane-js/ - */ -;(function (win,doc) { - - var humane, on, off, isArray, - eventing = false, - useTransitions = false, - animationInProgress = false, - humaneEl = null, - timeout = null, - useFilter = /msie [678]/i.test(navigator.userAgent), // sniff, sniff - vendors = { Webkit: 'webkit', Moz: '', O: 'o', ms: 'MS' }, - eventPrefix = "", - isSetup = false, - currentMessage = {}, - noop = function(){}, - events = { 'add': noop, 'show': noop, 'hide': noop }, - queue = []; - - if ('addEventListener' in win) { - on = function (obj,type,fn) { obj.addEventListener(type,fn,false) }; - off = function (obj,type,fn) { obj.removeEventListener(type,fn,false) }; - } - else { - on = function (obj,type,fn) { obj.attachEvent('on'+type,fn) }; - off = function (obj,type,fn) { obj.detachEvent('on'+type,fn) }; +;!function (win) { + var doc = document + + var ENV = { + on: function (el, type, cb) { + 'addEventListener' in win ? el.addEventListener(type,cb,false) : el.attachEvent('on'+type,cb) + }, + off: function (el, type, cb) { + 'removeEventListener' in win ? el.removeEventListener(type,cb,false) : el.detachEvent('on'+type,cb) + }, + bind: function (fn, ctx) { + return function () { fn.apply(ctx,arguments) } + }, + isArray: Array.isArray || function (obj) { return Object.prototype.toString.call(obj) === '[object Array]' }, + domLoaded: false, + config: function (preferred, fallback) { + return preferred != null ? preferred : fallback + }, + transSupport: false, + useFilter: /msie [678]/i.test(navigator.userAgent), // sniff, sniff + _checkTransition: function () { + var el = doc.createElement('div') + var vendors = { webkit: 'webkit', Moz: '', O: 'o', ms: 'MS' } + + for (var vendor in vendors) + if (vendor + 'Transition' in el.style) { + this.vendorPrefix = vendors[vendor] + this.transSupport = true + } + } } - - isArray = Array.isArray || function (obj) { return Object.prototype.toString.call(obj) === '[object Array]' }; - - function normalizeEvent(name) { - return eventPrefix ? eventPrefix + name : name.toLowerCase(); + ENV._checkTransition() + + var Humane = function (o) { + o || (o = {}) + this.queue = [] + this.baseCls = o.baseCls || 'humane' + this.addnCls = o.addnCls || '' + this.timeout = o.timeout || 2500 + this.waitForMove = o.waitForMove || false + this.clickToClose = o.clickToClose || false + this.forceNew = o.forceNew || false + + if (ENV.domLoaded) this._setupEl() + else ENV.on(win,'load',ENV.bind(this._setupEl, this)) } - function getConfig(type, config) { - return currentMessage.instance[config] !== void 0 ? currentMessage.instance[config] : win.humane[config]; - } - - on (win,'load', setup); - - function setup() { - humaneEl = doc.createElement('div'); - humaneEl.id = 'humane'; - humaneEl.className = 'humane'; - doc.body.appendChild(humaneEl); - for (vendor in vendors) { - if (vendor + 'TransitionProperty' in humaneEl.style) { - eventPrefix = vendors[vendor]; - useTransitions = true; + Humane.prototype = { + constructor: Humane, + _setupEl: function () { + var el = doc.createElement('div') + el.style.display = 'none' + doc.body.appendChild(el) + this.el = el + this.removeEvent = ENV.bind(this.remove,this) + this.transEvent = ENV.bind(this._afterAnimation,this) + ENV.domLoaded = true + }, + _afterTimeout: function () { + if (!ENV.config(this.currentMsg.waitForMove,this.waitForMove)) this.remove() + + else if (!this.removeEventsSet) { + ENV.on(doc.body,'mousemove',this.removeEvent) + ENV.on(doc.body,'click',this.removeEvent) + ENV.on(doc.body,'keypress',this.removeEvent) + ENV.on(doc.body,'touchstart',this.removeEvent) + this.removeEventsSet = true + } + }, + _run: function () { + if (this._animating || !this.queue.length || !this.el) return + + this._animating = true + if (this.currentTimer) { + clearTimeout(this.currentTimer) + this.currentTimer = null } - } - if (!useTransitions) animate = jsAnimateOpacity; // use js animation when no transition support - isSetup = true; - run(); - } - - function run() { - if (animationInProgress) return; - if (!queue.length) return; - - after = null; - animationInProgress = true; - if (timeout) { - clearTimeout(timeout); - timeout = null; - } - - var next = queue.shift(); - currentMessage = { type: next[0], message: next[1], instance: next[2], callback: next[3] }; - var content = currentMessage.message, - type = currentMessage.type; - - if ( getConfig(type, 'clickToClose') === true ) { - on (humaneEl, 'click', remove); - on (humaneEl, 'touchstart', remove); - } - - var timeoutInMillis = getConfig(type, 'timeout'); - - if (timeoutInMillis > 0) { - timeout = setTimeout(function(){ // allow notification to stay alive for timeout - if (!eventing) { - on (doc.body, 'mousemove', remove); - on (doc.body, 'click', remove); - on (doc.body, 'keypress', remove); - on (doc.body, 'touchstart', remove); - eventing = true; - if( getConfig(type, 'waitForMove') !== true ) remove(); - } - }, timeoutInMillis); - } - - events['show'](type,content,'show'); - if ( isArray(content) ) content = '