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
 
(6 revisões intermediárias por 2 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', '' );
$floatTOC.find( 'a' ).not( $current ).css( 'color', '' );
$floatTOC.find( 'a' ).not( $current ).css( 'font-weight', '' );
$current.css( 'background', '#254494' );
$current.css( 'color', 'white' );
$current.css( 'font-weight', 'bold' );
}
 
} else {
$floatTOC.css( {
visibility: 'hidden',
opacity: 0
} );
$mwPanel.show();
}
}
 
$window.on( 'scroll', $.throttle( 250, scrollHandler ) );
} );
} );
 
(function (d) { var js, id = "genially-embed-js", ref = d.getElementsByTagName("script")[0]; if (d.getElementById(id)) { return; } js = d.createElement("script"); js.id = id; js.async = true; js.src = "https://view.genial.ly/static/embed/embed.js"; ref.parentNode.insertBefore(js, ref); }(document));
 
$(document).ready( function() {
    $('#tree').bind('fancytreeinit', function(event, data) {
        data.tree.makeTitleVisible();
    });
})
 
/*!
jCarousel - v0.3.0 - 2013-11-22
http://sorgalla.com/jcarousel
Copyright (c) 2013 Jan Sorgalla; Licensed MIT
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
*/
(function(t){"use strict";var i=t.jCarousel={};i.version="0.3.0";var s=/^([+\-]=)?(.+)$/;i.parseTarget=function(t){var i=!1,e="object"!=typeof t?s.exec(t):null;return e?(t=parseInt(e[2],10)||0,e[1]&&(i=!0,"-="===e[1]&&(t*=-1))):"object"!=typeof t&&(t=parseInt(t,10)||0),{target:t,relative:i}},i.detectCarousel=function(t){for(var i;t.length>0;){if(i=t.filter("[data-jcarousel]"),i.length>0)return i;if(i=t.find("[data-jcarousel]"),i.length>0)return i;t=t.parent()}return null},i.base=function(s){return{version:i.version,_options:{},_element:null,_carousel:null,_init:t.noop,_create:t.noop,_destroy:t.noop,_reload:t.noop,create:function(){return this._element.attr("data-"+s.toLowerCase(),!0).data(s,this),!1===this._trigger("create")?this:(this._create(),this._trigger("createend"),this)},destroy:function(){return!1===this._trigger("destroy")?this:(this._destroy(),this._trigger("destroyend"),this._element.removeData(s).removeAttr("data-"+s.toLowerCase()),this)},reload:function(t){return!1===this._trigger("reload")?this:(t&&this.options(t),this._reload(),this._trigger("reloadend"),this)},element:function(){return this._element},options:function(i,s){if(0===arguments.length)return t.extend({},this._options);if("string"==typeof i){if(s===void 0)return this._options[i]===void 0?null:this._options[i];this._options[i]=s}else this._options=t.extend({},this._options,i);return this},carousel:function(){return this._carousel||(this._carousel=i.detectCarousel(this.options("carousel")||this._element),this._carousel||t.error('Could not detect carousel for plugin "'+s+'"')),this._carousel},_trigger:function(i,e,r){var n,o=!1;return r=[this].concat(r||[]),(e||this._element).each(function(){n=t.Event((s+":"+i).toLowerCase()),t(this).trigger(n,r),n.isDefaultPrevented()&&(o=!0)}),!o}}},i.plugin=function(s,e){var r=t[s]=function(i,s){this._element=t(i),this.options(s),this._init(),this.create()};return r.fn=r.prototype=t.extend({},i.base(s),e),t.fn[s]=function(i){var e=Array.prototype.slice.call(arguments,1),n=this;return"string"==typeof i?this.each(function(){var r=t(this).data(s);if(!r)return t.error("Cannot call methods on "+s+" prior to initialization; "+'attempted to call method "'+i+'"');if(!t.isFunction(r[i])||"_"===i.charAt(0))return t.error('No such method "'+i+'" for '+s+" instance");var o=r[i].apply(r,e);return o!==r&&o!==void 0?(n=o,!1):void 0}):this.each(function(){var e=t(this).data(s);e instanceof r?e.reload(i):new r(this,i)}),n},r}})(jQuery),function(t,i){"use strict";var s=function(t){return parseFloat(t)||0};t.jCarousel.plugin("jcarousel",{animating:!1,tail:0,inTail:!1,resizeTimer:null,lt:null,vertical:!1,rtl:!1,circular:!1,underflow:!1,relative:!1,_options:{list:function(){return this.element().children().eq(0)},items:function(){return this.list().children()},animation:400,transitions:!1,wrap:null,vertical:null,rtl:null,center:!1},_list:null,_items:null,_target:null,_first:null,_last:null,_visible:null,_fullyvisible:null,_init:function(){var t=this;return this.onWindowResize=function(){t.resizeTimer&&clearTimeout(t.resizeTimer),t.resizeTimer=setTimeout(function(){t.reload()},100)},this},_create:function(){this._reload(),t(i).on("resize.jcarousel",this.onWindowResize)},_destroy:function(){t(i).off("resize.jcarousel",this.onWindowResize)},_reload:function(){this.vertical=this.options("vertical"),null==this.vertical&&(this.vertical=this.list().height()>this.list().width()),this.rtl=this.options("rtl"),null==this.rtl&&(this.rtl=function(i){if("rtl"===(""+i.attr("dir")).toLowerCase())return!0;var s=!1;return i.parents("[dir]").each(function(){return/rtl/i.test(t(this).attr("dir"))?(s=!0,!1):void 0}),s}(this._element)),this.lt=this.vertical?"top":"left",this.relative="relative"===this.list().css("position"),this._list=null,this._items=null;var i=this._target&&this.index(this._target)>=0?this._target:this.closest();this.circular="circular"===this.options("wrap"),this.underflow=!1;var s={left:0,top:0};return i.length>0&&(this._prepare(i),this.list().find("[data-jcarousel-clone]").remove(),this._items=null,this.underflow=this._fullyvisible.length>=this.items().length,this.circular=this.circular&&!this.underflow,s[this.lt]=this._position(i)+"px"),this.move(s),this},list:function(){if(null===this._list){var i=this.options("list");this._list=t.isFunction(i)?i.call(this):this._element.find(i)}return this._list},items:function(){if(null===this._items){var i=this.options("items");this._items=(t.isFunction(i)?i.call(this):this.list().find(i)).not("[data-jcarousel-clone]")}return this._items},index:function(t){return this.items().index(t)},closest:function(){var i,e=this,r=this.list().position()[this.lt],n=t(),o=!1,l=this.vertical?"bottom":this.rtl&&!this.relative?"left":"right";return this.rtl&&this.relative&&!this.vertical&&(r+=this.list().width()-this.clipping()),this.items().each(function(){if(n=t(this),o)return!1;var a=e.dimension(n);if(r+=a,r>=0){if(i=a-s(n.css("margin-"+l)),!(0>=Math.abs(r)-a+i/2))return!1;o=!0}}),n},target:function(){return this._target},first:function(){return this._first},last:function(){return this._last},visible:function(){return this._visible},fullyvisible:function(){return this._fullyvisible},hasNext:function(){if(!1===this._trigger("hasnext"))return!0;var t=this.options("wrap"),i=this.items().length-1;return i>=0&&(t&&"first"!==t||i>this.index(this._last)||this.tail&&!this.inTail)?!0:!1},hasPrev:function(){if(!1===this._trigger("hasprev"))return!0;var t=this.options("wrap");return this.items().length>0&&(t&&"last"!==t||this.index(this._first)>0||this.tail&&this.inTail)?!0:!1},clipping:function(){return this._element["inner"+(this.vertical?"Height":"Width")]()},dimension:function(t){return t["outer"+(this.vertical?"Height":"Width")](!0)},scroll:function(i,s,e){if(this.animating)return this;if(!1===this._trigger("scroll",null,[i,s]))return this;t.isFunction(s)&&(e=s,s=!0);var r=t.jCarousel.parseTarget(i);if(r.relative){var n,o,l,a,h,u,c,f,d=this.items().length-1,_=Math.abs(r.target),p=this.options("wrap");if(r.target>0){var v=this.index(this._last);if(v>=d&&this.tail)this.inTail?"both"===p||"last"===p?this._scroll(0,s,e):t.isFunction(e)&&e.call(this,!1):this._scrollTail(s,e);else if(n=this.index(this._target),this.underflow&&n===d&&("circular"===p||"both"===p||"last"===p)||!this.underflow&&v===d&&("both"===p||"last"===p))this._scroll(0,s,e);else if(l=n+_,this.circular&&l>d){for(f=d,h=this.items().get(-1);l>f++;)h=this.items().eq(0),u=this._visible.index(h)>=0,u&&h.after(h.clone(!0).attr("data-jcarousel-clone",!0)),this.list().append(h),u||(c={},c[this.lt]=this.dimension(h),this.moveBy(c)),this._items=null;this._scroll(h,s,e)}else this._scroll(Math.min(l,d),s,e)}else if(this.inTail)this._scroll(Math.max(this.index(this._first)-_+1,0),s,e);else if(o=this.index(this._first),n=this.index(this._target),a=this.underflow?n:o,l=a-_,0>=a&&(this.underflow&&"circular"===p||"both"===p||"first"===p))this._scroll(d,s,e);else if(this.circular&&0>l){for(f=l,h=this.items().get(0);0>f++;){h=this.items().eq(-1),u=this._visible.index(h)>=0,u&&h.after(h.clone(!0).attr("data-jcarousel-clone",!0)),this.list().prepend(h),this._items=null;var g=this.dimension(h);c={},c[this.lt]=-g,this.moveBy(c)}this._scroll(h,s,e)}else this._scroll(Math.max(l,0),s,e)}else this._scroll(r.target,s,e);return this._trigger("scrollend"),this},moveBy:function(t,i){var e=this.list().position(),r=1,n=0;return this.rtl&&!this.vertical&&(r=-1,this.relative&&(n=this.list().width()-this.clipping())),t.left&&(t.left=e.left+n+s(t.left)*r+"px"),t.top&&(t.top=e.top+n+s(t.top)*r+"px"),this.move(t,i)},move:function(i,s){s=s||{};var e=this.options("transitions"),r=!!e,n=!!e.transforms,o=!!e.transforms3d,l=s.duration||0,a=this.list();if(!r&&l>0)return a.animate(i,s),void 0;var h=s.complete||t.noop,u={};if(r){var c=a.css(["transitionDuration","transitionTimingFunction","transitionProperty"]),f=h;h=function(){t(this).css(c),f.call(this)},u={transitionDuration:(l>0?l/1e3:0)+"s",transitionTimingFunction:e.easing||s.easing,transitionProperty:l>0?function(){return n||o?"all":i.left?"left":"top"}():"none",transform:"none"}}o?u.transform="translate3d("+(i.left||0)+","+(i.top||0)+",0)":n?u.transform="translate("+(i.left||0)+","+(i.top||0)+")":t.extend(u,i),r&&l>0&&a.one("transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd",h),a.css(u),0>=l&&a.each(function(){h.call(this)})},_scroll:function(i,s,e){if(this.animating)return t.isFunction(e)&&e.call(this,!1),this;if("object"!=typeof i?i=this.items().eq(i):i.jquery===void 0&&(i=t(i)),0===i.length)return t.isFunction(e)&&e.call(this,!1),this;this.inTail=!1,this._prepare(i);var r=this._position(i),n=this.list().position()[this.lt];if(r===n)return t.isFunction(e)&&e.call(this,!1),this;var o={};return o[this.lt]=r+"px",this._animate(o,s,e),this},_scrollTail:function(i,s){if(this.animating||!this.tail)return t.isFunction(s)&&s.call(this,!1),this;var e=this.list().position()[this.lt];this.rtl&&this.relative&&!this.vertical&&(e+=this.list().width()-this.clipping()),this.rtl&&!this.vertical?e+=this.tail:e-=this.tail,this.inTail=!0;var r={};return r[this.lt]=e+"px",this._update({target:this._target.next(),fullyvisible:this._fullyvisible.slice(1).add(this._visible.last())}),this._animate(r,i,s),this},_animate:function(i,s,e){if(e=e||t.noop,!1===this._trigger("animate"))return e.call(this,!1),this;this.animating=!0;var r=this.options("animation"),n=t.proxy(function(){this.animating=!1;var t=this.list().find("[data-jcarousel-clone]");t.length>0&&(t.remove(),this._reload()),this._trigger("animateend"),e.call(this,!0)},this),o="object"==typeof r?t.extend({},r):{duration:r},l=o.complete||t.noop;return s===!1?o.duration=0:t.fx.speeds[o.duration]!==void 0&&(o.duration=t.fx.speeds[o.duration]),o.complete=function(){n(),l.call(this)},this.move(i,o),this},_prepare:function(i){var e,r,n,o,l=this.index(i),a=l,h=this.dimension(i),u=this.clipping(),c=this.vertical?"bottom":this.rtl?"left":"right",f=this.options("center"),d={target:i,first:i,last:i,visible:i,fullyvisible:u>=h?i:t()};if(f&&(h/=2,u/=2),u>h)for(;;){if(e=this.items().eq(++a),0===e.length){if(!this.circular)break;if(e=this.items().eq(0),i.get(0)===e.get(0))break;if(r=this._visible.index(e)>=0,r&&e.after(e.clone(!0).attr("data-jcarousel-clone",!0)),this.list().append(e),!r){var _={};_[this.lt]=this.dimension(e),this.moveBy(_)}this._items=null}if(o=this.dimension(e),0===o)break;if(h+=o,d.last=e,d.visible=d.visible.add(e),n=s(e.css("margin-"+c)),u>=h-n&&(d.fullyvisible=d.fullyvisible.add(e)),h>=u)break}if(!this.circular&&!f&&u>h)for(a=l;;){if(0>--a)break;if(e=this.items().eq(a),0===e.length)break;if(o=this.dimension(e),0===o)break;if(h+=o,d.first=e,d.visible=d.visible.add(e),n=s(e.css("margin-"+c)),u>=h-n&&(d.fullyvisible=d.fullyvisible.add(e)),h>=u)break}return this._update(d),this.tail=0,f||"circular"===this.options("wrap")||"custom"===this.options("wrap")||this.index(d.last)!==this.items().length-1||(h-=s(d.last.css("margin-"+c)),h>u&&(this.tail=h-u)),this},_position:function(t){var i=this._first,s=i.position()[this.lt],e=this.options("center"),r=e?this.clipping()/2-this.dimension(i)/2:0;return this.rtl&&!this.vertical?(s-=this.relative?this.list().width()-this.dimension(i):this.clipping()-this.dimension(i),s+=r):s-=r,!e&&(this.index(t)>this.index(i)||this.inTail)&&this.tail?(s=this.rtl&&!this.vertical?s-this.tail:s+this.tail,this.inTail=!0):this.inTail=!1,-s},_update:function(i){var s,e=this,r={target:this._target||t(),first:this._first||t(),last:this._last||t(),visible:this._visible||t(),fullyvisible:this._fullyvisible||t()},n=this.index(i.first||r.first)<this.index(r.first),o=function(s){var o=[],l=[];i[s].each(function(){0>r[s].index(this)&&o.push(this)}),r[s].each(function(){0>i[s].index(this)&&l.push(this)}),n?o=o.reverse():l=l.reverse(),e._trigger(s+"in",t(o)),e._trigger(s+"out",t(l)),e["_"+s]=i[s]};for(s in i)o(s);return this}})}(jQuery,window),function(t){"use strict";t.jcarousel.fn.scrollIntoView=function(i,s,e){var r,n=t.jCarousel.parseTarget(i),o=this.index(this._fullyvisible.first()),l=this.index(this._fullyvisible.last());if(r=n.relative?0>n.target?Math.max(0,o+n.target):l+n.target:"object"!=typeof n.target?n.target:this.index(n.target),o>r)return this.scroll(r,s,e);if(r>=o&&l>=r)return t.isFunction(e)&&e.call(this,!1),this;for(var a,h=this.items(),u=this.clipping(),c=this.vertical?"bottom":this.rtl?"left":"right",f=0;;){if(a=h.eq(r),0===a.length)break;if(f+=this.dimension(a),f>=u){var d=parseFloat(a.css("margin-"+c))||0;f-d!==u&&r++;break}if(0>=r)break;r--}return this.scroll(r,s,e)}}(jQuery),function(t){"use strict";t.jCarousel.plugin("jcarouselControl",{_options:{target:"+=1",event:"click",method:"scroll"},_active:null,_init:function(){this.onDestroy=t.proxy(function(){this._destroy(),this.carousel().one("jcarousel:createend",t.proxy(this._create,this))},this),this.onReload=t.proxy(this._reload,this),this.onEvent=t.proxy(function(i){i.preventDefault();var s=this.options("method");t.isFunction(s)?s.call(this):this.carousel().jcarousel(this.options("method"),this.options("target"))},this)},_create:function(){this.carousel().one("jcarousel:destroy",this.onDestroy).on("jcarousel:reloadend jcarousel:scrollend",this.onReload),this._element.on(this.options("event")+".jcarouselcontrol",this.onEvent),this._reload()},_destroy:function(){this._element.off(".jcarouselcontrol",this.onEvent),this.carousel().off("jcarousel:destroy",this.onDestroy).off("jcarousel:reloadend jcarousel:scrollend",this.onReload)},_reload:function(){var i,s=t.jCarousel.parseTarget(this.options("target")),e=this.carousel();if(s.relative)i=e.jcarousel(s.target>0?"hasNext":"hasPrev");else{var r="object"!=typeof s.target?e.jcarousel("items").eq(s.target):s.target;i=e.jcarousel("target").index(r)>=0}return this._active!==i&&(this._trigger(i?"active":"inactive"),this._active=i),this}})}(jQuery),function(t){"use strict";t.jCarousel.plugin("jcarouselPagination",{_options:{perPage:null,item:function(t){return'<a href="#'+t+'">'+t+"</a>"},event:"click",method:"scroll"},_pages:{},_items:{},_currentPage:null,_init:function(){this.onDestroy=t.proxy(function(){this._destroy(),this.carousel().one("jcarousel:createend",t.proxy(this._create,this))},this),this.onReload=t.proxy(this._reload,this),this.onScroll=t.proxy(this._update,this)},_create:function(){this.carousel().one("jcarousel:destroy",this.onDestroy).on("jcarousel:reloadend",this.onReload).on("jcarousel:scrollend",this.onScroll),this._reload()},_destroy:function(){this._clear(),this.carousel().off("jcarousel:destroy",this.onDestroy).off("jcarousel:reloadend",this.onReload).off("jcarousel:scrollend",this.onScroll)},_reload:function(){var i=this.options("perPage");if(this._pages={},this._items={},t.isFunction(i)&&(i=i.call(this)),null==i)this._pages=this._calculatePages();else for(var s,e=parseInt(i,10)||0,r=this.carousel().jcarousel("items"),n=1,o=0;;){if(s=r.eq(o++),0===s.length)break;this._pages[n]=this._pages[n]?this._pages[n].add(s):s,0===o%e&&n++}this._clear();var l=this,a=this.carousel().data("jcarousel"),h=this._element,u=this.options("item");t.each(this._pages,function(i,s){var e=l._items[i]=t(u.call(l,i,s));e.on(l.options("event")+".jcarouselpagination",t.proxy(function(){var t=s.eq(0);if(a.circular){var e=a.index(a.target()),r=a.index(t);parseFloat(i)>parseFloat(l._currentPage)?e>r&&(t="+="+(a.items().length-e+r)):r>e&&(t="-="+(e+(a.items().length-r)))}a[this.options("method")](t)},l)),h.append(e)}),this._update()},_update:function(){var i,s=this.carousel().jcarousel("target");t.each(this._pages,function(t,e){return e.each(function(){return s.is(this)?(i=t,!1):void 0}),i?!1:void 0}),this._currentPage!==i&&(this._trigger("inactive",this._items[this._currentPage]),this._trigger("active",this._items[i])),this._currentPage=i},items:function(){return this._items},_clear:function(){this._element.empty(),this._currentPage=null},_calculatePages:function(){for(var t,i=this.carousel().data("jcarousel"),s=i.items(),e=i.clipping(),r=0,n=0,o=1,l={};;){if(t=s.eq(n++),0===t.length)break;l[o]=l[o]?l[o].add(t):t,r+=i.dimension(t),r>=e&&(o++,r=0)}return l}})}(jQuery),function(t){"use strict";t.jCarousel.plugin("jcarouselAutoscroll",{_options:{target:"+=1",interval:3e3,autostart:!0},_timer:null,_init:function(){this.onDestroy=t.proxy(function(){this._destroy(),this.carousel().one("jcarousel:createend",t.proxy(this._create,this))},this),this.onAnimateEnd=t.proxy(this.start,this)},_create:function(){this.carousel().one("jcarousel:destroy",this.onDestroy),this.options("autostart")&&this.start()},_destroy:function(){this.stop(),this.carousel().off("jcarousel:destroy",this.onDestroy)},start:function(){return this.stop(),this.carousel().one("jcarousel:animateend",this.onAnimateEnd),this._timer=setTimeout(t.proxy(function(){this.carousel().jcarousel("scroll",this.options("target"))},this),this.options("interval")),this},stop:function(){return this._timer&&(this._timer=clearTimeout(this._timer)),this.carousel().off("jcarousel:animateend",this.onAnimateEnd),this}})}(jQuery);
$(function() {
    $('.jcarousel')
        .on('jcarousel:create jcarousel:reload', function() {
            var element = $(this),
                width = element.innerWidth();
            // This shows 1 item at a time.
            // Divide `width` to the number of items you want to display,
            // eg. `width = width / 3` to display 3 items at a time.
            element.jcarousel('items').css('width', width + 'px');
        })
        .jcarousel({
            // Configuration goes here
            wrap: 'both',
            animation: 1500,
            center: true
        })
        .jcarouselAutoscroll({
            interval: 7500,
            target: '+=1',
            autostart: true,
        });
    $('.jcarousel-control-prev')
        .on('jcarouselcontrol:active', function() {
            $(this).removeClass('inactive');
        })
        .on('jcarouselcontrol:inactive', function() {
            $(this).addClass('inactive');
        })
        .jcarouselControl({
            target: '-=1'
        });
    $('.jcarousel-control-next')
        .on('jcarouselcontrol:active', function() {
            $(this).removeClass('inactive');
        })
        .on('jcarouselcontrol:inactive', function() {
            $(this).addClass('inactive');
        })
        .jcarouselControl({
            target: '+=1'
        });
    $('.jcarousel-pagination')
        .on('jcarouselpagination:active', 'a', function() {
            $(this).addClass('active');
        })
        .on('jcarouselpagination:inactive', 'a', function() {
            $(this).removeClass('active');
        })
        .jcarouselPagination();
});
// END Main Page carousel code
 
