MediaWiki talk:InterProject.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Vector.js[edit]

Here's the respective part from vector.js:

  
    function toggle($element) {
        $j.cookie('vector-nav-' + $element.parent().attr('id'), $element.parent().is('.collapsed'), {
            'expires': 30,
            'path': '/'
        });
        $element.parent().toggleClass('expanded').toggleClass('collapsed').find('div.body').slideToggle('fast');
    }
  
    $headings.keydown(function(event) {
        if (event.which == 13 || event.which == 32) {
            toggle($j(this));
        }
    }).mousedown(function() {
        toggle($j(this));
        $j(this).blur();
        return false;
    });

--DieBuche (talk) 13:46, 24 October 2010 (UTC)[reply]

And here's the original, including the code for setting the initial state. I'd rather like to keep reusing it instead of duplicating it if I possibly can, though. —Ilmari Karonen (talk) 01:03, 25 October 2010 (UTC)[reply]
An here's the patched bug, which enables us to add the new submenu at any time: https://bugzilla.wikimedia.org/show_bug.cgi?id=25726 --DieBuche (talk) 23:00, 1 November 2010 (UTC)[reply]
Wow, cool! I didn't even know jQuery could do that. Although I think that still leaves the issue of setting the initial state (based on cookies) unsolved. :( Would you happen to know some neat jQuery trick for that too? —Ilmari Karonen (talk) 01:53, 2 November 2010 (UTC)[reply]
I don't think that's possible without further changing collapsibleNav.js. Something like this should work though:

if ($.cookie('vector-nav-p-interproject')=='true') $('#p-interproject').mousedown();

--DieBuche (talk) 16:45, 4 November 2010 (UTC)[reply]

Sister projects[edit]

At Special:Recentchanges, link to "Sister projects" doesn't work. I can't find why. Similar thing happens on Meta. Any ideas? -Aleator (talk) 02:09, 29 November 2012 (UTC)[reply]

This seems to be caused by gerrit:30361 / gerrit:34702, which replaced the h5 elements by h3. I just fixed our version of the hack at ptwiki. Helder 19:48, 20 December 2012 (UTC)
✓ Done, Revision #88060112. –Krinkletalk 04:33, 19 January 2013 (UTC)[reply]

Wikibase Client[edit]

@Krinkle and Ilmari Karonen: does this script work with mw:Extension:Wikibase Client#Other projects sidebar? AFAIU that feature is going to be deployed on more and more sites, to gradually replace the old system. Hint: s:fr:Special:Diff/4387651/4517757. --Ricordisamoa 11:40, 11 August 2014 (UTC)[reply]

Cookie[edit]

@Krinkle, Ilmari Karonen, and DieBuche: , since the collapsable menu are not working anymore, does the following code still needed?

var state = $.cookie('vector-nav-' + interProject.id);
if (state === 'true') {
    $(interProject).addClass('expanded').find('.body, .pBody').show();
} else {
    $(interProject).addClass('collapsed');
}

--Andyrom75 (talk) 20:30, 3 December 2014 (UTC)[reply]

Yes, that could be safely removed. How are things going here? --DieBuche (talk) 11:16, 6 December 2014 (UTC)[reply]
@DieBuche: First you go to COM:RfA and then you'll remove it. I am so glad to hear from you :) If you have any other questions preventing you from getting started again, please e-Mail me or choose whatever way of communication you prefer. -- Rillke(q?) 12:08, 6 December 2014 (UTC)[reply]
@DieBuche: , thanks for your confirmation. I'll wait for your update. --Andyrom75 (talk) 13:07, 6 December 2014 (UTC)[reply]
✓ Done, Revision #141948923. –Krinkletalk 01:49, 9 December 2014 (UTC)[reply]

Shrinking the code[edit]

@Krinkle, Ilmari Karonen, and DieBuche: , do you see any issue on applying the following changes?

First change: to eliminate the use & check of nextSibling

[...]

