Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php |
— | — | @@ -16,6 +16,7 @@ |
17 | 17 | array( 'src' => 'Resources/jquery.textSelection.js', 'version' => 1 ), |
18 | 18 | array( 'src' => 'Resources/jquery.cookie.js', 'version' => 1 ), |
19 | 19 | array( 'src' => 'Resources/jquery.async.js', 'version' => 1 ), |
| 20 | + array( 'src' => 'Resources/jquery.browser.js', 'version' => 1 ), |
20 | 21 | ); |
21 | 22 | |
22 | 23 | |
Index: trunk/extensions/UsabilityInitiative/OptIn/OptIn.php |
— | — | @@ -17,7 +17,7 @@ |
18 | 18 | |
19 | 19 | /* Configuration */ |
20 | 20 | |
21 | | -$wgOptInStyleVersion = 0; |
| 21 | +$wgOptInStyleVersion = 1; |
22 | 22 | |
23 | 23 | // Preferences to set when users opt in |
24 | 24 | // array( prefname => value ) |
Index: trunk/extensions/UsabilityInitiative/OptIn/OptIn.js |
— | — | @@ -1,85 +1,3 @@ |
2 | | -/* |
3 | | - |
4 | | -jQuery Browser Plugin |
5 | | - * Version 2.3 |
6 | | - * 2008-09-17 19:27:05 |
7 | | - * URL: http://jquery.thewikies.com/browser |
8 | | - * Description: jQuery Browser Plugin extends browser detection capabilities and can assign browser selectors to CSS classes. |
9 | | - * Author: Nate Cavanaugh, Minhchau Dang, & Jonathan Neal |
10 | | - * Copyright: Copyright (c) 2008 Jonathan Neal under dual MIT/GPL license. |
11 | | - * JSLint: This javascript file passes JSLint verification. |
12 | | -*//*jslint |
13 | | - bitwise: true, |
14 | | - browser: true, |
15 | | - eqeqeq: true, |
16 | | - forin: true, |
17 | | - nomen: true, |
18 | | - plusplus: true, |
19 | | - undef: true, |
20 | | - white: true |
21 | | -*//*global |
22 | | - jQuery |
23 | | -*/ |
24 | | - |
25 | | -(function ($) { |
26 | | - $.browserTest = function (a, z) { |
27 | | - var u = 'unknown', x = 'X', m = function (r, h) { |
28 | | - for (var i = 0; i < h.length; i = i + 1) { |
29 | | - r = r.replace(h[i][0], h[i][1]); |
30 | | - } |
31 | | - |
32 | | - return r; |
33 | | - }, c = function (i, a, b, c) { |
34 | | - var r = { |
35 | | - name: m((a.exec(i) || [u, u])[1], b) |
36 | | - }; |
37 | | - |
38 | | - r[r.name] = true; |
39 | | - |
40 | | - r.version = (c.exec(i) || [x, x, x, x])[3]; |
41 | | - |
42 | | - if (r.name.match(/safari/) && r.version > 400) { |
43 | | - r.version = '2.0'; |
44 | | - } |
45 | | - |
46 | | - if (r.name === 'presto') { |
47 | | - r.version = ($.browser.version > 9.27) ? 'futhark' : 'linear_b'; |
48 | | - } |
49 | | - r.versionNumber = parseFloat(r.version, 10) || 0; |
50 | | - r.versionX = (r.version !== x) ? (r.version + '').substr(0, 1) : x; |
51 | | - r.className = r.name + r.versionX; |
52 | | - |
53 | | - return r; |
54 | | - }; |
55 | | - |
56 | | - a = (a.match(/Opera|Navigator|Minefield|KHTML|Chrome/) ? m(a, [ |
57 | | - [/(Firefox|MSIE|KHTML,\slike\sGecko|Konqueror)/, ''], |
58 | | - ['Chrome Safari', 'Chrome'], |
59 | | - ['KHTML', 'Konqueror'], |
60 | | - ['Minefield', 'Firefox'], |
61 | | - ['Navigator', 'Netscape'] |
62 | | - ]) : a).toLowerCase(); |
63 | | - |
64 | | - $.browser = $.extend((!z) ? $.browser : {}, c(a, /(camino|chrome|firefox|netscape|konqueror|lynx|msie|opera|safari)/, [], /(camino|chrome|firefox|netscape|netscape6|opera|version|konqueror|lynx|msie|safari)(\/|\s)([a-z0-9\.\+]*?)(\;|dev|rel|\s|$)/)); |
65 | | - |
66 | | - $.layout = c(a, /(gecko|konqueror|msie|opera|webkit)/, [ |
67 | | - ['konqueror', 'khtml'], |
68 | | - ['msie', 'trident'], |
69 | | - ['opera', 'presto'] |
70 | | - ], /(applewebkit|rv|konqueror|msie)(\:|\/|\s)([a-z0-9\.]*?)(\;|\)|\s)/); |
71 | | - |
72 | | - $.os = { |
73 | | - name: (/(win|mac|linux|sunos|solaris|iphone)/.exec(navigator.platform.toLowerCase()) || [u])[0].replace('sunos', 'solaris') |
74 | | - }; |
75 | | - |
76 | | - if (!z) { |
77 | | - $('html').addClass([$.os.name, $.browser.name, $.browser.className, $.layout.name, $.layout.className].join(' ')); |
78 | | - } |
79 | | - }; |
80 | | - |
81 | | - $.browserTest(navigator.userAgent); |
82 | | -})(jQuery); |
83 | | - |
84 | 2 | /* JavaScript for OptIn extension */ |
85 | 3 | |
86 | 4 | $( document ).ready( function() { |
— | — | @@ -99,11 +17,54 @@ |
100 | 18 | $( '.optin-resolution-y' ).val( screen.height ); |
101 | 19 | // Hide the fields? |
102 | 20 | } |
103 | | - /* |
104 | | - * We should probably refactor the code above and make it a jquery plugin |
105 | | - $.browser.name // String like "firefox" |
106 | | - $.browser.versionNumber // Floating point number like 3.5 |
107 | | - $.os.name // String like "mac" |
108 | | - // More info about usage: http://jquery.thewikies.com/browser |
109 | | - */ |
| 21 | + // Detect browser and version |
| 22 | + // BEWARE: this depends on the order of browsers in $wgOptInSurvey |
| 23 | + var browserIndex = -1; |
| 24 | + switch ( $.browser.name ) { |
| 25 | + case 'msie': |
| 26 | + browserIndex = $.browser.versionNumber - 5; |
| 27 | + break; |
| 28 | + case 'firefox': |
| 29 | + browserIndex = $.browser.versionNumber + 3; |
| 30 | + break; |
| 31 | + case 'chrome': |
| 32 | + browserIndex = $.browser.versionNumber + 7; |
| 33 | + break; |
| 34 | + case 'safari': |
| 35 | + browserIndex = $.browser.versionNumber + 7; |
| 36 | + break; |
| 37 | + case 'opera': |
| 38 | + if ( parseInt( $.browser.versionNumber ) == 9 ) { |
| 39 | + if ( $.browser.version.substr( 0, 3 ) == '9.5' ) |
| 40 | + browserIndex = 13; |
| 41 | + else |
| 42 | + browserIndex = 12; |
| 43 | + } else if ( parseInt( $.browser.versionNumber ) == 10 ) |
| 44 | + browserIndex = 14; |
| 45 | + break; |
| 46 | + } |
| 47 | + |
| 48 | + var osIndex = -1; |
| 49 | + switch ( $.os.name ) { |
| 50 | + case 'win': |
| 51 | + // Select Windows XP, can't tell the difference with Vista |
| 52 | + osIndex = 0; |
| 53 | + break; |
| 54 | + case 'mac': |
| 55 | + osIndex = 2; |
| 56 | + break; |
| 57 | + case 'linux': |
| 58 | + osIndex = 3; |
| 59 | + break; |
| 60 | + } |
| 61 | + |
| 62 | + if ( browserIndex == -1 ) |
| 63 | + $( '#survey-1' ).val( 'other' ); |
| 64 | + else |
| 65 | + $( '#survey-1' ).val( parseInt( browserIndex ) ); |
| 66 | + if ( osIndex == -1 ) |
| 67 | + $( '#survey-2' ).val( 'other' ); |
| 68 | + else |
| 69 | + $( '#survey-2' ).val( osIndex ); |
| 70 | + |
110 | 71 | }); |
\ No newline at end of file |
Index: trunk/extensions/UsabilityInitiative/Resources/jquery.browser.js |
— | — | @@ -0,0 +1,81 @@ |
| 2 | +/*
|
| 3 | +
|
| 4 | +jQuery Browser Plugin
|
| 5 | + * Version 2.3
|
| 6 | + * 2008-09-17 19:27:05
|
| 7 | + * URL: http://jquery.thewikies.com/browser
|
| 8 | + * Description: jQuery Browser Plugin extends browser detection capabilities and can assign browser selectors to CSS classes.
|
| 9 | + * Author: Nate Cavanaugh, Minhchau Dang, & Jonathan Neal
|
| 10 | + * Copyright: Copyright (c) 2008 Jonathan Neal under dual MIT/GPL license.
|
| 11 | + * JSLint: This javascript file passes JSLint verification.
|
| 12 | +*//*jslint
|
| 13 | + bitwise: true,
|
| 14 | + browser: true,
|
| 15 | + eqeqeq: true,
|
| 16 | + forin: true,
|
| 17 | + nomen: true,
|
| 18 | + plusplus: true,
|
| 19 | + undef: true,
|
| 20 | + white: true
|
| 21 | +*//*global
|
| 22 | + jQuery
|
| 23 | +*/
|
| 24 | +
|
| 25 | +(function ($) {
|
| 26 | + $.browserTest = function (a, z) {
|
| 27 | + var u = 'unknown', x = 'X', m = function (r, h) {
|
| 28 | + for (var i = 0; i < h.length; i = i + 1) {
|
| 29 | + r = r.replace(h[i][0], h[i][1]);
|
| 30 | + }
|
| 31 | +
|
| 32 | + return r;
|
| 33 | + }, c = function (i, a, b, c) {
|
| 34 | + var r = {
|
| 35 | + name: m((a.exec(i) || [u, u])[1], b)
|
| 36 | + };
|
| 37 | +
|
| 38 | + r[r.name] = true;
|
| 39 | +
|
| 40 | + r.version = (c.exec(i) || [x, x, x, x])[3];
|
| 41 | +
|
| 42 | + if (r.name.match(/safari/) && r.version > 400) {
|
| 43 | + r.version = '2.0';
|
| 44 | + }
|
| 45 | +
|
| 46 | + if (r.name === 'presto') {
|
| 47 | + r.version = ($.browser.version > 9.27) ? 'futhark' : 'linear_b';
|
| 48 | + }
|
| 49 | + r.versionNumber = parseFloat(r.version, 10) || 0;
|
| 50 | + r.versionX = (r.version !== x) ? (r.version + '').substr(0, 1) : x;
|
| 51 | + r.className = r.name + r.versionX;
|
| 52 | +
|
| 53 | + return r;
|
| 54 | + };
|
| 55 | +
|
| 56 | + a = (a.match(/Opera|Navigator|Minefield|KHTML|Chrome/) ? m(a, [
|
| 57 | + [/(Firefox|MSIE|KHTML,\slike\sGecko|Konqueror)/, ''],
|
| 58 | + ['Chrome Safari', 'Chrome'],
|
| 59 | + ['KHTML', 'Konqueror'],
|
| 60 | + ['Minefield', 'Firefox'],
|
| 61 | + ['Navigator', 'Netscape']
|
| 62 | + ]) : a).toLowerCase();
|
| 63 | +
|
| 64 | + $.browser = $.extend((!z) ? $.browser : {}, c(a, /(camino|chrome|firefox|netscape|konqueror|lynx|msie|opera|safari)/, [], /(camino|chrome|firefox|netscape|netscape6|opera|version|konqueror|lynx|msie|safari)(\/|\s)([a-z0-9\.\+]*?)(\;|dev|rel|\s|$)/));
|
| 65 | +
|
| 66 | + $.layout = c(a, /(gecko|konqueror|msie|opera|webkit)/, [
|
| 67 | + ['konqueror', 'khtml'],
|
| 68 | + ['msie', 'trident'],
|
| 69 | + ['opera', 'presto']
|
| 70 | + ], /(applewebkit|rv|konqueror|msie)(\:|\/|\s)([a-z0-9\.]*?)(\;|\)|\s)/);
|
| 71 | +
|
| 72 | + $.os = {
|
| 73 | + name: (/(win|mac|linux|sunos|solaris|iphone)/.exec(navigator.platform.toLowerCase()) || [u])[0].replace('sunos', 'solaris')
|
| 74 | + };
|
| 75 | +
|
| 76 | + if (!z) {
|
| 77 | + $('html').addClass([$.os.name, $.browser.name, $.browser.className, $.layout.name, $.layout.className].join(' '));
|
| 78 | + }
|
| 79 | + };
|
| 80 | +
|
| 81 | + $.browserTest(navigator.userAgent);
|
| 82 | +})(jQuery);
|