Support Offline: Mon - Fri / 08:00am - 05:00pm (GMT +7)
Your Time: Our Time:

file Load more keeps reloading the same articles

More
7 years 11 months ago #12780 by Rafael Petkowicz
I disable the load more articles and then enable it again when articles are loaded...
In code I added a boolean var $waitForLoad and then verify if articles are loaded to enable "load more" articles again.

Steps
Find:
modules/mod_jux_mashup/tmpl/default.php

change the Load More <script> section with the following..

<script type="text/javascript">
    jQuery(document).ready(function($){
      // -------------------Load more-------------------------------------
            var $showMore = $('#ShowMore'), // or whatever your show more button is called
                $container = $("#juxContainer<?php echo $module->id;?>");

                // New ways
                var $currentURL = '<?php echo  JURI::getInstance()->toString(); ?>';
                var $start = <?php echo $limit ?>;  // ajax start from last limit
                var $limit = <?php echo $ajaxlimit ?>;
                var $totalitem = <?php echo $total?>;
		var $waitForLoad = false;
                // Instantiate MixItup with a limit of 12 items
                $container.mixItUp({
                    animation: {
                        enable: <?php echo ($params->get('animation') == 1)?"true":"false";?>,
                        duration: <?php echo $params->get('animation_duration')?>,
                        effects: "<?php echo $params->get('animation_effect')?>"
                    },
                    load: {
                    filter: "all",
                    sort: "default"
                    },

                    layout: {
                        display: "inline-block",
                        containerClass: '<?php echo $load_layout;?>' // Add the class 'list' to the container on load
                    }
                });
              
                // Bind a click handler to the show more button
                $("#jux_mashup<?php echo $module->id;?>").on("click","#ShowMore",function() {
					if ($waitForLoad == false){
						$('#loadmore-text').text('loading...');
						$waitForLoad = true;					
						$.get($currentURL, { 
							moduleID: <?php echo $module->id; ?>, 
							start:$start, 
							limit: $limit 
						}, function(data){
								
								$start += $limit;
								var $newItems = $(data);
								var $target = $newItems.find('#juxContainer<?php echo $module->id; ?>').html();
								var $newContents = $($target);
								$container.mixItUp('append', $newContents, {});
								
								//if articles are loaded then enable the "load more" button again. If not.. ignore
								if ($container.mixItUp("isLoaded"))
								{
									$waitForLoad = false;
									$('#loadmore-text').text('<?php echo JText::_('JUX_VIEW_MORE'); ?>');
								}
								
							   if($totalitem <= $start){
								$('#jux_mashup<?php echo $module->id;?> .jux-loadmore').html('');
							}
						});
					}
					
                });
            //--------------------------------End loadmore------------------------------------------
    });        
</script>

Well sorry for the quick explanation..

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

Moderators: Jackie
Time to create page: 0.032 seconds
Powered by Kunena Forum