r53931 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53930‎ | r53931 | r53932 >
Date:12:54, 29 July 2009
Author:catrope
Status:deferred
Tags:
Comment:
OptIn: Partial implementation of storing detected browser+OS on opt-in time using AJAX
Modified paths:
  • /trunk/extensions/UsabilityInitiative/OptIn/OptIn.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/OptIn/SpecialOptIn.php (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/OptIn/SpecialOptIn.php
@@ -74,6 +74,10 @@
7575 }
7676 $this->setHeaders();
7777
 78+ if ( $wgRequest->wasPosted() ) {
 79+ // TODO: Handle AJAX request
 80+ }
 81+
7882 if ( self::isOptedIn( $wgUser ) ) {
7983 if ( $wgRequest->getVal( 'opt' ) == 'out' )
8084 // Just opted out
@@ -102,6 +106,16 @@
103107 if ( $wgRequest->getVal( 'opt' ) === 'in' ) {
104108 self::optIn( $wgUser );
105109 $wgOut->addWikiMsg( 'optin-success-in' );
 110+
 111+ global $wgJsMimeType, $wgOptInStyleVersion;
 112+ UsabilityInitiativeHooks::initialize();
 113+ UsabilityInitiativeHooks::addScript( 'OptIn/OptIn.js',
 114+ $wgOptInStyleVersion );
 115+ $url = $this->getTitle()->getFullURL();
 116+ $wgOut->addHTML( Xml::tags( 'script',
 117+ array( 'type' => $wgJsMimeType ),
 118+ "$(document).ready(function() { $.post( \"$url\", optInDetectBrowserOS() ); } );"
 119+ ) );
106120 } else if ( $wgRequest->getVal( 'opt' ) == 'feedback' ) {
107121 if ( $wgRequest->wasPosted() ) {
108122 $this->saveSurvey( $wgOptInFeedBackSurvey,
Index: trunk/extensions/UsabilityInitiative/OptIn/OptIn.js
@@ -1,41 +1,6 @@
22 /* JavaScript for OptIn extension */
33
4 -$( document ).ready( function() {
5 - $( '.optin-other-select' ).parent().hide();
6 - $( 'select.optin-need-other' ).change( function() {
7 - if( $(this).val() == 'other' )
8 - $( '#' + $(this).attr( 'id' ) + '-other' ).parent().slideDown( 'fast' );
9 - else
10 - $( '#' + $(this).attr( 'id' ) + '-other' ).parent().slideUp( 'fast' );
11 - });
12 -
13 - $( '.optin-other-radios, .optin-other-checks' ).click( function() {
14 - $(this).prev().prev().attr( 'checked', true );
15 - });
16 -
17 - $( '.survey-ifyes, .survey-ifno' ).hide();
18 - $( '.survey-yes, .survey-no' ).change( function() {
19 - yesrow = $( '#' + $(this).attr( 'name' ) + '-ifyes-row' );
20 - norow = $( '#' + $(this).attr( 'name' ) + '-ifno-row' );
21 - if( $(this).is( '.survey-yes:checked' ) ) {
22 - yesrow.slideDown( 'fast' );
23 - norow.slideUp( 'fast' );
24 - } else if( $(this).is( '.survey-no:checked' ) ) {
25 - yesrow.slideUp( 'fast' );
26 - norow.slideDown( 'fast' );
27 - }
28 - });
29 - // Load initial state
30 - $( '.survey-yes, .survey-no' ).change();
31 -
32 - // Detect screen resolution
33 - if ( screen.width && screen.height ) {
34 - $( '.optin-resolution-x' ).val( screen.width );
35 - $( '.optin-resolution-y' ).val( screen.height );
36 - // Hide the fields?
37 - }
38 - // Detect browser and version
39 - // BEWARE: this depends on the order of browsers in $wgOptInSurvey
 4+function optInDetectBrowserOS() {
405 var browserIndex = 'other';
416 switch ( $.browser.name ) {
427 case 'msie':
@@ -73,7 +38,46 @@
7439 osIndex = 'linux';
7540 break;
7641 }
 42+
 43+ return { browser: browserIndex, os: osIndex };
 44+}
7745
78 - $( '#survey-browser' ).val( browserIndex );
79 - $( '#survey-os' ).val( osIndex );
 46+$( document ).ready( function() {
 47+ $( '.optin-other-select' ).parent().hide();
 48+ $( 'select.optin-need-other' ).change( function() {
 49+ if( $(this).val() == 'other' )
 50+ $( '#' + $(this).attr( 'id' ) + '-other' ).parent().slideDown( 'fast' );
 51+ else
 52+ $( '#' + $(this).attr( 'id' ) + '-other' ).parent().slideUp( 'fast' );
 53+ });
 54+
 55+ $( '.optin-other-radios, .optin-other-checks' ).click( function() {
 56+ $(this).prev().prev().attr( 'checked', true );
 57+ });
 58+
 59+ $( '.survey-ifyes, .survey-ifno' ).hide();
 60+ $( '.survey-yes, .survey-no' ).change( function() {
 61+ yesrow = $( '#' + $(this).attr( 'name' ) + '-ifyes-row' );
 62+ norow = $( '#' + $(this).attr( 'name' ) + '-ifno-row' );
 63+ if( $(this).is( '.survey-yes:checked' ) ) {
 64+ yesrow.slideDown( 'fast' );
 65+ norow.slideUp( 'fast' );
 66+ } else if( $(this).is( '.survey-no:checked' ) ) {
 67+ yesrow.slideUp( 'fast' );
 68+ norow.slideDown( 'fast' );
 69+ }
 70+ });
 71+ // Load initial state
 72+ $( '.survey-yes, .survey-no' ).change();
 73+
 74+ // Detect screen resolution
 75+ if ( screen.width && screen.height ) {
 76+ $( '.optin-resolution-x' ).val( screen.width );
 77+ $( '.optin-resolution-y' ).val( screen.height );
 78+ // Hide the fields?
 79+ }
 80+
 81+ var detected = optInDetectBrowserOS();
 82+ $( '#survey-browser' ).val( detected.browser );
 83+ $( '#survey-os' ).val( detected.os );
8084 });

Status & tagging log