Article
3 comments

Close SharePoint Modal Dialogs with “Esc”-Key press

Whenever a list items will be checked or reviewed in SharePoint a modal dialog come up. This feature of SharePoint 2010 is really helpful from a usability point of view, because the user is able to return to the list where the interaction with the list item has been started by closing the modal dialog. When this will be done a couple of times a day, the user will always have to move the mouse pointer to the close button to close the dialog.

As user learned over the last couple of year, when the user want something to go away that pops out of the current browser window, no matter if it is a modal dialog, image or full screen video the use only have to press the “Esc”-Key to make it go away.

As I mentioned before this is not implemented in SharePoint now, but could be changed with a simple JavaScript and the usage of the Modal Dialog Framework implemented in SharePoint. To add this functionality I created a simple sandbox solution, which has a module and a JavaScript.

First of all the elements.xml contains the following definition:

<?xml version="1.0" encoding="utf-8"?>
xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
      ScriptSrc="~sitecollection/Style Library/FetchKeyStroke/CloseDialogOnEsc.js"
      Location="ScriptLink"
      Sequence="102"
      ></CustomAction>
  <Module Name="FetchKeyStroke" Url="Style Library">
    <File Path="FetchKeyStroke\CloseDialogOnEsc.js" 
          Url="FetchKeyStroke/CloseDialogOnEsc.js" />
  </Module>
</Elements>

The custom action register a JavaScript on the Master Page. The module definition deploy the JavaScript file the style library, the location for the deployment is URL parameter on the module. The JavaScript file only has few lines of code that capture the ESC-Key press  and close the mos recent dialog. The rest could be found in the following script.

document.onkeypress = function(e) {
    e = window.event || e;

    // Check if ESC-Key is pressed
    if (e.keyCode == 27) {

        // Check if a dialog was recently opened
        var dialog = SP.UI.ModalDialog.get_childDialog();
        if (dialog != null) {
            // Try to close the dialog
            SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.cancel,
                "Closed by ESC");
        }
    }
}

Conclusion

With this simple solution I think the usability in SharePoint could be improved a bit and based on SharePoint components like the modal dialog framework. jQuery would be to overweight for this task.

You can download the visual studio solution as well as the sandbox solution.

After the solution deployment a the site collection feature “Close Dialog on Esc-Key press” needs to be activated. In the Style Library the new added JavaScript file needs to be checked in.

Article
1 comment

SharePoint 2010 over IE 9: The perfect combination

The upcoming version of Internet Explorer is near at first public beta. The main features of the new Microsoft Browser is focused on performance and web standard compliance. Over the last couple of weeks the last technical preview was released and the first public beta will be released on 15. September 2010.

One of the new mayor benefits in IE9 is a whole new reengineered Javascript engine named Chakra. It has the ability for better useage of multi core CPU’s. In the SharePoint 2010 the new user interface use many javascript for rendering the menus. So what could be better as a solid fast browser engine.

First of all the good news. SharePoint 2010 and IE9 works as expected, which i find quite impressing for a pre-beta technical preview. As expected the Performance of SharePoint 2010 is much more better than on IE8. Currently i haven’t done any benchmarks but from my point of view loading IE9 loads 50% faster than IE8.

If do a test yourself you must be carful because IE9 try to load SharePoint 2010 in IE8 document mode. This behaviour could be switched using “Debug” menu or simply press ALT+9 Shortcut. Only with those setting you will get the best out of performance.

The latest pre-beta of IE9 is avaliable http://ie.microsoft.com/testdrive/.
Hopefully the beta will do the job quite well too.

Let’s give it a try and tell me what you think about SharePoint 2010 and IE9.