Index: trunk/extensions/UsabilityInitiative/OptIn/SpecialOptIn.php |
— | — | @@ -74,6 +74,10 @@ |
75 | 75 | } |
76 | 76 | $this->setHeaders(); |
77 | 77 | |
| 78 | + if ( $wgRequest->wasPosted() ) { |
| 79 | + // TODO: Handle AJAX request |
| 80 | + } |
| 81 | + |
78 | 82 | if ( self::isOptedIn( $wgUser ) ) { |
79 | 83 | if ( $wgRequest->getVal( 'opt' ) == 'out' ) |
80 | 84 | // Just opted out |
— | — | @@ -102,6 +106,16 @@ |
103 | 107 | if ( $wgRequest->getVal( 'opt' ) === 'in' ) { |
104 | 108 | self::optIn( $wgUser ); |
105 | 109 | $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 | + ) ); |
106 | 120 | } else if ( $wgRequest->getVal( 'opt' ) == 'feedback' ) { |
107 | 121 | if ( $wgRequest->wasPosted() ) { |
108 | 122 | $this->saveSurvey( $wgOptInFeedBackSurvey, |
Index: trunk/extensions/UsabilityInitiative/OptIn/OptIn.js |
— | — | @@ -1,41 +1,6 @@ |
2 | 2 | /* JavaScript for OptIn extension */ |
3 | 3 | |
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() { |
40 | 5 | var browserIndex = 'other'; |
41 | 6 | switch ( $.browser.name ) { |
42 | 7 | case 'msie': |
— | — | @@ -73,7 +38,46 @@ |
74 | 39 | osIndex = 'linux'; |
75 | 40 | break; |
76 | 41 | } |
| 42 | + |
| 43 | + return { browser: browserIndex, os: osIndex }; |
| 44 | +} |
77 | 45 | |
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 ); |
80 | 84 | }); |