User:The wub/common.js

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
// Swapsie daisy - swap label with a given alias
// TODO: stop long aliases getting truncated

$('.wikibase-entitytermsview .wikibase-toolbar-button-edit').click( function() {
    $('.wikibase-aliasesview-list-item').prepend('<a class="swap-with-label">⇄</a>');
    mw.loader.addStyleTag('.swap-with-label { margin-right: .2em; }');
    $('.swap-with-label').click( function(e) {
        var $alias = $(this).parent().find('.tagadata-label-text');
        var $label = $(this).closest('tr').find('.wikibase-labelview-input');
        var swap = $label.val();
        $label.val( $alias.val() );
        $alias.val( swap );
        $alias.trigger( 'input' );
    });
});