Removing last article separator

For Joomla! 1.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Locked
sthrudel
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Sun Mar 29, 2009 4:15 pm

Removing last article separator

Post by sthrudel » Fri Apr 03, 2009 8:21 pm

Hi all!

Since I didn't find any tutorial on how to remove last article separator, gave up trying to figure out how to hack the core and was to lazy to use overrides, I came up with a (quick) javascript solution. It does it's job but I still hope Joomla will support enabling/disabling last article separator in the next version. The bad thing about this kind of solution is that browser has to support javascript and of course have it enabled.

So here's what you have to do.

1. Create loaded.js file which contains the following javascript code

Code: Select all

hideLastSeparator();

function hideLastSeparator() {
	var elements = getElementsByClass("article_separator", null, "span");
	if(elements.length > 0) {
		elements[elements.length-1].style.display="none";
	}
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if (node == null) node = document;
	if (tag == null) tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if (pattern.test(els[i].className)) {
			classElements[j] = els[i];
			j++;
		}
	}
	
	return classElements;
}
2. Save loaded.js somewhere within Joomla directory tree.

3. Open you template file and add

Code: Select all

<script type="text/javascript" src="<?php echo $this->baseurl ?>/path/to/loaded.js"></script>
immediately before the closing body tag i.e. </body>.
Last edited by sthrudel on Mon Apr 06, 2009 4:52 pm, edited 1 time in total.

wrongjon
Joomla! Apprentice
Joomla! Apprentice
Posts: 34
Joined: Thu Oct 11, 2007 2:59 pm

Re: Removing last article separator

Post by wrongjon » Mon Apr 06, 2009 3:33 pm

Hi
Ive added this to an existing JS file so know its getting called but its not doing anything. any ideas?

regards
Jonathan

SOLVED
You must also add this to the JS file in order to invoke the event

Code: Select all

window.addEvent ('load', function() {
	hideLastSeparator();
});

sthrudel
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Sun Mar 29, 2009 4:15 pm

Re: Removing last article separator

Post by sthrudel » Mon Apr 06, 2009 4:10 pm

wrongjon wrote:Hi
Ive added this to an existing JS file so know its getting called but its not doing anything. any ideas?

regards
Jonathan

SOLVED
You must also add this to the JS file in order to invoke the event

Code: Select all

window.addEvent ('load', function() {
	hideLastSeparator();
});
Are 100% sure hideLastSeparator method was getting called after all the articles were loaded? I didn't add any event handler on my site and it works.

The reason I added hide separator method call right before the </body> tag and not in e.g. <body onload="..."> or window.addEvent like you did it is that in the latter case you can actually see the article separator disappear. At least I did when I tried it.

wrongjon
Joomla! Apprentice
Joomla! Apprentice
Posts: 34
Joined: Thu Oct 11, 2007 2:59 pm

Re: Removing last article separator

Post by wrongjon » Mon Apr 06, 2009 4:29 pm

Hi
I'm very sorry, I misread your original post and placed the script just before the <body> tag not the </body> tag.

It now works fine without the addevent as you say and its hidden immediately without flicker. :D

Thanks for this tip!

sthrudel
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Sun Mar 29, 2009 4:15 pm

Re: Removing last article separator

Post by sthrudel » Mon Apr 06, 2009 4:50 pm

wrongjon wrote:Hi
I'm very sorry, I misread your original post and placed the script just before the <body> tag not the </body> tag.

It now works fine without the addevent as you say and its hidden immediately without flicker. :D

Thanks for this tip!
Thank you too. I'll edit my post to emphasize this.

apropos
Joomla! Apprentice
Joomla! Apprentice
Posts: 48
Joined: Sun Oct 29, 2006 3:14 pm

Re: Removing last article separator

Post by apropos » Fri Apr 17, 2009 6:22 am

Very nice job, thanks!

dnote
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Mon Jun 21, 2010 10:02 pm

Re: Removing last article separator

Post by dnote » Mon Jun 21, 2010 10:05 pm

Hey, thanks for posting this great idea. I modified hideLastSeparator a bit so it will work for pages that contain multiple lists of articles (your code would only hide the very last article separator).

Code: Select all

function hideLastSeparator() {
  var elements = getElementsByClass("article_separator", null, "span");
  if(elements.length > 0) {
    for (var i=elements.length-1; i >= 0; i--)
    {
      if (i == elements.length - 1 || elements[i+1].parentNode != elements[i].parentNode)
        elements[i].style.display="none";
    }
  }
}

learwbc4
Joomla! Apprentice
Joomla! Apprentice
Posts: 43
Joined: Thu Sep 14, 2006 8:55 pm
Location: Pompano Beach
Contact:

Re: Removing last article separator

Post by learwbc4 » Thu Aug 12, 2010 8:00 pm

using latest joomla, 1.5.20, and i didn't have to put this snippet into the js file to make it work:

window.addEvent ('load', function() {
hideLastSeparator();
});

also, what does "multiple lists of articles" mean? what do you have to choose in menu manager to get "multiple lists of articles"?

dnote
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Mon Jun 21, 2010 10:02 pm

Re: Removing last article separator

Post by dnote » Thu Aug 12, 2010 8:14 pm

learwbc4 wrote:what does "multiple lists of articles" mean?
You can have more than one newsflash module on one page, or a blog layout and a newsflash module on one page. If I remember correctly also with a multicolumn layout in a blog page you would bump into problems, the code only hiding the last separator of the last column of the blog, not every column.


Locked

Return to “Joomla! 1.5 Coding”