MooDialog is a MooTools plugin to replace the native alert(), confirm() and promt() javascript functions by more stylish ones. You can use it also for other DOM elements, create an IFrame dialog or even create an Ajax Dialog
As of version 0.7 MooDialog uses MooTools 1.3 and is not compatible with MooTools 1.2.
First you have to include the javascript files and css file in the head of your html document.
<link href="../Source/css/MooDialog.css" rel="stylesheet" type="text/css" media="screen" /> <script src="../Source/MooDialog.js" type="text/javascript"></script>
And depending on the functionality you want you use, you have to include, for example, the following files
<script src="../Source/MooDialog.Alert.js" type="text/javascript"></script> <script src="../Source/MooDialog.Request.js" type="text/javascript"></script>
If you want to use the standard fancy fade-in and fade-out effects, you should include Overlay.js and MooDialog.Fx.js in your page:
<script src="../Source/Overlay.js" type="text/javascript"></script> <script src="../Source/MooDialog.Fx" type="text/javascript"></script>
MooDialog is packager ready. This means you can build MooDialog to a single file with
Build via Packager (ty cpojer)
./packager register /path/to/MooDialog ./packager build MooDialog/* > MooDialog.js
To build this plugin without external dependencies use
./packager build MooDialog/* +use-only MooDialog > MooDialog.js
MooDialog does not style any element with JavaScript, but only uses CSS. The Element.setStyle method is only used to show and hide the dialog.
You can use the class option to use your own styles, or change the MooDialog.css file.
var dialog = new MooDialog([options]);
In every last parameter you can set the following options.
With this method you can set the content of the dialog.
dialog.setContent(arg1[, arg2, arg3, ...]);
With this method you open the dialog. It will fire the beforeOpen and open events. It will fire the show event if the dialog is actually opened.
dialog.open();
With this method you close the dialog. It will fire the beforeClos and close events. If the dialog is actually closed, it will fire the hide event.
dialog.close();
Removes the dialog from the DOM
dialog.destroy();
This method returns the dialog wrapper element
var myDialog = new MooDialog(); $(myDialog);
Create a dialog from an element
new Element('div',{text: 'This is a custom element'}).MooDialog([options]); // Or an existing element from the DOM $('el').MooDialog();
Create a alert dialog, a replacement for alert()
<script src="../Source/MooDialog.Alert.js" type="text/javascript"></script>
Javascript
new MooDialog.Alert(message[, options]); // example new MooDialog.Alert('Hi there!');
Create a confirm dialog, a replacement for confirm()
<script src="../Source/MooDialog.Confirm.js" type="text/javascript"></script>
Javascript
new MooDialog.Confirm(message[, fn1, fn2, options]); // Examaple new MooDialog.Confirm('Are you sure you want to do this?', function(){ new MooDialog.Alert('You are!') }, function(){ new MooDialog.Alert('You are not'); });
Create a confirm dialog if the user really want to follow this link
$('confirmDelete').confirmLinkClick('Are you sure you want to click this link');
Create a confirm dialog if the user try to submit a form
document.getElement('form#myForm').confirmFormSubmit('Do you want to submit this form');'
Create an prompt dialog, replacement for prompt()
<script src="../Source/MooDialog.Prompt.js" type="text/javascript"></script>
Javascript
new MooDialog.Prompt(message[, fn, options]); // Example new MooDialog.Prompt('What is your name?', function(ret){ new MooDialog.Alert('Your name is ' + ret); });
Create an error message
<script src="../Source/MooDialog.Error.js" type="text/javascript"></script>
Javascript
new MooDialog.Error(message); // Example new MooDialog.Error('O No, What have you done!?');
Create a dialog with an IFrame
new MooDialog.IFrame(url[, options]); // Example new MooDialog.IFrame('http://www.mootools.net');
Get the dialog content by a Ajax Request
<script src="../Source/MooDialog.Request.js" type="text/javascript"></script>
Javascript
new MooDialog.Request(url[, RequestOptions, options]); // Example new MooDialog.Request('exampleText.html');
Because you cannot refer to the dialog instance if you put the requestopions as second argument, this is a separate method to set them. This helps you to change the content of the dialog on for example the onRequest event of Request.
var dialog = new MooDialog.Request('exampleText.html'); dialog.setRequestOptions({ onRequest: function(){ dialog.setContent('loading...'); } });
A note on comments here: These comments are moderated. No comments will show up until they are approved. Comments that are not productive (i.e. inflammatory, rude, etc) will not be approved.
Found a bug in this plugin? Please report it this repository's Github Issues.
blog comments powered by Disqus