Commit 0d1d57fb authored by webchick's avatar webchick

Issue #1440662 by sun, marthinal, nod_, larowlan: Fixed Prevent links in node...

Issue #1440662 by sun, marthinal, nod_, larowlan: Fixed Prevent links in node preview from being clicked.
parent c2874bbc
......@@ -3938,6 +3938,17 @@ function node_library_info() {
array('system', 'drupal.form'),
),
);
$libraries['drupal.node.preview'] = array(
'title' => 'Node preview',
'version' => VERSION,
'js' => array(
drupal_get_path('module', 'node') . '/node.preview.js' => array(),
),
'dependencies' => array(
array('system', 'jquery'),
array('system', 'drupal'),
),
);
$libraries['drupal.content_types'] = array(
'title' => 'Content types',
'version' => VERSION,
......
......@@ -182,6 +182,7 @@ function theme_node_preview($variables) {
$preview_trimmed_version = FALSE;
$elements = node_view(clone $node, 'teaser');
$elements['#attached']['library'][] = array('node', 'drupal.node.preview');
$trimmed = drupal_render($elements);
$elements = node_view($node, 'full');
$full = drupal_render($elements);
......
(function ($, Drupal) {
"use strict";
/**
* Disabling all links in node previews to prevent users from leaving the page.
*/
Drupal.behaviors.nodePreviewDestroyLinks = {
attach: function (context) {
var $preview = $(context).find('.node.preview').once('node-preview');
if ($preview.length) {
$preview.on('click.preview', 'a', function (e) {
e.preventDefault();
});
}
},
detach: function (context, settings, trigger) {
if (trigger === 'unload') {
var $preview = $(context).find('.node.preview').removeOnce('node-preview');
if ($preview.length) {
$preview.off('click.preview');
}
}
}
};
})(jQuery, Drupal);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment