MediaWiki:Common.js: mudanças entre as edições

De Wiki NBS
Ir para navegação Ir para pesquisar
Sem resumo de edição
Sem resumo de edição
 
(16 revisões intermediárias por 3 usuários não estão sendo mostradas)
Linha 1: Linha 1:
/* Códigos JavaScript aqui colocados serão carregados por todos aqueles que acessarem alguma página deste wiki */
/**
/*mw.loader.load( 'https://cdn.rawgit.com/prtksxna/persistent-toc/master/ptoc.css', 'text/css' );
* User script to accompany the Wikidata Image Positions tool,
mw.loader.load( 'https://cdn.rawgit.com/prtksxna/persistent-toc/master/ptoc.js', 'text/javascript' );*/
* showing “relative position within image” qualifiers on “depicts” statements
mw.loader.using( 'jquery.throttle-debounce', function () {
* as areas on a file.
$( function () {
*
var $window, $mwPanel, $floatTOC, scrollHandler,
* See also https://wd-image-positions.toolforge.org/ .
tocLimit, headingOffsets, headingThreshold,
*/
$toc = $( '#toc' );
( function ( mw, $ ) {
    if ( mw.config.get( 'wgNamespaceNumber' ) !== 6 ) {
        return; // not in the File: namespace
    }
    if ( mw.config.get( 'wgAction' ) !== 'view' || mw.config.get( 'wgDiffNewId' ) !== null ) {
    return; // not a regular file view
    }
    if ( mw.config.get( 'wgArticleId' ) === 0 ) {
    return; // no such file
    }


if ( !$toc.length ) {
    mw.hook( 'wikibase.entityPage.entityLoaded' ).add( function ( entity ) {
return;
    if ( !entity.statements ) {
}
    return; // no statements at all
    }
    var statements = [].concat(
    entity.statements.P180 || [], // depicts
    entity.statements.P9664 || [] // named place on map
);
        if ( !statements.some( function ( statement ) {
            return Object.prototype.hasOwnProperty.call( statement, 'qualifiers' ) &&
                Object.prototype.hasOwnProperty.call( statement.qualifiers, 'P2677' );
        } ) ) {
            return; // no relative position within image qualifiers on any relevant statement
        }


$window = $( window );
        var link = document.createElement( 'link' );
$mwPanel = $( '#mw-panel' );
        link.rel = 'stylesheet';
headingThreshold = $window.height() / 5.0;
        link.href = 'https://wd-image-positions.toolforge.org/static/depicted.css';
$floatTOC = $toc
        document.head.appendChild( link );
.clone()
        var style = document.createElement( 'style' );
.removeAttr( 'id' )
        style.textContent = '#file .wd-image-positions--depicted { visibility: hidden; }\n' +
.addClass( 'floatTOC' )
            '#file > div:hover .wd-image-positions--depicted { visibility: visible; }';
.appendTo( 'body' )
        document.head.appendChild( style );
.css( {
        $.get(
visibility: 'hidden',
            'https://wd-image-positions.toolforge.org/api/v1/depicteds_html/file/' +
opacity: 0
            encodeURIComponent( mw.config.get( 'wgTitle' ).replace(/ /g, '_') ) +
} );
            '?uselang=' + mw.config.get( 'wgUserLanguage' )
        ).then( function ( html ) {
            $( '#file a' ).first().append( html );
        }, console.error );
    } );


// Show the ToC ul even if its hidden
    function waitForImageAnnotator() {
$floatTOC.find( 'ul' ).show();
        var deferred = $.Deferred(),
 
            delay = 1,
// Hijack links so that we can scroll to the content
            file = document.getElementById( 'file' );
$floatTOC.find( 'a' ).click( function ( e ) {
        if ( file === null && mw.util.getParamValue( 'redirect' ) === 'no' ) {
$( 'html, body' ).animate( {
        return deferred.promise(); // redirect page
scrollTop: $( this.hash.replace( /\./g, '\\.' ) ).offset().top - headingThreshold
        // otherwise, if file is null, I’d like to see an error and investigate why –
} );
        // unclear if we should look up file again in the loop below,
return false;
        // or abort like here
} );
        }
 
        function check() {
 
            if ( file.firstElementChild.nodeName.toLowerCase() === 'div' ) {
tocLimit = $toc.offset().top + $toc.height();
                deferred.resolve();
headingOffsets = [];
            } else {
 
                setTimeout( check, delay *= 1.5 );
// Get all heading positions
            }
$('.mw-headline').each( function () {
        }
headingOffsets.push( [ $( this ).attr( 'id' ), $( this ).offset().top ] );
        check();
} );
        return deferred.promise();
 
    }
// For the window scroll event
   
scrollHandler = function () {
    waitForImageAnnotator().then( function () {
var $current,
        $( '#ImageAnnotationHelpButton' ).after(
scrollTop = $window.scrollTop();
            '&nbsp;/ <form style="display: inline" action="https://wd-image-positions.toolforge.org/file/' +
 
            mw.html.escape( encodeURIComponent( mw.config.get( 'wgTitle' ).replace( / /g, '_' ) ) ) +
if ( scrollTop > tocLimit ) {
            '"><button type="submit">Add a Structured Data region</button></form>'
$floatTOC.css( {
        );
visibility: 'visible',
    } );
opacity: 1
} )( mediaWiki, jQuery );
} );
$mwPanel.hide();
 
// Highlight current
var highlight = false;
// Current section is above the first heading below the top of the screen
$.each( headingOffsets, function ( i, v ) {
// Skip first as there's no previous heading before the first
if ( i !== 0 && ( scrollTop + headingThreshold ) < v[ 1 ] ) {
highlight = headingOffsets[ i - 1 ][ 0 ];
return false;
}
} );
 
if ( highlight ) {
$current = $floatTOC.find( 'a[href="#' + highlight + '"]' );
$floatTOC.find( 'a' ).not( $current ).css( 'background', '' );
$current.css( 'background', 'red' );
}
 
} else {
$floatTOC.css( {
visibility: 'hidden',
opacity: 0
} );
$mwPanel.show();
}
}
 
$window.on( 'scroll', $.throttle( 250, scrollHandler ) );
} );
} );

