/
jquery.humanize.js
47 lines (46 loc) · 1.48 KB
/
jquery.humanize.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* Copyright (c) 2008 Andy Kent (andrew.d.kent@gmail.com)
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
*
*
* Requires: jQuery 1.2+
*
****** CURRENTLY ONLY TESTED IN FF and Safari 3 *******
*/
(function($) {
$.humanize = function(msg,options){
if(typeof(msg)=='string') {
var o = $.extend($.humanize.defaults, options||{});
if($(o.baseSelector).length==0) $('body').append(o.container);
$(o.baseSelector).html(msg);
} else {
var o = $.extend($.humanize.defaults, msg||{});
};
$.humanize.mouseCatch = o.movementThreshold;
$(o.baseSelector).css('opacity',0)
.animate({opacity:o.opacity},o.fadeIn);
$(document).mousemove($.humanize.remove).click($.humanize.remove).keypress($.humanize.remove)
};
$.humanize.defaults = {
baseSelector : '.feedback',
container : '<p class="feedback"> </p>',
fadeIn : {easing:'swing', duration:1000},
fadeOut : {easing:'swing', duration:1000,complete:function(){$(this).remove()}},
opacity : 0.7,
movementThreshold : 3
};
$.humanize.mouseCatch = 3;
$.humanize.remove = function(e) {
if(e.type=='mousemove' && $.humanize.mouseCatch) {
$.humanize.mouseCatch-=1;
return
};
var o = $.humanize.defaults;
$(o.baseSelector)
.animate({opacity:0},o.fadeOut);
$(document)
.unbind('mousemove',$.humanize.remove)
.unbind('click',$.humanize.remove)
.unbind('keypress',$.humanize.remove)
};
})(jQuery);