if (toolBox && toolBox.nextSibling) {
    panel.insertBefore(interProject, toolBox.nextSibling);

[...]

with:

[...]

if (toolBox) {
    $(toolBox).after(interProject);

[...]

Second change: to eliminate completely the use of panel variable

[...]

    var panel;
    if (toolBox) {
        panel = toolBox.parentNode;
    } else {
        // stupid incompatible skins...
        var panelIds = ['mw-panel', 'panel', 'column-one', 'mw_portlets'];
        for (var i = 0; !panel && i < panelIds.length; i++) {
             panel = document.getElementById(panelIds[i]);
        }
        // can't find a place for the portlet, try to undo hiding
        if (!panel) {
            mw.util.addCSS('#interProject, #sisterProjects { display: block; }');
            return;
        }
    }

[...]

with:

[...]nothing[...]

and (on top of the first change)

[...]

panel.appendChild(interProject);

[...]

with:

[...]

$("div [role=navigation]").parent().last().append(interProject);

[...]

Looking at the overall change should be beneficial because we'll eliminate the previous for cycle, and also we have to consider that the last instruction (longer than the previous one) will be execute only when the toolbox portlet is not present: practically almost never.

Let me know your thoughts, --Andyrom75 (talk) 10:20, 20 December 2014 (UTC)[reply]

Note that this code doesn't make the code faster since it replaces direct DOM manipulation with jQuery abstraction methods (which perform the same actions, and more, underneath). However performance is not critical in this case and the difference is insignificant. The reduction in code size and improved readability of using .after() is generally desirable. The second change about using [role=navigation], however, looks rather strange, overly complex and slow. There should be no need to use such a poor CSS query combined with various DOM tree traversal methods to find the target parent for interProject node. –Krinkletalk 18:30, 3 January 2015 (UTC)[reply]

legacy Lanel?[edit]

@Krinkle and Ilmari Karonen:

Q: isn't the instance of legacyLanel in the following....

		for (var i = 0; !legacyPanel && i < panelIds.length; i++) {
			legacyLanel = document.getElementById(panelIds[i]);
		}

... snippet taken from the (most?) current version of this script a typo and really suppose to be legacyPanel instead?

Going by what else changed in the diff (Jan 15 2015) that introduced it -- it sure looks like that way to me but I've been wrong before so I have to ask :). -- George Orwell III (talk) 14:59, 14 March 2015 (UTC)[reply]

Fixed. Thank you! –Krinkletalk 16:02, 14 March 2015 (UTC)[reply]

Update for Wikibase[edit]

{{Editprotected}} In a matter of days, Wikibase will take care of this functionality. The wikis which already used this gadget usually want to keep their custom links, without creating duplicates. The code was updated at w:it:MediaWiki:InterProject.js to do this and IIRC is fully compatible. Can an admin or editinterface verify and update the code for all the wikis which call this? Nemo 12:07, 5 January 2016 (UTC)[reply]

User:Krinkle, User:Rillke or other JS speaking admins. Can you evaluate this request? --Jarekt (talk) 14:12, 6 January 2016 (UTC)[reply]
I'm not going to deal with this matter. Just noticed w:it:MediaWiki:InterProject.js has a lot of jQuery selectors and contains some Italian UI messages. -- Rillke(q?) 19:30, 6 January 2016 (UTC)[reply]
{{Not done}} then --Jarekt (talk) 14:11, 7 January 2016 (UTC)[reply]

This can't really be delayed. If you tell me how I can change the code to aid its adoption, please let me know. Other than translating from Italian, what needs to be done? Nemo 17:51, 7 January 2016 (UTC)[reply]

Nemo, would not this tool require arbitrary access to be activated for Commons. We are still waiting for it. --Jarekt (talk) 05:34, 11 January 2016 (UTC)[reply]
 Not done Nemo {{Editprotected}} is used for admins to add changes performed by the users without admin rights. It is not a template to use to propose a task that needs to be done. Unfortunately there does not seem to be anybody with the know-how who is willing to do the work. Maybe Phabricator? --Jarekt (talk) 13:32, 21 January 2016 (UTC)[reply]

Broken JavaScript[edit]

MediaWiki developers found that this page probably breaks JavaScript for users (example: not seeing the buttons when editing a page). You probably need to edit this .js page and/or MediaWiki:Gadgets-definition as in the examples at phabricator:T122755. List more pages to check.

If you have questions or need help, please ask at phabricator:T164242. You can login with your wiki account. Best wishes, Nemo 09:49, 14 May 2017 (UTC)[reply]

✓ Done, unbelievable, I got this load error on every relevant page. Nobody cares about 2 years. -- User: Perhelion 12:02, 22 May 2019 (UTC)[reply]

Add vector-menu-portal class[edit]

{{Editprotected}}

The CSS for this is broken, as the relevant selectors seem to have been changed. To fix this, please change the line interProject.className = ( mw.config.get( 'skin' ) === 'vector' ? 'portal' : 'portlet' ); to interProject.className = ( mw.config.get( 'skin' ) === 'vector' ? 'portal vector-menu-portal' : 'portlet' );

--Yair rand (talk) 21:18, 26 August 2020 (UTC)[reply]

✓ Done, please check that it works. --Lucas Werkmeister (talk) 20:29, 27 August 2020 (UTC)[reply]
Looks fixed, thank you. --Yair rand (talk) 20:37, 27 August 2020 (UTC)[reply]
Okay, great :) --Lucas Werkmeister (talk) 20:38, 27 August 2020 (UTC)[reply]

vector-menu-heading for h3 tag[edit]

{{Ep}}

@@ -43,12 +43,12 @@

 	interProject.id = 'p-interproject';

-	interProject.className = ( mw.config.get( 'skin' ) === 'vector' ? 'portal vector-menu-portal' : 'portlet' );
+	interProject.className = ( (mw.config.get( 'skin' ) === 'vector' || mw.config.get( 'skin' ) === 'vector-2022') ? 'portal vector-menu-portal' : 'portlet' );

 	interProject.innerHTML =
-		'<h3>' +
+		'<h3 class="vector-menu-heading">' +
 		( sisterPr && sisterPr.firstChild ? sisterPr.firstChild.innerHTML : 'Sister Projects' ) +
-		'</h3><div class="' + ( mw.config.get( 'skin' ) === 'vector' ? 'vector-menu-content' : 'pBody' ) + '">' +
+		'</h3><div class="' + ( (mw.config.get( 'skin' ) === 'vector' || mw.config.get( 'skin' ) === 'vector-2022') ? 'vector-menu-content' : 'pBody' ) + '">' +
 		interPr.innerHTML + '</div>';

 	if ( legacyPanel ) {

Add support to vector-2022, fix strange behavior problem with h3 tag. Stang 17:48, 10 March 2022 (UTC)[reply]

✓ Done --Lucas Werkmeister (talk) 21:44, 10 March 2022 (UTC)[reply]