2015-08-17 17:00:26 -07:00
/ * *
2018-11-23 12:29:20 +00:00
* DO NOT EDIT THIS FILE .
* See the following change record for more information ,
* https : //www.drupal.org/node/2815083
* @ preserve
* * /
2015-08-17 17:00:26 -07:00
( function ( $ , Drupal ) {
Drupal . behaviors . dialog = {
2018-11-23 12:29:20 +00:00
attach : function attach ( context , settings ) {
2015-08-17 17:00:26 -07:00
var $context = $ ( context ) ;
if ( ! $ ( '#drupal-modal' ) . length ) {
$ ( '<div id="drupal-modal" class="ui-front"/>' ) . hide ( ) . appendTo ( 'body' ) ;
}
var $dialog = $context . closest ( '.ui-dialog-content' ) ;
if ( $dialog . length ) {
if ( $dialog . dialog ( 'option' , 'drupalAutoButtons' ) ) {
$dialog . trigger ( 'dialogButtonsChange' ) ;
}
$dialog . dialog ( 'widget' ) . trigger ( 'focus' ) ;
}
var originalClose = settings . dialog . close ;
2018-11-23 12:29:20 +00:00
2015-08-17 17:00:26 -07:00
settings . dialog . close = function ( event ) {
2018-11-23 12:29:20 +00:00
for ( var _len = arguments . length , args = Array ( _len > 1 ? _len - 1 : 0 ) , _key = 1 ; _key < _len ; _key ++ ) {
args [ _key - 1 ] = arguments [ _key ] ;
}
originalClose . apply ( settings . dialog , [ event ] . concat ( args ) ) ;
2015-08-17 17:00:26 -07:00
$ ( event . target ) . remove ( ) ;
} ;
} ,
2018-11-23 12:29:20 +00:00
prepareDialogButtons : function prepareDialogButtons ( $dialog ) {
2015-08-17 17:00:26 -07:00
var buttons = [ ] ;
2016-09-07 13:26:21 -07:00
var $buttons = $dialog . find ( '.form-actions input[type=submit], .form-actions a.button' ) ;
2015-08-17 17:00:26 -07:00
$buttons . each ( function ( ) {
var $originalButton = $ ( this ) . css ( {
2015-08-27 12:03:05 -07:00
display : 'block' ,
2015-08-17 17:00:26 -07:00
width : 0 ,
height : 0 ,
padding : 0 ,
2016-09-07 13:26:21 -07:00
border : 0 ,
overflow : 'hidden'
2015-08-17 17:00:26 -07:00
} ) ;
buttons . push ( {
2015-09-04 13:20:09 -07:00
text : $originalButton . html ( ) || $originalButton . attr ( 'value' ) ,
class : $originalButton . attr ( 'class' ) ,
2018-11-23 12:29:20 +00:00
click : function click ( e ) {
2016-09-07 13:26:21 -07:00
if ( $originalButton . is ( 'a' ) ) {
$originalButton [ 0 ] . click ( ) ;
2018-11-23 12:29:20 +00:00
} else {
2016-09-07 13:26:21 -07:00
$originalButton . trigger ( 'mousedown' ) . trigger ( 'mouseup' ) . trigger ( 'click' ) ;
e . preventDefault ( ) ;
}
2015-08-17 17:00:26 -07:00
}
} ) ;
} ) ;
return buttons ;
}
} ;
Drupal . AjaxCommands . prototype . openDialog = function ( ajax , response , status ) {
if ( ! response . selector ) {
return false ;
}
var $dialog = $ ( response . selector ) ;
if ( ! $dialog . length ) {
2015-08-27 12:03:05 -07:00
$dialog = $ ( '<div id="' + response . selector . replace ( /^#/ , '' ) + '" class="ui-front"/>' ) . appendTo ( 'body' ) ;
2015-08-17 17:00:26 -07:00
}
2018-11-23 12:29:20 +00:00
2015-08-17 17:00:26 -07:00
if ( ! ajax . wrapper ) {
ajax . wrapper = $dialog . attr ( 'id' ) ;
}
response . command = 'insert' ;
response . method = 'html' ;
ajax . commands . insert ( ajax , response , status ) ;
if ( ! response . dialogOptions . buttons ) {
response . dialogOptions . drupalAutoButtons = true ;
response . dialogOptions . buttons = Drupal . behaviors . dialog . prepareDialogButtons ( $dialog ) ;
}
$dialog . on ( 'dialogButtonsChange' , function ( ) {
var buttons = Drupal . behaviors . dialog . prepareDialogButtons ( $dialog ) ;
$dialog . dialog ( 'option' , 'buttons' , buttons ) ;
} ) ;
response . dialogOptions = response . dialogOptions || { } ;
var dialog = Drupal . dialog ( $dialog . get ( 0 ) , response . dialogOptions ) ;
if ( response . dialogOptions . modal ) {
dialog . showModal ( ) ;
2018-11-23 12:29:20 +00:00
} else {
2015-08-17 17:00:26 -07:00
dialog . show ( ) ;
}
$dialog . parent ( ) . find ( '.ui-dialog-buttonset' ) . addClass ( 'form-actions' ) ;
} ;
Drupal . AjaxCommands . prototype . closeDialog = function ( ajax , response , status ) {
var $dialog = $ ( response . selector ) ;
if ( $dialog . length ) {
Drupal . dialog ( $dialog . get ( 0 ) ) . close ( ) ;
if ( ! response . persist ) {
$dialog . remove ( ) ;
}
}
$dialog . off ( 'dialogButtonsChange' ) ;
} ;
Drupal . AjaxCommands . prototype . setDialogOption = function ( ajax , response , status ) {
var $dialog = $ ( response . selector ) ;
if ( $dialog . length ) {
$dialog . dialog ( 'option' , response . optionName , response . optionValue ) ;
}
} ;
$ ( window ) . on ( 'dialog:aftercreate' , function ( e , dialog , $element , settings ) {
$element . on ( 'click.dialog' , '.dialog-cancel' , function ( e ) {
dialog . close ( 'cancel' ) ;
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
} ) ;
} ) ;
$ ( window ) . on ( 'dialog:beforeclose' , function ( e , dialog , $element ) {
$element . off ( '.dialog' ) ;
} ) ;
2018-11-23 12:29:20 +00:00
} ) ( jQuery , Drupal ) ;