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 = ''; - - humaneEl.innerHTML = content; - humaneEl.style.display = 'block'; - setTimeout(function(){ animate(1,type); },50) // prevent queueing display in animation - } - function animate (level,type,cb) { - if (level === 1) { - humaneEl.className = "humane humane-" + type + " humane-animate"; - } - else { - humaneEl.className = humaneEl.className.replace(" humane-animate",""); - on ( humaneEl, normalizeEvent('TransitionEnd'), function (){ end(); cb && cb(); }); - } - } + var msg = this.queue.shift() + var clickToClose = ENV.config(msg.clickToClose,this.clickToClose) - function remove (cb) { - off (doc.body, 'mousemove', remove); - off (doc.body, 'click', remove); - off (doc.body, 'keypress', remove); - off (doc.body, 'touchstart', remove); - // remove click and touchstart in case clickToClose was added - off (humaneEl, 'click', remove); - off (humaneEl, 'touchstart', remove); - eventing = false; - if (animationInProgress) animate(0, null, cb); - else if (cb) cb() - } + if (clickToClose) { + ENV.on(this.el,'click',this.removeEvent) + ENV.on(this.el,'touchstart',this.removeEvent) + } + var timeout = ENV.config(msg.timeout,this.timeout) - function end() { - // turn off animation event if supported, a little trigger happy - if (useTransitions) off ( humaneEl, normalizeEvent('TransitionEnd'), end ); - animationInProgress = false; - if (currentMessage.callback) currentMessage.callback(); - events['hide'](currentMessage.type, currentMessage.message,'hide'); - humaneEl.style.display = 'none'; - run(); - } + if (timeout > 0) + this.currentTimer = setTimeout(ENV.bind(this._afterTimeout,this), timeout) - var setOpacity = useFilter - ? function (opacity) { humaneEl.filters.item('DXImageTransform.Microsoft.Alpha').Opacity = opacity*100; } - : function (opacity) { humaneEl.style.opacity = String(opacity); } - - function jsAnimateOpacity (level, type, cb) { - var interval; - var opacity; - - if (level === 1) { - opacity = 0; - humaneEl.className = "humane humane-js-animate humane-" + type; - if (useFilter) setOpacity(0); // reset value so hover states work - humaneEl.style.zIndex = 1000000; - - interval = setInterval(function(){ - if (opacity < 1) { - opacity += 0.1; - if (opacity > 1) opacity = 1; - setOpacity(opacity); - } - else { - clearInterval(interval); - } - }, 100 / 20); - } - else { - opacity = 1; - interval = setInterval(function(){ - if(opacity > 0) { - opacity -= 0.1; - if (opacity < 0) opacity = 0; - setOpacity(opacity); - } - else { - humaneEl.className = humaneEl.className.replace(" humane-js-animate",""); - humaneEl.style.zIndex = -1; - clearInterval(interval); - end(); - cb && cb(); - } - }, 100 / 20); - } - } + // events['show'](type,content,'show') + if (ENV.isArray(msg.html)) msg.html = '' - function notifier (type) { - return function instance (message, cb) { - queue.push( [type, message, instance, cb] ); - events['add'](type, message, 'add'); - if (isSetup) run(); - } - } + this.el.innerHTML = msg.html + this.currentMsg = msg + this.el.className = this.baseCls + if (ENV.transSupport) { + this.el.style.display = 'block' + setTimeout(ENV.bind(this._showMsg,this),50) + } else { + this._showMsg() + } - // types - humane = notifier('log'); - humane.log = notifier('log'); - humane.error = notifier('error'); - humane.info = notifier('info'); - humane.success = notifier('success'); - humane.remove = remove; - - humane.create = function (options) { - var type = notifier(options.type || 'log'); - type.timeout = options.timeout || 2500; - type.waitForMove = options.waitForMove || false; - type.clickToClose = options.clickToClose || false; - return type; + }, + _setOpacity: function (opacity) { + if (ENV.useFilter) + this.el.filters.item('DXImageTransform.Microsoft.Alpha').Opacity = opacity*100 + else + this.el.style.opacity = String(opacity) + }, + _showMsg: function () { + var addnCls = ENV.config(this.currentMsg.addnCls,this.addnCls) + if (ENV.transSupport) { + this.el.className = this.baseCls+' '+addnCls+' '+this.baseCls+'-animate' + } + else { + var opacity = 0 + this.el.className = this.baseCls+' '+addnCls+' '+this.baseCls+'-js-animate' + this._setOpacity(0) // reset value so hover states work + this.el.style.display = 'block' + + var self = this + var interval = setInterval(function(){ + if (opacity < 1) { + opacity += 0.1 + if (opacity > 1) opacity = 1 + self._setOpacity(opacity) + } + else clearInterval(interval) + }, 30) + } + }, + _hideMsg: function () { + var addnCls = ENV.config(this.currentMsg.addnCls,this.addnCls) + if (ENV.transSupport) { + this.el.className = this.baseCls+' '+addnCls + ENV.on(this.el,ENV.vendorPrefix ? ENV.vendorPrefix+'TransitionEnd' : 'transitionend',this.transEvent) + } + else { + var opacity = 1 + var self = this + var interval = setInterval(function(){ + if(opacity > 0) { + opacity -= 0.1 + if (opacity < 0) opacity = 0 + self._setOpacity(opacity); + } + else { + self.el.className = self.baseCls+' '+addnCls + clearInterval(interval) + self._afterAnimation() + } + }, 30) + } + }, + _afterAnimation: function () { + if (ENV.transSupport) ENV.off(this.el,ENV.vendorPrefix ? ENV.vendorPrefix+'TransitionEnd' : 'transitionend',this.transEvent) + + if (this.currentMsg.cb) this.currentMsg.cb() + this.el.style.display = 'none' + + this._animating = false + // events['hide'](currentMessage.type, currentMessage.message,'hide'); + this._run() + }, + remove: function (e) { + var cb = typeof e == 'function' ? e : null + + ENV.off(doc.body,'mousemove',this.removeEvent) + ENV.off(doc.body,'click',this.removeEvent) + ENV.off(doc.body,'keypress',this.removeEvent) + ENV.off(doc.body,'touchstart',this.removeEvent) + ENV.off(this.el,'click',this.removeEvent) + ENV.off(this.el,'touchstart',this.removeEvent) + this.removeEventsSet = false + + if (cb) this.currentMsg.cb = cb + if (this._animating) this._hideMsg() + else if (cb) cb() + }, + log: function (html, o, cb, defaults) { + var msg = defaults || {} + + if (typeof o == 'function') cb = o + else if (o) + for (var opt in o) msg[opt] = o[opt] + + msg.html = html + if (cb) msg.cb = cb + this.queue.push(msg) + this._run() + return this + }, + spawn: function (defaults) { + var self = this + return function (html, o, cb) { + self.log.call(self,html,o,cb,defaults) + } + }, + create: function (o) { return new Humane(o) } } - // options - humane.timeout = 2500; - humane.waitForMove = false; - humane.clickToClose = false; - - // events - humane.on = function(type, handler){ events[type] = handler; }; - win.humane = humane; -})( window, document ); + win.humane = new Humane() +}(this); diff --git a/humane.min.js b/humane.min.js index f3cd965..6314d54 100644 --- a/humane.min.js +++ b/humane.min.js @@ -1,8 +1 @@ -/** - * 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(a,b){function t(a){return n?n+a:a.toLowerCase()}function u(b,c){return p.instance[c]!==void 0?p.instance[c]:a.humane[c]}function v(){j=b.createElement("div"),j.id="humane",j.className="humane",b.body.appendChild(j);for(vendor in m)vendor+"TransitionProperty"in j.style&&(n=m[vendor],h=!0);h||(x=B),o=!0,w()}function w(){if(i)return;if(!s.length)return;after=null,i=!0,k&&(clearTimeout(k),k=null);var a=s.shift();p={type:a[0],message:a[1],instance:a[2],callback:a[3]};var c=p.message,e=p.type;u(e,"clickToClose")===!0&&(d(j,"click",y),d(j,"touchstart",y));var h=u(e,"timeout");h>0&&(k=setTimeout(function(){g||(d(b.body,"mousemove",y),d(b.body,"click",y),d(b.body,"keypress",y),d(b.body,"touchstart",y),g=!0,u(e,"waitForMove")!==!0&&y())},h)),r.show(e,c,"show"),f(c)&&(c=""),j.innerHTML=c,j.style.display="block",setTimeout(function(){x(1,e)},50)}function x(a,b,c){a===1?j.className="humane humane-"+b+" humane-animate":(j.className=j.className.replace(" humane-animate",""),d(j,t("TransitionEnd"),function(){z(),c&&c()}))}function y(a){e(b.body,"mousemove",y),e(b.body,"click",y),e(b.body,"keypress",y),e(b.body,"touchstart",y),e(j,"click",y),e(j,"touchstart",y),g=!1,i?x(0,null,a):a&&a()}function z(){h&&e(j,t("TransitionEnd"),z),i=!1,p.callback&&p.callback(),r.hide(p.type,p.message,"hide"),j.style.display="none",w()}function B(a,b,c){var d,e;a===1?(e=0,j.className="humane humane-js-animate humane-"+b,l&&A(0),j.style.zIndex=1e6,d=setInterval(function(){e<1?(e+=.1,e>1&&(e=1),A(e)):clearInterval(d)},5)):(e=1,d=setInterval(function(){e>0?(e-=.1,e<0&&(e=0),A(e)):(j.className=j.className.replace(" humane-js-animate",""),j.style.zIndex=-1,clearInterval(d),z(),c&&c())},5))}function C(a){return function b(c,d){s.push([a,c,b,d]),r.add(a,c,"add"),o&&w()}}var c,d,e,f,g=!1,h=!1,i=!1,j=null,k=null,l=/msie [678]/i.test(navigator.userAgent),m={Webkit:"webkit",Moz:"",O:"o",ms:"MS"},n="",o=!1,p={},q=function(){},r={add:q,show:q,hide:q},s=[];"addEventListener"in a?(d=function(a,b,c){a.addEventListener(b,c,!1)},e=function(a,b,c){a.removeEventListener(b,c,!1)}):(d=function(a,b,c){a.attachEvent("on"+b,c)},e=function(a,b,c){a.detachEvent("on"+b,c)}),f=Array.isArray||function(a){return Object.prototype.toString.call(a)==="[object Array]"},d(a,"load",v);var A=l?function(a){j.filters.item("DXImageTransform.Microsoft.Alpha").Opacity=a*100}:function(a){j.style.opacity=String(a)};c=C("log"),c.log=C("log"),c.error=C("error"),c.info=C("info"),c.success=C("success"),c.remove=y,c.create=function(a){var b=C(a.type||"log");return b.timeout=a.timeout||2500,b.waitForMove=a.waitForMove||!1,b.clickToClose=a.clickToClose||!1,b},c.timeout=2500,c.waitForMove=!1,c.clickToClose=!1,c.on=function(a,b){r[a]=b},a.humane=c})(window,document); \ No newline at end of file +!function(a){var b=document,c={on:function(b,c,d){"addEventListener"in a?b.addEventListener(c,d,!1):b.attachEvent("on"+c,d)},off:function(b,c,d){"removeEventListener"in a?b.removeEventListener(c,d,!1):b.detachEvent("on"+c,d)},bind:function(a,b){return function(){a.apply(b,arguments)}},isArray:Array.isArray||function(a){return Object.prototype.toString.call(a)==="[object Array]"},domLoaded:!1,config:function(a,b){return a!=null?a:b},transSupport:!1,useFilter:/msie [678]/i.test(navigator.userAgent),_checkTransition:function(){var a=b.createElement("div"),c={webkit:"webkit",Moz:"",O:"o",ms:"MS"};for(var d in c)d+"Transition"in a.style&&(this.vendorPrefix=c[d],this.transSupport=!0)}};c._checkTransition();var d=function(b){b||(b={}),this.queue=[],this.baseCls=b.baseCls||"humane",this.addnCls=b.addnCls||"",this.timeout=b.timeout||2500,this.waitForMove=b.waitForMove||!1,this.clickToClose=b.clickToClose||!1,this.forceNew=b.forceNew||!1,c.domLoaded?this._setupEl():c.on(a,"load",c.bind(this._setupEl,this))};d.prototype={constructor:d,_setupEl:function(){var a=b.createElement("div");a.style.display="none",b.body.appendChild(a),this.el=a,this.removeEvent=c.bind(this.remove,this),this.transEvent=c.bind(this._afterAnimation,this),c.domLoaded=!0},_afterTimeout:function(){c.config(this.currentMsg.waitForMove,this.waitForMove)?this.removeEventsSet||(c.on(b.body,"mousemove",this.removeEvent),c.on(b.body,"click",this.removeEvent),c.on(b.body,"keypress",this.removeEvent),c.on(b.body,"touchstart",this.removeEvent),this.removeEventsSet=!0):this.remove()},_run:function(){if(this._animating||!this.queue.length||!this.el)return;this._animating=!0,this.currentTimer&&(clearTimeout(this.currentTimer),this.currentTimer=null);var a=this.queue.shift(),b=c.config(a.clickToClose,this.clickToClose);b&&(c.on(this.el,"click",this.removeEvent),c.on(this.el,"touchstart",this.removeEvent));var d=c.config(a.timeout,this.timeout);d>0&&(this.currentTimer=setTimeout(c.bind(this._afterTimeout,this),d)),c.isArray(a.html)&&(a.html=""),this.el.innerHTML=a.html,this.currentMsg=a,this.el.className=this.baseCls,c.transSupport?(this.el.style.display="block",setTimeout(c.bind(this._showMsg,this),50)):this._showMsg()},_setOpacity:function(a){c.useFilter?this.el.filters.item("DXImageTransform.Microsoft.Alpha").Opacity=a*100:this.el.style.opacity=String(a)},_showMsg:function(){var a=c.config(this.currentMsg.addnCls,this.addnCls);if(c.transSupport)this.el.className=this.baseCls+" "+a+" "+this.baseCls+"-animate";else{var b=0;this.el.className=this.baseCls+" "+a+" "+this.baseCls+"-js-animate",this._setOpacity(0),this.el.style.display="block";var d=this,e=setInterval(function(){b<1?(b+=.1,b>1&&(b=1),d._setOpacity(b)):clearInterval(e)},30)}},_hideMsg:function(){var a=c.config(this.currentMsg.addnCls,this.addnCls);if(c.transSupport)this.el.className=this.baseCls+" "+a,c.on(this.el,c.vendorPrefix?c.vendorPrefix+"TransitionEnd":"transitionend",this.transEvent);else var b=1,d=this,e=setInterval(function(){b>0?(b-=.1,b<0&&(b=0),d._setOpacity(b)):(d.el.className=d.baseCls+" "+a,clearInterval(e),d._afterAnimation())},30)},_afterAnimation:function(){c.transSupport&&c.off(this.el,c.vendorPrefix?c.vendorPrefix+"TransitionEnd":"transitionend",this.transEvent),this.currentMsg.cb&&this.currentMsg.cb(),this.el.style.display="none",this._animating=!1,this._run()},remove:function(a){var d=typeof a=="function"?a:null;c.off(b.body,"mousemove",this.removeEvent),c.off(b.body,"click",this.removeEvent),c.off(b.body,"keypress",this.removeEvent),c.off(b.body,"touchstart",this.removeEvent),c.off(this.el,"click",this.removeEvent),c.off(this.el,"touchstart",this.removeEvent),this.removeEventsSet=!1,d&&(this.currentMsg.cb=d),this._animating?this._hideMsg():d&&d()},log:function(a,b,c,d){var e=d||{};if(typeof b=="function")c=b;else if(b)for(var f in b)e[f]=b[f];return e.html=a,c&&(e.cb=c),this.queue.push(e),this._run(),this},spawn:function(a){var b=this;return function(c,d,e){b.log.call(b,c,d,e,a)}},create:function(a){return new d(a)}},a.humane=new d}(this); \ No newline at end of file diff --git a/index.html b/index.html index d8f40fb..31e94d0 100644 --- a/index.html +++ b/index.html @@ -2,6 +2,7 @@ humane.js + @@ -9,7 +10,7 @@ body { font-family: Ubuntu, sans-serif; padding: 80px; - background-color: #f0f0f0; + background-color: #60D6A7; } h1,h3 { font-family: 'Cabin Sketch', serif; @@ -37,19 +38,34 @@ pre { font-family: "Ubuntu Mono"; font-size: 0.9em; - background-color: #fff; - border: 1px solid #aaa; + width: 75%; + background-color: #007143; border-radius: 6px; - padding: 10px; - text-decoration: none; + padding: 5px 10px; + color: #fff; + cursor: pointer; + text-shadow: -1px 1px 1px #333; + box-shadow: 0px 8px 8px -8px #333; + -moz-transition: all 0.3s ease-out; + -webkit-transition: all 0.3s ease-out; + -ms-transition: all 0.3s ease-out; + -o-transition: all 0.3s ease-out; + transition: all 0.3s ease-out; + } + pre:hover { + background-color: #00ae68; } blockquote { font-size: 0.8em } - - + + + + + + Fork me on GitHub @@ -59,8 +75,8 @@

