Commit c90c317e authored by George's avatar George
Browse files

Issue #2907596 by Pranay Agarwal, Shani Maurya: Configurable button.

parent c11f0f55
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -4,11 +4,16 @@
 * Implements hook_preprocess_page().
 */
function animated_scroll_to_top_preprocess_page(&$variables) {
  $config = \Drupal::config('animated_scroll_to_top.settings');
  if ($config = \Drupal::config('animated_scroll_to_top.settings')) {
    $variables['#attached']['library'][] = 'animated_scroll_to_top/animated_scroll_to_top';
    $variables['#attached']['drupalSettings']['animated_scroll_to_top_position'] = $config->get('animated_scroll_to_top_position');
    $variables['#attached']['drupalSettings']['animated_scroll_to_top_button_bg_color'] = $config->get('animated_scroll_to_top_button_bg_color');
    $variables['#attached']['drupalSettings']['animated_scroll_to_top_button_hover_bg_color'] = $config->get('animated_scroll_to_top_button_hover_bg_color');
    $variables['#attached']['drupalSettings']['animated_scroll_to_top_button_height'] = $config->get('animated_scroll_to_top_button_height');
    $variables['#attached']['drupalSettings']['animated_scroll_to_top_button_width'] = $config->get('animated_scroll_to_top_button_width');
    $variables['#attached']['drupalSettings']['animated_scroll_to_top_button_bottom'] = $config->get('animated_scroll_to_top_button_bottom');
    $variables['#attached']['drupalSettings']['animated_scroll_to_top_button_position'] = $config->get('animated_scroll_to_top_button_position');
  }
}

