/** * HumaneJS * Humanized Messages for Notifications * @author Marc Harter (@wavded) * @contributers * Alexander (@bga_) * Jose (@joseanpg) * Will McKenzie (@OiNutter) * @example * humane('hello world'); * See more usage examples at: http://wavded.github.com/humane-js/ */ ;(function (win,doc) { var on, off, isArray, eventing = 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, queue = [], after = null; 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) }; } isArray = Array.isArray || function (obj) { return Object.prototype.toString.call(obj) === '[object Array]' }; function normalizeEvent(name) { return eventPrefix ? eventPrefix + name : name.toLowerCase(); } on (win,'load',function () { var transitionSupported = ( function (style) { var prefixes = ['MozT','WebkitT','OT','msT','KhtmlT','t']; for(var i = 0, prefix; prefix = prefixes[i]; i++) { if (prefix+'ransition' in style) return true; } return false; }(doc.body.style)); if (!transitionSupported) animate = jsAnimateOpacity; // use js animation when no transition support setup(); run(); }); function setup() { humaneEl = doc.createElement('div'); humaneEl.id = 'humane'; humaneEl.className = 'humane'; doc.body.appendChild(humaneEl); for (vendor in vendors){ if (humaneEl.style[vendor + 'TransitionProperty'] !== undefined) eventPrefix = vendors[vendor]; } isSetup = true; } function remove() { off (doc.body,'mousemove',remove); off (doc.body,'click',remove); off (doc.body,'keypress',remove); off (doc.body,'touchstart',remove); eventing = false; if (humane.clickToClose) { off (humaneEl,'click',remove); off (humaneEl, 'touchstart', remove); } if (animationInProgress) animate(0); } function run() { if (animationInProgress && !win.humane.forceNew) return; if (!queue.length) { remove(); return; } after = null; animationInProgress = true; if (timeout) { clearTimeout(timeout); timeout = null; } 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(!win.humane.waitForMove) remove(); } }, win.humane.timeout); if (humane.clickToClose) { on (humaneEl,'click',remove); on (humaneEl, 'touchstart', remove); } var next = queue.shift(), type = next[0], content = next[1], callback = next[2]; after = callback; if ( isArray(content) ) content = '