0

I have just started to use Sitecore a few months ago and I would like to change the size of the popup dialog in the Experience Editor as shown below.

Image of Sitecore Dialog

How and where can I change the size of this popup dialog? I assumed that it might be somewhere under \Website\sitecore\shell\Controls\Dialogs but the xml files under this folder does not seem to be the source of this popup dialog.

4

Sitecore does not make this easy. For some reason, the dialog size is hard-coded as 720px by 470px (SC 8.2) inside the AddRendering command (Sitecore.Shell.Applications.WebEdit.Commands.AddRendering). It is done in such a way that it would be very cumbersome to override, and not upgrade-friendly because you'd have to rewrite pretty much the entire command.

The only alternative I could find involves JavaScript, and the only way I could figure out to inject it on every Experience Editor page is through a processor (I used this article by jammykam as inspiration, which in turn refers to this post).

Processor:

using System.IO;
using Sitecore.Mvc.ExperienceEditor.Pipelines.RenderPageExtenders;

namespace DialogSizeAdjuster
{
    public class DialogSizeProcessor : RenderPageExtendersProcessor
    {
        protected override bool Render(TextWriter writer)
        {
            writer.Write(@"
                <script>
                var dialogSizeAdjusterFactory = function(originalFunction) {
                    return function(url, dialogArguments, features, request, modifiedHandling, openerWindow, dialogClosedCallback) {
                        features += ';getBestDialogSize:true'
                        originalFunction(url, dialogArguments, features, request, modifiedHandling, openerWindow, dialogClosedCallback)
                    }
                }
                var isDialogReady = function() {
                    return window.frameElement.contentWindow.document.readyState == 'complete' && window.parent &&
                        window.parent.document.getElementById('jqueryModalDialogsFrame') &&
                        window.parent.document.getElementById('jqueryModalDialogsFrame').contentWindow.showModalDialog
                }
                var adjustDialogSize = function() {
                    if(!isDialogReady()) {
                        setTimeout(adjustDialogSize, 1000)
                    } else {
                        var oldFunction = window.parent.document.getElementById('jqueryModalDialogsFrame').contentWindow.showModalDialog
                        window.parent.document.getElementById('jqueryModalDialogsFrame').contentWindow.showModalDialog = dialogSizeAdjusterFactory(oldFunction)
                    }
                }
                adjustDialogSize()
                </script>
            ");
            return true;
        }
    }
}

Config patch:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <mvc.renderPageExtenders>
          <processor type="DialogSizeAdjuster.DialogSizeProcessor, DialogSizeAdjuster" />
      </mvc.renderPageExtenders>
    </pipelines>
  </sitecore>
</configuration>

It's still pretty hacky, but it works. I did not hard-code the actual size, but instead I forced Sitecore to use a built-in algorithm to calculate the "best size" for the dialog (based on browser size).

If you'd prefer to hard-code a specific size, you can do this by altering the features parameter (log it to console first so you can see what's in it). In that case, it might be best to add the dimensions as parameters to the processor. You could also refer to an external Javascript file as outlined in the previously mentioned articles, and implement more complex logic.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.