2017-03-16 15:29:07 +00:00
/ * *
* @ file
2018-11-23 12:29:20 +00:00
* JavaScript behaviors for webform dialogs .
2017-03-16 15:29:07 +00:00
* /
2018-11-23 12:29:20 +00:00
( function ( $ , Drupal , drupalSettings ) {
2017-03-16 15:29:07 +00:00
'use strict' ;
2018-11-23 12:29:20 +00:00
// @see http://api.jqueryui.com/dialog/
Drupal . webform = Drupal . webform || { } ;
Drupal . webform . dialog = Drupal . webform . dialog || { } ;
Drupal . webform . dialog . options = Drupal . webform . dialog . options || { } ;
/ * *
* Open webform dialog using preset options .
*
* @ type { Drupal ~ behavior }
* /
Drupal . behaviors . webformDialog = {
attach : function ( context ) {
$ ( 'a.webform-dialog' , context ) . once ( 'webform-dialog' ) . each ( function ( ) {
var $a = $ ( this ) ;
// Get default options.
var options = $ . extend ( { } , Drupal . webform . dialog . options ) ;
// Get preset dialog options.
if ( $a . attr ( 'class' ) . match ( /webform-dialog-([a-z0-9_]+)/ ) ) {
var dialogOptionsName = RegExp . $1 ;
if ( drupalSettings . webform . dialog . options [ dialogOptionsName ] ) {
options = drupalSettings . webform . dialog . options [ dialogOptionsName ] ;
// Unset title.
delete options . title ;
}
}
// Get custom dialog options.
if ( $ ( this ) . data ( 'dialog-options' ) ) {
$ . extend ( options , $ ( this ) . data ( 'dialog-options' ) ) ;
}
var href = $a . attr ( 'href' ) ;
// Replace ENTITY_TYPE and ENTITY_ID placeholders and update the href.
// @see webform_page_attachments()
if ( href . indexOf ( '?source_entity_type=ENTITY_TYPE&source_entity_id=ENTITY_ID' ) !== - 1 ) {
if ( drupalSettings . webform . dialog . entity _type && drupalSettings . webform . dialog . entity _id ) {
href = href . replace ( 'ENTITY_TYPE' , encodeURIComponent ( drupalSettings . webform . dialog . entity _type ) ) ;
href = href . replace ( 'ENTITY_ID' , encodeURIComponent ( drupalSettings . webform . dialog . entity _id ) ) ;
}
else {
href = href . replace ( '?source_entity_type=ENTITY_TYPE&source_entity_id=ENTITY_ID' , '' ) ;
}
$a . attr ( 'href' , href ) ;
}
// Append _webform_dialog=1 to href to trigger Ajax support.
// @see \Drupal\webform\WebformSubmissionForm::setEntity
href += ( href . indexOf ( '?' ) === - 1 ? '?' : '&' ) + '_webform_dialog=1' ;
var element _settings = { } ;
element _settings . progress = { type : 'fullscreen' } ;
element _settings . url = href ;
element _settings . event = 'click' ;
element _settings . dialogType = $a . data ( 'dialog-type' ) || 'modal' ;
element _settings . dialog = options ;
element _settings . element = this ;
Drupal . ajax ( element _settings ) ;
} ) ;
2017-03-16 15:29:07 +00:00
}
} ;
2018-11-23 12:29:20 +00:00
} ) ( jQuery , Drupal , drupalSettings ) ;