Jump to content

MediaWiki:Centralnotice-template-blackout

From Meta, a Wikimedia project coordination wiki
<style>
#mw-sopaOverlay {
    /* Opera Mini doens't like position absolute */
    /* iOS doesn't like position fixed */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 500;
    color: #dedede;
    background: black url(//upload.wikimedia.org/wikipedia/commons/9/98/WP_SOPA_Splash_Full.jpg) no-repeat 0 0;
    overflow: auto;
    font-family:Times New Roman;
}

/* Monobook requires position, otherwise background is white+book instead of black */
body.skin-monobook #mw-sopaOverlay {
    position: absolute;
}

#mw-sopaColumn {
    position: absolute;
    top: 80px;
    left: 420px;
    width: 400px;
    color: #dedede;
    padding-bottom: 30px;
}
#mw-sopaHeadline {
    font-size: 1.7em;
    margin-bottom: 0.5em;
    color: #fff;
    overflow: hidden;
    text-align: justify;
}
#mw-sopaText { 
    margin-bottom: 1.5em;
    text-align: justify;
}
#mw-sopaColumn a {
    color: #eee;
    text-decoration: underline;
}
#mw-sopaColumn a:hover {
    color: #fff;
    cursor: pointer;
    text-decoration: underline;
}
#mw-sopaColumn a.action {
     margin-top: 2px;
}
.mw-sopaActionDiv {
   margin-left: 1em;
   margin-bottom: 1em;
}

.mw-sopaActionHead {
   font-weight: bold;
}
.mw-sopaSocial {
   float: left;
   text-align: center;
   margin-right: 12px;
   margin-bottom: 3px;
   font-size: small;
}
.mw-sopaSocial a {
   text-decoration: none;
}
</style>



