DESCRIPTION:

An implementation of lightbox style dialogs to replace native browser dialogs (alert, confirm, prompt).

FEATURES/PROBLEMS:

SYNOPSIS:

Showing simple alerts


$alert('This is a dialog');

Getting confirmation


$confirm('Are you sure?', function(yes) {
  if (yes) $alert('Good for you');
  else $alert('Boohoo');
});

Prompting a question


$prompt('What is your name?', function(answer) {
  if (answer) $alert('Hi, ' + answer);
  else $alert('How rude!');
});

Loading ajax content


new Dialog.Ajax('/path/to/content');

Doing something custom


new Dialog.Base({
  content: '<form action="/login" method="post"><p><label for="login">Login</label><br/><input type="text" name="login" id="login"/></p><p><label for="password">Password</label><br/><input type="password" name="password" id="password"/></p></form>',
  buttons: [
    {text: 'Login', close: false, onclick: function(event) {
      event.stop();
      event.element().up('.dialog').down('form').submit();
    }},
    {text: 'Cancel', close: true, onclick: Event.stopper}
  ],
  afterShow: function() {
    Dialog.current().contents.down('input').activate();
  }
});

Options to dialogs

You can set protototo defaults via DialogOptions.

By default protototo assumes that asset paths are:

If you want these to be different you can specify options before loading protototo:


DialogOptions = {
  assetPrefix: '/your/prefix', 
  stylesheetPath: '/path/to/stylesheet.css', // will look in /your/prefix/path/to/stylesheet.css
  busyImage: '/path/to/ajax/working.gif' // will look in /your/prefix/path/to/ajax/working.gif
};

Other default options for all dialogs (these are the actual defaults):


DialogOptions = {
  overlayOpacity: 0.75,
  transitionDuration: 0.4,
  defaultWidth: 400,
  Buttons: {
    template: new Template('<a href="#" class="#{className}">#{text}</a>') // how to build buttons
  }
};

Options you can pass to dialogs to override defaults:

Button descriptions depend on the template used to create buttons. The description should at least include the attributes needed to fill the template, a default className is provided.

Additionally each button description accepts

REQUIREMENTS:

INSTALL:

Then include the following in the html where you want protototo:


<script type="text/javascript" src="path/to/prototype.js"></script>
<script type="text/javascript" src="path/to/effects.js"></script>
<script type="text/javascript" src="path/to/protototo.js"></script>

LICENSE:

(The MIT License)

Copyright (c) 2009 Arni Einarsson arni.dwg@gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.