our ( $query, $cookie );
+sub _output {
+ my ( $response, $status ) = @_;
+ binmode STDOUT, ':encoding(UTF-8)';
+
+ if ( $query->param( 'callback' ) ) {
+ output_with_http_headers $query, $cookie, $query->param( 'callback' ) . '(' . $response->output . ');', 'js';
+ } else {
+ output_with_http_headers $query, $cookie, $response->output, 'json', $status;
+ }
+}
+
=head1 METHODS
=head2 init
$response->param( message => $error ) if ( $error );
$response->param( type => $type, %flags );
- output_with_http_headers $query, $cookie, $response->output, 'json', '400 Bad Request';
+ _output( $response, '400 Bad Request' );
exit;
}
}
$response->param( 'multi' => JSON::true, responses => \@responses_formatted, @flags );
- output_with_http_headers $query, $cookie, $response->output, 'json', '207 Multi-Status';
+ _output( $response, '207 Multi-Status' );
}
exit;
sub return_success {
my ( $class, $response ) = @_;
- output_with_http_headers $query, $cookie, $response->output, 'json';
+ _output( $response );
}
=head2 require_params
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(appendTo).append('<div id="'+humanMsg.msgID+'" class="humanMsg"><div id="'+humanMsg.msgID+'-contents"></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);
+ humanMsg.displayMsg('<p>' + msg + '</p>', options);
},
- displayMsg: function(msg, options, is_alert) {
+ logMsg: function(msg) {
+ 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 }) })
+ })
+ }
+ },
+
+ displayMsg: function(msg, options) {
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
- }
+ options = $.extend({
+ delay: 1000,
+ life: Infinity,
+ log: true,
+ className: '',
+ }, options);
+ clearTimeout(humanMsg.t1);
clearTimeout(humanMsg.t2);
// Inject message
- jQuery('#'+humanMsg.msgID+'-contents').html(is_alert ? ('<p>' + msg + '</p>') : msg)
+ jQuery('#'+humanMsg.msgID+'-contents').html(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 }) })
- })
- }
-
+ jQuery('#'+humanMsg.msgID).attr('class', 'humanMsg ' + options.className).show().animate({ opacity: humanMsg.msgOpacity}, 200, function() {
+ humanMsg.logMsg(msg, options);
})
// Watch for mouse & keyboard in `delay`
- humanMsg.t1 = setTimeout("humanMsg.bindEvents()", delay)
+ humanMsg.t1 = setTimeout("humanMsg.bindEvents()", options.delay)
// Remove message after `life`
- humanMsg.t2 = setTimeout("humanMsg.removeMsg()", life)
+ humanMsg.t2 = setTimeout("humanMsg.removeMsg()", options.life)
},
bindEvents: function() {