//Imagemap edit
if (mw.config.get('wgNamespaceNumber') == 6 && mw.config.get('wgAction') == 'view') {
// you can load or set translations here, by setting the global window variable window.ime_translations. e.g., to replace the title for
// "Create new area", set
/*
window.ime_translations = {
    newarea: 'Create new area new title'
};
*/
    mw.loader.load('//he.wikipedia.org/w/index.php?title=Mediawiki:Gadget-ime.js&action=raw&ctype=text/javascript');
}
 
//End Imagemap edit
 
//JS imagemap
 
$(function() {
 
var
//add this class to all elements created by the script. the reason is that we call the script again on
//window resize, and use the class to remove all the "artefacts" we created in the previous run.
myClassName = 'imageMapHighlighterArtefacts',
liHighlightClass = 'liHighlighting',
specialAreaMark = 'area_mark',
specialLiClassesMark = 'list_classes',
specialAreaMarkFile = 'area_mark_file',
// "2d context" attributes used for highlighting.
areaHighLighting = {
fillStyle: 'rgba(0,0,0,0.35)',
strokeStyle: 'yellow',
lineJoin: 'round',
lineWidth: 2
},
//every imagemap that wants highlighting, should reside in a div of this 'class':
hilightDivMarker = '.imageMapHighlighter',
// specifically for wikis - redlinks tooltip adds this message
en = mw && mw.config && mw.config.get('wgUserLanguage') == 'en',
expandLegend = en ? 'mostrar links por texto' : 'show links as text',
collapseLegend = en ? 'ocultar links com texto' : 'hide links as text',
files = [];
 
 
function drawMarker(context, areas) { // this is where the magic is done.
 
function drawPoly(coords) {
context.moveTo(coords.shift(), coords.shift());
while (coords.length)
context.lineTo(coords.shift(), coords.shift());
}
 
for (var i in areas) {
var coords = areas[i].coords.split(',');
context.beginPath();
switch (areas[i].shape) {
case 'rect': drawPoly([coords[0], coords[1], coords[0], coords[3], coords[2], coords[3], coords[2], coords[1]]); break;
case 'circle': context.arc(coords[0],coords[1],coords[2],0,Math.PI*2);  break;//x,y,r,startAngle,endAngle
case 'poly': drawPoly(coords); break;
}
context.closePath();
context.stroke();
context.fill();
}
}
 
function mouseAction(e) {
var $this = $(this),
activate = e.type == 'mouseover',
caption = $this.text(),
ol = $this.parent(),
context = ol.data('context'),
special = ol.data(specialAreaMark),
specialFile = ol.data(specialAreaMarkFile); //read JSON file addition
 
if (specialFile) {
if (files[specialFile]) {
$.extend(special, files[specialFile]);
always(activate, caption, context, ol, special, $this);
} else {
$.get(mw.util.wikiScript(), {
title: specialFile,
action: 'raw'
})
.done(function(data) {
files[specialFile] = JSON.parse(data);
$.extend(special, files[specialFile]);
})
.always(function() {
always(activate, caption, context, ol, special, $this);
});
}
} else
always(activate, caption, context, ol, special, $this);
}
 
function always(activate, caption, context, ol, special, $this) {
$this.toggleClass(liHighlightClass, activate); // mark/unmark the list item.
 
context.clearRect(0, 0, context.canvas.width, context.canvas.height); // prepare for a new day.
 
ol.find('li')
.each(function() {
var $li = $(this);
var licap = $li.text();
var param;
if (activate && licap === caption) { // highlight!!!
param = special && (special.hover && special.hover[licap]
|| getblocks(special, licap)) || areaHighLighting;
} else {
param = special && special.nover && (special.nover[licap] || special.nover
.default);
}
if (param) {
$.extend(context, param);
drawMarker(context, $li.data('areas'));
}
});
}
 
function getblocks(special, licap) {
if (special.hoverblocks) {
if (special.hoverblocks[licap])
return special.hoverblocks[licap].value;
for (var key in special.hoverblocks)
if (special.hoverblocks[key] && special.hoverblocks[key].list.indexOf(licap) >=0 )
return special.hoverblocks[key].value;
}
if (special.hover)
return special.hover.default;
}
function handleOneMap() {
var img = $(this),
w = img.width(),
h = img.height(),
infoIcon = img.next(),
parent = img.parent(),
map = img.siblings('map:first'),
dims = {
position: 'absolute',
width: w + 'px',
height: h + 'px',
border: 0,
top: 0,
left: 0
},
specialHighlight = img.closest(hilightDivMarker)
.data(specialAreaMark),
specialLiClasses = img.closest(hilightDivMarker)
.data(specialLiClassesMark),
specialHover = img.closest(hilightDivMarker)
.data(specialAreaMarkFile);
 
if (!('area', map)
.length)
return; //not an imagemap. inside "each" anonymous function, 'return' means "continue".
 
var jcanvas = $('<canvas>', {
'class': myClassName
})
.css(dims)
.attr({
width: w,
height: h
});
var bgimg = $('<img>', {
'class': myClassName,
src: img.attr('src')
})
.css(dims); //completely inert image. this is what we see.
var context = $.extend(jcanvas[0].getContext("2d"), areaHighLighting);
 
// this is where the magic is done: prepare a sandwich of the inert bgimg at the bottom,
// the canvas above it, and the original image on top,
// so canvas won't steal the mouse events.
// pack them all TIGHTLY in a newly minted "relative" div, so when page chnage
// (other scripts adding elements, window resize etc.), canvas and imagese remain aligned.
var div = $('<div>')
.css({
position: 'relative',
width: w + 'px',
height: h + 'px'
});
img.before(div); // put the div just above the image, and ...
div.append(bgimg) // place the background image in the div
.append(jcanvas) // and the canvas. both are "absolute", so they don't occupy space in the div
.append(img); // now yank the original image from the window and place it on the div.
img.fadeTo(1, 0); // make the image transparent - we see canvas and bgimg through it.
// the original, now transparent image is creating our mouse events
 
infoIcon.css({
position: 'relative'
}); // set position to info icon
var ol = $('<ol>', {
'class': myClassName
})
.css({
clear: 'both',
margin: 0,
listStyle: 'none',
maxWidth: w + 'px',
position: 'relative'
})
.data(specialAreaMark, specialHighlight)
.data(specialAreaMarkFile, specialHover)
.data('context', context);
var oldiv = $('<div>')
.html(ol)
.css({
clear: 'both',
margin: 0,
listStyle: 'none',
maxWidth: w + 'px',
position: 'relative'
})
.attr({
'data-expandtext': expandLegend,
'data-collapsetext': collapseLegend
});
 
// ol below image parent, hr below ol. original caption pushed below hr.
var $hr = $('<hr>', { 'class': myClassName }).css('clear', 'both');
parent.after($hr).after(oldiv);
$hr.clone().insertBefore($(oldiv));
var lis = {}; //collapse areas with same caption to one list item
var someli; // select arbitrary one
$('area', map)
.each(function() {
var text = this.title;
var li = lis[text]; // title already met? use the same li
if (!li) { //no? create a new one.
var href = this.href;
lis[text] = li = $('<li>', {
'class': myClassName
})
.append($('<a>', {
href: href,
text: text
}))
.on('mouseover mouseout', mouseAction)
.data('areas', [])
.addClass(specialLiClasses && (specialLiClasses[text] ||
specialLiClasses['default']))
.appendTo(ol);
if (specialLiClasses && specialLiClasses[text + ' super'])
li.find('a')
.addClass(specialLiClasses[text + ' super']);
}
li.data('areas')
.push(this); //add the area to the li
someli = li; // whichever - we just want one...
$(this)
.on('mouseover mouseout', function(e) {
li.trigger(e);
});
});
if (specialLiClasses && specialLiClasses.order) {
specialLiClasses.order.forEach(function(elem) {
var what = $(elem.what);
if (elem.dir === 'before') {
what.each(function(inner){$(what[inner])
.insertBefore($(what[inner]).parent().find(elem.where))});
} else {
what.each(function(inner){$(what[inner])
.insertAfter($(what[inner]).parent().find(elem.where))});
}
});
}
if (specialLiClasses && specialLiClasses.todefault) {
specialLiClasses.todefault.forEach(function(elem) {
$(elem).addClass(specialLiClasses.default);
});
}
if (someli) {
someli.trigger('mouseout');
}
oldiv.addClass('mw-collapsed')
.makeCollapsible();
ol.attr('style', ol.attr('style')
.replace('none', 'disc'));
}
 
function init() {
mw.util.addCSS('li.' + myClassName +
'{white-space:nowrap; font-size:88.36%;}\n' + //css for li element
'li.' + liHighlightClass + '{background-color:yellow;}\n' + //css for highlighted li element.
'.rtl li.' + myClassName + '{float: right; margin-left: 1.5em;}\n' +
'.ltr li.' + myClassName + '{float: left; margin-right: 1.5em;}\n' +
hilightDivMarker + ' .mw-collapsible-toggle {float: none}');
$(hilightDivMarker + ' img')
.each(handleOneMap);
}
 
//has at least one "imagehighlight" div, and canvas-capable browser:
if ( $(hilightDivMarker).length && $('<canvas>')[0].getContext ) {
mw.loader.using(['jquery.makeCollapsible', 'mediawiki.util'])
.done(init);
}
});

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 );