How to maximize a Modal Dialog in JavaScript?

The problem

Modal Dialogs in SharePoint 2010 are a really good feature. Moreover you can easily create your own dialogs and open them with just few lines of JavaScript :

Ok that’s cool, you can specify the size of the dialog, if the user can maximize it, close it and a lot of others things. But sometimes it can be interesting to let the dialog control some of these options. This is a very common scenario:

  • You are developing several application pages
  • These pages are opened in Modal Dialogs
  • The Dialogs are opened thanks to a User Control. A property of the User Control contains the URL of the application page to open.

Ok now you have developed an application page which contains a lot of content and you would prefer to maxmize the Dialog when opening it. Of course you can modify your User Control to use the showMaximized option when opening the dialog. But why the application page itself wouldn’t be able to maximize the dialog?

Let’s see how to that.

The solution

The main problem here is to get a reference on the actual dialog object. The JavaScript function showModalDialog returns this object but it is difficult to access it from the dialog. Fortunately there is a JavaScript function to do that (yes it is):

Now you can do a lot of things with this object. And of course one of these thing is calling internal functions that shouldn’t be called by non-Microsoft developers 🙂 So if you want to maximize the dialog when opening it you can use this code:

Yes the $z function switches the state of the dialog from “normal” to “maximized”. The $S_0 variable is set to true when the dialog is already maximized. Checking if this is the case avoids from switching the state of the dialog at each page refresh.

Of course you should be aware of the risks of using such a code since these functions are not documented and are subject to change without notice.

SharePoint 2010 Modal Dialog JavaScript internal functions

SharePoint 2010 Modal Dialog Basics

I have probably already worked with the Dialog Framework in a SharePoint 2010 environment. These dialogs are a very interesting feature that I really love. They can be used for a lot of things and of course you can create your owns dialogs to display data or ask for user input.

In this post I will describe briefly the basic functions that are documented on the MSDN and which enables you to work with Modal Dialogs. In a second part I will explain the usage of internal JavaScript functions that are not supposed to be called by custom code. You must be aware that these functions are not documented, ultimately your code should not use these functions because future updates could break down your custom features. But sometimes you need to go beyond the provided API when you have

Opening a Modal Dialog

Let’s begin with the easier and most useful part : opening a new Modal Dialog. For testing purpose I advise you to create an ASPX page inheriting from the default Master Page on a blank Team Site. Then you can add this code directly in a script block in the Main ContentPlaceHolder:

 I won’t go further in details about the different options available because you can now see the whole list on MSDN :

Rating does not work

Today I’m working on the new Ratings feature of SharePoint 2010. I think I had the same issue than everybody when enabling it for the first time : the ratings don’t refresh.

I enabled the Ratings on a Custom List and rate two items for testing purpose. And guess what? The blue stars are not showing!

So I read some blogs which speak about the “Social Rating Synchronization” timer job that must be runned to aggregate the ratings. Actually here is the description of the “Social Rating Synchronization Job”:

Timer Job to synchronize rating values between Social Database and Content database

And here is the description of the “Social Data Maintenance Job” (another timer job):

Aggregates social tags and ratings and cleans the social data change log.

So I think this is clear. You have to run these two jobs if you want to see your ratings refreshing.