Jump to content

User:TestBotOnly/index.html.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by TestBotOnly (talk | contribs) at 10:08, 17 June 2011 (Created page with '<html> <head> <script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script> <script type="text/javascript" src="jquery.cookie.js"></script> ...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
<html>

<head>

<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript" src="jquery.cookie.js"></script>

</head>

<body>

<style type="text/css">
#centralNotice.collapsed #editorSurvey2011 {
  display: none;
}

#editorSurvey2011 {
  position: relative;
  overflow: hidden;
  margin-bottom: 0.5em !important;
  background-color: #d7e4fa;
  background-repeat: repeat-x;
  border: solid 1px #a7d7f9; 
  display: none;
}

#editorSurvey2011-content {
  position:relative;
  padding: 20px;
  text-align: center;
}

#editorSurvey2011-logo {
  position: absolute;
  top: 20px;
  left: 25px;
  background-image: url(http:/media/wikipedia/commons/thumb/1/12/Wikimedia_logo_text_RGB.svg/60px-Wikimedia_logo_text_RGB.svg.png);
  height: 60px;
  width: 60px;
  background-repeat: no-repeat;
}

#editorSurvey2011 #cn-toggle-box {
  position: absolute;
  z-index: 98;
  top: 0px;
  right: 0px;
  float: right;
  font-size: 0em;
}
</style>

<div id="editorSurvey2011" style="display:none">
	<div id="editorSurvey2011-logo"> </div>
	<div id="editorSurvey2011-content">
		<!-- TODO: replace by localized {{{BannerHtml}}} -->
		<span style="font-size: 1em;line-height: 1.5em;">
			<a id="editorSurveyLink" target="_blank" href="http://survey.wikipediaresearch.org/?a=3&b=">
				<b>How satisfied are you with Wikipedia? <u>Your</u> feedback is important!</b>
				<br/>As a thank-you you get a chance of winning a Wikipedia T-shirt.
				<br/>Click here to participate in the survey!
			</a>
		</span>
	</div>
	<div id="cn-toggle-box">
		<a id="editorSurveyClose" href="#">
			<img border="0" src="http://bits.wikimedia.org/skins-1.17/common/images/closewindow.png" alt="Close" />
		</a>
	</div>
</div>

<script type="text/javascript">

const constSamplingRate = 1 / 1; //<!-- TODO: replace by localized {{{SamplingRate}}} -->
const constDisplayTimeSpan = 3 ; //<!-- TODO: replace by localized {{{DisplayTimeSpan}}} -->
 
const constDone = 'done';
const constTodo = 'todo';
 
$(document).ready( function() 
{
	wmdeslog( '$(document).ready' );

	// If the survey should not be hidden...
	if ( $.cookie( 'surveyStatus' ) != constDone ) 
	{
		initSurveyIfNeeded();
	}
} );
 
function initSurveyIfNeeded() 
{
	wmdeslog( 'initSurveyIfNeeded' );

	// If the users has been picked to participate in the survey
	if ( $.cookie( 'surveyStatus' ) == constTodo ) 
	{
		var startTime = $.cookie( 'surveyStartTime' );

		// If the start of the survey is set, display it when still within 5 mins, otherwise set done.
		if ( startTime != null ) 
		{
				if ( parseInt( startTime ) + ( 1000*60* constDisplayTimeSpan ) > (new Date()).getTime() ) 
				{
					displaySurvey();
				}
				else 
				{
					setSurveyStatus( constDone );
				}
		}	
		// If the start of the survey is not set, check for the right page (first page that is not an "action" page)
		else if ( window.location.toString().indexOf( 'action=' ) == -1 ) 
		{
			$.cookie( 'surveyStartTime', (new Date()).getTime().toString(), { 'expires': 31 /* days */, 'path': '/' } );

			// Notice for WMF reviewer: Would it possible to use the WMF tracker?
			$('head').append('<link rel="stylesheet" href="http://wikimediafoundation.org/tracker/bannerImpression.php?req=css&surveyView=1" type="text/css" />');

			displaySurvey();
		}
	}
	else 
	{
		// If the user is an editor, do lottery.
		if ( window.location.toString().indexOf( 'action=edit' ) != -1 ) 
		{
			var selectionSize = constSamplingRate ; 
			// If the user wins the lottery, set DisplayTodo
			if ( Math.random() < selectionSize ) 
			{
				setSurveyStatus( constTodo );
			} 
			// If the user loses, set done.
			else 
			{
				setSurveyStatus( constDone );
			}
		}
		// (If the user is not an editor, do nothing.)
	}
}
 
function setSurveyStatus( status ) 
{
	wmdeslog( 'setSurveyStatus: ' + status );
	$.cookie( 'surveyStatus', status, { 'expires': 31 /* days */, 'path': '/' } );
}

function displaySurvey() 
{
	wmdeslog( 'displaySurvey' );

	$( '#editorSurveyLink' ).click( onSurveyLinkClick );
	$( '#editorSurveyClose' ).click( onSurveyCloseClick );

	$( '#editorSurvey2011' ).show();
}

var isFirstClick = true;

function onSurveyLinkClick() 
{
	wmdeslog( 'onSurveyLinkClick' );
	if ( isFirstClick )
	{
		wmdeslog( 'onSurveyLinkClick - first click' );
		setSurveyStatus(constDone);

		var sender = $( this );
		sender.attr( 'href', sender.attr( 'href' ) + Math.random().toString().substring(2));

		isFirstClick = false;
	}
 	return true;
}

function onSurveyCloseClick()
{
	$( '#editorSurvey2011' ).hide();
	setSurveyStatus( constDone );
}

function wmdeslog( message ) {
	//console.log( 'WMDE survey: ' + message );
}

</script>

</body>

</html>