Skip to content

Commit

Permalink
Added click to close option
Browse files Browse the repository at this point in the history
Fixes #12
  • Loading branch information
wavded committed Dec 2, 2011
1 parent 1ed4ea5 commit 2db8911
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
24 changes: 14 additions & 10 deletions humane.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
* See more usage examples at: http://wavded.github.com/humane-js/
*/
;(function (win,doc) {
var on,
off,
var on,
off,
isArray,
eventing = false,
animationInProgress = false,
Expand All @@ -24,7 +24,7 @@
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) };
Expand All @@ -34,11 +34,11 @@
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) {

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'];
Expand Down Expand Up @@ -70,7 +70,8 @@
off (doc.body,'keypress',remove);
off (doc.body,'touchstart',remove);
eventing = false;
if (animationInProgress) animate(0);
if (humane.closeOnClick) { off (humaneEl,'click',remove); off (humaneEl, 'touchstart', remove); }
if (animationInProgress) animate(0);
}

function run() {
Expand All @@ -93,11 +94,13 @@
}
}, win.humane.timeout);

if (humane.closeOnClick) { 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 = '<ul><li>' + content.join('<li>') + '</ul>';

Expand All @@ -111,7 +114,7 @@
}
else {
humaneEl.className = humaneEl.className.replace(" humane-animate","");
if(after!=null)
if(after!=null)
on(humaneEl,normalizeEvent('TransitionEnd'),after);
end();
}
Expand All @@ -129,7 +132,7 @@
if (useFilter) {
return function(opacity){
humaneEl.filters.item('DXImageTransform.Microsoft.Alpha').Opacity = opacity*100;

}
}
else {
Expand Down Expand Up @@ -198,5 +201,6 @@
win.humane.timeout = 2500;
win.humane.waitForMove = false;
win.humane.forceNew = false;
win.humane.closeOnClick = false;

}( window, document));
2 changes: 1 addition & 1 deletion humane.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ <h3>Options</h3>
</blockquote>
<pre>humane.waitForMove = (true|false);</pre>
<blockquote>
<p>Wait for mouse, or keyboard action to be taken before clearing message (after timeout)</p>
<p>Wait for mouse, keyboard, or touch action to be taken before clearing message (after timeout)</p>
<p>
Try It:
<input type='radio' name='waitformove' onclick='humane.waitForMove = true'> true
Expand All @@ -116,6 +116,15 @@ <h3>Options</h3>
<input type='radio' name='forceNew' onclick='humane.forceNew = false' checked> false <small>(default)</small>
</p>
</blockquote>
<pre>humane.clickToClose = (true|false);</pre>
<blockquote>
<p>Click or touch the notification to close</p>
<p>
Try It:
<input type='radio' name='clickToClose' onclick='humane.clickToClose = true'> true
<input type='radio' name='clickToClose' onclick='humane.clickToClose = false' checked> false <small>(default)</small>
</p>
</blockquote>

<h3>Browser Support</h3>
<p>Uses CSS Transitions where available otherwise falls back to JS animation, degrades gracefully.</p>
Expand Down

0 comments on commit 2db8911

Please sign in to comment.