Koha/koha-tmpl/intranet-tmpl/prog/en/lib/jquery/plugins/humanmsg.js
Martin Renvoize f887edc3ab Bug 9335 - humanMsg popups don't disapear in webkit browsers
The popup message that appears after saving changes to system
preferences should dissapear upon any user actions (i.e mouse
click, mouse move, typing) but this does not happen in modern
webkit based browsers since jQuery was updated.

This patch adds the suggested fix to the jQuery plugin code as
suggested on https://code.google.com/p/humanmsg/issues/detail?id=9

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Tested with Google Chrome on Windows 7

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Tested with Google Chrome 22 and Firefox on Debian
Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
Tested with the following browsers:
  Mac: Chrome 23, Firefox 16.0.2, Opera 11.61, Safari 5.1.7
  Windows: IE8, Firefox 3.6.26
2013-01-07 21:12:10 -05:00

95 lines
3 KiB
JavaScript

/*
HUMANIZED MESSAGES 1.0
idea - http://www.humanized.com/weblog/2006/09/11/monolog_boxes_and_transparent_messages
home - http://humanmsg.googlecode.com
*/
var humanMsg = {
setup: function(appendTo, logName, msgOpacity) {
humanMsg.msgID = 'humanMsg';
humanMsg.logID = 'humanMsgLog';
// appendTo is the element the msg is appended to
if (appendTo == undefined) appendTo = 'body';
// The text on the Log tab
if (logName == undefined) logName = 'Message Log';
// Opacity of the message
humanMsg.msgOpacity = 0.8;
if (msgOpacity != undefined) humanMsg.msgOpacity = parseFloat(msgOpacity);
// Inject the message structure
jQuery(appendTo).append('<div id="'+humanMsg.msgID+'" class="humanMsg"><div class="round"></div><div id="'+humanMsg.msgID+'-contents"></div><div class="round"></div></div> <div id="'+humanMsg.logID+'"><p class="launcher">'+logName+'</p><ul></ul></div>')
jQuery('#'+humanMsg.logID+' p').click(
function() { jQuery(this).siblings('ul').slideToggle() }
)
},
displayAlert: function(msg, options) {
humanMsg.displayMsg(msg, options, true);
},
displayMsg: function(msg, options, is_alert) {
if (msg == '')
return;
if (options != undefined) {
delay = 'delay' in options ? parseInt(options.delay) * 1000 : 1000
life = 'life' in options ? parseInt(options.life) * 1000 : Infinity
} else {
delay = 1000
life = Infinity
}
clearTimeout(humanMsg.t2);
// Inject message
jQuery('#'+humanMsg.msgID+'-contents').html(is_alert ? ('<p>' + msg + '</p>') : msg)
// Show message
jQuery('#'+humanMsg.msgID).show().animate({ opacity: humanMsg.msgOpacity}, 200, function() {
jQuery('#'+humanMsg.logID)
.show().children('ul').prepend('<li>'+msg+'</li>') // Prepend message to log
.children('li:first').slideDown(200) // Slide it down
if ( jQuery('#'+humanMsg.logID+' ul').css('display') == 'none') {
jQuery('#'+humanMsg.logID+' p').animate({ bottom: 40 }, 200, 'linear', function() {
jQuery(this).animate({ bottom: 0 }, 300, 'swing', function() { jQuery(this).css({ bottom: 0 }) })
})
}
})
// Watch for mouse & keyboard in `delay`
humanMsg.t1 = setTimeout("humanMsg.bindEvents()", delay)
// Remove message after `life`
humanMsg.t2 = setTimeout("humanMsg.removeMsg()", life)
},
bindEvents: function() {
// Remove message if mouse is moved or key is pressed
jQuery(document)
.mousemove(humanMsg.removeMsg)
.click(humanMsg.removeMsg)
.keypress(humanMsg.removeMsg)
},
removeMsg: function() {
// Unbind mouse & keyboard
jQuery(document)
.unbind('mousemove', humanMsg.removeMsg)
.unbind('click', humanMsg.removeMsg)
.unbind('keypress', humanMsg.removeMsg)
// If message is fully transparent, fade it out
if ( Math.abs(jQuery('#'+humanMsg.msgID).css('opacity') - humanMsg.msgOpacity ) < 0.00001 )
jQuery('#'+humanMsg.msgID).animate({ opacity: 0 }, 500, function() { jQuery(this).hide() })
}
};
jQuery(document).ready(function(){
humanMsg.setup();
})