![]() | This is an archive of past discussions about MediaWiki:Common.js. Do not edit the contents of this page. If you wish to start a new discussion or revive an old one, please do so on the current talk page. |
Archive 5 | ← | Archive 8 | Archive 9 | Archive 10 | Archive 11 | Archive 12 | → | Archive 15 |
I'm not sure what changes were made, but boxes no longer collapse automatically if there are more than two on a page - and there is no longer any spacing between them. Please see the bottom of the Paris article for an example. I'm using Safari on Mac os X 10.4.10 (intel). Cheers. THEPROMENADER 07:58, 27 August 2007 (UTC)
See this diff. Why isn't the code at the bottom properly handled, causing the message to appear at the top of the page? —Ruud 16:39, 28 August 2007 (UTC)
document.writeln('<'+'div style="position:absolute'…
. Btw, I would really recommend nice and easy-on-the-server option "Don't show page content below diffs" ∴ Alex Smotrov 17:06, 28 August 2007 (UTC)
<div style="position:absolute'
is interpreted as wikitext. Yes, another way to avoid this would be using <pre> Mediawiki tag (which is not the same as HTML <pre> tag). I'm not sure what you mean about <code> tags ∴ Alex Smotrov 17:45, 28 August 2007 (UTC)
{{editprotected}}
This code will fix a problem in many navigation boxes where the header color is dark and the font color is light. The show/hide button always is dark blue, which means that with the dark background it cannot be read. This line will modify the color of the link if and only if a different header text color is specified in the table header. If the color is not changed, then the link will remain blue.
Add this line:
ButtonLink.style.color = Tables[i].getElementsByTagName( "tr" )[0].getElementsByTagName( "th" )[0].style.color;
Directly BEFORE these lines in function createCollapseButtons():
ButtonLink.setAttribute( "id", "collapseButton" + tableIndex ); ButtonLink.setAttribute( "href", "javascript:XcollapseTable(" + tableIndex + ");" ); ButtonLink.appendChild( ButtonText );
Thanks, --CapitalR 02:36, 3 September 2007 (UTC)
The anonnotice still isn't working correctly. I just opened Safari to see what it looked like, and three of them showed up at once, with two directly on top of each other. Don't know what the issue is, but I uploaded a screenshot (see here). --MZMcBride 20:33, 3 September 2007 (UTC)
So thanks for all the cheese that's falling off my screen, and the fact that it's a new piece of cheese with every link I click. It would be nice if someone would turn down the cheese factor by at least three orders of magnitude. Did noone notice that <blink>blinking</blink> popups went out of fashion last century because of how distracting they are? Clearly not round here, they didn't. Then, if you're going to write your advert all over my screen, would you at least please have the consideration not to make it collide with article titles like Department for Business, Enterprise and Regulatory Reform? This fun-and-games with live Mediawiki pages is all well and good for logged-in users, but actually does affect people who are logged out. Like me, almost all the time I use Wikipedia, for example. Yes, yes, I know the pit of financial doom that the Foundation stares into all the time, but for the love of $deity, would someone come up with a scheme that is well thought-out, doesn't use up ever more real-estate with advertising, doesn't mess up formatting, doesn't require 30-odd edits to a super-important page to get right, doesn't distract me from reading articles and isn't instituted on the whim of a random admin. Oh, and would said random passing admins please test their new ideas somewhere else than on possibly the most-used page on the entire site? Thanks and appreciation in advance, Splash - tk 12:18, 3 September 2007 (UTC)
Splash, your tone could be more constructive here. Your complaint about Department for Business, Enterprise and Regulatory Reform was addressed over at MediaWiki_talk:Anonnotice#Clashes_with_not-unreasonably_long_titles as far as I can tell. Although perhaps I'm wrong because instead of following up about it there you're simply spreading your complaints all over in ForestFire fashion. Mets' minor errors here have been unfortunate, but he's going to be changing his process in the future. What important is that they were minor errors and that they've been resolved. It's good that Mets' took the time to take action to move us forward... bad that a little more care wasn't taken, but these are mistakes we can all learn from. There is no need to be rude about it. --Gmaxwell 22:42, 3 September 2007 (UTC)
{{editprotected}} Specifically, please change:
position:absolute; z-index:100; right:100px; top:0px;
to:
position:absolute; z-index:100; right:100px; top:50px;
This will keep the collisions from occurring. Thank you. ←BenB4 09:49, 4 September 2007 (UTC)
Coincidentally, has anyone tried to obtain a diff between two previous versions of any page whilst logged out lately? There being nothing in this week's signpost indicating related changes, and the intermediate radio buttons disappearing at the same time as the spam randomises itself, I'm feeling a little suspicious. It could be another .js page altogether, of course. Splash - tk 10:38, 4 September 2007 (UTC)
diffcheck()
in http://en.wikipedia.org/skins-1.5/common/wikibits.js?97 and I have no idea why logging out would make any difference. Someone should post this on WP:VPT. I Well the diff buttons are fixed, but why would rewrting innerHTML invalidate logged-out users' handles but not logged in users'? ←BenB4 18:35, 4 September 2007 (UTC)
The reinstatement of this still clashed with article titles. It is to my mind completely unacceptable that it do so. The main difference between [1] and [2] appears to be the top:3px and font-size:100%, and so I've changed them to be the same as in mediawiki:anonnotice ie top:0px and font-size:80%. This has the effect of making the text look rather small, not sure why. But at least it no longer disrupts the title line(s).
Incidentally, why must there be so much formatting in these messages? There black, blue, grey, bold, italics, bullets and punctuation. dewiki just uses plain text and a link. Is that not enough? Splash - tk 12:27, 5 September 2007 (UTC)
I've got a script together that should fix most of the PNG transparency issues in Internet Explorer 6. Comments would we welcome at Wikipedia:Village pump (technical)#JavaScript PNG transparency fix. —Remember the dot (talk) 02:48, 8 September 2007 (UTC)
{{editprotected}}
Edokter has just confirmed at the main discussion thread that this script works without problems. I have extensively tested the script myself and now request that it be added to common.js. The code to add is given at Wikipedia:Village pump (technical)#JavaScript PNG transparency fix. —Remember the dot (talk) 23:14, 8 September 2007 (UTC)
window.attachEvent("onload", PngFix)
should be replaced with addOnloadHook
(the former is specific to IE, but it's best to synchronize everything with the latter). I'm not too fond of innerHTML either, but if the script works, it works... GracenotesT § 01:08, 9 September 2007 (UTC)
{{editprotected}}
window.attachEvent("onload", PngFix)
to window.addOnloadHook(PngFix)
. —Remember the dot (talk) 01:23, 9 September 2007 (UTC)For IE in some cases window.addOnloadHook is not the same as onload event, so that change should have been tested first. Also, how about asking the devs to move the code into IEFixes.js instead? ∴ Alex Smotrov 03:19, 9 September 2007 (UTC)
I loaded IE6 to test the fix, and I found that some images (such as those used in Template:Proposed and Template:Historical) now appear vertically stretched (on my end, at least). Is anyone else seeing this? —David Levy 08:27, 9 September 2007 (UTC)
{{editprotected}}
A bug has been identified which causes borders to fail to display in IE 5.5 and 6. I believe that changing the code to make images into divs instead of spans will resolve this. So, please change the PngFix function to read:
function PngFix() { if (document.body.filters) { for(var i=0; i<document.images.length; i++) { var img = document.images[i] var imgName = img.src.toUpperCase() if (imgName.substring(imgName.length-3, imgName.length) == "PNG") { var imgID = (img.id) ? "id='" + img.id + "' " : "" var imgClass = (img.className) ? "class='" + img.className + "' " : "" var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' " var imgStyle = "display:inline-block; vertical-align:middle;" + img.style.cssText if (img.align == "left") imgStyle = "float:left;" + imgStyle if (img.align == "right") imgStyle = "float:right;" + imgStyle if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" img.outerHTML = strNewHTML i = i-1 } } } }
—Remember the dot (talk) 00:09, 10 September 2007 (UTC)
Never mind - changing it to a div would probably break more things than it fixes. Instead, try changing sizingMethod='scale'
to sizingMethod='image'
—Remember the dot (talk) 00:31, 10 September 2007 (UTC)
sizingMethod='image'
has fixed the distortion on some flags, but the border problem persists. Interestingly, flag icons that are still based on jpg images do show the grey border. It's just PNG and SVG that do not. Andrwsc 00:38, 10 September 2007 (UTC){{editprotected}}
function PngFix() { if (document.body.filters) { for(var i=0; i<document.images.length; i++) { var img = document.images[i] var imgName = img.src.toUpperCase() if (imgName.substring(imgName.length-3, imgName.length) == "PNG") { var imgID = (img.id) ? "id='" + img.id + "' " : "" var imgClass = (img.className) ? "class='" + img.className + "' " : "" var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' " var imgStyle = "display:inline-block; vertical-align:middle;" + img.style.cssText if (img.align == "left") imgStyle = "float:left;" + imgStyle if (img.align == "right") imgStyle = "float:right;" + imgStyle if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle var strNewHTML = "<div " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='image');\"></div>" img.outerHTML = strNewHTML i = i-1 } } } }
—Remember the dot (talk) 00:48, 10 September 2007 (UTC)
{{editprotected}}
OK, I've found a fix (and tested it in my userpace on the Commons), but you'll have to edit two files. Change the pngfix code to read:
/* Correctly handle PNG transparency in Win IE 5.5 & 6. http://homepage.ntlworld.com/bobosola. Updated 18-Jan-2006. Tweaked 10 Sep 2007 (UTC) by Remember_the_dot so that it works properly inside Common.js http://homepage.ntlworld.com/bobosola/pnginfo.htm states "This page contains more information for the curious or those who wish to amend the script for special needs", which I take as permission to modify or adapt this script freely. I release my changes into the public domain. */ function PngFix() { if (document.body.filters) { for(var i=0; i<document.images.length; i++) { var img = document.images[i] var imgName = img.src.toUpperCase() if (imgName.substring(imgName.length-3, imgName.length) == "PNG") { var imgID = (img.id) ? "id='" + img.id + "' " : "" var imgClass = (img.className) ? "class='" + img.className + "' " : "" var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' " var imgStyle = "display:inline-block; vertical-align:middle;" + img.style.cssText if (img.align == "left") imgStyle = "float:left;" + imgStyle if (img.align == "right") imgStyle = "float:right;" + imgStyle if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"font-size:0; display:inline-block;" + imgStyle + "\"><span style=\'width:" + img.width + "; height:" + img.height + "; display:inline-block; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\"" + img.src + "\', sizingMethod='image');\"></span></span>" img.outerHTML = strNewHTML i = i-1 } } } } if (navigator.appName == "Microsoft Internet Explorer") { var version = parseFloat(navigator.appVersion.split("MSIE")[1]) if (version <= 6 && version >= 5.5) { window.addOnloadHook(PngFix) } }
Then hop over to Mediawiki:Common.css and add the following:
/* Enables borders on PNG images in IE 5.5 and 6 */ .thumbborder { border:1px solid #DDDDDD; }
In the future, the Mediawiki software may do all this automatically. But as for right now, we have to work with what we've got.
For the technically minded, I moved all the CSS styling information to a span outside the image, and made the image's span separate. I had to set the font-size property of the outer span to 0 in order to make it shrink-wrap the inner span. —Remember the dot (talk) 03:34, 10 September 2007 (UTC)
addOnloadHook is not specifically a function of the window object, so that might need to be altered. I do realize philosophy differs on this, but it might be a good idea to have some discussion of an {{editprotected}} request before it's implemented. But, again, this is a wiki. Things are reversible. GracenotesT § 06:16, 10 September 2007 (UTC)
{{flagicon|China}}
({{flagicon|Côte d'Ivoire}}
I'm surprised it even WORKS! I see so many syntax errors in the code above (" and ' mixed, missing "px" in width and height parameters, etc.), but when I test my cleaned up code, the image diappears! This is maddening... — Edokter • Talk • 19:46, 10 September 2007 (UTC)
OK, got the cleanup done! only problem remains the ' and " in the image (hint) title: if I use ' , all text in the hint past a ' is truncated. If i use ", everything after " is truncated. If I use no quotes, everything after the first space disappears... I need a thridt quote character. :/ My code is here: http://commons.wikimedia.orghttps://demo.azizisearch.com/lite/wikipedia/page/User:Edokter/monobook.js — Edokter • Talk • 21:44, 10 September 2007 (UTC)
{{editprotected}}
Here is a cleaned-up version of the code. I have tested it in my userspace on the Commons and believe that it will resolve the title attribute issues.
/* Correctly handle PNG transparency in Win IE 5.5 & 6. http://homepage.ntlworld.com/bobosola. Updated 18-Jan-2006. Tweaked 11 Sep 2007 (UTC) by Remember_the_dot so that it works properly inside Common.js http://homepage.ntlworld.com/bobosola/pnginfo.htm states "This page contains more information for the curious or those who wish to amend the script for special needs", which I take as permission to modify or adapt this script freely. I release my changes into the public domain. */ function PngFix() { if (document.body.filters) { for(var i = 0; i < document.images.length; i++) { var img = document.images[i] var imgName = img.src.toUpperCase() if (imgName.substring(imgName.length - 3, imgName.length) == "PNG") { var imgID = (img.id) ? "id=\"" + img.id + "\" " : "" var imgClass = (img.className) ? "class=\"" + img.className + "\" " : "" var imgTitle = (img.title) ? "title=\"" + img.title + "\" " : "" var imgStyle = "display:inline-block; font-size:0; vertical-align:middle;" + img.style.cssText if (img.align == "left") imgStyle = "float:left;" + imgStyle if (img.align == "right") imgStyle = "float:right;" + imgStyle if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + imgStyle + "\"><span style=\"width:" + img.width + "px; height:" + img.height + "px; display:inline-block; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img.src + "');\"></span></span>" img.outerHTML = strNewHTML i-- } } } } if (navigator.appName == "Microsoft Internet Explorer") { var version = parseFloat(navigator.appVersion.split("MSIE")[1]) if (version <= 6 && version >= 5.5) { window.addOnloadHook(PngFix) } }
—Remember the dot (talk) 02:21, 11 September 2007 (UTC)
Well, I found a new (small) problem. Have a look at {{resolved}} source and talk page. Apparrently the filter doesn't like exotic unicode characters in the image filename. There is probably no fix but to 'ban' exotic unicode in filenames (not sure what the policy is on that anyway). — Edokter • Talk • 16:26, 11 September 2007 (UTC)
{{editprotected}}
The fix for the Unicode image naming problem is actually quite simple. I've debugged it on Commons and (with the help of [4], kudos to Edokter) found a fix. Just change
+ img.src +
to
+ encodeURI(img.src) +
And change "Tweaked 11 Sep 2007" to "Tweaked 12 Sep 2007", or remove the date entirely if you like. —Remember the dot (talk) 02:44, 12 September 2007 (UTC)
Cheers Dot & MZ! I promise not to panic again if I find another bug (which I suspect won't happen for a long time). — Edokter • Talk • 11:46, 12 September 2007 (UTC)
Besides javascript to get IE6 to render PNS correctly, there are also other methods that may in the end be a better sulotion for MediaWiki. There are "CSS only" implementations, and even PHP solutions. This may be worth looking into in the long run. Just a thought... — Edokter • Talk • 21:56, 13 September 2007 (UTC)
I went through and optimized the code to reduce unneccessary processing. Give this a try:
/* Correctly handle PNG transparency in Win IE 5.5 & 6. http://homepage.ntlworld.com/bobosola. Updated 18-Jan-2006. Adapted for Wikipedia by Remember_the_dot http://homepage.ntlworld.com/bobosola/pnginfo.htm states "This page contains more information for the curious or those who wish to amend the script for special needs", which I take as permission to modify or adapt this script freely. I release my changes into the public domain. */ function PngFix() { if (document.body.filters) { var documentImages = document.images for (var i = 0; i < documentImages.length;) { var img = documentImages[i] var imgSrc = img.src if (imgSrc.substr(imgSrc.length - 3).toLowerCase() == "png") { var imgID = (img.id) ? "id=\"" + img.id + "\" " : "" var imgClass = (img.className) ? "class=\"" + img.className + "\" " : "" var imgTitle = (img.title) ? "title=\"" + img.title + "\" " : "" var imgStyle = "display:inline-block; font-size:0; vertical-align:middle;" + img.style.cssText if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle img.outerHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + imgStyle + "\"><span style=\"width:" + img.width + "px; height:" + img.height + "px; display:inline-block; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + encodeURI(imgSrc) + "');\"></span></span>" } else { i++ } } } } if (navigator.appName == "Microsoft Internet Explorer") { var version = navigator.appVersion.substr(22, 3) if (version == "6.0" || version == "5.5") { window.addOnloadHook(PngFix) } }
Now, even though I did cut out a bunch of unneccessary processing, I left in support for images with id and title attributes even though the MediaWiki software usually does not use these attributes on images. I didn't want to have this code work in most cases but seemingly randomly mess up the page's XHTML in others. —Remember the dot (talk) 04:45, 14 September 2007 (UTC)
Oh, and in case you were wondering, I did test this script on the Commons and it appears to work fine. —Remember the dot (talk) 04:48, 14 September 2007 (UTC)
I just made a minor change to the above code to improve performance a bit more. —Remember the dot (talk) 06:08, 14 September 2007 (UTC)
{{editprotected}}
Thinking about this, I realized why the code has been dramatically slowing page load times on IE6. It's because the MediaWiki function "window.addOnloadHook" is executed before all the images load, causing the script to make browser the wait for every single image to load before displaying the page. Here is a revised version of the code that goes back to using "window.attachEvent", which will allow the browser to load all the images (though with opaque backgrounds) before changing the backgrounds to transparent. The end result for the user will be the ability to use the page freely with opaque backgrounds until all the images load, then the page will freeze for a moment (the user probably won't even notice this) while the backgrounds are made transparent.
This code also disables running the script on an image if the image uses an imagemap. In the current "live" script there is a bug that causes imagemaps to fail to work with PNG/SVG images.
/* Correctly handle PNG transparency in Win IE 5.5 & 6. http://homepage.ntlworld.com/bobosola. Updated 18-Jan-2006. Adapted for Wikipedia by Remember_the_dot http://homepage.ntlworld.com/bobosola/pnginfo.htm states "This page contains more information for the curious or those who wish to amend the script for special needs", which I take as permission to modify or adapt this script freely. I release my changes into the public domain. */ function PngFix() { if (document.body.filters) { var documentImages = document.images for (var i = 0; i < documentImages.length;) { var img = documentImages[i] var imgSrc = img.src if (imgSrc.substr(imgSrc.length - 3).toLowerCase() == "png" && !img.useMap) { var imgID = (img.id) ? "id=\"" + img.id + "\" " : "" var imgClass = (img.className) ? "class=\"" + img.className + "\" " : "" var imgTitle = (img.title) ? "title=\"" + img.title + "\" " : "" var imgStyle = "display:inline-block; font-size:0; vertical-align:middle;" + img.style.cssText if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle img.outerHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + imgStyle + "\"><span style=\"width:" + img.width + "px; height:" + img.height + "px; display:inline-block; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + encodeURI(imgSrc) + "');\"></span></span>" } else { i++ } } } } if (navigator.appName == "Microsoft Internet Explorer") { var version = navigator.appVersion.substr(22, 3) if (version == "6.0" || version == "5.5") { window.attachEvent("onload", PngFix) } }
Again, let me reiterate that this script is not nearly as good as upgrading to Internet Explorer 7 or using a different browser such as Firefox. Firefox does work on Windows 2000.—Remember the dot (talk) 20:34, 14 September 2007 (UTC)
I found another possible problem, hopefully related the window.addOnloadHook method an possibly fixed by the change to window.attachEvent. Wikipedia:Route diagram template containes a partially collapsed table containing SVGs. When clicking 'Show', I see no images in the resulting area being expanded, probably because they haven't been rendered yet? — Edokter • Talk • 22:49, 14 September 2007 (UTC)
{{editprotected}}
In order to resolve the issues that the previous code caused, I request that the PngFix function be changed as follows:
function PngFix() { if (document.body.filters) { var documentImages = document.images for (var i = 0; i < documentImages.length; i++) { var img = documentImages[i] var imgSrc = img.src if (imgSrc.substr(imgSrc.length - 3).toLowerCase() == "png") { img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + encodeURI(imgSrc) + "')" img.src = "http://upload.wikimedia.org/wikipedia/commons/d/db/Must_left-click_image_again_before_saving.gif" if (img.parentElement.href) { img.style.cursor = "hand" } } } } }
This makes use of a different solution, leaving the img
tags intact but filling in the proprietary filter property and then changing the src
attributes to point to a 1px transparent GIF image. This allows for much faster code, support for imagemaps, resolves issues with the editing toolbar, and even allows MediaWiki's checkered image background to be displayed. The only downside is that the "Save Picture As" right-click menu item will try and save the 1px transparent GIF image instead of the image the user actually sees. I've tried to mitigate the problem as best I can by naming the image Image:Must left-click image again before saving.gif. —Remember the dot (talk) 17:10, 15 September 2007 (UTC)
Oh, and yes, I've tested this on the Commons, and it works great. —Remember the dot (talk) 17:10, 15 September 2007 (UTC)
border
and thumb
parameters again. This could be fixed using a CSS class, ie, .img.pngfixed
. — Edokter • Talk • 19:44, 15 September 2007 (UTC){{editprotected}}
Well, I couldn't get the lightning-fast version to work right, but here is a revised copy of PngFix() which will add support for transparency + imagemaps, support for the checkered background, and last if not least fix the edit toolbar problem.
function PngFix() { if (document.body.filters) { var documentImages = document.images for (var i = 0; i < documentImages.length;) { var img = documentImages[i] var imgSrc = img.src if (imgSrc.substr(imgSrc.length - 3).toLowerCase() == "png" && !img.onclick) { var imgID = (img.id) ? "id=\"" + img.id + "\" " : "" var imgClass = (img.className) ? "class=\"" + img.className + "\" " : "" var imgTitle = (img.title) ? "title=\"" + img.title + "\" " : "" var imgStyle = "display:inline-block; font-size:0; vertical-align:middle;" + img.style.cssText var imgUseMap = (img.useMap) ? "usemap=\"" + img.useMap + "\" " : "" if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle img.outerHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + imgStyle + "\"><img src=\"http://upload.wikimedia.org/wikipedia/commons/d/db/Must_left-click_image_again_before_saving.gif\" style=\"width:" + img.width + "px; height:" + img.height + "px; display:inline-block; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + encodeURI(imgSrc) + "');\"" + imgUseMap + "/></span>" } else { i++ } } } }
—Remember the dot (talk) 23:57, 15 September 2007 (UTC)
{{editprotected}}
OK, forget about the code above. Just change
if (imgSrc.substr(imgSrc.length - 3).toLowerCase() == "png" && !img.useMap)
to
if (imgSrc.substr(imgSrc.length - 3).toLowerCase() == "png" && !img.useMap && !img.onclick)
This will simply resolve the problem with the edit toolbar, no more. —Remember the dot (talk) 00:09, 16 September 2007 (UTC)
Which version of the code should be changed to? Which change, exactly, should be made? There are a lot of suggestions in the above thread, and I'm not sure which one the request is to change. --ais523 14:38, 17 September 2007 (UTC)
outerHTML
and innerHTML
). We'll have to see if this new approach is any faster. —Remember the dot (talk) 21:17, 19 September 2007 (UTC)I've modified the code to avoid using outerHTML
to better comply with W3C standards, but the new code does not appear to be significantly faster. Would anyone else be willing to test this new code on, say, Commons:Category:Icons for railway descriptions, and let me know if it appears to go any faster?
function PngFix() { if (document.body.filters) { var documentImages = document.images for (var i = 0; i < documentImages.length;) { var img = documentImages[i] var imgSrc = img.src if (imgSrc.substr(imgSrc.length - 3).toLowerCase() == "png" && !img.useMap && !img.onclick) { var outerSpan = document.createElement("span") var innerSpan = document.createElement("span") var outerSpanStyle = outerSpan.style var innerSpanStyle = innerSpan.style outerSpan.id = img.id outerSpan.className = img.className outerSpan.title = img.title outerSpanStyle.cssText = img.style.cssText outerSpanStyle.display = "inline-block" outerSpanStyle.fontSize = "0" outerSpanStyle.verticalAlign = "middle" if (img.parentElement.href) outerSpanStyle.cursor = "hand" innerSpanStyle.width = img.width + "px" innerSpanStyle.height = img.height + "px" innerSpanStyle.display = "inline-block" innerSpanStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + encodeURI(imgSrc) + "')" outerSpan.appendChild(innerSpan) img.parentNode.replaceChild(outerSpan, img) } else { i++ } } } }
—Remember the dot (talk) 01:58, 20 September 2007 (UTC)
Small bug found (I changed the code accordingly):
if (img.parentElement.href) outerSpanStyle.cursor = "hand"
Should be:
if (img.parentElement.href) innerSpanStyle.cursor = "hand"
Otherwise seems OK, not faster though, but I think the bulk of the speed is lost in the filter itself, not the javascript. Also, the images seem to load twice using the span method, something that was not the case with the src=blank.gif, which does speed up a bit. — Edokter • Talk • 20:40, 21 September 2007 (UTC)
outerSpanStyle = img.style
to
outerSpanStyle.cssText = img.style.cssText
All of the CSS styling for the outer span wasn't actually being applied. Thanks for catching that!
But...from your comments it sounded like you weren't having any problems with the solution that involves a 1px transparent image. So I tried that solution again and was not able to reproduce the problems I was having with it earlier. Here is a simplified version of that script, please let me know if it works all right for you:
function PngFix() { if (document.body.filters) { var documentImages = document.images var documentImagesLength = documentImages.length for (var i = 0; i < documentImagesLength; i++) { var img = documentImages[i] var imgSrc = img.src if (imgSrc.substr(imgSrc.length - 3).toLowerCase() == "png") { if (img.className == "thumbimage" || img.className == "thumbborder") { img.width = img.width - 2 img.height = img.height - 2 } img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + encodeURI(imgSrc) + "', sizingMethod='crop')" img.src = "http://upload.wikimedia.org/wikipedia/commons/d/db/Must_left-click_image_again_before_saving.gif" } } } }
—Remember the dot (talk) 03:17, 22 September 2007 (UTC)
[[Image:Tournesol.png|100px|border]]
and you'll see what I mean. —Remember the dot (talk) 21:34, 22 September 2007 (UTC)if (img.className == "thumbimage" || img.className == "thumbborder") { img.width = img.width - 2 img.height = img.height - 2 }
(Deindent) OK, here's some brainstorming... is it possible to enclose the <img> within a span (as opposed to two spans), and have the span implement the border instead? (Edit: You tried this above). I still prefer this version, and I don't share your concern; First, the image dimension isn't really changed, and exotic layouts wouldn't normally use a border anyway. 2nd, I believe .thumborder and .thumbimage are not likely to be changed. — Edokter • Talk • 21:26, 24 September 2007 (UTC)
function PngFix() { if (document.body.filters) { var documentImages = document.images for (var i = 0; i < documentImages.length; i++) { var img = documentImages[i] var imgSrc = img.src if (imgSrc.substr(imgSrc.length - 3).toLowerCase() == "png") { var outerSpan = document.createElement("span") var outerSpanStyle = outerSpan.style var imgStyle = img.style outerSpan.className = img.className outerSpanStyle.cssText = img.style.cssText outerSpanStyle.fontSize = "0" outerSpanStyle.hasLayout = "true" img.className = "" imgStyle.cssText = "" imgStyle.verticalAlign = "middle" imgStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + encodeURI(imgSrc) + "')" img.src = "http://upload.wikimedia.org/wikipedia/commons/d/db/Must_left-click_image_again_before_saving.gif" img.parentNode.replaceChild(outerSpan, img) outerSpan.appendChild(img) } } } }
—Remember the dot (talk) 02:57, 26 September 2007 (UTC)
The above code doesn't show the borders at all, and all images jump 1px to the left and down. Sorry if I seem a bit frustrated. I just think if it can be done right, it should be. I have been brainstorming a bit, and have come up with a mix of both methods, depending if there is a border or not. I just need to figure out how to create a outer span (I'm not that good in javascript); Here's the code I have tested so far; if you can integrate the above code into that part that needs a span, I think we actually have a very good solution:
function PngFix() { if (document.body.filters) { var documentImages = document.images for (var i = 0; i < documentImages.length; i++) { var img = documentImages[i] var imgSrc = img.src if (imgSrc.substr(imgSrc.length - 3).toLowerCase() == "png") { img.src = "http://upload.wikimedia.org/wikipedia/commons/d/db/Must_left-click_image_again_before_saving.gif" img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + encodeURI(imgSrc) + "', sizingMethod='crop')" if (img.className == "thumbborder" || img.className == "thumbimage") { img.style.border = "none" // remove current border first // create container span with parent class style to put img tag in. } } } } }
That way, borderless images load fast (and pages with lots of images ususally don't have borders), while those with border are encapsulated in a span with border. No distortions, best of both worlds. — Edokter • Talk • 13:31, 26 September 2007 (UTC)
img.style.cssText
...img.style.cssText
empty/undifened, and thus are the broders not showing??? (Test here.) — Edokter • Talk • 22:49, 26 September 2007 (UTC)(code moved down)
— Edokter • Talk • 01:51, 27 September 2007 (UTC)
Imagemaps also work perfectly! So we can
So that leaves !img.useMap!img.onclick
. What does that filter out and where can I test this? If the editing toolbar uses .onclick... then that is working as well. — Edokter • Talk • 12:39, 27 September 2007 (UTC)
!img.onclick
prevents the script from running on the edit toolbar buttons. Code that doesn't remove the original img element shouldn't need this filter.function PngFix() { if (document.body.filters) { var documentImages = document.images for (var i = 0; i < documentImages.length; i++) { var img = documentImages[i] var imgSrc = img.src if (imgSrc.substr(imgSrc.length - 3).toLowerCase() == "png") { img.src = "http://upload.wikimedia.org/wikipedia/commons/c/ce/Transparent.gif" img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + encodeURI(imgSrc) + "', sizingMethod='image')" if (img.currentStyle.borderWidth != "0px" && img.currentStyle.borderStyle != "none") { var imgID = (img.id) ? "id=\"" + img.id + "\" " : "" var imgClass = (img.className) ? "class=\"" + img.className + "\" " : "" var imgTitle = (img.title) ? "title=\"" + img.title + "\" " : "" var curStyle = img.currentStyle var imgStyle = "style=\"vertical-align: middle; display: " + curStyle.display + "; font-size: " + curStyle.fontSize + "; border: " + curStyle.borderWidth + " " + curStyle.borderStyle + " " + curStyle.borderColor + ";\"" img.className = "" img.outerHTML = "<span " + imgID + imgClass + imgTitle + imgStyle + ">" + img.outerHTML + "</span>" } } } } }
OK, try again. — Edokter • Talk • 23:37, 27 September 2007 (UTC)
{{editprotected}}
{{editprotected}}
There is an issue where an incorrectly formatted table causes a JS error. That doesn't look like much of a problem, but it also means that all JS that should be run after this specific function stops dead in its tracks.
The problem is in function createCollapseButtons(). ButtonLink.style.color = Tables[i].getElementsByTagName( "tr" )[0].getElementsByTagName( "th" )[0].style.color;
Before this is run, there should be if
checks that verify if there are any tr
and th
elements at all in the table. --TheDJ (talk • contribs) 22:12, 14 September 2007 (UTC)
if ( header )
check. If that is move up to the top of this loop, before the button and links are created, then the issue is solved. Seems the easiest approach in this case. --TheDJ (talk • contribs) 22:25, 14 September 2007 (UTC)
{{template doc}}
modifier scriptaddOnloadHook(function () {
if( wgCanonicalNamespace == "Template" && document.getElementById("doc_editlinks") ) {
var editsection = document.getElementById("doc_editlinks");
editsection.innerHTML = '[<a href="' + wgServer + 'https://demo.azizisearch.com/lite/wikipedia/page/ + wgPageName + '/doc" title="View the template documentation for this page">view</a>]' + " " + '[<a href="'+ wgServer + wgScript + '?title=' + wgPageName + '/doc&action=edit" title="Edit the template documentation for this page">edit</a>]';
}
});
This script turns the "[edit]" link into an href (such as the one that allows editing of a section on a page). Would anyone be opposed to its addition to MediaWiki:Common.js? —[[
Animum | talk]]
14:35, 30 September 2007 (UTC)