MediaWiki talk:Gadget-edittop.js/Archive 1
This is an archive of past discussions about MediaWiki:Gadget-edittop.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 1 |
Introduction
{{editprotected}}
Please change "first section" to "introduction", since I read "first section" as the text contained within the first header, not before it (and suspect others might as well). GracenotesT § 04:56, 20 December 2007 (UTC)
- Yes, it's definitely either «introduction» or «zero section». Another suggestion: using word [edit] in brackets would make the description easier to understand. Also, I strongly believe that every gadget in the list, however simple, should be a link to it's description page (one of the reasons is to have a talk page to discuss a gadget) ∴ AlexSm 06:05, 20 December 2007 (UTC)
- Done most of these changes, apart from adding the link (which is a good idea, but a page to link it to is needed; put {{editprotected}} back up once there is one and I or another admin will link to it). Although 'section 0' is how I think of the intro section, I used "introduction section" on the interface message because it's clear to new users and unambiguous for established editors. --ais523 10:06, 20 December 2007 (UTC)
Fixes: icons and uncluded sections
Please replace the current code with the one below. The new version:
- in addition to "featured article", also checks for "protected" and "spoken version" absolutely positioned icons, and moves the [edit] link to the left if needed
- For example, see Bird with the current gadget code.
- Another possible option is to move [edit] link under the header.
- checks if the first [edit] link belongs to the section on the included page, and then changes the tooltip into "Edit section: 0" (so the tooltip is not localized in this case)
- For example, see Template:Infobox Election with the current gadget code.
- Note that the check relies on the new parser which should be live in a couple of days, so new code can be tested at http://wiki.riteme.site/wiki/Template:Infobox_Election?timtest=newpp
∴ AlexSm 21:04, 21 January 2008 (UTC)
if (wgAction == 'view' && wgNamespaceNumber >=0)
addOnloadHook(editTopSection)
function editTopSection(){
var h2s = document.getElementsByTagName('H2')
var h2 = h2s[0]
if (!h2) return
if (h2.parentNode.id == 'toctitle') h2 = h2s[1]
if (!h2) return
var span = h2.firstChild
if (!span || span.className != 'editsection') return
var zero = span.cloneNode(true)
if (document.getElementById('featured-star')) zero.style.marginRight = '20px'
if (document.getElementById('spoken-icon')) zero.style.marginRight = '40px'
if (document.getElementById('administrator') && zero.style.marginRight) zero.style.marginRight = '65px'
var parent = document.getElementsByTagName('H1')[0]
parent.insertBefore(zero, parent.firstChild)
var a = zero.getElementsByTagName('A')[0]
if (a.href.indexOf('§ion=T') == -1 )
a.title = a.title.replace(/:.*$/,': 0')
else
a.title = 'Edit section: 0'
a.setAttribute('href', wgScript + '?title='+wgPageName + '&action=edit§ion=0')
}
I have added the checks for other absolute icons
I can't understand what the other code does, and I've added localization anyway so it would have to be changed. —Random832 18:21, 29 January 2008 (UTC)
- The script looks for an existing [edit] link below, and then duplicates it on the top, changing it's tooltip from "Edit section: <name>" (on the user language) to "Edit section: 0". That was the whole point of this script: it does not need additional localization. Only when the first section is transcluded (like on the page Template:Infobox Election), the script has to use English tooltip, but these cases are rare. And of course, one could also say that for a gadget simply saying "0" is not good enough ∴ AlexSm 18:55, 29 January 2008 (UTC)
Localization Error
Line 14, ja: ... - this line ends with a comma which appears to be an error since it the last item in the initialization list. Franamax (talk) 00:09, 30 January 2008 (UTC)
Selecting the title with a triple-click
One of the more annoying side effects of an editlink after the title is that a tripleclick (which could have been used before to comfortably select the title) also selects the [edit] texts. Is it possible to circumvent this somehow? (I experimented with -moz-user-select:none and selectable=no on huwiki, where top level edit link is on by default, but neither worked. On the other hand, the selected region seemed to be based - at least in Firefox - on the limits of the block level element, not on the visual position, so some clever HTML formatting might be able to help.) --Tgr (talk) 21:00, 28 February 2008 (UTC)
- Triple-click ... interesting, I'm going to use this little trick. Anyway, the top [edit] link is designed to behave the same way as other [edit] links, and they are all getting selected when you triple-click on sections headers. I would not want to change HTML formatting, because then the top [edit] would be different and this might have some undesireable consequences. I'm also not sure about
selectable
attribute. However,-moz-user-select
seems to work just fine in my old Firefox 1.5 like this:.editsection {-moz-user-select:none}
in personal monobook.css, this makes all [edit] links unselectable. Please note that (for some reason) the class is callededitsectionmoved
on huwiki. For other browsers I can only recommend using slightly different editTop version that would place [edit] under heading, as described in User talk:Alex Smotrov/edittop.js#Link under page heading. —AlexSm 22:19, 28 February 2008 (UTC)
In FF2 the [edit] text is not highlighted if its set to -moz-user-select:none, but it still gets copyed to the clipboard (and i think selectable doesn't even make it through the sanitizer). --Tgr (talk) 09:33, 29 February 2008 (UTC)
- True, not highlighed but gets selected nonetheless... Well, then I can only suggest using the script that would insert [edit] under H1 header. I could write it if needed. Actually, maybe this is a better position anyway, because [edit] link allows users to edit the section including all subsections, and technically all normal H2 sections are "subsections" of top H1 "section", so placing [edit] on top of H1 is a bit misleading. On the other hand, there is some stuff underneath as well, like coordinates and maybe something else too. —AlexSm 03:50, 6 March 2008 (UTC)
What makes it move to the left
Or better... what triggers it to move to the left? I'm puzzled because the top edit link overlaps the {{Administrator}} icon on user pages (and the template page itself), eventhough it has "administartor" as it's id. — Edokter • Talk • 13:17, 6 March 2008 (UTC)
- The current gadget code is aware about protection icons, like
{{Pp-semi-protected|small=yes}}
, which uses {{Pp-meta}} which (for some reason) also hasid="administrator"
and has"right:55px"
, see Bird for an example. Since protection icons can also be present on user pages, imho one of those templates needs to be fixed to use some other DOM id. Then we can try to fix the gadget. —AlexSm 14:47, 6 March 2008 (UTC)- I see what the problem is:
&& zero.style.marginRight
, which remains empty because the other two aren't true. Changing to id to 'featured-star' in the template fixed it, but can we add a user defined id and check for that as well in the 'featured-star' line, ie. id=top-icon? — Edokter • Talk • 15:29, 6 March 2008 (UTC)- I'm not sure I understand your suggestion. In any case, if this is going to fix the problem, why not. —AlexSm 18:46, 6 March 2008 (UTC)
- Just suggesting using another id in addition to, and instead of "featured-star" for user created icons. So it becomes:
- I'm not sure I understand your suggestion. In any case, if this is going to fix the problem, why not. —AlexSm 18:46, 6 March 2008 (UTC)
- I see what the problem is:
if (document.getElementById('featured-star') || document.getElementById('top-icon')) zero.style.marginRight = '25px';
Bug: Templates with transcluded documentation
The script show an edit link on templates with thanscluded {{documentation}}, and susequently (and erroniously) links to the first section of the documentation page. This can be filtered out by changing
if (!span || span.className != 'editsection') return;
to
if (!span || span.className != 'editsection' || span.id = 'doc_editlinks') return;
— Edokter • Talk • 14:11, 8 March 2008 (UTC)
- This happens whenever first [edit] link belongs to a transcluded page (non necessarily to documentation subpage), so your solution is only partial. for example, see Wikipedia:Requests for adminship. I already suggested a fix above, see #Fixes: icons and uncluded sections and the next section. The suggested code always uses
wgPageName+'&action=edit§ion=0'
for a link, and checks whether [edit] belongs to transcluded page before generating a tooltip. —AlexSm 15:51, 8 March 2008 (UTC)
Nostalgia skin
Is this meant to be used only with the MonoBook skin? A version of this compatible with the Nostalgia skin would be highly desirable. NerdyNSK (talk) 10:11, 6 October 2008 (UTC)
- The gadget works in all skins. —AlexSm 14:43, 6 October 2008 (UTC)
Included sections fix
{{editprotected}}
Please replace the last lines
if(localtitles[wgUserLanguage]) a.title = localtitles[wgUserLanguage];
// TODO check for content of header, to get a more precise replacement
else a.title = a.title.replace(/:.*$/,': 0');
})
with
if (a.href.indexOf('§ion=T') == -1){
a.title = a.title.replace(/:.*$/,': 0')
a.setAttribute('href', a.href.replace(/§ion=\d+/,'§ion=0'));
}else{//transcluded
a.title = localtitles['en']
a.setAttribute('href', wgScript+'?title='+encodeURIComponent(wgPageName)+'&action=edit§ion=0')
}
if (localtitles[wgUserLanguage]) a.title = localtitles[wgUserLanguage]
})
to make sure the gadget works properly on the pages where the 1st section is transcluded from another page. It has been discussed before (see top section) but never implemented. —AlexSm 16:00, 6 October 2008 (UTC)
- Done I asume it's tested. — Edokter • Talk • 20:55, 6 October 2008 (UTC)
Incorrect section link + request
Hey Alex, I've noticed that occasionally when using this script, clicking the edit link will bring up the edit screen for section 2 instead of section 0. I have a sneaking suspicion this has to do with improper use of headers on the page in question (e.g. the first header is level 3 instead of level 2), but I'll have to try and track down one of the pages it happens on, and maybe whip up a testpage in my userspace for you. In addition, would it be possible for you to modify this script to also add a lead edit link when you're looking through an article's history and you arrive at the current revision (for instance, User:Dinoguy1000/List of Shaman King chapters most recent diff as of today)? Note that in such cases, edit links are provided for all other sections, and I think there are at least two obvious ways for you to check for whether it's the diff of the current revision. I can't count the number of times I've wanted to do this, but been forced to click to view the article before clicking the lead edit link. Thoughts? —Dinoguy1000 16:35, 4 October 2008 (UTC)
- Ok, I'll wait for you to find me an example. As for the 2nd issue, I do see the top [edit] link on most recent oldid (using the gadget); that's strange, what browser do you use? —AlexSm 04:57, 5 October 2008 (UTC)
- I didn't feel like looking through my whole watchlist to hunt down an example, so I just whipped up a sample page. It seems my suspicions were correct, it has to do with the first section being a level 3 header (I didn't test with more than one consecutive, or a level 4 or lower, etc.). And for the second issue, see for example this diff version of User:Dinoguy1000/Anime. No top section edit link in FF or IE (note that the permalink version does have a section edit link for me, though). BTW, should this discussion be moved to the gadget talk page, since you've deprecated this script in favor of the gadget version? —Dinoguy1000 18:19, 6 October 2008 (UTC)
- The 1st problem should be fixed by my recent change request on the gadget talk page.
- When you show a link to the diff, you have to remember that some users might see it like this, without the page content (personally, I think this should have been a default option in preferences).
- Anyway, this issue with diff page content is with extra H2 header "Current revision as of ...". This can be fixed in the gadget code (with
getElementsByClassName(document.body, 'span', 'editsection')
) for the price of slightly slower execution, so I'm not sure it's worth it. - Yes, you might move this to the gadvet discussion page.
- —AlexSm 19:20, 6 October 2008 (UTC)
This discussion was moved here from User talk:Alex Smotrov/edittop.js —Dinoguy1000 20:04, 6 October 2008 (UTC)
- Yeah, I actually read through the discussion here after posting my reply and saw your proposed change. As for the second issue, I knew about the previewless diff option, but forgot about it -- thanks for reminding me! I suppose I could live without this functionality, or just copy the code to a subpage of mine and add the functionality there. In any case, it's not that important... —Dinoguy1000 20:07, 6 October 2008 (UTC)
All right, since Edokter implemented your edit request, the edit link on my sample page correctly refers to section 0 now. —Dinoguy1000 21:22, 6 October 2008 (UTC)
Hey alex, where in the code would I insert the "getElementsByClassName" snippet above to enable edittop links on diff pages? I've decided that this is bugging me too much, so I'm gonna copy the code to my userspace and modify it, even at the cost of a little page execution time. —Dinoguy1000 22:17, 22 October 2008 (UTC)
No edit link on pages with no level two sections
See for example Legend of the Galactic Heroes release history, a list with all level three headers. As you can see, there's no edit link for the lead being inserted. —Dinoguy1000 18:02, 25 October 2008 (UTC)
- My new version fixes this as well btw. As long as there is ANY editsection on the page, the section0 editsection will be produced. --TheDJ (talk • contribs) 12:00, 25 November 2008 (UTC)
Spanish translation
I think "Editar sección superior" would be a good Spanish translation of "Edit lead section" (although it actually translates to "Edit top section", the meaning is basically the same... see also en --> es Google translation of "Edit lead section" & "Edit top section" and the reverse translation of the resulting phrases). —Dinoguy1000 01:24, 25 November 2008 (UTC)
New version that is aware of any topicon
I have created a new version of this script. diff User:TheDJ/Gadget-edittop.js. It will put the edit section always at the far right, and moves topicons (including those in userspace) to the left by the amount of pixels the edit section occupies. Any objections to such changes ? --TheDJ (talk • contribs) 11:38, 25 November 2008 (UTC)
- The new code seems slower, but as long as it's cross-browser I guess I don't mind. —AlexSm 15:12, 25 November 2008 (UTC)
- I'm planning on deploying this code, so that people stop using "id=featured-star" in user namespace to work around this gadget not working with any of their icons. --TheDJ (talk • contribs) 13:41, 27 April 2009 (UTC)
- Interested to see how it goes. — Edokter • Talk • 14:33, 27 April 2009 (UTC)
Done --TheDJ (talk • contribs) 11:55, 28 April 2009 (UTC)
- I notice this also adds an edit link to current diff pages, something I've often wished the gadget would do. All I have to say is, it's about time. =) 「ダイノガイ千?!」(Dinoguy1000) 20:55, 28 April 2009 (UTC)
- No one seems to have noticed the change so far. Seems ideal. —TheDJ (talk • contribs) 23:17, 29 April 2009 (UTC)
- I discovered a gitch at List of Doctor Who serials; only the protection icon is moved, the featured star is not. — Edokter • Talk • 20:59, 11 May 2009 (UTC)
- Seems to work here. Have you tried with Firefox, perhaps it's IE specific. ? —TheDJ (talk • contribs) 21:31, 11 May 2009 (UTC)
- Works for me, too, though there's a pretty big gap between the icons. 「ダイノガイ千?!」(Dinoguy1000) 08:40, 12 May 2009 (UTC)
- Yes, the gap is for the spoken article icon. I have alternate code that can avoid the gap, but still keep order. It is however much more complicated. —TheDJ (talk • contribs) 10:45, 12 May 2009 (UTC)
- Works for me, too, though there's a pretty big gap between the icons. 「ダイノガイ千?!」(Dinoguy1000) 08:40, 12 May 2009 (UTC)
- I fixed it on the page. It is IE specific, ususally when wikitables with 100% width is used. Wikitables have a margin that causes the content div to be too wide... in IE. — Edokter • Talk • 11:34, 12 May 2009 (UTC)
- So both icons were actually shifted, but not far enough, due to the "mis-aligned" content div ? —TheDJ (talk • contribs) 12:12, 12 May 2009 (UTC)
- Correct. If any element pushes the content div boundary to the right, the icons move with it, due to the absolute positioning. — Edokter • Talk • 12:16, 12 May 2009 (UTC)
- So both icons were actually shifted, but not far enough, due to the "mis-aligned" content div ? —TheDJ (talk • contribs) 12:12, 12 May 2009 (UTC)
regex
{{editprotected}} please change line
a.title = a.title.replace(/:.*$/,': 0')
to
a.title = a.title.replace(/(: ?|:).*$/,'$10')
so that it can support languages using full-width colons, such as Chinese. --Liangent (talk) 14:18, 16 July 2009 (UTC)
- Do you have a specific page that shows this problem ? —TheDJ (talk • contribs) 14:54, 16 July 2009 (UTC)
- Any page with parameter &uselang=zh --Liangent (talk) 04:26, 17 July 2009 (UTC)
- Done. PS it might be useful to add the actual translation string for 'Edit lead section'. What was changed now, is supposed to be just a fallback method. —TheDJ (talk • contribs) 10:13, 17 July 2009 (UTC)
- Any page with parameter &uselang=zh --Liangent (talk) 04:26, 17 July 2009 (UTC)
Czech translation
{{Editprotected}} Hi, please add Czech translation of "Edit lead section":
cs: 'Editovat úvodní sekci',
Thanks. --Sevela.p 17:47, 1 March 2010 (UTC)
- Done —TheDJ (talk • contribs) 19:37, 1 March 2010 (UTC)
Korean translation
{{Editprotected}} Please add Korean translation of "Edit lead section":
ko: '도입부를 편집',
Thanks. -- ChongDae (talk) 14:07, 26 March 2010 (UTC)
- Done —TheDJ (talk • contribs) 20:49, 26 March 2010 (UTC)
Edit link too large in Vector
Ever noticed that in Vector, the page title, being a h1.firstHeading
, is not the same size as other h1
headers? It is slightly larger, namely 1.0em x 1.6em, as opposed to 188% x 0.8em (=1.5em). Not a big deal, but it does cause the top edit link to be too large (default size is 53% of h1
headers). Setting it to 50% would fix this. Is it possible to inject the following CSS, only when Vector is in use? — Edokter • Talk • 17:58, 18 November 2010 (UTC)
h1.firstHeading span.editsection {font-size: 50%;}