Index: trunk/extensions/MarkAsHelpful/MarkAsHelpful.php |
— | — | @@ -42,3 +42,14 @@ |
43 | 43 | 'remoteExtPath' => 'MarkAsHelpful/modules' |
44 | 44 | ); |
45 | 45 | |
| 46 | +$wgResourceModules['ext.markAsHelpful'] = $mbResourceTemplate + array( |
| 47 | + 'styles' => 'ext.markAsHelpful/ext.markAsHelpful.css', |
| 48 | + 'scripts' => 'ext.markAsHelpful/ext.markAsHelpful.js', |
| 49 | + 'messages' => array( |
| 50 | + 'helpful-text', |
| 51 | + ), |
| 52 | + 'position' => 'bottom', |
| 53 | + 'dependencies' => array( |
| 54 | + 'mediawiki.util' |
| 55 | + ), |
| 56 | +); |
\ No newline at end of file |
Index: trunk/extensions/MarkAsHelpful/modules/ext.markAsHelpful/ext.markAsHelpful.css |
— | — | @@ -0,0 +1,33 @@ |
| 2 | +.mw-mah-wrapper { |
| 3 | + font-size: .8em; |
| 4 | + color: #7E7E7E; |
| 5 | +} |
| 6 | + |
| 7 | +.mw-mah-wrapper .mah-helpful-state { |
| 8 | + font-size: 1em; |
| 9 | + line-height: 1em; |
| 10 | +} |
| 11 | + |
| 12 | +.mw-mah-wrapper .mah-helpful-state .mah-helpful-icon { |
| 13 | + /* @embed */ |
| 14 | + background: transparent url( images/mah-helpful-dull.png ) left top no-repeat; |
| 15 | + height: 16px; |
| 16 | + width: 16px; |
| 17 | + float:left; |
| 18 | +} |
| 19 | + |
| 20 | +.mw-mah-wrapper .mah-helpful-state .mah-helpful-icon:hover { |
| 21 | + /* @embed */ |
| 22 | + background: transparent url( images/mah-helpful-hover.png ) left top no-repeat; |
| 23 | + height: 16px; |
| 24 | + width: 16px; |
| 25 | + float: left; |
| 26 | +} |
| 27 | + |
| 28 | +.mw-mah-wrapper .mah-helpful-state .mah-helpful-marked-icon { |
| 29 | + /* @embed */ |
| 30 | + background: transparent url( images/mah-helpful-marked.png ) left top no-repeat; |
| 31 | + height: 16px; |
| 32 | + width: 16px; |
| 33 | + float: left; |
| 34 | +} |
\ No newline at end of file |
Index: trunk/extensions/MarkAsHelpful/modules/ext.markAsHelpful/ext.markAsHelpful.js |
— | — | @@ -0,0 +1,114 @@ |
| 2 | +/** |
| 3 | + * Front-end scripting core for the MarkAsHelpful MediaWiki extension |
| 4 | + * |
| 5 | + * @author Rob Moen, 2011 |
| 6 | + */ |
| 7 | + |
| 8 | +(function( $ ) { |
| 9 | + |
| 10 | + var mah = mw.mah = { |
| 11 | + |
| 12 | + selector: '[class^=markashelpful-]', |
| 13 | + |
| 14 | + init: function() { |
| 15 | + var $mahWrap = $( '<div />' ).attr( 'class', 'mw-mah-wrapper' ); |
| 16 | + |
| 17 | + $( mah.selector ).each ( function () { |
| 18 | + $( this ).append( $mahWrap ); |
| 19 | + mah.loadItem( $(this) ); |
| 20 | + }); |
| 21 | + }, |
| 22 | + |
| 23 | + /* |
| 24 | + * Return object of item properties |
| 25 | + */ |
| 26 | + getItemProperties: function( $item ) { |
| 27 | + var tag = $item.attr( 'class' ), |
| 28 | + properties = { |
| 29 | + 'item': tag.split('-')[2], // item id |
| 30 | + 'type': tag.split('-')[1] // item type (eg, moodbarfeedbackresponse) |
| 31 | + }; |
| 32 | + return properties; |
| 33 | + }, |
| 34 | + |
| 35 | + /* |
| 36 | + * Load the current state of the MarkAsHelpful item |
| 37 | + */ |
| 38 | + loadItem: function( $item ) { |
| 39 | + var props = mah.getItemProperties( $item ); |
| 40 | + |
| 41 | + var request = { |
| 42 | + 'action': 'getmarkashelpfulitem', |
| 43 | + 'item': props.item, |
| 44 | + 'type': props.type, |
| 45 | + 'format': 'json' |
| 46 | + |
| 47 | + }; |
| 48 | + |
| 49 | + $.post( mw.util.wikiScript('api'), request, |
| 50 | + function( data ) { |
| 51 | + if ( data && data.query && data.query.mahitem && |
| 52 | + data.query.mahitem.length > 0 |
| 53 | + ) { |
| 54 | + var $content = $j( data.query.mahitem[0].formatted ); |
| 55 | + $item.find( '.mw-mah-wrapper' ).replaceWith( $content ); |
| 56 | + } else { |
| 57 | + // Failure, remove the item for now. |
| 58 | + $item.find( '.mw-mah-wrapper' ).remove(); |
| 59 | + } |
| 60 | + }, 'json' ) |
| 61 | + .error( function() { |
| 62 | + // Error, remove the item for now. |
| 63 | + $item.find( '.mw-mah-wrapper' ).remove(); |
| 64 | + } ); |
| 65 | + }, |
| 66 | + /* |
| 67 | + * API call to mark or unmark an item as helpful. |
| 68 | + */ |
| 69 | + markItem: function( $item, action ) { |
| 70 | + var props = mah.getItemProperties( $item ), |
| 71 | + clientData = $.client.profile(), |
| 72 | + request; |
| 73 | + props.mbaction = action; |
| 74 | + |
| 75 | + apiRequest = $.extend( { |
| 76 | + 'page': mw.config.get( 'wgPageName' ), |
| 77 | + 'useragent': clientData.name + '/' + clientData.versionNumber, |
| 78 | + 'system': clientData.platform, |
| 79 | + 'token': mw.config.get('mbEditToken'), |
| 80 | + 'format': 'json' |
| 81 | + }, props ); |
| 82 | + |
| 83 | + $.ajax( { |
| 84 | + type: 'post', |
| 85 | + url: mw.util.wikiScript( 'api' ), |
| 86 | + data: apiRequest, |
| 87 | + success: mah.loadItem( $item ), |
| 88 | + dataType: 'json' |
| 89 | + } ); |
| 90 | + |
| 91 | + } |
| 92 | + }; |
| 93 | + |
| 94 | + // Some live events for the different modes |
| 95 | + |
| 96 | + /* |
| 97 | + * Click Event for marking an item as helpful. |
| 98 | + */ |
| 99 | + $('.markashelpful-mark').live( 'click', function() { |
| 100 | + $item = $(this).parent().parent(); |
| 101 | + mah.markItem ( $item, 'mark' ); |
| 102 | + } ); |
| 103 | + |
| 104 | + /* |
| 105 | + * Click Event for removing helpful status from an item. |
| 106 | + */ |
| 107 | + $('.markashelpful-undo').live( 'click', function() { |
| 108 | + $item = $(this).parent().parent(); |
| 109 | + mah.markItem ( $item, 'unmark' ); |
| 110 | + } ); |
| 111 | + |
| 112 | + // Initialize MarkAsHelpful |
| 113 | + mah.init(); |
| 114 | + |
| 115 | +} ) ( jQuery ); |
\ No newline at end of file |