Index: trunk/phase3/resources/mediawiki/mediawiki.api.js |
— | — | @@ -12,15 +12,21 @@ |
13 | 13 | * can override the parameter defaults and ajax default options. |
14 | 14 | * XXX document! |
15 | 15 | * |
| 16 | + * TODO share api objects with exact same config. |
| 17 | + * |
16 | 18 | * ajax options can also be overriden on every get() or post() |
17 | 19 | * |
18 | 20 | * @param options {Mixed} can take many options, but must include at minimum the API url. |
19 | 21 | */ |
20 | 22 | mw.Api = function( options ) { |
21 | 23 | |
| 24 | + if ( options === undefined ) { |
| 25 | + options = {}; |
| 26 | + } |
| 27 | + |
22 | 28 | // make sure we at least have a URL endpoint for the API |
23 | 29 | if ( options.url === undefined ) { |
24 | | - throw new Error( 'Configuration error - needs url property' ); |
| 30 | + options.url = mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) + '/api' + mw.config.get( 'wgScriptExtension' ); |
25 | 31 | } |
26 | 32 | |
27 | 33 | this.url = options.url; |
Index: trunk/phase3/resources/mediawiki/mediawiki.feedback.js |
— | — | @@ -31,18 +31,32 @@ |
32 | 32 | |
33 | 33 | /** |
34 | 34 | * Thingy for collecting user feedback on a wiki page |
35 | | - * @param {mw.api} api properly configured to talk to this wiki |
36 | | - * @param {mw.Title} the title of the page where you collect feedback |
37 | | - * @param {String} optional - message key for the title of the dialog box |
| 35 | + * @param {Array} options -- optional, all properties optional. |
| 36 | + * api: {mw.Api} if omitted, will just create a standard API |
| 37 | + * title: {mw.Title} the title of the page where you collect feedback. Defaults to "Feedback". |
| 38 | + * dialogTitleMessageKey: {String} message key for the title of the dialog box |
38 | 39 | */ |
39 | | - mw.Feedback = function( api, feedbackTitle, dialogTitleMessageKey ) { |
40 | | - var _this = this; |
41 | | - this.api = api; |
42 | | - this.feedbackTitle = feedbackTitle; |
43 | | - this.dialogTitleMessageKey = dialogTitleMessageKey; |
44 | | - if ( this.dialogTitleMessageKey === undefined ) { |
45 | | - this.dialogTitleMessageKey = 'feedback-submit'; |
| 40 | + mw.Feedback = function( options ) { |
| 41 | + |
| 42 | + if ( options === undefined ) { |
| 43 | + options = {}; |
46 | 44 | } |
| 45 | + |
| 46 | + if ( options.api === undefined ) { |
| 47 | + options.api = new mw.Api(); |
| 48 | + } |
| 49 | + |
| 50 | + if ( options.title === undefined ) { |
| 51 | + options.title = new mw.Title( 'Feedback' ); |
| 52 | + } |
| 53 | + |
| 54 | + if ( options.dialogTitleMessageKey === undefined ) { |
| 55 | + options.dialogTitleMessageKey = 'feedback-submit'; |
| 56 | + } |
| 57 | + |
| 58 | + this.api = options.api; |
| 59 | + this.feedbackTitle = options.title; |
| 60 | + this.dialogTitleMessageKey = options.dialogTitleMessageKey; |
47 | 61 | this.setup(); |
48 | 62 | }; |
49 | 63 | |