Community Central

Forum:Syntax correction


Syntax correction

Forum page

19,653pages on
this wiki
Add New Page

This Forum has been archived

Visit the new Forums
Forums: Index Support Requests Syntax correction
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.
Note: This topic has been unedited for 1817 days. It is considered archived - the discussion is over. Do not add to unless it really needs a response.

Hi, can you tell me if there is some errors in this code?

$(function() {
   if( $('.navbar a').attr('href') == wgArticlePath ){
     $('.this').css({'color' : '#000000', 'font-weight' : 'bold'});

I'll explain what I want to do: when I get a DPL output list, the link to the current page is rendered as normal link, while normally the wiki syntax convert it in bold plain text. I want to correct it. (the links are in a element with class navbar). leviathan_89 14:27, 4 May, 2012 (UTC)

I came up with a code that will work for that. However, I don't know much about JavaScript, so someone else may be able to tell you a better solution.
$(function() {
	var myLink = $('.navbar a[href="/wiki/' + wgPageName + '"]');
	myLink.css({'color' : '#000000', 'font-weight' : 'bold'});
--Gardimuer { ʈalk } 18:47, May 4, 2012 (UTC)
I'm sorry but that doesn't work... leviathan_89 19:49, 4 May, 2012 (UTC)

Ok, I noticed that it doesn't work for certain pages, I'm using this code:

$(function() {
    $('.navbar a[href="/wiki/'+ encodeURIComponent(wgPageName) +'"]').css({'color' : '#000000', 'font-weight' : 'bold'});

which works, but for some articles with symbols it doesn't. An example would be "Sant'Urea" which is rendered as <a title="Sant'Urea" href="/wiki/Sant%27Urea">Sant'Urea</a>. How can I fix that? leviathan_89 21:48, 4 May, 2012 (UTC)

I see what the problem is. The DPL is replacing special characters in the link urls, such that Sant'Urea becomes Sant%27Urea. You were on the right track with trying to convert the wgPageName variable into URL code. Unfortunately, the DPL doesn't seem to be following the normal URL encoding rules. As far as I can tell, trying to match the href attribute might require code to replace individual characters in wgPageName.
An alternative would be to try matching the title attribute instead, like so:
$(function() {
	$('.navbar a[title="' + wgPageName + '"]').css({'color' : '#000000', 'font-weight' : 'bold'});
--Gardimuer { ʈalk } 22:45, May 4, 2012 (UTC)
Good idea, I'll go with that. Thanks. leviathan_89 22:57, 4 May, 2012 (UTC)

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.