https://www.mediawiki.org/wiki/Special:Code/MediaWiki/112158
Revision: 112158
Author: krinkle
Date: 2012-02-22 22:33:49 +0000 (Wed, 22 Feb 2012)
Log Message:
-----------
[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:
trunk/extensions/MarkAsHelpful/modules/ext.markAsHelpful/ext.markAsHelpful.js
===================================================================
---
trunk/extensions/MarkAsHelpful/modules/ext.markAsHelpful/ext.markAsHelpful.js
2012-02-22 22:16:44 UTC (rev 112157)
+++
trunk/extensions/MarkAsHelpful/modules/ext.markAsHelpful/ext.markAsHelpful.js
2012-02-22 22:33:49 UTC (rev 112158)
@@ -4,91 +4,107 @@
* @author Rob Moen, 2011
*/
-(function( $ ) {
+( function ( $, mw ) {
- var mah = mw.mah = {
+ var mah = mw.markAsHelpful = {
loadedItems: [],
- selector: '[class^=markashelpful]', //class of element(s) to
apply MarkAsHelpful to.
+ // Class of element(s) to apply MarkAsHelpful to.
+ selector: '[class^="markashelpful"]',
- init: function() {
+ init: function () {
var props, thisItem;
- $( mah.selector ).each( function ( i, e ) {
- props = mah.getItemProperties( $(this) );
- thisItem = props.type + props.item; //create an
item reference to place in the loaded items array.
+
+ $( mah.selector ).each( function ( i, el ) {
+ props = mah.getItemProperties( $(el) );
+ // Create an item reference to place in the
loaded items array.
+ thisItem = props.type + props.item;
- //load once per type+id because user can copy /
paste element on the talk page and load the same item many times.
+ // Load once per type+id because user can copy
/ paste element on the talk page
+ // and load the same item many times.
if( $.inArray( thisItem, mah.loadedItems ) ===
-1 ) {
mah.loadedItems.push( thisItem );
- mah.loadItem( $( this ) );
+ mah.loadItem( $( el ) );
}
});
},
- /*
+
+ /**
* Return object of item properties
+ * @param $item
*/
- getItemProperties: function( $item ) {
- var tag = $item.attr( 'class' ),
- //item properties are stored in
classname to prevent parser from stripping out non html 5 objects.
- //(eg data-markashelpful-item)
- properties = {
- 'item': tag.split( '-' )[2], //
item id
- 'type': tag.split( '-' )[1] //
item type (eg, mbresponse)
- };
- return properties;
+ getItemProperties: function ( $item ) {
+ var tag, props;
+
+ tag = $item.attr( 'class' );
+ // Item properties are stored in classname to prevent
parser from stripping
+ // out non html 5 objects. (eg. data-markashelpful-item)
+ props = {
+ // item id
+ item: tag.split( '-' )[2],
+ // item type (eg, mbresponse)
+ type: tag.split( '-' )[1]
+ };
+ return props;
},
- /*
+
+ /**
* Load the current state of the MarkAsHelpful item
+ * @param $item
*/
- loadItem: function( $item ) {
- var props = mah.getItemProperties( $item ),
- request = {
- 'action':
'getmarkashelpfulitem',
- 'item': props.item,
- 'type': props.type,
- 'page': mw.config.get(
'wgPageName' ),
- 'format': 'json'
- };
+ loadItem: function ( $item ) {
+ var props, request;
+ props = mah.getItemProperties( $item );
+ request = {
+ format: 'json',
+ action: 'getmarkashelpfulitem',
+ item: props.item,
+ type: props.type,
+ page: mw.config.get( 'wgPageName' )
+ };
+
$.ajax({
type: 'POST',
url: mw.util.wikiScript('api'),
cache: false,
data: request,
- success: function( data ) {
+ success: function ( data ) {
+ var $content;
if ( data.getmarkashelpfulitem &&
-
data.getmarkashelpfulitem.result == 'success' &&
+
data.getmarkashelpfulitem.result === 'success' &&
data.getmarkashelpfulitem.formatted
) {
- var $content = $(
data.getmarkashelpfulitem.formatted );
+ $content = $(
data.getmarkashelpfulitem.formatted );
$item.html( $content );
- } else {
- // Failure, do nothing to the
item for now
}
+ // else: Failure, do nothing to the
item for now else
},
- error: function ( data ) {
+ error: function () {
// Failure, do nothing to the item for
now
},
dataType: 'json'
});
},
- /*
+
+ /**
* API call to mark or unmark an item as helpful.
*/
- markItem: function( $clicked, action ) {
- var $item = $clicked.parent().parent(),
- props = mah.getItemProperties( $item ),
- clientData = $.client.profile(),
- request;
+ markItem: function ( $clicked, action ) {
+ var $item, props, clientData, request;
+
+ $item = $clicked.parent().parent();
+ props = mah.getItemProperties( $item );
+ clientData = $.client.profile();
props.mahaction = action;
request = $.extend( {
- 'action': 'markashelpful',
- 'page': mw.config.get( 'wgPageName' ),
- 'useragent': clientData.name + '/' +
clientData.versionNumber,
- 'system': clientData.platform,
- 'token': mw.user.tokens.get( 'editToken' ),
- 'format': 'json'
+ action: 'markashelpful',
+ format: 'json',
+ page: mw.config.get( 'wgPageName' ),
+ useragent: clientData.name + '/' +
clientData.versionNumber,
+ system: clientData.platform,
+ token: mw.user.tokens.get( 'editToken' )
}, props );
$.ajax( {
@@ -105,22 +121,24 @@
// Some live events for the different modes
- $(document).ready( function() {
- /*
+ $(document).ready( function () {
+
+ /**
* Click Event for marking an item as helpful.
*/
- $( '.markashelpful-mark' ).live( 'click', function() {
+ $( '.markashelpful-mark' ).live( 'click', function () {
mah.markItem( $(this), 'mark' );
} );
- /*
+ /**
* Click Event for removing helpful status from an item.
*/
- $( '.markashelpful-undo' ).live( 'click', function() {
+ $( '.markashelpful-undo' ).live( 'click', function () {
mah.markItem( $(this), 'unmark' );
} );
// Initialize MarkAsHelpful
mah.init();
} );
-} ) ( jQuery );
+
+}( jQuery, mediaWiki ) );
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs