* added add-media-wizard entry point which is compatible with wikiEditor style button...
authorMichael Dale <dale@users.mediawiki.org>
Tue, 13 Oct 2009 21:41:30 +0000 (21:41 +0000)
committerMichael Dale <dale@users.mediawiki.org>
Tue, 13 Oct 2009 21:41:30 +0000 (21:41 +0000)
js2/editPage.js
js2/mwEmbed/libAddMedia/remoteSearchDriver.js
js2/mwEmbed/mv_embed.js
js2/mwEmbed/php/languages/mwEmbed.i18n.php

index 290589d..63958ff 100644 (file)
@@ -24,19 +24,28 @@ var defaultAddMediaConfig = {
 js2AddOnloadHook( function() {
        var amwConf = $j.extend( true, defaultAddMediaConfig, mwAddMediaConfig );
        // kind of tricky, it would be nice to use run on ready "loader" call here
-       if( typeof $j.wikiEditor != 'undefined' ) {
-               setTimeout( function() {
-                       $j( '.wikiEditor-ui [rel=file]' ).unbind().addMediaWiz(
+       if( typeof $j.wikiEditor != 'undefined' ) {             
+                       $j( 'textarea#wpTextbox1' ).bind( 'wikiEditor-toolbar-buildSection-main',
+                   function( e, section ) {
+                       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 );
+                               }
+                           };
+                       }
+                   }
+               );
+       }else{
+               //add to the old-toolbar
+               if( $j('#btn-add-media-wiz').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
                        );
-               }, 100 );
-       }
-       //add to the old-toolbar all the time:
-       if( $j('#btn-add-media-wiz').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
-               );
+               }
        }
 });
index a89b61d..74cb956 100644 (file)
@@ -387,7 +387,6 @@ remoteSearchDriver.prototype = {
                        }
                }               
 
