2015-08-18 00:00:26 +00: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-18 00:00:26 +00:00
( function ( $ , Drupal ) {
Drupal . behaviors . nodePreviewDestroyLinks = {
2018-11-23 12:29:20 +00:00
attach : function attach ( context ) {
2015-08-18 00:00:26 +00:00
function clickPreviewModal ( event ) {
if ( event . button === 0 && ! event . altKey && ! event . ctrlKey && ! event . metaKey && ! event . shiftKey ) {
event . preventDefault ( ) ;
var $previewDialog = $ ( '<div>' + Drupal . theme ( 'nodePreviewModal' ) + '</div>' ) . appendTo ( 'body' ) ;
Drupal . dialog ( $previewDialog , {
title : Drupal . t ( 'Leave preview?' ) ,
2018-11-23 12:29:20 +00:00
buttons : [ {
text : Drupal . t ( 'Cancel' ) ,
click : function click ( ) {
$ ( this ) . dialog ( 'close' ) ;
2015-08-18 00:00:26 +00:00
}
2018-11-23 12:29:20 +00:00
} , {
text : Drupal . t ( 'Leave preview' ) ,
click : function click ( ) {
window . top . location . href = event . target . href ;
}
} ]
2015-08-18 00:00:26 +00:00
} ) . showModal ( ) ;
}
}
2018-11-23 12:29:20 +00:00
var $preview = $ ( context ) . once ( 'node-preview' ) ;
2015-08-18 00:00:26 +00:00
if ( $ ( context ) . find ( '.node-preview-container' ) . length ) {
2018-11-23 12:29:20 +00:00
$preview . on ( 'click.preview' , 'a:not([href^="#"], .node-preview-container a)' , clickPreviewModal ) ;
2015-08-18 00:00:26 +00:00
}
} ,
2018-11-23 12:29:20 +00:00
detach : function detach ( context , settings , trigger ) {
2015-08-18 00:00:26 +00:00
if ( trigger === 'unload' ) {
var $preview = $ ( context ) . find ( '.content' ) . removeOnce ( 'node-preview' ) ;
if ( $preview . length ) {
$preview . off ( 'click.preview' ) ;
}
}
}
} ;
Drupal . behaviors . nodePreviewSwitchViewMode = {
2018-11-23 12:29:20 +00:00
attach : function attach ( context ) {
2015-08-18 00:00:26 +00:00
var $autosubmit = $ ( context ) . find ( '[data-drupal-autosubmit]' ) . once ( 'autosubmit' ) ;
if ( $autosubmit . length ) {
$autosubmit . on ( 'formUpdated.preview' , function ( ) {
$ ( this . form ) . trigger ( 'submit' ) ;
} ) ;
}
}
} ;
Drupal . theme . nodePreviewModal = function ( ) {
2018-11-23 12:29:20 +00:00
return '<p>' + Drupal . t ( 'Leaving the preview will cause unsaved changes to be lost. Are you sure you want to leave the preview?' ) + '</p><small class="description">' + Drupal . t ( 'CTRL+Left click will prevent this dialog from showing and proceed to the clicked link.' ) + '</small>' ;
2015-08-18 00:00:26 +00:00
} ;
2018-11-23 12:29:20 +00:00
} ) ( jQuery , Drupal ) ;