Split allowing &suggest requests in API opensearch from $wgEnableMWSuggest to a separ...
[mediawiki.git] / js2 / editPage.js
blob936dc2d264c6c43c60752ff15fa840710eea46f0
1 /*
2  * JS2-style replacement for MediaWiki edit.js
3  * (right now it just supports the toolbar)
4  */
6 // Setup configuration vars (if not set already)
7 if( !mwAddMediaConfig )
8         var mwAddMediaConfig = {};
10 //The default editPage AMW config
11 var defaultAddMediaConfig = {
12                 'profile': 'mediawiki_edit',
13                 'target_textbox': '#wpTextbox1',
14                 // Note: selections in the textbox will take over the default query
15                 'default_query': wgTitle,
16                 'target_title': wgPageName,
17                 // Here we can setup the content provider overrides
18                 'enabled_cps':['wiki_commons'],
19                 // The local wiki API URL:
20                 'local_wiki_api_url': wgServer + wgScriptPath + '/api.php'
23 js2AddOnloadHook( function() {
24         var amwConf = $j.extend( true, defaultAddMediaConfig, mwAddMediaConfig );
25         // kind of tricky, it would be nice to use run on ready "loader" call here
26         var didWikiEditorBind = false;
27         
28         //setup the drag drop binding (will only work for html5 upload browsers) 
29         //$j( 'textarea#wpTextbox1' ).dragFileUpload();
30         
31         //set up the add-media-wizard binding: 
32         if( typeof $j.wikiEditor != 'undefined' ) {
33                         $j( 'textarea#wpTextbox1' ).bind( 'wikiEditor-toolbar-buildSection-main',
34                     function( e, section ) {
35                         didWikiEditorBind = true;
36                         if ( typeof section.groups.insert.tools.file !== 'undefined' ) {
37                             section.groups.insert.tools.file.action = {
38                                 'type': 'callback',
39                                 'execute': function() { 
40                                         js_log('click add media wiz');
41                                         $j.addMediaWiz( amwConf );
42                                 }
43                             };
44                         }
45                     }
46                 );
47         }               
48         //add to old toolbar if wikiEditor did not remove '#toolbar' from the page:    
49         setTimeout(function(){                                  
50                 if( $j('#btn-add-media-wiz').length == 0 && $j( '#toolbar' ).length != 0 ){
51                         $j( '#toolbar' ).append( '<img style="cursor:pointer" id="btn-add-media-wiz" src="' +
52                                 mv_skin_img_path + 'Button_add_media.png">' );
53                         $j( '#btn-add-media-wiz' ).addMediaWiz(
54                                 amwConf
55                         );
56                 }else{
57                         //make sure the wikieditor got binded: 
58                         if( !didWikiEditorBind )
59                                 $j(".tool [rel='file']").addMediaWiz( amwConf );
60                 }
61         }, 120)
62 });