This Forum has been archived

Visit the new Forums
Forums: Index Support Requests Hiding text with javascript/jQuery
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.

50px-Replacement filing cabinet.svg

Note: This topic has been unedited for 1956 days. It is considered archived - the discussion is over. Do not add to unless it really needs a response.

tl;dr: I'm writing Javascript code to hide spoilers in articles on Amalur Wiki and need help hiding text nodes (text not wrapped in any tags).

To spare y'all having to look for the link, yes, I know there's a similar script on dev wiki, but it hides the entire article, while I only want to hide sections that contain a spoiler tag. E.g consider a page like this:

Some spoiler-free text here...
{{Spoilers (Reckoning)}}
Spoiler-heavy text here

more spoilers...

blah blah

*some note
{{Spoilers (Reckoning)}}
*a massive spoiler note here

gallery code here

What I want is to hide the content between {{Spoilers (Reckoning)}} and the next section header.

I already have the code for this (found here), but need help hiding text nodes that somehow sometimes appear in articles. Here's an example of how the script works - first case it works perfectly, second it does not hide all content.

Correct: Spoilers Visible Spoilers Hidden
Broken: Spoilers Visible Spoilers Hidden

What breaks it is the fact that sometimes plain text is rendered as text nodes instead of being wrapped in p tags, despite no major differences in wiki markup. The example problematic page is here and the good page is here. Spoilers are hidden on page load, and can be shown by clicking on the spoiler banner above the section to be revealed.

Now, I obviously don't want to scour the entire wiki looking for such pages and correcting the markup (don't even know what causes text to be rendered differently, we don't use p or span tags explicitly on our wiki, just plain wiki code). I tried searching on Google for generic ways to select text nodes that appear after certain tags, but it seems that's not possible.

Main point: Is there a more wiki-specific way to select and hide such text nodes?

-- Gyumaou (Talk) 10:48, May 15, 2012 (UTC)

It would be simpler if you used a system like the spoiler templates on the Dragon Age wiki. Instead of trying to automatically hide everything between the template tag and the next heading, you should just place the text to be hidden inside of the template. Here's an example of a page with many spoiler tags on the Dragon Age wiki: w:c:dragonage:Werewolf.
Limitations of the spoiler tags on the Dragon Age Wiki:
  • Equals signs ("=") or pipe symbols ("|") included in the text to be hidden may cause the template to break in pages. However, this is pretty rare, and I don't think it would be a problem for you. If it is a problem, you could use {{!}} and {{=}} templates.
  • Since the hidden text is placed inside of the template, editing the text might be less intuitive for people who use Wikia's rich text editor interface instead of source mode. (They would see the green puzzle piece symbol instead of the text.) But I personally wouldn't view that as a limitation, since it's Wikia's fault if their interface confuses people.
--Gardimuer { ʈalk } 16:47, May 15, 2012 (UTC)
That's a pretty good idea there. I've been to DA wiki a few times but somehow forgot about their way of hiding spoilers. I'll talk to the other admins on Amalur wiki, see what they think about a solution like that. Thanks! Still, I can't help but wonder why some wiki text renders like that. It'll keep bugging me, it will.
-- Gyumaou (Talk) 08:30, May 17, 2012 (UTC)