MediaWiki talk:Common.js/Archive 17: Difference between revisions

Content deleted Content added
MiszaBot II (talk | contribs)
m Archiving 2 thread(s) from MediaWiki talk:Common.js.
MiszaBot II (talk | contribs)
m Archiving 2 thread(s) from MediaWiki talk:Common.js.
Line 116:
 
Like this:<br>[[File:Button base.png]][[File:Button base.png]]<br>[[File:Button base.png]][[File:Button base.png]]<br>[[Special:Contributions/140.112.7.59|140.112.7.59]] ([[User talk:140.112.7.59|talk]]) 06:52, 21 October 2009 (UTC)
== Anontips banner ==
 
I'd like to disable the anontips banner ("Wikipedia is sustained by people like you. Please donate today.", etc.) before the start of the next fundraiser. This year's fundraiser banners will be particularly large and noticeable; there's really no need to clutter the reader's screen with multiple donate messages. In addition, the non-donate messages are stale and the break will hopefully give us some time to write fresh content. Any objections? --[[User:MZMcBride|MZMcBride]] ([[User talk:MZMcBride|talk]]) 00:37, 27 October 2009 (UTC)
 
: Forgot that we have [[MediaWiki:Monobook.css]] too. Probably good if change some of the more stagnant elements in the site. Looking at the code I came up with the following improvement to shave bytes by using wikilinking. <source lang=javascript>div.innerHTML = message[whichMessage].replace(/\[\[([^[\]{|}]+)\]\]/g, "[[$1|$1]]").replace(/\[\[([^[\]{|}]+)\|(.+?)\]\]('??\w*)/g, '<a href="'+wgArticlePath+'" title="$1">$2$3</a>');</source> It has the add benefit that the links work better on the secure server. Also, for accessibility we should be attaching this div to the end of the page so it isn't the first text read aloud by screen readers. — [[User:Dispenser|Dispenser]] 03:41, 27 October 2009 (UTC)
::Now we just a javascript implementation of the parser and we'll be set! — [[User:RockMFR|RockMFR]] 23:20, 27 October 2009 (UTC)
 
When does the fundraiser start ? What is the HTML that is going to be used for this years centralnotice ? I was pondering about just changing insertBefore() of the addition to an appendChild(), but I think there were browsers that had issues with appendChild(). I agree with MZMcBride that changing that is important, but does anyone remember which browsers were having trouble with appendChild and wether we still support those ? —[[User:TheDJ|Th<span style="color: green">e</span>DJ]] ([[User talk:TheDJ|talk]] • [[Special:Contributions/TheDJ|contribs]]) 23:39, 27 October 2009 (UTC)
 
:According to [[m:Fundraising_2009/Timeline]] Soft launch on Nov 3 and full launch Nov 7. — [[User:Dispenser|Dispenser]] 02:13, 28 October 2009 (UTC)
 
So we'll add "needs a code rewrite" to the list of reasons I've now [http://en.wikipedia.org/w/index.php?title=MediaWiki:Monobook.js&diff=prev&oldid=322588403 removed] the banner. Copied below for posterity and for improvements. --[[User:MZMcBride|MZMcBride]] ([[User talk:MZMcBride|talk]]) 19:26, 28 October 2009 (UTC)
{{collapse top}}
<source lang="javascript">
/** Anon tips and donation banner **************************
*
* Description: This implements an anon tips / donation banner. It includes a workaround for
* the Z-index bug found in Internet Explorer. It correctly places the anon notice
* on the page, even under IE6. See this Google search for more information about the bug:
* http://www.google.com/search?q=z-index+ie6+bug
* Maintainers: [[User:Gmaxwell]], [[User:MZMcBride]]
*/
 
if(wgUserName == null) addOnloadHook((function (){
var message=new Array();
message[0]='Your <a href="http://wikimediafoundation.org/wiki/Donate/Now/en?utm_source=enwiki_00&utm_medium=anon_donation_banner&utm_campaign=spontaneous_donation" class="extiw" title="wikimedia:Fundraising"><b>continued donations</b></a> keep Wikipedia running!';
message[1]='<a href="http://wikimediafoundation.org/wiki/Donate/Now/en?utm_source=enwiki_01&utm_medium=anon_donation_banner&utm_campaign=spontaneous_donation" class="extiw" title="foundation:Fundraising"><b>Make a donation</b></a> to Wikipedia and give the gift of knowledge!';
message[2]='Wikipedia is sustained by people like you. Please <a href="http://wikimediafoundation.org/wiki/Donate/Now/en?utm_source=enwiki_02&utm_medium=anon_donation_banner&utm_campaign=spontaneous_donation" class="extiw" title="foundation:fundraising"><b>donate</b></a> today.';
message[3]='Help us improve Wikipedia by <a href="http://wikimediafoundation.org/wiki/Donate/Now/en?utm_source=enwiki_03&utm_medium=anon_donation_banner&utm_campaign=spontaneous_donation" class="extiw" title="foundation:Fundraising"><b>supporting it financially</b></a>.';
message[4]='You can <a href="http://wikimediafoundation.org/wiki/Donate/Now/en?utm_source=enwiki_04&utm_medium=anon_donation_banner&utm_campaign=spontaneous_donation" class="extiw" title="wikimedia:Fundraising"><b>support Wikipedia</b></a> by making a tax-deductible donation.'
message[5]='Help us provide free content to the world by <a href="http://wikimediafoundation.org/wiki/Donate/Now/en?utm_source=enwiki_05&utm_medium=anon_donation_banner&utm_campaign=spontaneous_donation" class="extiw" title="foundation:Fundraising"><b>donating today</b></a>!';
message[6]='<a href="http://en.wikipedia.org/wiki/Wikipedia:Researching_with_Wikipedia" title="Wikipedia:Researching with Wikipedia">Learn more about using Wikipedia for research.</a>';
message[7]='<a href="http://en.wikipedia.org/wiki/Wikipedia:Ten_things_you_may_not_know_about_Wikipedia" title="Wikipedia:Ten things you may not know about Wikipedia">Ten things you may not know about Wikipedia.</a>';
message[8]='<a href="http://en.wikipedia.org/wiki/Wikipedia:Ten_things_you_may_not_know_about_images_on_Wikipedia" title="Wikipedia:Ten things you may not know about images on Wikipedia">Ten things you may not know about images on Wikipedia.</a>';
message[9]='<a href="http://en.wikipedia.org/wiki/Wikipedia:Citing_Wikipedia" title="Wikipedia:Citing Wikipedia">Learn more about citing Wikipedia.</a>';
message[10]='Have questions? <a href="http://en.wikipedia.org/wiki/Wikipedia:Questions" title="Wikipedia:Questions">Find out how to ask questions and get answers.</a>';
message[11]='<a href="http://en.wikipedia.org/wiki/Wikipedia:Basic_navigation" title="Wikipedia:Basic navigation">Find out more about navigating Wikipedia and finding information.</a>';
message[12]='<a href="http://en.wikipedia.org/wiki/Wikipedia:Contributing_to_Wikipedia" title="Wikipedia:Contributing to Wikipedia">Interested in contributing to Wikipedia?</a>';
var weightLimit = 6;
var biasPercent = 0.815;
var whichMessage = (Math.random() < biasPercent) ? weightLimit : message.length;
whichMessage = Math.floor(Math.random() * whichMessage);
var wrapper = document.getElementById("globalWrapper");
if (wrapper) {
var div = document.createElement('div');
div.id = "anon-banner";
div.className = "noprint";
div.style.cssText = "position:absolute; z-index:40; left:155px; top:1px; clear:both; float:left; font-size:90%; font-style:italic; white-space:nowrap";
div.innerHTML = message[whichMessage];
wrapper.insertBefore(div, wrapper.firstChild);
}
}));
</source>
{{collapse bottom}}
 
== Simplify ==
 
Hello!
 
I think we could simplify this code from the function ''toggleNavigationBar''
<source lang="javascript">
if ( hasClass( NavChild, 'NavPic' ) ) {
NavChild.style.display = 'none';
}
if ( hasClass( NavChild, 'NavContent') ) {
NavChild.style.display = 'none';
}
</source>
to
<source lang="javascript">
if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent') ) {
NavChild.style.display = 'none';
}
</source>
 
and this one
<source lang="javascript">
if (hasClass(NavChild, 'NavPic')) {
NavChild.style.display = 'block';
}
if (hasClass(NavChild, 'NavContent')) {
NavChild.style.display = 'block';
}
</source>
to
<source lang="javascript">
if (hasClass(NavChild, 'NavPic') || hasClass(NavChild, 'NavContent')) {
NavChild.style.display = 'block';
}
</source>
 
What do you think? [[User:Heldergeovane|Helder]] ([[User talk:Heldergeovane|talk]]) 18:47, 29 October 2009 (UTC)
:No objections. Though realistically, it won't make much of a difference in both speed and size of the script. —[[User:TheDJ|Th<span style="color: green">e</span>DJ]] ([[User talk:TheDJ|talk]] • [[Special:Contributions/TheDJ|contribs]]) 19:49, 29 October 2009 (UTC)
::Or maybe all this part
<source lang="javascript">
// if shown now
if (NavToggle.firstChild.data == NavigationBarHide) {
for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
if ( hasClass( NavChild, 'NavPic' ) ) {
NavChild.style.display = 'none';
}
if ( hasClass( NavChild, 'NavContent') ) {
NavChild.style.display = 'none';
}
}
NavToggle.firstChild.data = NavigationBarShow;
// if hidden now
} else if (NavToggle.firstChild.data == NavigationBarShow) {
for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
if (hasClass(NavChild, 'NavPic')) {
NavChild.style.display = 'block';
}
if (hasClass(NavChild, 'NavContent')) {
NavChild.style.display = 'block';
}
}
NavToggle.firstChild.data = NavigationBarHide;
}
</source>
::could be changed to
<source lang="javascript">
for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
if (hasClass(NavChild, 'NavPic') || hasClass(NavChild, 'NavContent')) {
NavChild.style.display = (NavToggle.firstChild.data == NavigationBarHide) ? 'none' : 'block'
}
}
</source>
::It seems a lot simpler, isn't? ;-) [[User:Heldergeovane|Helder]] ([[User talk:Heldergeovane|talk]]) 18:20, 30 October 2009 (UTC)
:::Add the forgotten <code>NavToggle.firstChild.data = ...</code> and then your code is very similar to what I had for a year in [[:ru:MediaWiki:Common.js]] (collapseDiv() function), so naturally I support this simplification. However, the en.wp style of JS programming seems to be "the more lines of code, the merrier". — [[user:Alex Smotrov|AlexSm]] 19:31, 30 October 2009 (UTC)