Forums: Index → General Discussion → Script to hide "Read more" section on pages with navboxes
Fandom's forums are a place for the community to help other members.
To contact staff directly or to report bugs, please use Special:Contact.
To contact staff directly or to report bugs, please use Special:Contact.
Something I whipped up and thought I'd share to help tame a stubborn feature. Adapted from Wikipedia's dynamic navigation bars code. Uses JavaScript to hide the "Read more" section if a page contains a table with "navbox" class.
Add to your MediaWiki:Common.js:
function hideReadMore() { // iterate over all < table >-elements tables = document.getElementsByTagName("table"); for( var i=0; NavboxTable = tables[i]; i++ ) { if (hasClass(NavboxTable, "navbox")) { // if found a navbox table, iterate over all < nav >-elements navs = document.getElementsByTagName("nav"); for( var j=0; RPMNav = navs[j]; j++ ) { if (hasClass(RPMNav, "RelatedPagesModule")) { // for each RelatedPagesModule nav, hide it RPMNav.setAttribute('style', 'display:none;'); } } // only need to do this for the first navbox table we find break; } } } addOnloadHook( hideReadMore );
If the table in your navbox template doesn't already have the "navbox" class, change this:
{| class="wikitable" ...
to this:
{| class="wikitable navbox" ...
Rigel Kent 01:09, May 16, 2012 (UTC)
- Could you please direct me to a page where this error is happening? I don't think I've ever seen this "read more" thing. Course, maybe that's because I've just never used the navbox class. Surely if there's a problem with navbox, the simpler solution is just not to use that class. Creating a new class seems a simpler, non-JS way to solve the problem. Why not just create
table.nav-box
or another name of your choosing? czechout ☎ ✍ fly tardis 01:17: Wed 16 May 2012- The code works perfectly. (I think.) Just sharing for anyone who wants to copy it. Rigel Kent 01:26, May 16, 2012 (UTC)
- Could you please direct me to a page where this error is happening? I don't think I've ever seen this "read more" thing. Course, maybe that's because I've just never used the navbox class. Surely if there's a problem with navbox, the simpler solution is just not to use that class. Creating a new class seems a simpler, non-JS way to solve the problem. Why not just create
- I'm sure it does work :) You'd obviously have no interest in posting code that didn't. I don't doubt your coding skill in the slightest. I just a) have never seen this problem (and would like to!) and b) don't understand why a JS solution would be better than just changing the CSS class to something which isn't affected by the problems associated with navbox. czechout ☎ ✍ fly tardis 01:42: Wed 16 May 2012
- Oh, I see what you mean!
- By stubborn feature, I meant "Read more" is stubborn, not navboxes. I love navboxes, doesn't everyone?
- This script keeps navboxes, which editors put it when wanted, from getting crowded out by a redundant "Read more" on the same page, which editors may not want. While still allowing "Read more" to appear on pages without navboxes. Rigel Kent 03:34, May 16, 2012 (UTC)
- I'm sure it does work :) You'd obviously have no interest in posting code that didn't. I don't doubt your coding skill in the slightest. I just a) have never seen this problem (and would like to!) and b) don't understand why a JS solution would be better than just changing the CSS class to something which isn't affected by the problems associated with navbox. czechout ☎ ✍ fly tardis 01:42: Wed 16 May 2012
- Yeah, but where does this "read more" occur? I've never seen it before. Can you direct me to a page somewhere that it's happening? czechout ☎ ✍ fly tardis 14:02: Wed 16 May 2012
- The "Read more" section is added to the bottom of most pages on wikis where the extension is enabled. For example, look at the bottom of this page: http://bioshock.wikia.com/wiki/Cigarettes?useskin=wikia --Gardimuer { ʈalk } 16:17, May 16, 2012 (UTC)