Skip to content

Commit

Permalink
[ui:dialog] fix #2551 trigger dialogopen event before open the dialog
Browse files Browse the repository at this point in the history
Example: Make the edit dialog the same size as the elFinder node

To define with `handlers.dialogopen: [Fn]` of the client setting or `elFinderInstance.bind('dialogopen', [Fn])`.

```javascript
handlers : {
    dialogopen : function(e, fm) {
        var dialog = e.data.dialog,
            elfNode;
        if (dialog.hasClass('elfinder-dialog-edit')) {
            elfNode = fm.getUI();
            dialog.css({
                top: 0,
                left: 0,
                width: elfNode.width(),
                height: elfNode.height()
            }).trigger('resize', { init : true });
        }
    }
}
```
  • Loading branch information
nao-pon committed Jun 19, 2018
1 parent 2cb1e73 commit d6b9ac9
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions js/ui/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ $.fn.elfinderdialog = function(opts, fm) {
if ((dialog = this.closest('.ui-dialog')).length) {
if (opts === 'open') {
if (dialog.css('display') === 'none') {
dialog.trigger('posinit').fadeIn(120, function() {
dialog.trigger('open');
// Need dialog.show() and hide() to detect elements size in open() callbacks
dialog.trigger('posinit').show().trigger('open').hide();
dialog.fadeIn(120, function() {
fm.trigger('dialogopened', {dialog: dialog});
});
}
Expand Down Expand Up @@ -353,8 +354,6 @@ $.fn.elfinderdialog = function(opts, fm) {
});
})
.on('open', function() {
var d = $(this);

if (syncSize.enabled) {
if (opts.height && opts.height !== 'auto') {
dialog.trigger('resize', {init: true});
Expand Down Expand Up @@ -393,6 +392,8 @@ $.fn.elfinderdialog = function(opts, fm) {

dialog.trigger('totop');

fm.trigger('dialogopen', {dialog: dialog});

typeof(opts.open) == 'function' && $.proxy(opts.open, self[0])();

if (opts.closeOnEscape) {
Expand Down Expand Up @@ -687,7 +688,7 @@ $.fn.elfinderdialog = function(opts, fm) {
overflow : dialog.css('overflow')
};

dialog.trigger('posinit').data('margin-y', self.outerHeight(true) - self.height());
dialog.data('margin-y', self.outerHeight(true) - self.height());

if (opts.resizable) {
dialog.resizable({
Expand All @@ -714,12 +715,12 @@ $.fn.elfinderdialog = function(opts, fm) {
}).data('hasResizable', true);
}

typeof(opts.create) == 'function' && $.proxy(opts.create, this)();

numberToTel();

tabstopsInit();

typeof(opts.create) == 'function' && $.proxy(opts.create, this)();

opts.autoOpen && self.elfinderdialog('open');

});
Expand Down

0 comments on commit d6b9ac9

Please sign in to comment.