Index: trunk/extensions/ArticleFeedback/modules/ext.articleFeedback-alpha/ext.articleFeedback-alpha.css |
— | — | @@ -0,0 +1,186 @@ |
| 2 | +/* |
| 3 | + * Styles for Article Assessment |
| 4 | + */ |
| 5 | + |
| 6 | +.article-assessment-wrapper #article-assessment-rate, |
| 7 | +.article-assessment-wrapper #article-assessment-ratings { |
| 8 | + background: #f7f7f7; |
| 9 | + float: left; |
| 10 | +} |
| 11 | + |
| 12 | +.article-assessment-wrapper #article-assessment-rate { |
| 13 | + width: 650px; |
| 14 | + margin-right: 10px; |
| 15 | +} |
| 16 | +.article-assessment-wrapper legend { |
| 17 | + font-weight: bold; |
| 18 | +} |
| 19 | +.article-assessment-wrapper .field-wrapper { |
| 20 | + float: left; |
| 21 | + width: 270px; |
| 22 | + padding-right: 28px; |
| 23 | +} |
| 24 | +.article-assessment-wrapper .rating-field { |
| 25 | + float: right; |
| 26 | + width: 125px; |
| 27 | + line-height: 24px; |
| 28 | + padding-right: 5px; |
| 29 | +} |
| 30 | +.article-assessment-wrapper .rating-field-label{ |
| 31 | + float: left; |
| 32 | + font-weight: bold; |
| 33 | + line-height: 24px; |
| 34 | +} |
| 35 | +.article-assessment-wrapper .rating-field-label { |
| 36 | + margin-right: 10px; |
| 37 | +} |
| 38 | +.article-assessment-wrapper .rating-field-hint { |
| 39 | + width: 11px; |
| 40 | + height: 24px; |
| 41 | + display: block; |
| 42 | + float: right; |
| 43 | + background: url(images/question.png) 0 50% no-repeat; |
| 44 | +} |
| 45 | +.article-assessment-wrapper .rating-field-hint:hover { |
| 46 | + background: url(images/question-hover.png) 0 50% no-repeat; |
| 47 | +} |
| 48 | + |
| 49 | +.article-assessment-wrapper .article-assessment-flash { |
| 50 | + float: left; |
| 51 | + font-size: 11px; |
| 52 | + padding: 1px 5px; |
| 53 | + width: 560px; |
| 54 | + text-align: left; |
| 55 | + display: block; |
| 56 | +} |
| 57 | +.article-assessment-wrapper .article-assessment-stale-msg { |
| 58 | + background: #d6f3ff; |
| 59 | + border: 2px solid #5dc9f4; |
| 60 | +} |
| 61 | +.article-assessment-wrapper .article-assessment-success-msg { |
| 62 | + background: #e8e8e8; |
| 63 | + border: 2px solid #006505; |
| 64 | +} |
| 65 | +.article-assessment-wrapper .article-assessment-error-msg { |
| 66 | + background: #e8e8e8; |
| 67 | + border: 2px solid #a91100; |
| 68 | +} |
| 69 | +.article-assessment-wrapper .article-assessment-rating-field-name { |
| 70 | + float: left; |
| 71 | + width: 110px; |
| 72 | + font-weight: bold; |
| 73 | + font-size: 11px; |
| 74 | +} |
| 75 | +.article-assessment-wrapper .article-assessment-rating-field-value-wrapper { |
| 76 | + background: url(images/rating-base.png) 0 0 no-repeat; |
| 77 | + width: 120px; |
| 78 | + height: 13px; |
| 79 | + display: block; |
| 80 | + float: left; |
| 81 | + padding: 2px; |
| 82 | + text-indent: -9999px; |
| 83 | + margin-top: 4px; |
| 84 | +} |
| 85 | +.article-assessment-wrapper .article-assessment-rate-instructions, |
| 86 | +.article-assessment-wrapper .article-assessment-rate-feedback, |
| 87 | +.article-assessment-wrapper .article-assessment-show-ratings, |
| 88 | +.article-assessment-wrapper .article-assessment-hide-ratings { |
| 89 | + font-size: 11px; |
| 90 | + font-style: italic; |
| 91 | +} |
| 92 | +.article-assessment-wrapper .article-assessment-rate-instructions { |
| 93 | + float: left; |
| 94 | +} |
| 95 | +.article-assessment-wrapper .article-assessment-rate-feedback { |
| 96 | + float: right; |
| 97 | +} |
| 98 | +.article-assessment-wrapper .article-assessment-rating-field-value-wrapper .article-assessment-rating-field-value { |
| 99 | + background: url(images/rating-bar.png) 0 0 no-repeat; |
| 100 | + height: 9px; |
| 101 | + float: right; |
| 102 | + display: block; |
| 103 | +} |
| 104 | +.article-assessment-wrapper .article-assessment-rating-fields { |
| 105 | + margin: 8px 0; |
| 106 | +} |
| 107 | +.article-assessment-wrapper .article-assessment-rating-fields .field-wrapper { |
| 108 | + margin-bottom: 5px; |
| 109 | +} |
| 110 | +.article-assessment-rating-count { |
| 111 | + font-size: 11px; |
| 112 | + margin-left: 5px; |
| 113 | + float: left; |
| 114 | +} |
| 115 | +.article-assessment-submit input { |
| 116 | + margin: 2px 0; |
| 117 | + float: right; |
| 118 | +} |
| 119 | +.article-assessment-wrapper .article-assessment-ratings-disabled .article-assessment-rating-field-value-wrapper { |
| 120 | + background: urlimages/rating-base-disabled.png) 0 0 no-repeat; |
| 121 | +} |
| 122 | +.article-assessment-wrapper .article-assessment-ratings-disabled .article-assessment-rating-field-value { |
| 123 | + display: none; |
| 124 | +} |
| 125 | +.article-assessment-wrapper .article-assessment-ratings-disabled .article-assessment-rating-count { |
| 126 | + visibility: hidden; |
| 127 | + |
| 128 | +} |
| 129 | +.article-assessment-wrapper .article-assessment-ratings-disabled .article-assessment-rating-field-name { |
| 130 | + color: #9f9f9f; |
| 131 | +} |
| 132 | + |
| 133 | +/* Simple Survey Dialog Styling */ |
| 134 | +#article-assessment-dialog.loading { |
| 135 | + display: block; |
| 136 | + height: 24px; |
| 137 | + width: 24px; |
| 138 | + background: url(images/loading.gif) center no-repeat; |
| 139 | + text-indent: -9999px; |
| 140 | + margin: 0 auto; |
| 141 | +} |
| 142 | +#article-assessment-dialog textarea { |
| 143 | + margin-left: -2em; |
| 144 | + padding-right: 2em; |
| 145 | +} |
| 146 | +.article-assessment-error-msg { |
| 147 | + padding: 20px 0; |
| 148 | +} |
| 149 | + |
| 150 | + |
| 151 | +/* Self Clearing Floats */ |
| 152 | +.article-assessment-wrapper .article-assessment-information:after, |
| 153 | +.article-assessment-wrapper .field-wrapper:after, |
| 154 | +.article-assessment-wrapper .article-assessment-rating-fields:after, |
| 155 | +.article-assessment-rating:after, |
| 156 | +.article-assessment-wrapper .article-assessment-submit:after, |
| 157 | +.article-assessment-wrapper .rating-fields:after { |
| 158 | + content: "."; |
| 159 | + display: block; |
| 160 | + height: 0; |
| 161 | + clear: both; |
| 162 | + visibility: hidden; |
| 163 | +} |
| 164 | +.article-assessment-wrapper .field-wrapper, |
| 165 | +.article-assessment-wrapper .article-assessment-information, |
| 166 | +.article-assessment-wrapper .article-assessment-rating-fields, |
| 167 | +.article-assessment-rating, |
| 168 | +.article-assessment-wrapper .article-assessment-submit, |
| 169 | +.article-assessment-wrapper .rating-fields { |
| 170 | + display: inline-block; |
| 171 | +} |
| 172 | +* html .article-assessment-wrapper .field-wrapper, |
| 173 | +* html .article-assessment-wrapper .article-assessment-information, |
| 174 | +* html .article-assessment-wrapper .article-assessment-rating-fields, |
| 175 | +* html .article-assessment-rating, |
| 176 | +* html .article-assessment-wrapper .article-assessment-submit, |
| 177 | +* html .article-assessment-wrapper .rating-fields { |
| 178 | + height: 1%; |
| 179 | +} |
| 180 | +.article-assessment-wrapper .field-wrapper, |
| 181 | +.article-assessment-wrapper .article-assessment-information, |
| 182 | +.article-assessment-wrapper .article-assessment-rating-fields, |
| 183 | +.article-assessment-rating, |
| 184 | +.article-assessment-wrapper .article-assessment-submit, |
| 185 | +.article-assessment-wrapper .rating-fields { |
| 186 | + display: block; |
| 187 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/ArticleFeedback/modules/ext.articleFeedback-alpha/ext.articleFeedback-alpha.css |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 188 | + native |
Index: trunk/extensions/ArticleFeedback/modules/ext.articleFeedback-alpha/ext.articleFeedback-alpha.js |
— | — | @@ -0,0 +1,516 @@ |
| 2 | +( function( $ ) { |
| 3 | + $.ArticleAssessment = { |
| 4 | + 'config': { |
| 5 | + 'authtoken': '', |
| 6 | + 'userID': '', |
| 7 | + 'pageID': wgArticleId, |
| 8 | + 'revID': wgCurRevisionId |
| 9 | + }, |
| 10 | + 'messages': {}, |
| 11 | + 'settings': { |
| 12 | + 'endpoint': wgScriptPath + '/api.php?', |
| 13 | + 'fieldMessages' : [ |
| 14 | + 'wellsourced', |
| 15 | + 'neutrality', |
| 16 | + 'completeness', |
| 17 | + 'readability' |
| 18 | + ], |
| 19 | + 'fieldHintSuffix': '-tooltip', |
| 20 | + 'fieldPrefix': 'articleassessment-rating-', |
| 21 | + 'fieldHTML': '<div class="field-wrapper"> \ |
| 22 | + <label class="rating-field-label"></label> \ |
| 23 | + <select class="rating-field"> \ |
| 24 | + <option value="1">1</option> \ |
| 25 | + <option value="2">2</option> \ |
| 26 | + <option value="3">3</option> \ |
| 27 | + <option value="4">4</option> \ |
| 28 | + <option value="5">5</option> \ |
| 29 | + </select> \ |
| 30 | + </div>', |
| 31 | + 'structureHTML': '<div class="article-assessment-wrapper nonopopups"> \ |
| 32 | + <form action="rate" method="post" id="article-assessment"> \ |
| 33 | + <fieldset id="article-assessment-rate"> \ |
| 34 | + <legend></legend> \ |
| 35 | + <div class="article-assessment-information"> \ |
| 36 | + <span class="article-assessment-rate-instructions"></span> \ |
| 37 | + <span class="article-assessment-rate-feedback"></span> \ |
| 38 | + </div> \ |
| 39 | + <div class="article-assessment-rating-fields"></div> \ |
| 40 | + <div class="article-assessment-submit"> \ |
| 41 | + <input type="submit" value="Submit" /> \ |
| 42 | + </div> \ |
| 43 | + </fieldset> \ |
| 44 | + <fieldset id="article-assessment-ratings"> \ |
| 45 | + <legend></legend> \ |
| 46 | + <div class="article-assessment-information"> \ |
| 47 | + <span class="article-assessment-show-ratings"></span> \ |
| 48 | + <span class="article-assessment-hide-ratings"></span> \ |
| 49 | + </div> \ |
| 50 | + </fieldset> \ |
| 51 | + </form> \ |
| 52 | + </div>', |
| 53 | + 'ratingHTML': '<div class="article-assessment-rating"> \ |
| 54 | + <span class="article-assessment-rating-field-name"></span> \ |
| 55 | + <span class="article-assessment-rating-field-value-wrapper"> \ |
| 56 | + <span class="article-assessment-rating-field-value">0%</span> \ |
| 57 | + </span> \ |
| 58 | + <span class="article-assessment-rating-count"></span> \ |
| 59 | + </div>' |
| 60 | + }, |
| 61 | + |
| 62 | + 'fn' : { |
| 63 | + 'init': function( $$options ) { |
| 64 | + // merge options with the config |
| 65 | + var settings = $.extend( {}, $.ArticleAssessment.settings, $$options ); |
| 66 | + var config = $.ArticleAssessment.config; |
| 67 | + // if this is an anon user, get a unique identifier for them |
| 68 | + // load up the stored ratings and update the markup if the cookie exists |
| 69 | + var userToken = $.cookie( 'mwArticleAssessmentUserToken' ); |
| 70 | + if ( typeof userToken == 'undefined' || userToken == null ) { |
| 71 | + function randomString( string_length ) { |
| 72 | + var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz"; |
| 73 | + var randomstring = ''; |
| 74 | + for ( var i = 0; i < string_length; i++ ) { |
| 75 | + var rnum = Math.floor( Math.random() * chars.length ); |
| 76 | + randomstring += chars.substring( rnum, rnum + 1 ); |
| 77 | + } |
| 78 | + return randomstring; |
| 79 | + } |
| 80 | + userToken = randomString( 32 ); |
| 81 | + $.cookie( |
| 82 | + 'mwArticleAssessmentUserToken', |
| 83 | + userToken, |
| 84 | + { 'expires': 30, 'path': '/' } |
| 85 | + ); |
| 86 | + } |
| 87 | + if ( !wgUserName ) { |
| 88 | + config.userID = userToken; |
| 89 | + } |
| 90 | + // setup our markup using the template variables in settings |
| 91 | + var $structure = $( settings.structureHTML ), |
| 92 | + instructions = mediaWiki.msg( 'articleassessment-pleaserate' ), |
| 93 | + feedback = mediaWiki.msg( 'articleassessment-featurefeedback' ), |
| 94 | + yourfeedback = mediaWiki.msg( 'articleassessment-yourfeedback'), |
| 95 | + articlerating = mediaWiki.msg( 'articleassessment-articlerating' ), |
| 96 | + resultshide = mediaWiki.msg( 'articleassessment-results-hide' ), |
| 97 | + resultsshow = mediaWiki.msg( 'articleassessment-results-show' ); |
| 98 | + submitbutton = mediaWiki.msg( 'articleassessment-submit' ); |
| 99 | + $structure |
| 100 | + .find( '#article-assessment-rate legend' ) |
| 101 | + .html( yourfeedback ) |
| 102 | + .end() |
| 103 | + .find( '.article-assessment-rate-instructions' ) |
| 104 | + .html( instructions ) |
| 105 | + .end() |
| 106 | + .find( '.article-assessment-rate-feedback' ) |
| 107 | + .html( feedback ) |
| 108 | + .find( '.feedbacklink' ) |
| 109 | + .wrap( '<a href="#"></a>' ) |
| 110 | + .parent() |
| 111 | + .click( $.ArticleAssessment.fn.showFeedback ) |
| 112 | + .end() |
| 113 | + .end() |
| 114 | + .end() |
| 115 | + .find( '#article-assessment-ratings legend' ) |
| 116 | + .html( articlerating ) |
| 117 | + .end() |
| 118 | + .find( '.article-assessment-show-ratings' ) |
| 119 | + .html( resultsshow ) |
| 120 | + .find( '.showlink' ) |
| 121 | + .wrap( '<a href="#"></a>' ) |
| 122 | + .parent() |
| 123 | + .click( $.ArticleAssessment.fn.showRatings ) |
| 124 | + .end() |
| 125 | + .end() |
| 126 | + .end() |
| 127 | + .find( '.article-assessment-hide-ratings' ) |
| 128 | + .html( resultshide ) |
| 129 | + .find ( '.hidelink' ) |
| 130 | + .wrap( '<a href="#"></a>' ) |
| 131 | + .parent() |
| 132 | + .click( $.ArticleAssessment.fn.hideRatings ) |
| 133 | + .end() |
| 134 | + .end() |
| 135 | + .end() |
| 136 | + .find( '.article-assessment-submit input' ) |
| 137 | + .val( submitbutton ) |
| 138 | + .end(); |
| 139 | + // hide the feedback link if we need to |
| 140 | + if( $.cookie( 'mwArticleAssessmentHideFeedbackLink' ) ) { |
| 141 | + $structure |
| 142 | + .find( '.article-assessment-rate-feedback' ) |
| 143 | + .hide(); |
| 144 | + } |
| 145 | + for ( var i = 0; i < settings.fieldMessages.length; i++ ) { |
| 146 | + var $field = $( settings.fieldHTML ), |
| 147 | + $rating = $( settings.ratingHTML ), |
| 148 | + label = mediaWiki.msg( settings.fieldPrefix + settings.fieldMessages[i] ), |
| 149 | + field = settings.fieldMessages[i], |
| 150 | + hint = mediaWiki.msg( |
| 151 | + settings.fieldPrefix + settings.fieldMessages[i] + |
| 152 | + settings.fieldHintSuffix |
| 153 | + ), |
| 154 | + count = mediaWiki.msg( 'articleassessment-noratings', 0, 0 ); |
| 155 | + // initialize the field html |
| 156 | + $field |
| 157 | + .attr( 'id', 'articleassessment-rate-' + field ) |
| 158 | + .find( 'label' ) |
| 159 | + .attr( 'for', 'rating_' + field ) |
| 160 | + .attr( 'original-title', hint ) |
| 161 | + .html( label ) |
| 162 | + .end() |
| 163 | + .find( 'select' ) |
| 164 | + .attr( 'id', 'rating_' + field ) |
| 165 | + .attr( 'name', 'rating[' + field + ']' ); |
| 166 | + // initialize the rating html |
| 167 | + $rating |
| 168 | + .attr( 'id', 'articleassessment-rating-' + field ) |
| 169 | + .find( '.article-assessment-rating-field-name' ) |
| 170 | + .html( label ) |
| 171 | + .end() |
| 172 | + .find( '.article-assessment-rating-count' ) |
| 173 | + .html( count ); |
| 174 | + // append the field and rating html |
| 175 | + $structure |
| 176 | + .find( '.article-assessment-rating-fields' ) |
| 177 | + .append( $field ) |
| 178 | + .end() |
| 179 | + .find( '#article-assessment-ratings' ) |
| 180 | + .append( $rating ); |
| 181 | + } |
| 182 | + // store our settings and configuration for later |
| 183 | + $structure.find( '#article-assessment' ) |
| 184 | + .data( |
| 185 | + 'articleAssessment-context', |
| 186 | + { 'settings': settings, 'config': config } |
| 187 | + ); |
| 188 | + $( '#catlinks' ).before( $structure ); |
| 189 | + // Hide the ratings initially |
| 190 | + $.ArticleAssessment.fn.hideRatings(); |
| 191 | + |
| 192 | + |
| 193 | + // set the height of our smaller fieldset to match the taller |
| 194 | + if ( |
| 195 | + $( '#article-assessment-rate' ).height() > |
| 196 | + $( '#article-assessment-ratings' ).height() ) { |
| 197 | + $( '#article-assessment-ratings' ) |
| 198 | + .css( 'minHeight', $( '#article-assessment-rate' ).height() ); |
| 199 | + } else { |
| 200 | + $( '#article-assessment-rate' ) |
| 201 | + .css( 'minHeight', $( '#article-assessment-ratings' ).height() ); |
| 202 | + } |
| 203 | + // attempt to fetch the ratings |
| 204 | + $.ArticleAssessment.fn.getRatingData(); |
| 205 | + |
| 206 | + // initialize the star plugin |
| 207 | + $( '.rating-field' ).each( function() { |
| 208 | + $(this) |
| 209 | + .wrapAll( '<div class="rating-field"></div>' ) |
| 210 | + .parent() |
| 211 | + .stars( { |
| 212 | + inputType: 'select', |
| 213 | + callback: function( value, link ) { |
| 214 | + // remove any stale or rated classes |
| 215 | + value.$stars.each( function() { |
| 216 | + $(this) |
| 217 | + .removeClass( 'ui-stars-star-stale' ) |
| 218 | + .removeClass( 'ui-stars-star-rated' ); |
| 219 | + // enable our submit button if it's still disabled |
| 220 | + $( '#article-assessment input:disabled' ) |
| 221 | + .removeAttr( 'disabled' ); |
| 222 | + } ); |
| 223 | + } |
| 224 | + } ); |
| 225 | + } ); |
| 226 | + // intialize the tooltips |
| 227 | + $( '.field-wrapper label[original-title]' ).each( function() { |
| 228 | + $(this) |
| 229 | + .after( $( '<span class="rating-field-hint" />' ) |
| 230 | + .attr( 'original-title', $(this).attr( 'original-title' ) ) |
| 231 | + .tipsy( { gravity : 'se', opacity: '0.9' } ) ); |
| 232 | + } ); |
| 233 | + // bind submit event to the form |
| 234 | + $( '#article-assessment' ) |
| 235 | + .submit( function() { $.ArticleAssessment.fn.submitRating(); return false; } ); |
| 236 | + // prevent the submit button for being active until all ratings are filled out |
| 237 | + $( '#article-assessment input[type=submit]' ) |
| 238 | + .attr( 'disabled', 'disabled' ); |
| 239 | + }, |
| 240 | + 'showRatings': function() { |
| 241 | + $( '#article-assessment-ratings' ) |
| 242 | + .removeClass( 'article-assessment-ratings-disabled' ) |
| 243 | + .find( '.article-assessment-show-ratings' ) |
| 244 | + .hide() |
| 245 | + .end() |
| 246 | + .find( '.article-assessment-hide-ratings' ) |
| 247 | + .show(); |
| 248 | + return false; |
| 249 | + }, |
| 250 | + 'hideRatings': function() { |
| 251 | + $( '#article-assessment-ratings' ) |
| 252 | + .addClass( 'article-assessment-ratings-disabled' ) |
| 253 | + .find( '.article-assessment-hide-ratings' ) |
| 254 | + .hide() |
| 255 | + .end() |
| 256 | + .find( '.article-assessment-show-ratings' ) |
| 257 | + .show(); |
| 258 | + return false; |
| 259 | + |
| 260 | + }, |
| 261 | + |
| 262 | + // Request the ratings data for the current article |
| 263 | + 'getRatingData': function() { |
| 264 | + var config = $( '#article-assessment' ).data( 'articleAssessment-context' ).config; |
| 265 | + var requestData = { |
| 266 | + 'action': 'query', |
| 267 | + 'list': 'articleassessment', |
| 268 | + 'aapageid': config.pageID, |
| 269 | + 'aauserrating': 1, |
| 270 | + 'format': 'json' |
| 271 | + } |
| 272 | + if ( config.userID.length == 32 ) { |
| 273 | + requestData.aaanontoken = config.userID; |
| 274 | + } |
| 275 | + |
| 276 | + var request = $.ajax( { |
| 277 | + url: wgScriptPath + '/api.php', |
| 278 | + data: requestData, |
| 279 | + dataType: 'json', |
| 280 | + success: $.ArticleAssessment.fn.afterGetRatingData, |
| 281 | + error: function( XMLHttpRequest, textStatus, errorThrown ) { |
| 282 | + $.ArticleAssessment.fn.flashNotice( mediaWiki.msg( 'articleassessment-error' ), |
| 283 | + { 'class': 'article-assessment-error-msg' } ); |
| 284 | + } |
| 285 | + } ); |
| 286 | + }, |
| 287 | + 'afterGetRatingData' : function( data ) { |
| 288 | + var settings = $( '#article-assessment' ).data( 'articleAssessment-context' ).settings, |
| 289 | + userHasRated = false; |
| 290 | + // add the correct data to the markup |
| 291 | + if ( typeof data.query != 'undefined' && typeof data.query.articleassessment != 'undefined' && |
| 292 | + typeof data.query.articleassessment[0] != 'undefined' ) { |
| 293 | + for ( var r in data.query.articleassessment[0].ratings ) { |
| 294 | + var rating = data.query.articleassessment[0].ratings[r], |
| 295 | + $rating = $( '#' + rating.ratingdesc ), |
| 296 | + count = rating.count, |
| 297 | + total = ( rating.total / count ).toFixed( 1 ), |
| 298 | + label = mediaWiki.msg( 'articleassessment-noratings', total, count ); |
| 299 | + $rating |
| 300 | + .find( '.article-assessment-rating-field-value' ) |
| 301 | + .text( total ) |
| 302 | + .end() |
| 303 | + .find( '.article-assessment-rating-count' ) |
| 304 | + .html( label ); |
| 305 | + if( rating.userrating ) { |
| 306 | + userHasRated = true; |
| 307 | + // this user rated. Word. Show them their ratings |
| 308 | + var $rateControl = $( '#' + rating.ratingdesc.replace( 'rating', 'rate' ) + ' .rating-field' ); |
| 309 | + $rateControl.stars( 'select', rating.userrating ); |
| 310 | + } |
| 311 | + } |
| 312 | + // show the ratings if the user has rated |
| 313 | + if( userHasRated ) { |
| 314 | + $.ArticleAssessment.fn.showRatings(); |
| 315 | + } |
| 316 | + // if the rating is more than 5 revisions old, mark it as stale |
| 317 | + if ( typeof data.query.articleassessment[0].stale != 'undefined' ) { |
| 318 | + // add the stale star class to each on star |
| 319 | + $( '.ui-stars-star-on' ) |
| 320 | + .addClass( 'ui-stars-star-stale' ); |
| 321 | + // add the stale message |
| 322 | + var msg = mediaWiki.msg( 'articleassessment-stalemessage-norevisioncount' ); |
| 323 | + $.ArticleAssessment.fn.flashNotice( msg, { 'class': 'article-assessment-stale-msg' } ); |
| 324 | + } else { |
| 325 | + // if it's not a stale rating, we want to make the stars blue |
| 326 | + $( '.ui-stars-star-on' ).addClass( 'ui-stars-star-rated' ); |
| 327 | + } |
| 328 | + } |
| 329 | + // initialize the ratings |
| 330 | + $( '.article-assessment-rating-field-value' ).each( function() { |
| 331 | + $(this) |
| 332 | + .css( { |
| 333 | + 'width': 120 - ( 120 * ( parseFloat( $(this).text() ) / 5 ) ) + 'px' |
| 334 | + } ) |
| 335 | + } ); |
| 336 | + }, |
| 337 | + 'submitRating': function() { |
| 338 | + var config = $( '#article-assessment' ).data( 'articleAssessment-context' ).config; |
| 339 | + // clear out the stale message |
| 340 | + $.ArticleAssessment.fn.flashNotice( ); |
| 341 | + |
| 342 | + // lock the star inputs & submit |
| 343 | + $( '.rating-field' ).stars( 'disable' ); |
| 344 | + $( '#article-assessment input' ).attr( 'disabled', 'disabled' ); |
| 345 | + // get our results for submitting |
| 346 | + var results = {}; |
| 347 | + $( '.rating-field input' ).each( function() { |
| 348 | + // expects the hidden inputs to have names like 'rating[field-name]' which we use to |
| 349 | + // be transparent about what values we're sending to the server |
| 350 | + var fieldName = $(this).attr( 'name' ).match( /\[([a-zA-Z0-9\-]*)\]/ )[1]; |
| 351 | + results[ fieldName ] = $(this).val(); |
| 352 | + } ); |
| 353 | + var request = $.ajax( { |
| 354 | + url: wgScriptPath + '/api.php', |
| 355 | + type: 'POST', |
| 356 | + data: { |
| 357 | + 'action': 'articleassessment', |
| 358 | + 'revid': config.revID, |
| 359 | + 'pageid': config.pageID, |
| 360 | + 'r1' : results['wellsourced'], |
| 361 | + 'r2' : results['neutrality'], |
| 362 | + 'r3' : results['completeness'], |
| 363 | + 'r4' : results['readability'], |
| 364 | + 'anontoken': config.userID, |
| 365 | + 'format': 'json' |
| 366 | + }, |
| 367 | + dataType: 'json', |
| 368 | + success: $.ArticleAssessment.fn.afterSubmitRating, |
| 369 | + error: function( XMLHttpRequest, textStatus, errorThrown ) { |
| 370 | + $.ArticleAssessment.fn.flashNotice( mediaWiki.msg( 'articleassessment-error' ), |
| 371 | + { 'class': 'article-assessment-error-msg' } ); |
| 372 | + } |
| 373 | + } ); |
| 374 | + }, |
| 375 | + 'afterSubmitRating': function ( data ) { |
| 376 | + // update the ratings |
| 377 | + $.ArticleAssessment.fn.getRatingData(); |
| 378 | + // set the stars to rated status |
| 379 | + $( '.ui-stars-star-on' ).addClass( 'ui-stars-star-rated' ); |
| 380 | + // unlock the stars & submit |
| 381 | + $( '.rating-field' ).stars( 'enable' ); |
| 382 | + $( '#article-assessment input:disabled' ).removeAttr( 'disabled' ); |
| 383 | + // update the results |
| 384 | + |
| 385 | + // show the results |
| 386 | + $.ArticleAssessment.fn.showRatings(); |
| 387 | + // say thank you |
| 388 | + $.ArticleAssessment.fn.flashNotice( mediaWiki.msg( 'articleassessment-thanks' ), |
| 389 | + { 'class': 'article-assessment-success-msg' } ); |
| 390 | + }, |
| 391 | + // places a message on the interface |
| 392 | + 'flashNotice': function( text, options ) { |
| 393 | + if ( arguments.length == 0 ) { |
| 394 | + // clear existing messages, but don't add a new one |
| 395 | + $( '#article-assessment .article-assessment-flash' ).remove(); |
| 396 | + } else { |
| 397 | + // clear and add a new message |
| 398 | + $( '#article-assessment .article-assessment-flash' ).remove(); |
| 399 | + var className = options['class']; |
| 400 | + // create our new message |
| 401 | + $msg = $( '<div />' ) |
| 402 | + .addClass( 'article-assessment-flash' ) |
| 403 | + .html( text ); |
| 404 | + // if the class option was passed, add it |
| 405 | + if( options['class'] ) { |
| 406 | + $msg.addClass( options['class'] ); |
| 407 | + } |
| 408 | + // place our new message on the page |
| 409 | + $( '#article-assessment .article-assessment-submit' ) |
| 410 | + .append( $msg ); |
| 411 | + } |
| 412 | + }, |
| 413 | + 'showFeedback': function() { |
| 414 | + var $dialogDiv = $( '#article-assessment-dialog' ); |
| 415 | + if ( $dialogDiv.size() == 0 ) { |
| 416 | + $dialogDiv = $( '<div id="article-assessment-dialog" class="loading" />' ) |
| 417 | + .dialog( { |
| 418 | + width: 600, |
| 419 | + height: 400, |
| 420 | + bgiframe: true, |
| 421 | + autoOpen: true, |
| 422 | + modal: true, |
| 423 | + title: mediaWiki.msg( 'articleassessment-survey-title' ), |
| 424 | + close: function() { |
| 425 | + $(this) |
| 426 | + .dialog( 'option', 'height', 400 ) |
| 427 | + .find( '.article-assessment-success-msg, .article-assessment-error-msg' ) |
| 428 | + .remove() |
| 429 | + .end() |
| 430 | + .find( 'form' ) |
| 431 | + .show(); |
| 432 | + } |
| 433 | + } ); |
| 434 | + $dialogDiv.load( |
| 435 | + wgScript + '?title=Special:SimpleSurvey&survey=articlerating&raw=1', |
| 436 | + function() { |
| 437 | + $(this).find( 'form' ).bind( 'submit', $.ArticleAssessment.fn.submitFeedback ); |
| 438 | + $(this).removeClass( 'loading' ); |
| 439 | + } |
| 440 | + ); |
| 441 | + } |
| 442 | + $dialogDiv.dialog( 'open' ); |
| 443 | + return false; |
| 444 | + }, |
| 445 | + 'submitFeedback': function() { |
| 446 | + var $dialogDiv = $( '#article-assessment-dialog' ); |
| 447 | + $dialogDiv |
| 448 | + .find( 'form' ) |
| 449 | + .hide() |
| 450 | + .end() |
| 451 | + .addClass( 'loading' ); |
| 452 | + // Submit straight to the special page. Yes, this is a dirty dirty hack |
| 453 | + // Build request from form data |
| 454 | + var formData = {}; |
| 455 | + $dialogDiv.find( 'input[type=text], input[type=radio]:checked, input[type=checkbox]:checked, ' + |
| 456 | + 'input[type=hidden], textarea' ).each( function() { |
| 457 | + var name = $(this).attr( 'name' ); |
| 458 | + if ( name !== '' ) { |
| 459 | + if ( name.substr( -2 ) == '[]' ) { |
| 460 | + var trimmedName = name.substr( 0, name.length - 2 ); |
| 461 | + if ( typeof formData[trimmedName] == 'undefined' ) { |
| 462 | + formData[trimmedName] = []; |
| 463 | + } |
| 464 | + formData[trimmedName].push( $(this).val() ); |
| 465 | + } else { |
| 466 | + formData[name] = $(this).val(); |
| 467 | + } |
| 468 | + } |
| 469 | + } ); |
| 470 | + formData.title = 'Special:SimpleSurvey'; |
| 471 | + |
| 472 | + $.ajax( { |
| 473 | + url: wgScript, |
| 474 | + type: 'POST', |
| 475 | + data: formData, |
| 476 | + dataType: 'html', |
| 477 | + success: function( data ) { |
| 478 | + // This is an evil screenscraping method to determine whether |
| 479 | + // the submission was successful |
| 480 | + var success = $( data ).find( '.simplesurvey-success' ).size() > 0; |
| 481 | + // TODO: Style success-msg, error-msg |
| 482 | + var $msgDiv = $( '<div />' ) |
| 483 | + .addClass( success ? 'article-assessment-success-msg' : 'article-assessment-error-msg' ) |
| 484 | + .html( mediaWiki.msg( success? 'articleassessment-survey-thanks' : 'articleassessment-error' ) ) |
| 485 | + .appendTo( $dialogDiv ); |
| 486 | + $dialogDiv.removeClass( 'loading' ); |
| 487 | + |
| 488 | + // This is absurdly unnecessary from the looks of it, but it seems this is somehow |
| 489 | + // needed in certain cases. |
| 490 | + $dialogDiv.dialog( 'option', 'height', $msgDiv.height() + 100 ); |
| 491 | + |
| 492 | + if ( success ) { |
| 493 | + // Hide the dialog link |
| 494 | + $( '#article-assessment .article-assessment-rate-feedback' ).hide(); |
| 495 | + // set a cookie to keep the dialog link hidden |
| 496 | + $.cookie( 'mwArticleAssessmentHideFeedbackLink', true, { 'expires': 30, 'path': '/' } ); |
| 497 | + |
| 498 | + } |
| 499 | + }, |
| 500 | + error: function( XMLHttpRequest, textStatus, errorThrown ) { |
| 501 | + // TODO: Duplicates code, factor out, maybe |
| 502 | + var $msgDiv = $( '<div />' ) |
| 503 | + .addClass( 'article-assessment-error-msg' ) |
| 504 | + .html( mediaWiki.msg( 'articleassessment-error' ) ) |
| 505 | + .appendTo( $dialogDiv ); |
| 506 | + $dialogDiv.removeClass( 'loading' ); |
| 507 | + $dialogDiv.dialog( 'option', 'height', $msgDiv.height() + 100 ); |
| 508 | + } |
| 509 | + } ); |
| 510 | + return false; |
| 511 | + } |
| 512 | + } |
| 513 | + }; |
| 514 | + $( document ).ready( function () { |
| 515 | + $.ArticleAssessment.fn.init( ); |
| 516 | + } ); //document ready |
| 517 | +} )( jQuery ); |
Property changes on: trunk/extensions/ArticleFeedback/modules/ext.articleFeedback-alpha/ext.articleFeedback-alpha.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 518 | + native |