Tuesday, September 1, 2009

Open Comments form with Highslide

The code below overrides the default browser's window.open popup and make it into a Highslide popup.

First go to Dashbord --> Setting --> Comments --> Comment form placement and check for Pop-up window.
Then go to Dashbord --> Layout --> Edit HTML and paste this between the head tags, below the included Highslide js file:
// Override the window.open method
window.open = function(url, name, options) {
   var opener, width, height, anchors;

   // locate the opener by the url
   anchors = document.getElementsByTagName('a');
   for (var i = 0; i < anchors.length; i++) {
      if (anchors[i].href == url) {
         opener = anchors[i];
         break;
      }
   }
   // get the size
   width = options.match(/width=([0-9]+)/);
   if (width) width = width[1];
   height = options.match(/height=([0-9]+)/);
   if (height) height = height[1];

   // open it
   hs.htmlExpand(opener, {
      objectType: 'iframe',
      src: url,
      width: width,
      height: height
   });
}