The simplest case certainly is the buttonless info box having just a body section and no buttons. It can be closed by pressing ESC or by clicking on the cross icon in the upper right corner of the popup.
The first argument 'info' is the
popup's id.
The second argument is
the configuration object.
new ProtoPopup('info', { body : 'Forget this info', width: '200px' }).show();
<div id="info" class="proto-popup">
<img src="img/cancel.png" class="proto-popup-cancel"/>
<div id="info-header" class="proto-popup-header"/>
<div id="info-body" class="proto-popup-body">Forget this info</div>
<div id="info-footer" class="proto-popup-footer"/>
</div>
The downside of this somewhat raw usage is that each time you click the button a new ProtoPopup object having the same id is created. Moreover, when pressing ESC or clicking the cancel icon the popup is hidden, but not destroyed. Consequence: ProtoPopup DIVs keep accumulating at the bottom of the HTML body... Very bad. Also, one of the promised features – position memory across showing/hiding – is not available with this approach. Try it. Press the above button, move the popup, close it, and press the button once more: it will be again centered on the screen, instead of appearing where you closed it.
What we need, then, is a singleton, like in the following example.
To always use the same popup, the class method get() is what you want.
ProtoPopup.get('refined_info', {
body : 'Forget this info',
width: '200px'
}).show();
In other situations you might want to have a reusable info() function handy.
Reusables function are created using the makeFunction() class method.
var info = ProtoPopup.makeFunction('reusable_info', {
header : 'Announcement',
width: '200px'
});
info('Forget this info');
info('Forget this info, too');
var debug = ProtoPopup.makeFunction('debug', {
header : 'Debug output',
appendBody : true,
width: '200px'
});
debug('First debug message');
debug('More debugging');
ProtoPopup.get('modal', {
body : new Element('div').update('This is a modal alert'),
modal: true,
width: '200px'
}).show();
ProtoPopup.Alert.get('alert', {
body : new Element('div').update('This is an alert!'),
width: '200px',
cancelIconSrc: false,
closeBtnLabel: 'Kapatmak',
}).show();
var p = ProtoPopup.Dialog.get('dialog', {
body : new Element('div')
.update('Do you want to save the changes you made?'),
cancelIconSrc: false,
width: '200px',
buttons: [
{
name: 'dont_save',
label: 'Don\'t Save',
onClick: function() { p.hide(); alert('You clicked "Don\'t Save"') },
giveFocus: false, // default
vertical: 'after-footer', // default
horizontal: 'left', // default
},
{
name: 'cancel',
label: 'Cancel',
onClick: function() { p.hide(); alert('You clicked "Cancel"') }
vertical: 'after-footer'
},
{
name: 'save',
label: 'Save',
onClick: function() { p.hide(); alert('You clicked "Save"') },
giveFocus: true,
horizontal: 'right',
vertical: 'after-footer'
},
]
}).show();
As popups are identified via their id, you may keep around multiple popups at any one time, each having it's own object, each remembering its previous position. So you might have an info() popup, an error() popup...