Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

smoothly scroll to the edited post, after edit-form submission #69

Open
wants to merge 2 commits into
base: 8.x-1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions js/liveblog.editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
isLoading = false
})
}
target.on('liveblog-post--edit-form--removed', function (e) {
var offset = target.offset()
offset.top -= 100
$('html, body').animate({
'scrollTop': offset.top
})
target.closest('.liveblog-post').addClass('liveblog-post--edit--finished')
})
}
else {
// TODO remove editor
Expand Down
14 changes: 13 additions & 1 deletion src/Form/LiveblogPostForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Drupal\liveblog\Form;

use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\InvokeCommand;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
Expand Down Expand Up @@ -181,7 +183,17 @@ protected function actions(array $form, FormStateInterface $form_state) {
public function ajaxRebuildCallback(array $form, FormStateInterface $form_state) {
// Hide the form after editing on the node page.
if ($this->getOperation() == 'edit' && $this->isJSONEditForm()) {
return ['#markup' => ''];
$response = new AjaxResponse();
$response->addCommand(new InvokeCommand(
'#' . $this->getFormRebuildWrapperId(),
'trigger',
array('liveblog-post--edit-form--removed')
));
$response->addCommand(new InvokeCommand(
'#' . $this->getFormRebuildWrapperId() . ' form.liveblog-post-form',
'remove'
));
return $response;
}
return $form;
}
Expand Down