better shoutbox rendering

flocke28
Topic Author
Posts: 0
5 years 3 months ago - 5 years 3 months ago #3432 by flocke28
better shoutbox rendering was created by flocke28
Hi there, the flickering of the Ajax refresh is nerved. So i changend something.

/media/mod_shoutbox/js/mod_shoutbox.js

function JJShoutbox.getPosts
var request = {
			'option'         : 'com_ajax',
			'module'         : 'shoutbox',
			'method'         : 'getPosts',
			'format'         : 'json',
			'jjshout[id]'    : lastID, /* add last id */
			'jjshout[title]' : params.title,
		};

disable 	//params.instance.find('#jjshoutboxoutput').empty().prepend($('<div class="jj-shout-new"></div>'));

Change from:  //params.instance.find('.jj-shout-new').after(response.data.html + historyButton);

to: $('#jjshoutboxoutput .jj-shout-new').after(response.data.html) 


and changed in helper:

/modules/mod_shoutbox/helper.php

function getPostsAjax()

added var $post["id"] like	$shouts = $helper->getShouts($offset, $helper->getParams()->get('maximum'), JText::_('SHOUT_DATABASEERRORSHOUT'), $post["id"]);


function getShouts($offset, $number, $message, $id) /* add $id */
try
		{
			$shouts = $this->getShoutData($offset, $number, $id); /* add $id */
		}


function getShoutData($offset, $number, $id) /* add $id  */

$query = $this->db->getQuery(true)
		->select('*')
		->from($this->db->qn('#__shoutbox'))
		->order($this->db->qn('id') . ' DESC')
		/* only Shout IDs greater then last known lastID */
		->where($this->db->qn('id') . ' > ' . (int)$id)
		//
		->setLimit($number, $offset);

And i enable Ajax refresh for guest:
 /modules/mod_shoutbox/tmpl/default.php

<?php if (!$user->guest): ?>
		setInterval(function(){
			var JJ_ShoutGetParams = {
				title         : '<?php echo $title; ?>',
				sound         : <?php echo $sound; ?>,
				notifications : <?php echo $notifications; ?>,
				Itemid        : '<?php echo $Itemid; ?>',
				instance      : JJ_instance,
				loggedInUser  : '<?php echo $displayName == 'user' ? $user->username : $user->name; ?>',
				history       : JJ_history,
			};

			JJShoutbox.getPosts(JJ_ShoutGetParams);
		}, <?php echo $refresh; ?>);
		
				<?php else :?> /* enable Ajax Refresh for guests */
		setInterval(function(){
			var JJ_ShoutGetParams = {
				title         : '<?php echo $title; ?>',
				sound         : <?php echo $sound; ?>,
				notifications : <?php echo $notifications; ?>,
				Itemid        : '<?php echo $Itemid; ?>',
				instance      : JJ_instance,
				history       : JJ_history,
			};

			JJShoutbox.getPosts(JJ_ShoutGetParams);
		}, <?php echo $refresh; ?>);
		<?php endif; ?>
/* Delete oldest Shouts in Shoutbox */
setInterval(function() {
		if ($('#jjshoutboxoutput > div').length > (<?php echo $number; ?>+1)) {
		$('#jjshoutboxoutput > div:last-child').remove();
		}		
		},250); 

Have fun
Last edit: 5 years 3 months ago by flocke28.

Please Log in or Create an account to join the conversation.

Lodder
Lodder's Avatar
Posts: 1185
5 years 3 months ago - 5 years 3 months ago #3433 by Lodder
Replied by Lodder on topic better shoutbox rendering
Hi flocke,

I don't know what you mean by "nerved", but I'll look into the changes you made.

Also, if you want to enable the Ajax refresh for guests, you don't need to edit any code. It's an option in the Shoutbox settings.

Regards,
Lodder
Last edit: 5 years 3 months ago by Lodder.

Please Log in or Create an account to join the conversation.

flocke28
Topic Author
Posts: 0
5 years 3 months ago #3434 by flocke28
Replied by flocke28 on topic better shoutbox rendering
Hi Lodder, shouts with a image are flickering on refresh with your old code. My changes fix that..

Please Log in or Create an account to join the conversation.

Lodder
Lodder's Avatar
Posts: 1185
5 years 3 months ago #3435 by Lodder
Replied by Lodder on topic better shoutbox rendering
ah ok thanks for reporting. I'll look into it during the week.

Please Log in or Create an account to join the conversation.

Powered by Kunena Forum