MediaWiki talk:Gadget-edittop.js
From Wikipedia, the free encyclopedia
Contents |
[edit] 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://en.wikipedia.org/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') }
[edit] 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)
[edit] 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)
[edit] 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 called editsectionmoved 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)
[edit] 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: && 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)
if (document.getElementById('featured-star') || document.getElementById('top-icon'))
zero.style.marginRight = '25px';
[edit] 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)

