Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
],
"dependencies": {
"component/emitter": "1.1.3",
"component/overlay": "0.3.1",
"component/overlay": "0.3.5",
"component/domify": "1.3.1",
"component/event": "0.1.4",
"component/classes": "1.2.1",
Expand Down
41 changes: 25 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ Dialog.prototype.effect = function(type){
*/

Dialog.prototype.modal = function(){
this._overlay = overlay();
this.overlay();
return this;
};

Expand All @@ -182,14 +182,7 @@ Dialog.prototype.modal = function(){
*/

Dialog.prototype.overlay = function(opts){
var self = this;
opts = opts || { closable: true };
var o = overlay(opts);
o.on('hide', function(){
self._overlay = null;
self.hide();
});
this._overlay = o;
this._overlayOptions = opts || { closable: true };
return this;
};

Expand Down Expand Up @@ -234,13 +227,9 @@ Dialog.prototype.fixed = function(){

Dialog.prototype.show = function(){
var overlay = this._overlay;
var self = this;

// overlay
if (overlay) {
overlay.show();
this._classes.add('modal');
}
this.showOverlay();

// escape
if (!overlay || overlay.closable) this.escapable();
Expand All @@ -260,10 +249,30 @@ Dialog.prototype.show = function(){

Dialog.prototype.hideOverlay = function(){
if (!this._overlay) return;
this._overlay.remove();
this._overlay.off('hide');
this._overlay.hide();
this._overlay = null;
};

/**
* Show the overlay.
*
* @api private
*/

Dialog.prototype.showOverlay = function(){
var self = this;

if (!self._overlayOptions) return;
self._overlay = overlay(self._overlayOptions)
.once('hide', function(){
self._overlay = null;
self.hide();
})
.show();
self._classes.add('modal');
};

/**
* Hide the dialog with optional delay of `ms`,
* otherwise the dialog is removed immediately.
Expand All @@ -282,7 +291,7 @@ Dialog.prototype.hide = function(ms){
events.unbind(document, 'keydown', self._escKeyCallback);
}

// prevent thrashing - this isn't used
// prevent thrashing
self.hiding = true;

// duration
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"component-event": "^0.1.0",
"component-emitter": "^1.1.1",
"domify": "^1.1.1",
"overlay-component": "^0.3.0",
"overlay-component": "^0.3.5",
"component-classes": "^1.1.3",
"stringify": "^3.1.0"
},
Expand Down
7 changes: 5 additions & 2 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@
.on('hide', function(){
console.log('closed fourth');

dialog('Click the overlay to close')
var overlayDialog = dialog('Click the overlay to close')
.effect('slide')
.overlay()
.show()
.on('hide', function(){
.once('hide', function(){
console.log('closed fifth');

dialog('Modal')
Expand All @@ -93,6 +93,9 @@
.show()
.on('hide', function(){
console.log('closed eight');

//test overlay once again (#21)
overlayDialog.show();
});

});
Expand Down
47 changes: 47 additions & 0 deletions test/reuse.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!DOCTYPE 5>
<html>
<head>
<title>Dialog</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="../build/build.css" />
<style>
body {
margin: 0;
}
.dialog .title {
display: inline-block;
margin: 0 0 5px 0;
font-size: 18px;
font-weight: normal;
}
.dialog p {
margin: 0;
padding: 0;
font-size: .9em;
}
.dialog.off-center {
top: 20px;
left: 15%;
}
</style>
</head>
<body>
<title>Dialog</title>
<script src="../build/build.js"></script>
<script>
var dialog = require('dialog');
var n = 0;
var overlayDialog = dialog('Click the overlay or close button')
.closable()
.overlay()
.effect('slide')
.on('hide', function(){
console.log('closed', ++n);
setTimeout(function() {
overlayDialog.show();
}, 300);
})
.show();
</script>
</body>
</html>