From 42164e77787962fc68afad33bb37a501cd9a1d9a Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Wed, 6 Sep 2017 17:18:55 +0200 Subject: [PATCH] Fixed smooth scrolling in task and ticket comments, which does not work in Safari --- .../includes/nodecomment.forms.inc | 58 +++++++++---------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/modules/nodecomment/includes/nodecomment.forms.inc b/modules/nodecomment/includes/nodecomment.forms.inc index 106f72d..8e4c351 100644 --- a/modules/nodecomment/includes/nodecomment.forms.inc +++ b/modules/nodecomment/includes/nodecomment.forms.inc @@ -2,10 +2,10 @@ /** * Node Comment terminology: - * + * * "target node" * node which is being commented on - * + * * "target comment" * nodecomment which is being replied to */ @@ -13,7 +13,7 @@ /** * Implementation of hook_form_alter(). */ -function nodecomment_form_alter(&$form, &$form_state, $form_id) { +function nodecomment_form_alter(&$form, &$form_state, $form_id) { global $user; // Make sure we alter node form. @@ -22,11 +22,11 @@ function nodecomment_form_alter(&$form, &$form_state, $form_id) { $form['type']['#value'] .'_node_form' != $form_id) { return; } - + $node = &$form['#node']; $mode = _comment_get_display_setting('mode', $node); $flat = in_array($mode, array(COMMENT_MODE_FLAT_COLLAPSED, COMMENT_MODE_FLAT_EXPANDED)); - + // Convert dashes to underscores as we get type from menu path. $type = str_replace('-', '_', arg(2)); @@ -37,26 +37,26 @@ function nodecomment_form_alter(&$form, &$form_state, $form_id) { && !empty($type) && in_array($type, nodecomment_get_comment_types()) ) { - + $node_context = arg(3); $comment_context = arg(4); - + $node->comment_target_nid = $node_context; // If the parrent comment context is not set, use 0 (thread root). $node->comment_target_cid = is_numeric($comment_context) ? $comment_context : 0; - + $target_node = node_load($node_context); $target_comment = node_load(is_numeric($comment_context) ? $comment_context : $node_context); - // Show the node which this comment is replying to. + // Show the node which this comment is replying to. if (!isset($form['#prefix'])) { $form['#prefix'] = ''; } // In flat mode we use target comment context to store the data, but - // still show the target node. + // still show the target node. $form['#prefix'] .= node_view($flat ? $target_node : $target_comment); } - + if (isset($node->comment_target_nid)) { // We're altering a nodecomment form. _nodecomment_alter_nodecomment_form($form, $node, $target_node, $target_comment); @@ -64,25 +64,25 @@ function nodecomment_form_alter(&$form, &$form_state, $form_id) { if (nodecomment_get_comment_type($node->type)) { // This is node edit form for a content type with nodecomments. - - // Make sure that node_comment property is set up, if the node wasn't + + // Make sure that node_comment property is set up, if the node wasn't // loaded using node_load(), e.g. if it was passed from API call. if (!isset($node->node_comment) && isset($node->comment)) { $node->node_comment = $node->comment; } - + // Load real value because it's the form to change it. $form['comment_settings']['comment']['#default_value'] = $node->node_comment; - - // Add workaround for fake forms: some modules (for example, Node Gallery) + + // Add workaround for fake forms: some modules (for example, Node Gallery) // use node form id in their special forms. They don't always copy comment // setting form element from the real node form, which can lead to breakage // of our logics. // To protect against these fake forms, we insert special marker - // into form which will continue its life in node object. Fake forms won't - // have the marker, which will allow us to detect them in + // into form which will continue its life in node object. Fake forms won't + // have the marker, which will allow us to detect them in // hook_nodeapi('presave') and to react properly. - // This is not bullet-proof though, cause if the faked form decided to + // This is not bullet-proof though, cause if the faked form decided to // change the setting, we would overwrite it's values in 'presave'. // This will stay for now, until better solution replaces it. $form['comment_settings']['nodecomment_real_node_form'] = array( @@ -92,7 +92,7 @@ function nodecomment_form_alter(&$form, &$form_state, $form_id) { } if (in_array($type, nodecomment_get_comment_types())) { - drupal_add_js('$jq(\'html\').delay(100).animate({scrollTop:$("#node-form").offset().top},2400);', 'inline', 'footer'); + drupal_add_js('$jq(function(){$(\'html,body\').animate({scrollTop:$("#node-form").offset().top},2000);});', 'inline', 'footer'); } } @@ -148,12 +148,12 @@ function _nodecomment_alter_nodecomment_form(&$form, $node, $target_node = NULL, } else { // This is a pure comment. - - // Remove settings that have no meaning on comments. + + // Remove settings that have no meaning on comments. $form['menu']['#access'] = FALSE; $form['path']['#access'] = FALSE; $form['comment_settings']['#access'] = FALSE; - + // Remove the teaser splitter if body field is present. if (isset($form['body_field']) && is_array($form['body_field']['#after_build'])) { $teaser_js_build = array_search('node_teaser_js', $form['body_field']['#after_build']); @@ -161,7 +161,7 @@ function _nodecomment_alter_nodecomment_form(&$form, $node, $target_node = NULL, $form['body_field']['teaser_js']['#access'] = FALSE; $form['body_field']['teaser_include']['#access'] = FALSE; } - + // Set up an automatic title in case it's new nodecomment. // Use target comment title, not target node. if (empty($node->nid)) { @@ -174,7 +174,7 @@ function _nodecomment_alter_nodecomment_form(&$form, $node, $target_node = NULL, $form['title']['#default_value'] = $re . $target_comment->title; } } - + // Make the title not required: $form['title']['#required'] = FALSE; if (variable_get('comment_subject_field_'. $target_node->type, 1) != 1) { @@ -193,10 +193,10 @@ function _nodecomment_alter_nodecomment_form(&$form, $node, $target_node = NULL, '#value' => $target_node->language ); } - + // When previewing nodecomment, scroll to preview. // Note that we add anchor for blank node so that scrolling works on first - // preview too. + // preview too. if ($node->build_mode === NODE_BUILD_PREVIEW || !isset($node->nid)) { $form['#action'] .= '#preview'; } @@ -295,7 +295,7 @@ function nodecomment_node_form_validate(&$form, &$form_state) { * Redirect the node form to the right place. */ function nodecomment_node_form_submit(&$form, &$form_state) { - $node = $form['#node']; + $node = $form['#node']; $nid = $form_state['nid']; if (empty($node->nid)) { $node->nid = $nid; @@ -326,5 +326,5 @@ function nodecomment_form_node_delete_confirm_alter(&$form, &$form_state) { ); $form['actions']['cancel']['#value'] = l(t('Cancel'), 'node/'. $node->comment_target_nid); } - } + } }