humane.js

A simple, modern, framework-independent, well-tested, unobtrusive, notification system.
Utilizes CSS transitions when available, falls back to JS animation when not. Includes mobile support.

-

Select A Theme: - @@ -70,103 +86,70 @@

Select A Theme:

Click a code sample below to see it in action:

- -
humane("Welcome Back");
-humane.log("Welcome Back");
-
- -
humane.info("Record <b>392</b> has been updated");
-
- -
humane.error("Invalid Username and/or Password");
-
- -
humane.success(["List","of","Items"]);
-
- -
humane("Second parameter takes a callback that's fired when finished", function(){
-   document.body.style.backgroundColor="#6699FF";
-});
-
+
humane.log("Welcome Back")
+
humane.log("Record 392 has been updated")
+
humane.log(["List","of","Items"])
+
humane.log("Callback when finished", function(){ document.body.style.backgroundColor="#a66000" })
+
humane.log("Options can be passed", { timeout: 4000, clickToClose: true, addnCls: 'humane-error' })
+

Options

-
humane.timeout = (number of milliseconds);
+

Options can be specified in a variety of ways. Either by the entire instance as shown below, or per notification, as shown above:

+
humane.timeout = 5000 // default: 2500
-

Sets the delay before a message fades out.

-

- Try It: - 2500 (2s - default) - 5000 (5s) - 500 (0.5s) - 0 (no timeout) -