Edição atual tal como às 13h00min de 22 de maio de 2024

/**
 * User script to accompany the Wikidata Image Positions tool,
 * showing “relative position within image” qualifiers on “depicts” statements
 * as areas on a file.
 * 
 * See also https://wd-image-positions.toolforge.org/ .
 */
( function ( mw, $ ) {
    if ( mw.config.get( 'wgNamespaceNumber' ) !== 6 ) {
        return; // not in the File: namespace
    }
    if ( mw.config.get( 'wgAction' ) !== 'view' || mw.config.get( 'wgDiffNewId' ) !== null ) {
    	return; // not a regular file view
    }
    if ( mw.config.get( 'wgArticleId' ) === 0 ) {
    	return; // no such file
    }

    mw.hook( 'wikibase.entityPage.entityLoaded' ).add( function ( entity ) {
    	if ( !entity.statements ) {
    		return; // no statements at all
    	}
    	var statements = [].concat(
    		entity.statements.P180 || [], // depicts
    		entity.statements.P9664 || [] // named place on map
		);
        if ( !statements.some( function ( statement ) {
            return Object.prototype.hasOwnProperty.call( statement, 'qualifiers' ) &&
                Object.prototype.hasOwnProperty.call( statement.qualifiers, 'P2677' );
        } ) ) {
            return; // no relative position within image qualifiers on any relevant statement
        }

        var link = document.createElement( 'link' );
        link.rel = 'stylesheet';
        link.href = 'https://wd-image-positions.toolforge.org/static/depicted.css';
        document.head.appendChild( link );
        var style = document.createElement( 'style' );
        style.textContent = '#file .wd-image-positions--depicted { visibility: hidden; }\n' +
            '#file > div:hover .wd-image-positions--depicted { visibility: visible; }';
        document.head.appendChild( style );
        $.get(
            'https://wd-image-positions.toolforge.org/api/v1/depicteds_html/file/' +
            encodeURIComponent( mw.config.get( 'wgTitle' ).replace(/ /g, '_') ) +
            '?uselang=' + mw.config.get( 'wgUserLanguage' )
        ).then( function ( html ) {
            $( '#file a' ).first().append( html );
        }, console.error );
    } );

    function waitForImageAnnotator() {
        var deferred = $.Deferred(),
            delay = 1,
            file = document.getElementById( 'file' );
        if ( file === null && mw.util.getParamValue( 'redirect' ) === 'no' ) {
        	return deferred.promise(); // redirect page
        	// otherwise, if file is null, I’d like to see an error and investigate why –
        	// unclear if we should look up file again in the loop below,
        	// or abort like here
        }
        function check() {
            if ( file.firstElementChild.nodeName.toLowerCase() === 'div' ) {
                deferred.resolve();
            } else {
                setTimeout( check, delay *= 1.5 );
            }
        }
        check();
        return deferred.promise();
    }
    
    waitForImageAnnotator().then( function () {
        $( '#ImageAnnotationHelpButton' ).after(
            '&nbsp;/ <form style="display: inline" action="https://wd-image-positions.toolforge.org/file/' +
            mw.html.escape( encodeURIComponent( mw.config.get( 'wgTitle' ).replace( / /g, '_' ) ) ) +
            '"><button type="submit">Add a Structured Data region</button></form>'
        );
    } );
} )( mediaWiki, jQuery );