/*
- * js2 style replacement for mediaWiki edit.js
+ * JS2-style replacement for MediaWiki edit.js
+ * (right now it just supports the toolbar)
*/
-//setup configuration vars:
-if(!mwAddMediaConfig)
- var mwAddMediaConfig = {
- 'profile':'mediawiki_edit',
- 'target_textbox': '#wpTextbox1',
- //note selections in the textbox will take over the default query
- 'default_query': wgTitle,
- 'target_title':wgPageName,
- //here we can setup the conten provider overides
- 'cpconfig': {},
-
- //the local wiki api url:
- 'local_wiki_api_url': wgServer + wgScriptPath + '/api.php'
- };
+// Setup configuration vars (if not set already)
+if( !mwAddMediaConfig )
+ var mwAddMediaConfig = {};
-js2AddOnloadHook( function(){
- mwEditPageHelper.init();
-});
-var mwEditPageHelper = {
- init:function(){
- var _this = this;
- //@@todo check for new version of toolbar and via toolbar api:
- if(typeof $j.fn.toolbar == 'undefined'){
- //add the add-media-wizard button for old toolbar:
- $j('#toolbar').append('<img style="cursor:pointer" id="btn-add-media-wiz" src="' + mv_skin_img_path + 'Button_add_media.png">');
- $j('#btn-add-media-wiz').addMediaWiz(
- mwAddMediaConfig
- );
+//The default editPage AMW config
+var defaultAddMediaConfig = {
+ 'profile': 'mediawiki_edit',
+ 'target_textbox': '#wpTextbox1',
+ // Note: selections in the textbox will take over the default query
+ 'default_query': wgTitle,
+ 'target_title': wgPageName,
+ // Here we can setup the content provider overrides
+ 'enabled_cps':['wiki_commons'],
+ // The local wiki API URL:
+ 'local_wiki_api_url': wgServer + wgScriptPath + '/api.php'
+};
+
+js2AddOnloadHook( function() {
+ var amwConf = $j.extend( true, defaultAddMediaConfig, mwAddMediaConfig );
+ // kind of tricky, it would be nice to use run on ready "loader" call here
+ var didWikiEditorBind = false;
+
+ //setup the drag drop binding (will only work for html5 upload browsers)
+ //$j( 'textarea#wpTextbox1' ).dragFileUpload();
+
+ //set up the add-media-wizard binding:
+ if( typeof $j.wikiEditor != 'undefined' ) {
+ $j( 'textarea#wpTextbox1' ).bind( 'wikiEditor-toolbar-buildSection-main',
+ function( e, section ) {
+ didWikiEditorBind = true;
+ if ( typeof section.groups.insert.tools.file !== 'undefined' ) {
+ section.groups.insert.tools.file.action = {
+ 'type': 'callback',
+ 'execute': function() {
+ js_log('click add media wiz');
+ $j.addMediaWiz( amwConf );
+ }
+ };
+ }
+ }
+ );
+ }
+ //add to old toolbar if wikiEditor did not remove '#toolbar' from the page:
+ setTimeout(function(){
+ if( $j('#btn-add-media-wiz').length == 0 && $j( '#toolbar' ).length != 0 ){
+ $j( '#toolbar' ).append( '<img style="cursor:pointer" id="btn-add-media-wiz" src="' +
+ mv_skin_img_path + 'Button_add_media.png">' );
+ $j( '#btn-add-media-wiz' ).addMediaWiz(
+ amwConf
+ );
+ }else{
+ //make sure the wikieditor got binded:
+ if( !didWikiEditorBind )
+ $j(".tool [rel='file']").addMediaWiz( amwConf );
}
- }
-}
+ }, 120)
+ //drag drop for editbar:
+ //$j('textarea#wpTextbox1').dragFileUpload();
+});