-
                //set up the target invocation:
                if( $j( this.target_invocation ).length==0 ){
                        js_log("RemoteSearchDriver:: no target invocation provided (will have to run your own doInitDisplay() )");
@@ -409,16 +408,23 @@ remoteSearchDriver.prototype = {
                this.add_interface_bindings();
 
                //update the target binding to just un-hide the dialog:
-               $j(this.target_invocation).unbind().click(function(){
-                         js_log("re-open");
-                         //update the base text:
-                         if( _this.target_textbox )
-                                       _this.getTexboxSelection();
-                         //$j(_this.target_container).dialog("open");
-                         $j(_this.target_container).parents('.ui-dialog').fadeIn('slow');
-                         //re-center the dialog:
-                         $j(_this.target_container).dialog('option', 'position','center');
-                });
+               if( this.target_invocation ){
+                       $j(this.target_invocation).unbind().click(function(){
+                               js_log("doInitDisplay:target_invocation: click doReDisp");
+                                _this.doReDisplay();
+                        });
+                }
+       },
+       doReDisplay: function(){
+               var _this = this;
+               js_log("doReDisplay::");
+               //update the base text:
+               if( _this.target_textbox )
+                       _this.getTexboxSelection();
+               //$j(_this.target_container).dialog("open");
+               $j(_this.target_container).parents('.ui-dialog').fadeIn('slow');
+               //re-center the dialog:
+               $j(_this.target_container).dialog('option', 'position','center');
        },
        //gets the in and out points for insert position or grabs the selected text for search
        getTexboxSelection:function(){
@@ -475,7 +481,7 @@ remoteSearchDriver.prototype = {
                        js_log( 'width: ' + $j(window).width() +  ' height: ' + $j(window).height());
                        var cConf = {};
                        cConf['cancel'] = function(){
-                               _this.cancelClipEditCB()
+                               _this.cancelClipEditCB();
                        }
                        function doResize(){
                                js_log('do resize:: ' + _this.target_container);                                
@@ -492,9 +498,10 @@ remoteSearchDriver.prototype = {
                                resizable:false,
                                buttons:cConf,                                                          
                                close: function() {
-                                       //if we are 'editing' a item close that                                 
-                                       _this.cancelClipEditCB();
-                                       js_log('closed modal');
+                                       //if we are 'editing' a item close that 
+                                       //@@todo maybe prompt the user?                                         
+                                       _this.cancelClipEditCB();                                               
+                                       //$j(this).dialog('close');             
                                        $j(this).parents('.ui-dialog').fadeOut('slow');
                                }
                        });                             
index 41242e4..bc73c17 100644 (file)
@@ -617,7 +617,8 @@ $mw.lang.loadGM({
        "mwe-size-megabytes" : "$1 MB",
        "mwe-size-kilobytes" : "$1 K",
        "mwe-size-bytes" : "$1 B",
-       "mwe-error_load_lib" : "Error: JavaScript $1 was not retrievable or does not define $2"
+       "mwe-error_load_lib" : "Error: JavaScript $1 was not retrievable or does not define $2",
+       "mwe-loading-add-media-wiz": "Loading add media wizard"
 });
 
 
@@ -1180,18 +1181,43 @@ function mv_remove_modal( speed ) {
 function mv_jqueryBindings() {
        js_log( 'mv_jqueryBindings' );
        (function( $ ) {
-               $.fn.addMediaWiz = function( iObj, callback ) {
-                       // First set the cursor for the button to "loading"
-                       $j( this.selector ).css( 'cursor', 'wait' ).attr( 'title', gM( 'mwe-loading_title' ) );
-
-                       iObj['target_invocation'] = this.selector;
+               //non selector based add-media-wizard direct invocation with loader
+               $.addMediaWiz = function( iObj, callback ){                     
+                       js_log(".addMediaWiz call");
+                       //check if already loaded:
+                       if( _global['rsdMVRS'] ){
+                               _global['rsdMVRS'].doReDisplay();
+                               if( callback )
+                                       callback( _global['rsdMVRS'] );
+                               return ;
+                       }
+                       //display a loader: 
+                       $.addLoaderDialog( gM('mwe-loading-add-media-wiz') );
+                       //load the addMedia wizard without a target: 
+                       $.fn.addMediaWiz ( iObj, function( amwObj ){
+                               //close the dialog
+                               $.closeLoaderDialog();
+                               //do the add-media-wizard display
+                               amwObj.doInitDisplay();                         
+                               //call the parent callback:
+                               if( callback )
+                                       callback( _global['rsdMVRS'] ); 
+                       });
+               }
+               $.fn.addMediaWiz = function( iObj, callback ) {                 
+                       if( this.selector ){                    
+                               // First set the cursor for the button to "loading"
+                               $j( this.selector ).css( 'cursor', 'wait' ).attr( 'title', gM( 'mwe-loading_title' ) );
+                               //set the target: 
+                               iObj['target_invocation'] = this.selector;
+                       }
 
                        // Load the mv_embed_base skin:
                        loadExternalCss( mv_jquery_skin_path + 'jquery-ui-1.7.1.custom.css' );
                        loadExternalCss( mv_embed_path + 'skins/' + mwConfig['skin_name']+'/styles.css' );
                        // Load all the required libs:
                        mvJsLoader.jQueryCheck( function() {
-                               // Load with staged dependencies (for IE and Safari that don't execute in order)
+                               // Load with staged dependencies (for IE that does not execute in order)
                                mvJsLoader.doLoadDepMode([
                                        [       'remoteSearchDriver',
                                                '$j.cookie',
@@ -1398,12 +1424,13 @@ function mv_jqueryBindings() {
                $.addLoaderDialog = function( msg_txt ){
                        if( $('#mwe_tmp_loader').length != 0 )
                                $('#mwe_tmp_loader').remove();
-
+                       
+                       //append the style free loader ontop: 
                        $('body').append('<div id="mwe_tmp_loader" title="' + msg_txt + '" >' +
-                                       gM('mwe-checking-resource') + '<br>' +
+                                       msg_txt + '<br>' +
                                        mv_get_loading_img() +
                        '</div>');
-
+                       //turn the loader into a real dialog loader: 
                        mvJsLoader.doLoadDepMode([
                                [
                                        '$j.ui'
index c2f95ac..a5f46c5 100644 (file)
@@ -103,6 +103,7 @@ $messages['en'] = array(
        'mwe-size-kilobytes' => '$1 K',
        'mwe-size-bytes' => '$1 B',
        'mwe-error_load_lib' => 'Error: JavaScript $1 was not retrievable or does not define $2',
+       'mwe-loading-add-media-wiz' => "Loading add media wizard",
 
        /*
         * js file: /libAddMedia/mvFirefogg.js