JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.1
[ckeditor.git] / _source / plugins / image / dialogs / image.js
index 7507ff2..9b127c9 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
 For licensing, see LICENSE.html or http://ckeditor.com/license\r
 */\r
 \r
@@ -195,6 +195,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
        var imageDialog = function( editor, dialogType )\r
        {\r
+               var previewPreloader;\r
+\r
                var onImgLoadEvent = function()\r
                {\r
                        // Image is ready.\r
@@ -212,7 +214,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                resetSize( this );\r
 \r
                        if ( this.firstLoad )\r
-                               switchLockRatio( this, 'check' );\r
+                               CKEDITOR.tools.setTimeout( function(){ switchLockRatio( this, 'check' ); }, 0, this );\r
+\r
                        this.firstLoad = false;\r
                        this.dontResetSize = false;\r
                };\r
@@ -253,16 +256,17 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                this.firstLoad = true;\r
                                this.addLink = false;\r
 \r
-                               //Hide loader.\r
-                               CKEDITOR.document.getById( 'ImagePreviewLoader' ).setStyle( 'display', 'none' );\r
-                               // Preview\r
-                               this.preview = CKEDITOR.document.getById( 'previewImage' );\r
-\r
                                var editor = this.getParentEditor(),\r
                                        sel = this.getParentEditor().getSelection(),\r
                                        element = sel.getSelectedElement(),\r
                                        link = element && element.getAscendant( 'a' );\r
 \r
+                               //Hide loader.\r
+                               CKEDITOR.document.getById( 'ImagePreviewLoader' ).setStyle( 'display', 'none' );\r
+                               // Create the preview before setup the dialog contents.\r
+                               previewPreloader = new CKEDITOR.dom.element( 'img', editor.document );\r
+                               this.preview = CKEDITOR.document.getById( 'previewImage' );\r
+\r
                                // Copy of the image\r
                                this.originalElement = editor.document.createElement( 'img' );\r
                                this.originalElement.setAttribute( 'alt', '' );\r
@@ -492,8 +496,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                                                        original.on( 'error', onImgLoadErrorEvent, dialog );\r
                                                                                                        original.on( 'abort', onImgLoadErrorEvent, dialog );\r
                                                                                                        original.setAttribute( 'src', newUrl );\r
-                                                                                                       dialog.preview.setAttribute( 'src', newUrl );\r
 \r
+                                                                                                       // Query the preloader to figure out the url impacted by based href.\r
+                                                                                                       previewPreloader.setAttribute( 'src', newUrl );\r
+                                                                                                       dialog.preview.setAttribute( 'src', previewPreloader.$.src );\r
                                                                                                        updatePreview( dialog );\r
                                                                                                }\r
                                                                                                // Dont show preview if no URL given.\r
@@ -1053,7 +1059,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                                        '<div id="ImagePreviewLoader" style="display:none"><div class="loading">&nbsp;</div></div>'+\r
                                                                                        '<div id="ImagePreviewBox">'+\r
                                                                                        '<a href="javascript:void(0)" target="_blank" onclick="return false;" id="previewLink">'+\r
-                                                                                       '<img id="previewImage" src="" alt="" /></a>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. '+\r
+                                                                                       '<img id="previewImage" alt="" /></a>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. '+\r
                                                                                        'Maecenas feugiat consequat diam. Maecenas metus. Vivamus diam purus, cursus a, commodo non, facilisis vitae, '+\r
                                                                                        'nulla. Aenean dictum lacinia tortor. Nunc iaculis, nibh non iaculis aliquam, orci felis euismod neque, sed ornare massa mauris sed velit. Nulla pretium mi et risus. Fusce mi pede, tempor id, cursus ac, ullamcorper nec, enim. Sed tortor. Curabitur molestie. Duis velit augue, condimentum at, ultrices a, luctus ut, orci. Donec pellentesque egestas eros. Integer cursus, augue in cursus faucibus, eros pede bibendum sem, in tempus tellus justo quis ligula. Etiam eget tortor. Vestibulum rutrum, est ut placerat elementum, lectus nisl aliquam velit, tempor aliquam eros nunc nonummy metus. In eros metus, gravida a, gravida sed, lobortis id, turpis. Ut ultrices, ipsum at venenatis fringilla, sem nulla lacinia tellus, eget aliquet turpis mauris non enim. Nam turpis. Suspendisse lacinia. Curabitur ac tortor ut ipsum egestas elementum. Nunc imperdiet gravida mauris.' +\r
                                                                                        '</div>'+'</div>'\r