+4 −0
Original line number Diff line number Diff line
animated_scroll_to_top_position: 1
animated_scroll_to_top_button_bg_color: '#CCCCCC'
animated_scroll_to_top_button_hover_bg_color: '#000000'
animated_scroll_to_top_button_height: 50
animated_scroll_to_top_button_width: 50
animated_scroll_to_top_button_bottom: 50
animated_scroll_to_top_button_position: 100
+0 −3
Original line number Diff line number Diff line
.scrollup {
  width: 50px;
  height: 50px;
  position: fixed;
  bottom: 50px;  
  text-indent: -9999px;
  background: url('../images/arrow.png') center no-repeat;
  border-radius: 5px;
+6 −0
Original line number Diff line number Diff line
@@ -6,10 +6,16 @@
        var position = drupalSettings.animated_scroll_to_top_position;
        var button_bg_color = drupalSettings.animated_scroll_to_top_button_bg_color;
        var hover_button_bg_color = drupalSettings.animated_scroll_to_top_button_hover_bg_color;
        var button_height = drupalSettings.animated_scroll_to_top_button_height;
        var button_width = drupalSettings.animated_scroll_to_top_button_width;
        var button_position_bottom = drupalSettings.animated_scroll_to_top_button_bottom + "px";
        var button_position_left_right = drupalSettings.animated_scroll_to_top_button_position + "px";
        if (position == 1) {
          $('.scrollup').css({"left": "100px", "background-color": button_bg_color});
          $('.scrollup').css({"left":button_position_left_right,"background-color":button_bg_color, "height":button_height, "width":button_width, "bottom":button_position_bottom });
        } else {
          $('.scrollup').css({"right": "100px", "background-color": button_bg_color});
          $('.scrollup').css({"right":button_position_left_right,"background-color":button_bg_color, "height":button_height, "width":button_width, "bottom":button_position_bottom });
        }
        $(".scrollup").hover(function () {
          $(this).css("background-color", hover_button_bg_color);
+43 −11
Original line number Diff line number Diff line
@@ -5,8 +5,8 @@ namespace Drupal\animated_scroll_to_top\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;

/*
 * Configure animated scroll to top settings for this site.
/**
 * Configure animated scroll to top settings.
 */
class AnimatedScrollToTopForm extends ConfigFormBase {

@@ -30,7 +30,6 @@ class AnimatedScrollToTopForm extends ConfigFormBase {
   * Implements buildForm().
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    
    $config = $this->config('animated_scroll_to_top.settings');

    $form['animated_scroll_to_top_position'] = [
@@ -43,18 +42,49 @@ class AnimatedScrollToTopForm extends ConfigFormBase {
      ],
      '#default_value' => $config->get('animated_scroll_to_top_position'),
    ];

    $form['animated_scroll_to_top_button_bg_color'] = [
      '#title' => $this->t('Animated scroll to top button background color'),
      '#description' => $this->t('Animated scroll to top button background color.'),
      '#type' => 'color',
      '#default_value' => $config->get('animated_scroll_to_top_button_bg_color'),
    ];

    $form['animated_scroll_to_top_button_hover_bg_color'] = [
      '#title' => $this->t('Animated scroll to top button hover background color'),
      '#description' => $this->t('Animated scroll to top button hover background color.'),
      '#type' => 'color',
      '#default_value' => $config->get('animated_scroll_to_top_button_hover_bg_color'),
    ];

    $form['animated_scroll_to_top_button_position'] = [
      '#title' => $this->t('Animated scroll to top button position from left/right'),
      '#description' => $this->t('Animated scroll to top button position from left/right.'),
      '#type' => 'number',
      '#default_value' => $config->get('animated_scroll_to_top_button_position'),
    ];

    $form['animated_scroll_to_top_button_height'] = [
      '#title' => $this->t('Animated scroll to top button height'),
      '#description' => $this->t('Animated scroll to top button height.'),
      '#type' => 'number',
      '#default_value' => $config->get('animated_scroll_to_top_button_height'),
    ];

    $form['animated_scroll_to_top_button_width'] = [
      '#title' => $this->t('Animated scroll to top button width'),
      '#description' => $this->t('Animated scroll to top button width.'),
      '#type' => 'number',
      '#default_value' => $config->get('animated_scroll_to_top_button_width'),
    ];

    $form['animated_scroll_to_top_button_bottom'] = [
      '#title' => $this->t('Animated scroll to top button position from bottom'),
      '#description' => $this->t('Animated scroll to top button position from bottom.'),
      '#type' => 'number',
      '#default_value' => $config->get('animated_scroll_to_top_button_bottom'),
    ];

    return parent::buildForm($form, $form_state);
  }

@@ -62,15 +92,17 @@ class AnimatedScrollToTopForm extends ConfigFormBase {
   * Implement submitForm().
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $animated_scroll_to_top_position = $form_state->getValues('animated_scroll_to_top_position');
    $animated_scroll_to_top_button_bg_color = $form_state->getValues('animated_scroll_to_top_button_bg_color');
    $animated_scroll_to_top_button_hover_bg_color = $form_state->getValues('animated_scroll_to_top_button_hover_bg_color');
    
    $config = $this->config('animated_scroll_to_top.settings')
      ->set('animated_scroll_to_top_position', $animated_scroll_to_top_position['animated_scroll_to_top_position'])
      ->set('animated_scroll_to_top_button_bg_color', $animated_scroll_to_top_position['animated_scroll_to_top_button_bg_color'])
      ->set('animated_scroll_to_top_button_hover_bg_color', $animated_scroll_to_top_position['animated_scroll_to_top_button_hover_bg_color'])
    $values = $form_state->getValues();
    $this->config('animated_scroll_to_top.settings')
      ->set('animated_scroll_to_top_position', $values['animated_scroll_to_top_position'])
      ->set('animated_scroll_to_top_button_bg_color', $values['animated_scroll_to_top_button_bg_color'])
      ->set('animated_scroll_to_top_button_hover_bg_color', $values['animated_scroll_to_top_button_hover_bg_color'])
      ->set('animated_scroll_to_top_button_height', $values['animated_scroll_to_top_button_height'])
      ->set('animated_scroll_to_top_button_width', $values['animated_scroll_to_top_button_width'])
      ->set('animated_scroll_to_top_button_bottom', $values['animated_scroll_to_top_button_bottom'])
      ->set('animated_scroll_to_top_button_position', $values['animated_scroll_to_top_button_position'])
      ->save();
    parent::submitForm($form, $form_state);
  }

}