X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Fmediawiki%2Fmediawiki.feedback.js;h=1afe51eff6fd1659bb5d9aad374f279ccf018f31;hb=4d8cff99e75c690a418dd887152d90b9d08844ad;hp=e96d8c711a2bf1a1aaaf0429100a54c9fab309fa;hpb=d50d0a56da2c7264d7b75ea755bc4ed6297487ec;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/mediawiki/mediawiki.feedback.js b/resources/mediawiki/mediawiki.feedback.js index e96d8c711a..1afe51eff6 100644 --- a/resources/mediawiki/mediawiki.feedback.js +++ b/resources/mediawiki/mediawiki.feedback.js @@ -1,5 +1,5 @@ /** - * mediawiki.Feedback + * mediawiki.feedback * * @author Ryan Kaldari, 2010 * @author Neil Kandalgaonkar, 2010-11 @@ -22,22 +22,22 @@ * Minimal example in how to use it: * * var feedback = new mw.Feedback(); - * $( '#myButton' ).click( function() { feedback.launch(); } ); + * $( '#myButton' ).click( function () { feedback.launch(); } ); * * You can also launch the feedback form with a prefilled subject and body. * See the docs for the launch() method. */ -( function( mw, $, undefined ) { +( function ( mw, $ ) { /** * Thingy for collecting user feedback on a wiki page * @param {Array} options -- optional, all properties optional. - * api: {mw.Api} if omitted, will just create a standard API - * title: {mw.Title} the title of the page where you collect feedback. Defaults to "Feedback". - * dialogTitleMessageKey: {String} message key for the title of the dialog box - * bugsLink: {mw.Uri|String} url where bugs can be posted - * bugsListLink: {mw.Uri|String} url where bugs can be listed + * api: {mw.Api} if omitted, will just create a standard API + * title: {mw.Title} the title of the page where you collect feedback. Defaults to "Feedback". + * dialogTitleMessageKey: {String} message key for the title of the dialog box + * bugsLink: {mw.Uri|String} url where bugs can be posted + * bugsListLink: {mw.Uri|String} url where bugs can be listed */ - mw.Feedback = function( options ) { + mw.Feedback = function ( options ) { if ( options === undefined ) { options = {}; } @@ -67,64 +67,80 @@ }; mw.Feedback.prototype = { - setup: function() { - var _this = this; - - var $feedbackPageLink = $( '' ) - .attr( { 'href': _this.title.getUrl(), 'target': '_blank' } ) - .css( { 'white-space': 'nowrap' } ); - - var $bugNoteLink = $( '' ).attr( { 'href': '#' } ).click( function() { _this.displayBugs(); } ); - - var $bugsListLink = $( '' ).attr( { 'href': _this.bugsListLink, 'target': '_blank' } ); - + setup: function () { + var $feedbackPageLink, + $bugNoteLink, + $bugsListLink, + fb = this; + + $feedbackPageLink = $( '' ) + .attr( { + href: fb.title.getUrl(), + target: '_blank' + } ) + .css( { + whiteSpace: 'nowrap' + } ); + + $bugNoteLink = $( '' ).attr( { href: '#' } ).click( function () { + fb.displayBugs(); + } ); + + $bugsListLink = $( '' ).attr( { + href: fb.bugsListLink, + target: '_blank' + } ); + + // TODO: Use a stylesheet instead of these inline styles this.$dialog = - $( '
' ).append( + $( '
' ).append( $( '
' ).append( - $( '' ).append( - $( '

' ).msg( + $( '' ).append( + $( '

' ).msg( 'feedback-bugornote', $bugNoteLink, - _this.title.getNameText(), + fb.title.getNameText(), $feedbackPageLink.clone() ) ), - $( '

' ).append( + $( '
' ).append( mw.msg( 'feedback-subject' ), - $( '
' ), - $( '' ) + $( '
' ), + $( '' ) ), - $( '
' ).append( + $( '
' ).append( mw.msg( 'feedback-message' ), - $( '
' ), - $( '' ) + $( '
' ), + $( '' ) ) ), $( '' ).append( $( '

' ).msg( 'feedback-bugcheck', $bugsListLink ) ), - $( '

' ).append( + $( '' ).append( mw.msg( 'feedback-adding' ), - $( '
' ), - $( '' ) + $( '
' ), + $( '' ) ), - $( '' ).msg( - 'feedback-thanks', _this.title.getNameText(), $feedbackPageLink.clone() + $( '' ).msg( + 'feedback-thanks', fb.title.getNameText(), $feedbackPageLink.clone() ), - $( '' ).append( - $( '' ) + $( '' ).append( + $( '' ) ) ); // undo some damage from dialog css - this.$dialog.find( 'a' ).css( { 'color': '#0645ad' } ); + this.$dialog.find( 'a' ).css( { + color: '#0645ad' + } ); this.$dialog.dialog({ width: 500, autoOpen: false, title: mw.msg( this.dialogTitleMessageKey ), modal: true, - buttons: _this.buttons + buttons: fb.buttons }); this.subjectInput = this.$dialog.find( 'input.feedback-subject' ).get(0); @@ -132,98 +148,119 @@ }, - display: function( s ) { + display: function ( s ) { this.$dialog.dialog( { buttons:{} } ); // hide the buttons this.$dialog.find( '.feedback-mode' ).hide(); // hide everything this.$dialog.find( '.feedback-' + s ).show(); // show the desired div }, - displaySubmitting: function() { + displaySubmitting: function () { this.display( 'submitting' ); }, - displayBugs: function() { - var _this = this; + displayBugs: function () { + var fb = this, + bugsButtons = {}; this.display( 'bugs' ); - var bugsButtons = {}; - bugsButtons[ mw.msg( 'feedback-bugnew' ) ] = function() { window.open( _this.bugsLink, '_blank' ); }; - bugsButtons[ mw.msg( 'feedback-cancel' ) ] = function() { _this.cancel(); }; - this.$dialog.dialog( { buttons: bugsButtons } ); + bugsButtons[ mw.msg( 'feedback-bugnew' ) ] = function () { + window.open( fb.bugsLink, '_blank' ); + }; + bugsButtons[ mw.msg( 'feedback-cancel' ) ] = function () { + fb.cancel(); + }; + this.$dialog.dialog( { + buttons: bugsButtons + } ); }, - displayThanks: function() { - var _this = this; + displayThanks: function () { + var fb = this, + closeButton = {}; this.display( 'thanks' ); - var closeButton = {}; - closeButton[ mw.msg( 'feedback-close' ) ] = function() { _this.$dialog.dialog( 'close' ); }; - this.$dialog.dialog( { buttons: closeButton } ); + closeButton[ mw.msg( 'feedback-close' ) ] = function () { + fb.$dialog.dialog( 'close' ); + }; + this.$dialog.dialog( { + buttons: closeButton + } ); }, /** * Display the feedback form * @param {Object} optional prefilled contents for the feedback form. Object with properties: - * subject: {String} - * message: {String} + * subject: {String} + * message: {String} */ - displayForm: function( contents ) { - var _this = this; - this.subjectInput.value = (contents && contents.subject) ? contents.subject : ''; - this.messageInput.value = (contents && contents.message) ? contents.message : ''; + displayForm: function ( contents ) { + var fb = this, + formButtons = {}; + this.subjectInput.value = ( contents && contents.subject ) ? contents.subject : ''; + this.messageInput.value = ( contents && contents.message ) ? contents.message : ''; this.display( 'form' ); // Set up buttons for dialog box. We have to do it the hard way since the json keys are localized - var formButtons = {}; - formButtons[ mw.msg( 'feedback-submit' ) ] = function() { _this.submit(); }; - formButtons[ mw.msg( 'feedback-cancel' ) ] = function() { _this.cancel(); }; + formButtons[ mw.msg( 'feedback-submit' ) ] = function () { + fb.submit(); + }; + formButtons[ mw.msg( 'feedback-cancel' ) ] = function () { + fb.cancel(); + }; this.$dialog.dialog( { buttons: formButtons } ); // put the buttons back }, - displayError: function( message ) { - var _this = this; + displayError: function ( message ) { + var fb = this, + closeButton = {}; this.display( 'error' ); this.$dialog.find( '.feedback-error-msg' ).msg( message ); - var closeButton = {}; - closeButton[ mw.msg( 'feedback-close' ) ] = function() { _this.$dialog.dialog( 'close' ); }; + closeButton[ mw.msg( 'feedback-close' ) ] = function () { + fb.$dialog.dialog( 'close' ); + }; this.$dialog.dialog( { buttons: closeButton } ); }, - cancel: function() { + cancel: function () { this.$dialog.dialog( 'close' ); }, - submit: function() { - var _this = this; - - // get the values to submit - var subject = this.subjectInput.value; + submit: function () { + var subject, message, + fb = this; - var message = "User agent: " + navigator.userAgent + "\n\n" - + this.messageInput.value; - if ( message.indexOf( '~~~' ) == -1 ) { - message += " ~~~~"; - } - - this.displaySubmitting(); - - var ok = function( result ) { + function ok( result ) { if ( result.edit !== undefined ) { if ( result.edit.result === 'Success' ) { - _this.displayThanks(); + fb.displayThanks(); } else { - _this.displayError( 'feedback-error1' ); // unknown API result + // unknown API result + fb.displayError( 'feedback-error1' ); } } else { - _this.displayError( 'feedback-error2' ); // edit failed + // edit failed + fb.displayError( 'feedback-error2' ); } - }; + } - var err = function( code, info ) { - _this.displayError( 'feedback-error3' ); // ajax request failed - }; + function err() { + // ajax request failed + fb.displayError( 'feedback-error3' ); + } + + // Get the values to submit. + subject = this.subjectInput.value; + + // We used to include "mw.html.escape( navigator.userAgent )" but there are legal issues + // with posting this without their explicit consent + message = this.messageInput.value; + if ( message.indexOf( '~~~' ) === -1 ) { + message += ' ~~~~'; + } + + this.displaySubmitting(); this.api.newSection( this.title, subject, message, ok, err ); - }, // close submit button function + }, /** * Modify the display form, and then open it, focusing interface on the subject. @@ -231,7 +268,7 @@ * subject: {String} * message: {String} */ - launch: function( contents ) { + launch: function ( contents ) { this.displayForm( contents ); this.$dialog.dialog( 'open' ); this.subjectInput.focus(); @@ -239,4 +276,4 @@ }; -} )( window.mediaWiki, jQuery ); +}( mediaWiki, jQuery ) );