User:Amadalvarez/common.js

From Wikidata
Jump to navigation Jump to search

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)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
//  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// Show parent classes  

//
 mw.loader.load( '//www.wikidata.org/w/index.php?title=User:TomT0m/classification.js&action=raw&ctype=text/javascript' ); // [[User:TomT0m/classification.js]]     

//  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
mw.loader.load('//tools.wmflabs.org /wikidata-todo/autodesc.js');  //  Ignore its function !!
//  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// proposal of article name from the most commons in the rest of languages
//
mw.loader.load("//www.wikidata.org/w/index.php?title=User:Joern/altLabels.js&action=raw&ctype=text/javascript");				// shortcut to add most common labels   [[d:User:Joern/altLabels.js]]
//  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// Re-order values within statement
//
importScript( 'User:Tohaomg/rearrange values.js' );   // Re-order values within statement [[d:User:Tohaomg/rearrange values.js//
//  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

//
// Help to edit music items
//

mw.loader.load("//www.wikidata.org/w/index.php?title=User:Nikki/ExMusica.js&action=raw&ctype=text/javascript");

//  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//

// Duplicate item in left menu bar
//
importScript( 'User:Magnus_Manske/duplicate_item.js' );   // Duplicate item [[d:User:Magnus_Manske/duplicate_item.js
//
//  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// WikiBridge. Genera entradeta article en la llengua que vulguis  (actualment desactivat)
//
// importScript( 'User:Bargioni/WikiBridge_conf.js' );   // WikiBridge. (vídeo: https://www.youtube.com/watch?v=xtuNY6t5ufM

// importScript( 'User:Bargioni/WikiBridge.js' );       // WikiBridge.

//
//  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//

// Prova de Labelcollector

//

mw.loader.load( '//www.wikidata.org/w/index.php?title=User:YMS/labelcollect.js&action=raw&ctype=text/javascript' ); // [[User:YMS/labelcollect.js]]

//

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

//
// Prova de Quickpresets. NO implementat perquè té una sintaxi complexa per fer els models i no aborda estructures complexes de statements. Amb un bon item model i el copy claims s'aconsegueixen millor velocitat.

// pàgines creades i que mantinc: User:Amadalvarez/quickpresets_settings.js ....
// importScript( 'User:Amadalvarez/quickpresets_settings.js' );
// importScript( 'User:MichaelSchoenitzer/quickpresets.js' );  //quick presets 
/**
 * Script to switch images in a shared space; it's used by {{switcher2}} in cawiki
 * original source: [[:fr:special:permalink/165756873]] version: 2020-07-26
 */
//  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function GeoBox_Init($content) {
    $content.find( 'div.img_toogle' ).each( function ( i, Container ) {
        Container.id = 'img_toogle_' + i;
        var Boxes = $( Container ).find( '.geobox' );
        if (Boxes.length < 2) {
            return;
        }
        var ToggleLinksDiv = document.createElement('ul');
        ToggleLinksDiv.id = 'geoboxToggleLinks_' + i;
        Boxes.each( function ( a, ThisBox ) {
            ThisBox.id = 'geobox_' + i + '_' + a;
            var ThisAlt = ThisBox.getElementsByTagName('img')[0].alt;
            var toggle = document.createElement('a');
            toggle.id = 'geoboxToggle_' + i + '_' + a;
            toggle.textContent = ThisAlt;
            toggle.href = 'javascript:';
            toggle.onclick = function (e) {
                e.preventDefault();
                GeoBox_Toggle(this);
            };
            var Li = document.createElement('li');
            Li.appendChild(toggle);
            ToggleLinksDiv.appendChild(Li);
            if (a === (Boxes.length - 1)) {
                toggle.style.color = '#888';
                toggle.style.pointerEvents = 'none';
            } else {
                ThisBox.style.display = 'none';
            }
        } );
        Container.appendChild(ToggleLinksDiv);
    } );
}

function GeoBox_Toggle(link) {
    var ImgToggleIndex = link.id.replace('geoboxToggle_', '').replace(/_.*/g, '');
    var GeoBoxIndex = link.id.replace(/.*_/g, '');
    var ImageToggle = document.getElementById('img_toogle_' + ImgToggleIndex);
    var Links = document.getElementById('geoboxToggleLinks_' + ImgToggleIndex);
    var Geobox = document.getElementById('geobox_' + ImgToggleIndex + '_' + GeoBoxIndex);
    var Link = document.getElementById('geoboxToggle_' + ImgToggleIndex + '_' + GeoBoxIndex);
    if ( !ImageToggle || !Links || !Geobox || !Link ) {
        return;
    }
    $( ImageToggle ).find( '.geobox' ).each( function ( _, ThisgeoBox ) {
        if (ThisgeoBox.id === Geobox.id) {
            ThisgeoBox.style.display = '';
        } else {
            ThisgeoBox.style.display = 'none';
        }
    } );
    $( Links ).find( 'a' ).each( function ( _, thisToggleLink ) {
        if (thisToggleLink.id === Link.id) {
            thisToggleLink.style.color = '#888';
            thisToggleLink.style.pointerEvents = 'none';
        } else {
            thisToggleLink.style.color = '';
            thisToggleLink.style.pointerEvents = '';
        }
    } );
}

mw.hook( 'wikipage.content' ).add( GeoBox_Init );