Popup

docs

As I refactored CNET's javascript I kept coming across little functions like this:

function makePopup(url) {
  window.open(url, 'toolbar=.....');
}

Developers (here at least) hated having to write the syntax for generating new windows so they'd litter the place with a bunch of these little functions and it was annoying me.

So I basically wrote a wrapper class for opening windows that makes it work in a more MooTools-ish way:

var myPopup = new Browser.Popup('http://www.mootools.net',{
  width: 500,
  height: 600
});
execute this code

All the other stuff. The toolbars, the window location, the status, the scrollbars, etc. They all have defaults so you can leave them out. You don't even need the width and height in the example above. So, full blown, you can do this:

var myPopup = new Browser.Popup('http://www.mootools.net', {
  width: 500,
  /*everything below here are the defaults, 
    so you could omit them*/
  height: 600,
  x: 50,
  y: 50,
  toolbar: 0,
  location: 0,
  directories: 0,
  status: 0,
  scrollbars: 'auto',
  resizeable: 1,
  name: 'popup'
});
execute this code

The object you get back, the instance of the Browser.Popup class, has a few useful properties.

.focus() focuses the popup, .close() will close the popup, and .window is the window element itself.


cnet-libraries/02-browser/03-popup.txt · Last modified: 2008/12/25 12:42 by aaron-n