r75653 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75652‎ | r75653 | r75654 >
Date:17:11, 29 October 2010
Author:krinkle
Status:resolved (Comments)
Tags:
Comment:
$.client has been enhanced and made easier since the initial version, may aswell be used directly (r75593)
Modified paths:
  • /trunk/phase3/resources/mediawiki.util/mediawiki.util.js (modified) (history)
  • /trunk/phase3/resources/mediawiki.util/mediawiki.util.test.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/mediawiki.util/mediawiki.util.test.js
@@ -78,14 +78,6 @@
7979 '\\.st\\{e\\}\\$st (string)');
8080 mw.test.addTest('typeof $.fn.checkboxShiftClick',
8181 'function (string)');
82 - mw.test.addTest('typeof mw.util.isBrowser( \'safari\' )',
83 - 'boolean (string)');
84 - mw.test.addTest('typeof mw.util.isLayout( \'webKit\' )',
85 - 'boolean (string)');
86 - mw.test.addTest('typeof mw.util.isPlatform( \'MAC\' )',
87 - 'boolean (string)');
88 - mw.test.addTest('typeof mw.util.isBrowserVersion( \'5\' )',
89 - 'boolean (string)');
9082 mw.test.addTest('typeof mw.util.rawurlencode',
9183 'function (string)');
9284 mw.test.addTest('mw.util.rawurlencode( \'Test: A&B/Here\' )',
Index: trunk/phase3/resources/mediawiki.util/mediawiki.util.js
@@ -15,33 +15,33 @@
1616 // Any initialisation after the DOM is ready
1717 $(function () {
1818
19 - // Populate clientProfile var
20 - mw.util.clientProfile = $.client.profile();
 19+ // Initiate jQuery.client.profile
 20+ $.client.profile();
2121
2222 // Set tooltipAccessKeyPrefix
2323
2424 // Opera on any platform
25 - if ( mw.util.isBrowser('opera') ) {
 25+ if ( $.client.profile.name == 'opera' ) {
2626 this.tooltipAccessKeyPrefix = 'shift-esc-';
2727
2828 // Chrome on any platform
29 - } else if ( mw.util.isBrowser('chrome') ) {
 29+ } else if ( $.client.profile.name == 'chrome' ) {
3030 // Chrome on Mac or Chrome on other platform ?
31 - this.tooltipAccessKeyPrefix = mw.util.isPlatform('mac') ? 'ctrl-option-' : 'alt-';
 31+ this.tooltipAccessKeyPrefix = $.client.profile.platform == 'mac' ? 'ctrl-option-' : 'alt-';
3232
3333 // Non-Windows Safari with webkit_version > 526
34 - } else if ( !mw.util.isPlatform('win') && mw.util.isBrowser('safari') && webkit_version > 526 ) {
 34+ } else if ( $.client.profile.platform !== 'win' && $.client.profile.name == 'safari' && $.client.profile.layoutVersion > 526 ) {
3535 this.tooltipAccessKeyPrefix = 'ctrl-alt-';
3636
3737 // Safari/Konqueror on any platform, or any browser on Mac (but not Safari on Windows)
38 - } else if ( !( mw.util.isPlatform('win') && mw.util.isBrowser('safari') )
39 - && ( mw.util.isBrowser('safari')
40 - || mw.util.isPlatform('mac')
41 - || mw.util.isBrowser('konqueror') ) ) {
 38+ } else if ( !( $.client.profile.platform == 'win' && $.client.profile.name == 'safari' )
 39+ && ( $.client.profile.name == 'safari'
 40+ || $.client.profile.platform == 'mac'
 41+ || $.client.profile.name == 'konqueror' ) ) {
4242 this.tooltipAccessKeyPrefix = 'ctrl-';
4343
4444 // Firefox 2.x
45 - } else if ( mw.util.isBrowser('firefox') && mw.util.isBrowserVersion('2') ) {
 45+ } else if ( $.client.profile.name == 'firefox' && $.client.profile.versionBase == '2' ) {
4646 this.tooltipAccessKeyPrefix = 'alt-shift-';
4747 }
4848
@@ -66,69 +66,7 @@
6767
6868 /* Main body */
6969
70 - // Holds result of $.client.profile()
71 - // Populated by init()
72 - 'clientProfile' : {},
73 -
7470 /**
75 - * Checks if the current browser matches
76 - *
77 - * @example mw.util.isBrowser( 'safari' );
78 - * @param String str name of a browser (case insensitive). Check jquery.client.js for possible values
79 - * @return Boolean true if the browsername matches the clients browser
80 - */
81 - 'isBrowser' : function( str ) {
82 - str = (str + '').toLowerCase();
83 - return this.clientProfile.name == str;
84 - },
85 -
86 - /**
87 - * Checks if the current layout matches
88 - *
89 - * @example mw.util.isLayout( 'webkit' );
90 - * @param String str name of a layout engine (case insensitive). Check jquery.client.js for possible values
91 - * @return Boolean true if the layout engine matches the clients browser
92 - */
93 - 'isLayout' : function( str ) {
94 - str = (str + '').toLowerCase();
95 - return this.clientProfile.layout == str;
96 - },
97 -
98 - /**
99 - * Checks if the current layout engine version matches
100 - *
101 - * @example mw.util.isLayoutVersion( 533 );
102 - * @param Number num version number of a layout engine.
103 - * @return Boolean true if the layout engine matches the clients browser
104 - */
105 - 'isLayoutVersion' : function( num ) {
106 - return this.clientProfile.layoutVersion == num;
107 - },
108 -
109 - /**
110 - * Checks if the current layout matches
111 - *
112 - * @example mw.util.isPlatform( 'mac' );
113 - * @param String str name of a platform (case insensitive). Check jquery.client.js for possible values
114 - * @return Boolean true if the platform matches the clients platform
115 - */
116 - 'isPlatform' : function( str ) {
117 - str = (str + '').toLowerCase();
118 - return this.clientProfile.platform == str;
119 - },
120 -
121 - /**
122 - * Checks if the current browser version matches
123 - *
124 - * @example mw.util.isBrowserVersion( '5' );
125 - * @param String str version number without decimals
126 - * @return Boolean true if the version number matches the clients browser
127 - */
128 - 'isBrowserVersion' : function( str ) {
129 - return this.clientProfile.versionBase === str;
130 - },
131 -
132 - /**
13371 * Encodes the string like PHP's rawurlencode
13472 *
13573 * @param String str string to be encoded

Follow-up revisions

RevisionCommit summaryAuthorDate
r75752Follow-up r75653 + replacing this. with mw.utilkrinkle22:20, 31 October 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r75593porting is_opera, is_safari_win etc. to mw.util as isBrowser('..'), isPlatfor...krinkle23:19, 27 October 2010

Comments

#Comment by Catrope (talk | contribs)   20:30, 31 October 2010
					// Initiate jQuery.client.profile
+					$.client.profile();
[...]
+					if ( $.client.profile.name == 'opera' ) {

That's not how it works. You're supposed to just use $.client.profile().name and profile() is smart enough to only to the heavy lifting once.

Status & tagging log