r109183 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109182‎ | r109183 | r109184 >
Date:18:50, 17 January 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
some js improvements suggested by Krinkle
Modified paths:
  • /trunk/extensions/EducationProgram/resources/ep.api.js (modified) (history)
  • /trunk/extensions/EducationProgram/resources/ep.instructor.js (modified) (history)
  • /trunk/extensions/EducationProgram/resources/ep.js (modified) (history)
  • /trunk/extensions/EducationProgram/resources/ep.pager.js (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/resources/ep.js
@@ -6,54 +6,58 @@
77 * @author Jeroen De Dauw <jeroendedauw at gmail dot com>
88 */
99
10 -window.educationProgram = new( function() {
11 -
12 - this.compatMode = null;
13 -
14 - this.msg = function () {
15 - // Yeah, doing it here, since "mw.loader.using( 'mediawiki.language',"
16 - // does not have mediaWiki.language loaded.
17 - if ( this.compatMode === null ) {
18 - this.compatMode = typeof window.mediaWiki.language.gender === 'undefined';
19 -
20 - if ( window.educationProgram.compatMode ) {
21 - mw.language.gender = function( gender, forms ) {
22 - if ( !forms || forms.length === 0 ) {
23 - return '';
24 - }
25 - forms = mw.language.preConvertPlural( forms, 2 );
26 - if ( gender === 'male' ) {
27 - return forms[0];
28 - }
29 - if ( gender === 'female' ) {
30 - return forms[1];
31 - }
32 - return ( forms.length === 3 ) ? forms[2] : forms[0];
33 - };
34 -
35 - mw.jqueryMsg.htmlEmitter.prototype.gender = function( nodes ) {
36 - var gender;
37 - if ( nodes[0] && nodes[0].options instanceof mw.Map ){
38 - gender = nodes[0].options.get( 'gender' );
39 - } else {
40 - gender = nodes[0];
41 - }
42 - var forms = nodes.slice(1);
43 - return this.language.gender( gender, forms );
44 - };
 10+( function ( $, mw ) {
 11+
 12+ var compatMode = undefined;
 13+
 14+ var ep = {
 15+ msg: function () {
 16+ // Yeah, doing it here, since "mw.loader.using( 'mediawiki.language',"
 17+ // does not have mediaWiki.language loaded.
 18+ if ( compatMode === undefined ) {
 19+ compatMode = window.mediaWiki.language.gender === undefined;
 20+
 21+ if ( compatMode ) {
 22+ mw.language.gender = function( gender, forms ) {
 23+ if ( !forms || forms.length === 0 ) {
 24+ return '';
 25+ }
 26+ forms = mw.language.preConvertPlural( forms, 2 );
 27+ if ( gender === 'male' ) {
 28+ return forms[0];
 29+ }
 30+ if ( gender === 'female' ) {
 31+ return forms[1];
 32+ }
 33+ return ( forms.length === 3 ) ? forms[2] : forms[0];
 34+ };
 35+
 36+ mw.jqueryMsg.htmlEmitter.prototype.gender = function( nodes ) {
 37+ var gender;
 38+ if ( nodes[0] && nodes[0].options instanceof mw.Map ){
 39+ gender = nodes[0].options.get( 'gender' );
 40+ } else {
 41+ gender = nodes[0];
 42+ }
 43+ var forms = nodes.slice(1);
 44+ return this.language.gender( gender, forms );
 45+ };
 46+ }
4547 }
 48+
 49+ if ( compatMode ) {
 50+ return gM.apply( this, arguments );
 51+ }
 52+ else {
 53+ return mw.msg.apply( this, arguments );
 54+ }
 55+ },
 56+
 57+ msge: function () {
 58+ return mw.html.escape( this.msg.apply( this, arguments ) );
4659 }
47 -
48 - if ( this.compatMode ) {
49 - return gM.apply( this, arguments );
50 - }
51 - else {
52 - return mw.msg.apply( this, arguments );
53 - }
54 - };
55 -
56 - this.msge = function () {
57 - return mw.html.escape( this.msg.apply( this, arguments ) );
58 - };
59 -
60 -} );
 60+ }
 61+
 62+ mw.educationProgram = ep;
 63+
 64+}( jQuery, mediaWiki ) );
Index: trunk/extensions/EducationProgram/resources/ep.api.js
@@ -6,9 +6,9 @@
77 * @author Jeroen De Dauw <jeroendedauw at gmail dot com>
88 */
99
10 -window.educationProgram.api = new( function() {
 10+( function ( $, mw ) {
1111
12 - this.remove = function( data, callback ) {
 12+ mw.educationProgram.remove = function( data, callback ) {
1313 var requestArgs = {
1414 'action': 'deleteeducation',
1515 'format': 'json',
@@ -29,40 +29,6 @@
3030 }
3131 );
3232 };
33 -
34 - this.instructor = function( args ) {
35 - var requestArgs = $.extend( {
36 - 'action': 'instructor',
37 - 'format': 'json',
38 - 'token': window.mw.user.tokens.get( 'editToken' )
39 - }, args );
40 -
41 - var deferred = $.Deferred();
42 -
43 - $.post(
44 - wgScriptPath + '/api.php',
45 - requestArgs,
46 - function( data ) {
47 - if ( data.hasOwnProperty( 'success' ) && data.success ) {
48 - deferred.resolve();
49 - }
50 - else {
51 - deferred.reject();
52 - }
53 - }
54 - );
55 -
56 - return deferred.promise();
57 - };
58 -
59 - this.addInstructor = function( args ) {
60 - args.subaction = 'add';
61 - return this.instructor( args );
62 - };
63 -
64 - this.removeInstructor = function( args ) {
65 - args.subaction = 'remove';
66 - return this.instructor( args );
67 - };
6833
69 -} );
 34+}( jQuery, mediaWiki ) );
 35+
Index: trunk/extensions/EducationProgram/resources/ep.instructor.js
@@ -6,8 +6,10 @@
77 * @author Jeroen De Dauw <jeroendedauw at gmail dot com>
88 */
99
10 -(function( $, mw, ep ) {
11 -
 10+(function( $, mw ) {
 11+
 12+ var ep = mw.educationProgram;
 13+
1214 $( document ).ready( function() {
1315
1416 $( '.ep-instructor-remove' ).click( function( event ) {
@@ -148,7 +150,7 @@
149151 'text': ep.msg( 'ep-instructor-add-cancel-button' ),
150152 'id': 'ep-instructor-add-cancel-button',
151153 'click': function() {
152 - $dialog.dialog( 'close' );
 154+ _this.$dialog.dialog( 'close' );
153155 }
154156 }
155157 ]
@@ -195,4 +197,4 @@
196198
197199 } );
198200
199 -})( window.jQuery, window.mediaWiki, window.educationProgram );
\ No newline at end of file
 201+})( window.jQuery, window.mediaWiki );
\ No newline at end of file
Index: trunk/extensions/EducationProgram/resources/ep.pager.js
@@ -6,8 +6,10 @@
77 * @author Jeroen De Dauw <jeroendedauw at gmail dot com>
88 */
99
10 -(function ( $, mw, ep ) {
 10+(function ( $, mw ) {
1111
 12+ var ep = mw.educationProgram;
 13+
1214 $( document ).ready( function () {
1315
1416 $( '.ep-pager-clear' ).click( function () {
@@ -101,4 +103,4 @@
102104
103105 } );
104106
105 -})( window.jQuery, window.mediaWiki, window.educationProgram );
\ No newline at end of file
 107+})( window.jQuery, window.mediaWiki );
\ No newline at end of file

Status & tagging log