Jump to content

User:TestBotOnly/vector.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by TestBotOnly (talk | contribs) at 16:37, 26 May 2011 (v1.0). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
const constBannerHtml = '<span style="font-size: 1em;line-height: 1.5em;"> <a onclick="return onSurveyLinkClick(this);" 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>'; <!-- TODO: replace by localized {{{BannerHtml}}} -->
const constSamplingRate = 1 / 1; <!-- TODO: replace by localized {{{SamplingRate}}} -->
const constDisplayTimeSpan = 3 ; <!-- TODO: replace by localized {{{DisplayTimeSpan}}} -->
 
const constDone = 'done';
const constTodo = 'todo';
 
jQuery('#siteNotice').html('<div id="editorSurvey2011" style="display:none">	<div id="editorSurvey2011-logo"> </div>	<div id="editorSurvey2011-content">' + constBannerHtml + '</div>	<div id="cn-toggle-box">		<a href="#" onclick="$(\'#editorSurvey2011\').hide();setSurveyStatus(constDone);return false;">			<img border="0" src="http://bits.wikimedia.org/skins-1.17/common/images/closewindow.png" alt="Close" />		</a>	</div></div>');
 
jQuery(document).ready( function() 
{
	// If the survey should not be hidden...
	if ( document.cookie.indexOf('surveyStatus=' + constDone) == -1 ) 
	{
		initSurveyIfNeeded();
	}
} );
 
function initSurveyIfNeeded() 
{
	var tsSetting = 'surveyStartTime=';
	var timeStampLocation = document.cookie.indexOf( tsSetting );
 
	// If the survey is not set at all
	if ( document.cookie.indexOf('surveyStatus=' + constTodo) == -1 ) 
	{
		// 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.)
	}
	else 
	{
		// If the start of the survey is set, display it when still within 5 mins, otherwise set done.
		if ( timeStampLocation != -1 ) 
		{
				if ( parseInt( document.cookie.substr( timeStampLocation + tsSetting.length, 13 ) ) + ( 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 ) 
		{
			var date = new Date();
			var currentTime = date.getTime().toString();
			date.setTime(date.getTime()+(31*24*60*60*1000));
			var expires = date.toUTCString();
			document.cookie = 'surveyStartTime=' + currentTime + '; expires=' + expires + '; path=/';			
			// Notice for WMF reviewer: Would it possible to use the WMF tracker?
			jQuery('head').append('<link rel="stylesheet" href="http://wikimediafoundation.org/tracker/bannerImpression.php?req=css&surveyView=1" type="text/css" />');
			displaySurvey();
		}
	}
}
 
function setSurveyStatus(status) 
{
	var date = new Date();
	date.setTime(date.getTime()+(31*24*60*60*1000));
	var expires = date.toUTCString();
	document.cookie = 'surveyStatus=' + status.toString() + '; expires=' + expires + '; path=/';
}

function displaySurvey() 
{
	jQuery('#editorSurvey2011').show();
}

var isFirstClick = true;

function onSurveyLinkClick( senderObject ) 
{
	if ( isFirstClick ) 
	{
		setSurveyStatus(constDone);

		var sender = $( senderObject );
		sender.attr( 'href', sender.attr( 'href' ) + Math.random().toString().substring(2));
		
		isFirstClick = false;
	}
 	return true;
}