<script type="text/javascript">
( function ($) {
	// n.b. community has decided for full blackout including Special pages,
	// but it is hard to do stuff in the meantime without this.
	var namespaceWhitelist = ['Special'];

	// see Wikipedia:SOPA_initiative/Blackout_screen_testing
	var pageWhitelist = [
'Stop Online Piracy Act',
'PROTECT IP Act',
'Online Protection and Enforcement of Digital Trade Act',
'Censorship',
'Special:CongressLookup',
'Special:NoticeTemplate',
'Special:NoticeTemplate/view',
'Wikipedia:Text of Creative Commons Attribution-ShareAlike 3.0 Unported License',
'Wikipedia:General disclaimer',
'Wikipedia:Contact us',
'Wikipedia:About',
'Wikipedia:Copyright violations',
'Wikipedia:Copyrights',
'Wikipedia:Five pillars',
'Digital Millennium Copyright Act',
'DNS cache poisoning',
'Censorship',
'Wikipedia:SOPA initiative',
'Wikipedia:SOPA initiative/Action',
'Wikipedia:SOPA initiative/Actions by other communities',
'Wikipedia:SOPA initiative/Media',
'Wikipedia:SOPA initiative/Learn more',
'Wikipedia:SOPA initiative/Mobile Learn more',
'Wikipedia:SOPA initiative/Legal overview',
'Wikipedia:SOPA initiative/Take action',
'SOPA',
'PIPA',
'OPEN',
'Censorship',
'Special:CongressFail',
'Special:CongressLookup',
'List of organizations with official stances on the Stop Online Piracy Act',
'Internet censorship',
'User talk:Jimbo Wales',
'Wikipedia:Legal disclaimer'
	];
	var geoHasUsRep = [
		'US', // USA
		'PR', // Puerto Rico
		'VI',  // Virgin Islands
		'MP', // Northern Mariana Islands
		'AS', // American Samoa
		'GU'  // Guam
	];
	var preload = [];
	var i;

	// Exclude some namespaces
	if ( $.inArray( wgCanonicalNamespace, namespaceWhitelist ) !== -1 ) {
		return;
	}

	// Exclude some individual pages
	for ( i = 0; i < pageWhitelist.length; i++ ) {
		if ( pageWhitelist[i] === wgPageName || pageWhitelist[i] === wgPageName.replace( /_/g, ' ' ) ) {
			return;
		}
	}

        // Whitelist the innumerable "Contact us" subpages
	var contactUsSubpages = /^Wikipedia:Contact_us\//;
	if ( contactUsSubpages.test( wgPageName ) ) {
		return;
	}

        var urlParams = {};
        (function () {
            var e,
                a = /\+/g,  
                r = /([^&=]+)=?([^&]*)/g,
                d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
                q = window.location.search.substring(1);

            while (e = r.exec(q)) {
                urlParams[d(e[1])] = d(e[2]);
            }
        })();

        var country = 'ZZ';
        if ( urlParams.country ) {
            country = urlParams.country;
        } else if ( window.Geo && window.Geo.country ) {
            country = window.Geo.country;
        }
            
	var hasUsRep = false;
        for ( i = 0; i < geoHasUsRep.length; i++ ) {
		if ( geoHasUsRep[i] === country ) {
		    hasUsRep = true;
		    break;
		}
	}

	var overlay = $('<div id="mw-sopaOverlay"></div>');
	var column = $('<div id="mw-sopaColumn"></div>');
	var headline = $('<div id="mw-sopaHeadline">{{{wp-sopa-title}}}</div>');
	var intro = $('<div id="mw-sopaText">{{{wp-sopa-blocktext}}}</div>');
	var validateZip = function(zip) {
		return /^\s*[0-9]{5}([- ]?[0-9]{4})?\s*$/.test(zip);
	};

	var action = $('<div id="mw-sopaAction"></div>');
	if ( hasUsRep ) {
		action.append( $('<p class="mw-sopaActionHead">{{{wp-sopa-zipform-intro}}}</p><div class="mw-sopaActionDiv"><form action="/wiki/Special:CongressLookup" action="GET"><label for="zip">{{{wp-sopa-zipform-label}}}</label> <input name="zip" type="text" size="5"> <input id="sopa-zipform-submit" type="submit" value="{{{wp-sopa-zipform-submit}}}"></form></div>' ) );

		action.find('#sopa-zipform-submit').click(
			function(e) {
				var enteredZip = action.find('input[name="zip"]').val();
				if ( ! validateZip( enteredZip ) ) {
					alert( '{{{wp-sopa-zipform-invalid}}}');
					e.preventDefault();
					action.find('input[name="zip"]').focus();
				}
			} );
	} else {
    var $socialDiv = $('<div>');
  
  
    var socialSites = [
      {
        url: 'https://www.facebook.com/sharer.php?u=' + encodeURIComponent( '{{{wp-sopa-facebook-link}}}' ),
        title: '{{{wp-sopa-facebook-button}}}',
        hi: '//upload.wikimedia.org/wikipedia/commons/b/b9/WP_SOPA_sm_icon_facebook_ffffff.png',
        icon: '//upload.wikimedia.org/wikipedia/commons/2/2a/WP_SOPA_sm_icon_facebook_dedede.png',
        'popup': false
      },
      {
        url: 'https://plus.google.com/share?url=' + encodeURIComponent( '{{{wp-sopa-google-plus-post}}}' ),
        title: '{{{wp-sopa-google-plus-button}}}',
        hi: '//upload.wikimedia.org/wikipedia/commons/a/a1/WP_SOPA_sm_icon_gplus_ffffff.png',
        icon: '//upload.wikimedia.org/wikipedia/commons/0/08/WP_SOPA_sm_icon_gplus_dedede.png',
        'popup': true
      },
      {
        url: 'https://twitter.com/intent/tweet?original_referer=' + encodeURIComponent( window.location ) + '&text=' + encodeURIComponent( '{{{wp-sopa-tweet}}}' ),
        title: '{{{wp-sopa-twitter-button}}}',
        hi: '//upload.wikimedia.org/wikipedia/foundation/8/8a/WP_SOPA_sm_icon_twitter_ffffff.png',
        icon: '//upload.wikimedia.org/wikipedia/foundation/4/45/WP_SOPA_sm_icon_twitter_dedede.png',
        'popup': false
      }
    ];

    for ( i = 0; i < socialSites.length; i++ ) {
      ( function ( site )  {
        function linkify( $item ) {
          var $link = $( '<a></a>' )
            .css( 'text-decoration', 'none' )
            .attr( 'href', site.url )
            .append( $item );
          var target = 'wpblackout_' + site.title + '_share';
          if ( site.popup ) {
            $link.click( function() {
              window.open(
                site.url,
                target,
                'resizable=yes,width=500,height=300,left=' + (screen.availWidth/2-250) + ',top=' + (screen.availHeight/2-150)
              );
              return false;
            } );
          } else {
            $link.attr( 'target', target );
          }
          return $link;
        }
        var $icon = $( '<img></img>' ).attr( { 'width': 33, 'height': 33, 'src': site.icon } );
        var $iconLink = linkify( $icon );
        preload.push( site.hi );
        var $wordLink = linkify( site.title );
        var $div = $( '<div class="mw-sopaSocial"></div>' );
        $div.hover(
          function() {
          $icon.attr( 'src', site.hi );
          $wordLink.css( 'color', '#fff' );
        },
        function() {
          $icon.attr( 'src', site.icon );
          $wordLink.css( 'color', '#dedede' );
        });
        $div.append( $iconLink, $('<br>'), $wordLink );
        $socialDiv.append($div);
      } )( socialSites[i] );
    }
    action.append(
      $( '<p class="mw-sopaActionHead">{{{wp-sopa-social-media-intro}}}</p>' ),
      $( '<div class="mw-sopaActionDiv"></div>' ).append(
        $socialDiv,
        $( '<div style="clear: both;"></div>' )
      )
    );

	}

	column.append( headline, intro, action );
	overlay.append( column );

	$('body').children().hide();
	$('body').append(overlay);
	$('<style id="mw-sopa-blackout">#mw-page-base, #mw-head-base, #content, #mw-head, #mw-panel, #footer { display: none; }</style>').appendTo('head');

	var preloaded = [];
	for ( i = 0; i < preload.length; i++ ) {
		preloaded[i] = new Image();
		preloaded[i].src = preload[i];
	}

} )(jQuery);
</script>