+

Sets the delay before a message fades out (set to 0 for no timeout).

-
humane.waitForMove = (true|false);
+
humane.waitForMove = true // default: false

Wait for mouse, keyboard, or touch action to be taken before clearing message (after timeout)

-

- Try It: - true - false (default) -

-
humane.clickToClose = (true|false);
+
humane.clickToClose = true // default: false

Click or touch the notification to close

-

- Try It: - true - false (default) -

-
humane.remove(callback);
+
humane.addnCls = 'humane-info' // default: ''
-

Force remove current notification, takes an optional callback fired when finished

-

- Try It: - humane.remove(function(){ alert('removed') }) -

+

Specify an additional class to apply when notifying (nice when you only want to change just a little bit of the style)

- -

Customizing Options Per Type

-

All the options are also customizable by type. For example, say you wanted errors to always stay up until the user moved the mouse.

-
-humane.error.waitForMove = true;
-humane.error('Stays up a until mouse move');
-humane.log('Gets removed after timeout');
-

Or say you want success messages to remain up forever unless a user clicks them:

+

Create instances with humane.create

+

Create a completely new instance of humane using humane.create().

-humane.success.timeout = 0;
-humane.success.clickToClose = true;
-humane.success('Will stay up forever until click or humane.remove()');
-humane.remove(function() { // removed }); // force remove
-

Or you want all messages to have 3s timeout (3000) but 'info' messages to have shorter timeout of 1s (1000)

-
-humane.timeout = 3000;
-humane.info.timeout = 1000;
-humane.log('I'm up for 3 seconds');
-humane.info('I'm up for 1 second');
- -

Creating a Custom Notifier

-

You can create your own custom notifier that takes a type plus any of the options listed above (w/ those defaults unless overridden)

-
-var error = humane.create({ type: 'error', waitForMove: true });
-error('Yikes');
+var notify = humane.create({ timeout: 4000, baseCls: 'humane-bigbox' }) +notify.log('Custom Notifier') -

Events

-

humane.js provides some events more intended for plumbing purposes, say you wanted to implement stacking or logging:

-
humane.on('add', function(type, message) { ... });
-
-

Fires when a new message is added to the queue

-
-
humane.on('show', function(type, message) { ... });
+

There are a options that can also be applied when creating an instance:

+
humane.baseCls = 'humane' // default: 'humane'
-

Fires when a message is about to be shown

+

Specify an base class

-
humane.on('hide', function(type, message) { ... });
+ +

Spawn notifiers with humane.spawn

+

Create a custom notifier using humane.spawn().

+
+humane.info = humane.spawn({ addnCls: 'humane-libnotify-info', timeout: 1000 })
+humane.info('Info Themed Notifier')
+
+humane.error = humane.spawn({ addnCls: 'humane-libnotify-error', timeout: 1000 })
+humane.error('Error Themed Notifier')
+ +

Force remove current notification

+
humane.remove(function(){ alert('removed') })
-

Fires when a message is hidden and removed

+

Force remove current notification, takes an optional callback fired when finished (note each instance has its own remove)

+

Go crazy

+

With all this power, you are bound to go CRAZY! Click the sample below to go crazy:

+
+var bigbox = humane.create({baseCls: 'humane-bigbox', timeout: 1000})
+bigbox.error = bigbox.spawn({addnCls: 'humane-bigbox-error'})
+bigbox.log('Oh!').error('No!')
+
+var libnotify = humane.create({baseCls: 'humane-libnotify', addnCls: 'humane-libnotify-info'})
+libnotify.log('Notified')
+
+var jacked = humane.create({baseCls: 'humane-jackedup', addnCls: 'humane-jackedup-success'})
+jacked.log("What's up here!")
+

Browser Support

Uses CSS Transitions where available otherwise falls back to JS animation, degrades gracefully.