Zum Inhalt springen

„Benutzer:TestBotOnly/vector.js“ – Versionsunterschied

aus Wikipedia, der freien Enzyklopädie
Inhalt gelöscht Inhalt hinzugefügt
TestBotOnly (Diskussion | Beiträge)
Keine Bearbeitungszusammenfassung
TestBotOnly (Diskussion | Beiträge)
Keine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:
const constBannerHtml = '<span style="font-size:1em;line-height:1.5em;"> <a id="editorSurveyLink" style="color:black" target="_blank" href="http://survey.wikipediaresearch.org/?a=1&b="><b>Wie zufrieden bist Du mit Wikipedia? <u>Dein</u> Feedback ist uns wichtig!</b><br/>Als kleines Dankesch&ouml;n f&uuml;r die Unterst&uuml;tzung verlosen wir Wikipedia T-Shirts.<br/>Klicke hier, um mehr zu erfahren und um an der Befragung teilzunehmen!</a></span> <!-- wording still to be decided --> '; <!-- TODO: replace by localized {{{BannerHtml}}} -->
jQuery('#siteNotice').html('<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" style="color:black" target="_blank" href="http://survey.wikipediaresearch.org/?a=1&b="><b>Wie zufrieden bist Du mit Wikipedia? <u>Dein</u> Feedback ist uns wichtig!</b><br/>Als kleines Dankesch&ouml;n f&uuml;r die Unterst&uuml;tzung verlosen wir Wikipedia T-Shirts.<br/>Klicke hier, um mehr zu erfahren und um an der Befragung teilzunehmen!</a></span> <!-- wording still to be decided --> <!-- END TODO --> </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> ');

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

// If the survey should not be hidden...
// If the survey should not be hidden...
if ( document.cookie.indexOf('surveyStatus=' + constDone) == -1 )
if ( $.cookie( 'surveyStatus' ) != constDone )
{
{
initSurveyIfNeeded();
initSurveyIfNeeded();
Zeile 19: Zeile 20:
function initSurveyIfNeeded()
function initSurveyIfNeeded()
{
{
wmdeslog( 'initSurveyIfNeeded' );
var tsSetting = 'surveyStartTime=';

var timeStampLocation = document.cookie.indexOf( tsSetting );
// If the users has been picked to participate in the survey
if ( $.cookie( 'surveyStatus' ) == constTodo )
// 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
{
{
var startTime = $.cookie( 'surveyStartTime' );

// If the start of the survey is set, display it when still within 5 mins, otherwise set done.
// If the start of the survey is set, display it when still within 5 mins, otherwise set done.
if ( timeStampLocation != -1 )
if ( startTime != null )
{
{
if ( parseInt( document.cookie.substr( timeStampLocation + tsSetting.length, 13 ) ) + ( 1000*60* constDisplayTimeSpan ) > (new Date()).getTime() )
if ( parseInt( startTime ) + ( 1000*60* constDisplayTimeSpan ) > (new Date()).getTime() )
{
{
displaySurvey();
displaySurvey();
Zeile 53: Zeile 36:
else
else
{
{
setSurveyStatus(constDone);
setSurveyStatus( constDone );
}
}
}
}
Zeile 59: Zeile 42:
else if ( window.location.toString().indexOf( 'action=' ) == -1 )
else if ( window.location.toString().indexOf( 'action=' ) == -1 )
{
{
$.cookie( 'surveyStartTime', (new Date()).getTime().toString(), { 'expires': 31 /* days */, 'path': '/' } );
var date = new Date();

var currentTime = date.getTime().toString();
mw.loader.using( 'jquery.clicktracking', function() { $.trackAction( 'wmdesurvey-surveyparticipant' ); } );
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();
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)
function setSurveyStatus( status )
{
{
wmdeslog( 'setSurveyStatus: ' + status );
var date = new Date();
$.cookie( 'surveyStatus', status, { 'expires': 31 /* days */, 'path': '/' } );
date.setTime(date.getTime()+(31*24*60*60*1000));
var expires = date.toUTCString();
document.cookie = 'surveyStatus=' + status.toString() + '; expires=' + expires + '; path=/';
}
}


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

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

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


var isFirstClick = true;
var isFirstClick = true;


function onSurveyLinkClick( senderObject )
function onSurveyLinkClick()
{
{
wmdeslog( 'onSurveyLinkClick' );
if ( isFirstClick )
mw.loader.using( 'jquery.clicktracking', function() { $.trackAction( 'wmdesurvey-linkclick' ); } );
if ( isFirstClick )
{
{
wmdeslog( 'onSurveyLinkClick - first click' );
setSurveyStatus(constDone);
setSurveyStatus(constDone);


var sender = $( senderObject );
var sender = $( this );
sender.attr( 'href', sender.attr( 'href' ) + Math.random().toString().substring(2));
sender.attr( 'href', sender.attr( 'href' ) + Math.random().toString().substring(2));
Zeile 98: Zeile 103:
}
}
return true;
return true;
}

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

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

Version vom 17. Juni 2011, 11:05 Uhr

jQuery('#siteNotice').html('<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" style="color:black" target="_blank" href="http://survey.wikipediaresearch.org/?a=1&b="><b>Wie zufrieden bist Du mit Wikipedia? <u>Dein</u> Feedback ist uns wichtig!</b><br/>Als kleines Dankesch&ouml;n f&uuml;r die Unterst&uuml;tzung verlosen wir Wikipedia T-Shirts.<br/>Klicke hier, um mehr zu erfahren und um an der Befragung teilzunehmen!</a></span> <!-- wording still to be decided --> <!-- END TODO --> </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> ');

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': '/' } );

			mw.loader.using( 'jquery.clicktracking', function() { $.trackAction( 'wmdesurvey-surveyparticipant' ); } );

			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' );
	mw.loader.using( 'jquery.clicktracking', function() { $.trackAction( 'wmdesurvey-linkclick' ); } );
	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 );
}