r112158 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112157‎ | r112158 | r112159 >
Date:22:33, 22 February 2012
Author:krinkle
Status:ok
Tags:
Comment:
[MarkAsHelpful] js/css clean up
* Store main object in mw.markAsHelpful instead of ambiguous mw.mah (hey Mark!), keeping local 'mah' alias as it is.
* Aliasing 'mw' from global 'mediaWiki' object locally.
* Whitespace / conventions / documentation
Modified paths:
  • /trunk/extensions/MarkAsHelpful/modules/ext.markAsHelpful/ext.markAsHelpful.js (modified) (history)

Diff [purge]

Index: trunk/extensions/MarkAsHelpful/modules/ext.markAsHelpful/ext.markAsHelpful.js
@@ -4,91 +4,107 @@
55 * @author Rob Moen, 2011
66 */
77
8 -(function( $ ) {
 8+( function ( $, mw ) {
99
10 - var mah = mw.mah = {
 10+ var mah = mw.markAsHelpful = {
1111 loadedItems: [],
12 - selector: '[class^=markashelpful]', //class of element(s) to apply MarkAsHelpful to.
 12+ // Class of element(s) to apply MarkAsHelpful to.
 13+ selector: '[class^="markashelpful"]',
1314
14 - init: function() {
 15+ init: function () {
1516 var props, thisItem;
16 - $( mah.selector ).each( function ( i, e ) {
17 - props = mah.getItemProperties( $(this) );
18 - thisItem = props.type + props.item; //create an item reference to place in the loaded items array.
 17+
 18+ $( mah.selector ).each( function ( i, el ) {
 19+ props = mah.getItemProperties( $(el) );
 20+ // Create an item reference to place in the loaded items array.
 21+ thisItem = props.type + props.item;
1922
20 - //load once per type+id because user can copy / paste element on the talk page and load the same item many times.
 23+ // Load once per type+id because user can copy / paste element on the talk page
 24+ // and load the same item many times.
2125 if( $.inArray( thisItem, mah.loadedItems ) === -1 ) {
2226 mah.loadedItems.push( thisItem );
23 - mah.loadItem( $( this ) );
 27+ mah.loadItem( $( el ) );
2428 }
2529 });
2630 },
27 - /*
 31+
 32+ /**
2833 * Return object of item properties
 34+ * @param $item
2935 */
30 - getItemProperties: function( $item ) {
31 - var tag = $item.attr( 'class' ),
32 - //item properties are stored in classname to prevent parser from stripping out non html 5 objects.
33 - //(eg data-markashelpful-item)
34 - properties = {
35 - 'item': tag.split( '-' )[2], // item id
36 - 'type': tag.split( '-' )[1] // item type (eg, mbresponse)
37 - };
38 - return properties;
 36+ getItemProperties: function ( $item ) {
 37+ var tag, props;
 38+
 39+ tag = $item.attr( 'class' );
 40+ // Item properties are stored in classname to prevent parser from stripping
 41+ // out non html 5 objects. (eg. data-markashelpful-item)
 42+ props = {
 43+ // item id
 44+ item: tag.split( '-' )[2],
 45+ // item type (eg, mbresponse)
 46+ type: tag.split( '-' )[1]
 47+ };
 48+ return props;
3949 },
40 - /*
 50+
 51+ /**
4152 * Load the current state of the MarkAsHelpful item
 53+ * @param $item
4254 */
43 - loadItem: function( $item ) {
44 - var props = mah.getItemProperties( $item ),
45 - request = {
46 - 'action': 'getmarkashelpfulitem',
47 - 'item': props.item,
48 - 'type': props.type,
49 - 'page': mw.config.get( 'wgPageName' ),
50 - 'format': 'json'
51 - };
 55+ loadItem: function ( $item ) {
 56+ var props, request;
5257
 58+ props = mah.getItemProperties( $item );
 59+ request = {
 60+ format: 'json',
 61+ action: 'getmarkashelpfulitem',
 62+ item: props.item,
 63+ type: props.type,
 64+ page: mw.config.get( 'wgPageName' )
 65+ };
 66+
5367 $.ajax({
5468 type: 'POST',
5569 url: mw.util.wikiScript('api'),
5670 cache: false,
5771 data: request,
58 - success: function( data ) {
 72+ success: function ( data ) {
 73+ var $content;
5974
6075 if ( data.getmarkashelpfulitem &&
61 - data.getmarkashelpfulitem.result == 'success' &&
 76+ data.getmarkashelpfulitem.result === 'success' &&
6277 data.getmarkashelpfulitem.formatted
6378 ) {
64 - var $content = $( data.getmarkashelpfulitem.formatted );
 79+ $content = $( data.getmarkashelpfulitem.formatted );
6580 $item.html( $content );
66 - } else {
67 - // Failure, do nothing to the item for now
6881 }
 82+ // else: Failure, do nothing to the item for now else
6983 },
70 - error: function ( data ) {
 84+ error: function () {
7185 // Failure, do nothing to the item for now
7286 },
7387 dataType: 'json'
7488 });
7589
7690 },
77 - /*
 91+
 92+ /**
7893 * API call to mark or unmark an item as helpful.
7994 */
80 - markItem: function( $clicked, action ) {
81 - var $item = $clicked.parent().parent(),
82 - props = mah.getItemProperties( $item ),
83 - clientData = $.client.profile(),
84 - request;
 95+ markItem: function ( $clicked, action ) {
 96+ var $item, props, clientData, request;
 97+
 98+ $item = $clicked.parent().parent();
 99+ props = mah.getItemProperties( $item );
 100+ clientData = $.client.profile();
85101 props.mahaction = action;
86102 request = $.extend( {
87 - 'action': 'markashelpful',
88 - 'page': mw.config.get( 'wgPageName' ),
89 - 'useragent': clientData.name + '/' + clientData.versionNumber,
90 - 'system': clientData.platform,
91 - 'token': mw.user.tokens.get( 'editToken' ),
92 - 'format': 'json'
 103+ action: 'markashelpful',
 104+ format: 'json',
 105+ page: mw.config.get( 'wgPageName' ),
 106+ useragent: clientData.name + '/' + clientData.versionNumber,
 107+ system: clientData.platform,
 108+ token: mw.user.tokens.get( 'editToken' )
93109 }, props );
94110
95111 $.ajax( {
@@ -105,22 +121,24 @@
106122
107123 // Some live events for the different modes
108124
109 - $(document).ready( function() {
110 - /*
 125+ $(document).ready( function () {
 126+
 127+ /**
111128 * Click Event for marking an item as helpful.
112129 */
113 - $( '.markashelpful-mark' ).live( 'click', function() {
 130+ $( '.markashelpful-mark' ).live( 'click', function () {
114131 mah.markItem( $(this), 'mark' );
115132 } );
116133
117 - /*
 134+ /**
118135 * Click Event for removing helpful status from an item.
119136 */
120 - $( '.markashelpful-undo' ).live( 'click', function() {
 137+ $( '.markashelpful-undo' ).live( 'click', function () {
121138 mah.markItem( $(this), 'unmark' );
122139 } );
123140
124141 // Initialize MarkAsHelpful
125142 mah.init();
126143 } );
127 -} ) ( jQuery );
 144+
 145+}( jQuery, mediaWiki ) );

Follow-up revisions

RevisionCommit summaryAuthorDate
r112159[MarkAsHelpful] js/css clean up...krinkle22:45, 22 February 2012

Status & tagging log