Fixed smooth scrolling in task and ticket comments, which does not work in Safari
This commit is contained in:
parent
c3e1439b06
commit
42164e7778
1 changed files with 29 additions and 29 deletions
|
@ -2,10 +2,10 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Node Comment terminology:
|
* Node Comment terminology:
|
||||||
*
|
*
|
||||||
* "target node"
|
* "target node"
|
||||||
* node which is being commented on
|
* node which is being commented on
|
||||||
*
|
*
|
||||||
* "target comment"
|
* "target comment"
|
||||||
* nodecomment which is being replied to
|
* nodecomment which is being replied to
|
||||||
*/
|
*/
|
||||||
|
@ -13,7 +13,7 @@
|
||||||
/**
|
/**
|
||||||
* Implementation of hook_form_alter().
|
* 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;
|
global $user;
|
||||||
|
|
||||||
// Make sure we alter node form.
|
// 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) {
|
$form['type']['#value'] .'_node_form' != $form_id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$node = &$form['#node'];
|
$node = &$form['#node'];
|
||||||
$mode = _comment_get_display_setting('mode', $node);
|
$mode = _comment_get_display_setting('mode', $node);
|
||||||
$flat = in_array($mode, array(COMMENT_MODE_FLAT_COLLAPSED, COMMENT_MODE_FLAT_EXPANDED));
|
$flat = in_array($mode, array(COMMENT_MODE_FLAT_COLLAPSED, COMMENT_MODE_FLAT_EXPANDED));
|
||||||
|
|
||||||
// Convert dashes to underscores as we get type from menu path.
|
// Convert dashes to underscores as we get type from menu path.
|
||||||
$type = str_replace('-', '_', arg(2));
|
$type = str_replace('-', '_', arg(2));
|
||||||
|
|
||||||
|
@ -37,26 +37,26 @@ function nodecomment_form_alter(&$form, &$form_state, $form_id) {
|
||||||
&& !empty($type)
|
&& !empty($type)
|
||||||
&& in_array($type, nodecomment_get_comment_types())
|
&& in_array($type, nodecomment_get_comment_types())
|
||||||
) {
|
) {
|
||||||
|
|
||||||
$node_context = arg(3);
|
$node_context = arg(3);
|
||||||
$comment_context = arg(4);
|
$comment_context = arg(4);
|
||||||
|
|
||||||
$node->comment_target_nid = $node_context;
|
$node->comment_target_nid = $node_context;
|
||||||
// If the parrent comment context is not set, use 0 (thread root).
|
// If the parrent comment context is not set, use 0 (thread root).
|
||||||
$node->comment_target_cid = is_numeric($comment_context) ? $comment_context : 0;
|
$node->comment_target_cid = is_numeric($comment_context) ? $comment_context : 0;
|
||||||
|
|
||||||
$target_node = node_load($node_context);
|
$target_node = node_load($node_context);
|
||||||
$target_comment = node_load(is_numeric($comment_context) ? $comment_context : $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'])) {
|
if (!isset($form['#prefix'])) {
|
||||||
$form['#prefix'] = '';
|
$form['#prefix'] = '';
|
||||||
}
|
}
|
||||||
// In flat mode we use target comment context to store the data, but
|
// 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);
|
$form['#prefix'] .= node_view($flat ? $target_node : $target_comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($node->comment_target_nid)) {
|
if (isset($node->comment_target_nid)) {
|
||||||
// We're altering a nodecomment form.
|
// We're altering a nodecomment form.
|
||||||
_nodecomment_alter_nodecomment_form($form, $node, $target_node, $target_comment);
|
_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)) {
|
if (nodecomment_get_comment_type($node->type)) {
|
||||||
// This is node edit form for a content type with nodecomments.
|
// 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.
|
// loaded using node_load(), e.g. if it was passed from API call.
|
||||||
if (!isset($node->node_comment) && isset($node->comment)) {
|
if (!isset($node->node_comment) && isset($node->comment)) {
|
||||||
$node->node_comment = $node->comment;
|
$node->node_comment = $node->comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load real value because it's the form to change it.
|
// Load real value because it's the form to change it.
|
||||||
$form['comment_settings']['comment']['#default_value'] = $node->node_comment;
|
$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
|
// 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
|
// setting form element from the real node form, which can lead to breakage
|
||||||
// of our logics.
|
// of our logics.
|
||||||
// To protect against these fake forms, we insert special marker
|
// To protect against these fake forms, we insert special marker
|
||||||
// into form which will continue its life in node object. Fake forms won't
|
// 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
|
// have the marker, which will allow us to detect them in
|
||||||
// hook_nodeapi('presave') and to react properly.
|
// 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'.
|
// change the setting, we would overwrite it's values in 'presave'.
|
||||||
// This will stay for now, until better solution replaces it.
|
// This will stay for now, until better solution replaces it.
|
||||||
$form['comment_settings']['nodecomment_real_node_form'] = array(
|
$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())) {
|
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 {
|
else {
|
||||||
// This is a pure comment.
|
// 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['menu']['#access'] = FALSE;
|
||||||
$form['path']['#access'] = FALSE;
|
$form['path']['#access'] = FALSE;
|
||||||
$form['comment_settings']['#access'] = FALSE;
|
$form['comment_settings']['#access'] = FALSE;
|
||||||
|
|
||||||
// Remove the teaser splitter if body field is present.
|
// Remove the teaser splitter if body field is present.
|
||||||
if (isset($form['body_field']) && is_array($form['body_field']['#after_build'])) {
|
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']);
|
$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_js']['#access'] = FALSE;
|
||||||
$form['body_field']['teaser_include']['#access'] = FALSE;
|
$form['body_field']['teaser_include']['#access'] = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up an automatic title in case it's new nodecomment.
|
// Set up an automatic title in case it's new nodecomment.
|
||||||
// Use target comment title, not target node.
|
// Use target comment title, not target node.
|
||||||
if (empty($node->nid)) {
|
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;
|
$form['title']['#default_value'] = $re . $target_comment->title;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make the title not required:
|
// Make the title not required:
|
||||||
$form['title']['#required'] = FALSE;
|
$form['title']['#required'] = FALSE;
|
||||||
if (variable_get('comment_subject_field_'. $target_node->type, 1) != 1) {
|
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
|
'#value' => $target_node->language
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// When previewing nodecomment, scroll to preview.
|
// When previewing nodecomment, scroll to preview.
|
||||||
// Note that we add anchor for blank node so that scrolling works on first
|
// 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)) {
|
if ($node->build_mode === NODE_BUILD_PREVIEW || !isset($node->nid)) {
|
||||||
$form['#action'] .= '#preview';
|
$form['#action'] .= '#preview';
|
||||||
}
|
}
|
||||||
|
@ -295,7 +295,7 @@ function nodecomment_node_form_validate(&$form, &$form_state) {
|
||||||
* Redirect the node form to the right place.
|
* Redirect the node form to the right place.
|
||||||
*/
|
*/
|
||||||
function nodecomment_node_form_submit(&$form, &$form_state) {
|
function nodecomment_node_form_submit(&$form, &$form_state) {
|
||||||
$node = $form['#node'];
|
$node = $form['#node'];
|
||||||
$nid = $form_state['nid'];
|
$nid = $form_state['nid'];
|
||||||
if (empty($node->nid)) {
|
if (empty($node->nid)) {
|
||||||
$node->nid = $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);
|
$form['actions']['cancel']['#value'] = l(t('Cancel'), 'node/'. $node->comment_target_nid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue