Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kolya-me’s picture

Assigned: Unassigned » kolya-me

We (@InternetDevels team) have no answer in this issue for a long time, so we start working on it.

tarekdj’s picture

Hi id.webik, sorry to be late. Thank you for your initiative. I'm currently planning to launch a local sprint to upgrade the module. This will be an opportunity to noobs to learn. I apreciate your help.

kolya-me’s picture

Assigned: kolya-me » Unassigned
Status: Active » Needs review
FileSize
12.75 KB

Here is patch that porting the module to Drupal 8.

We are keen on further development of scroll_to_top module. So, we would like to be part of the story in future.
Is there any chance of me (@InternetDevels team) joining the project as the maintainers?

Development sponsored by InternetDevels.

tarekdj’s picture

Issue tags: +TUNIS_2014_JANUARY, +drupalsprint
tarekdj’s picture

Status: Needs review » Needs work

Patch works fine. But needs more coding standards improvement.

tarekdj’s picture

  1. +++ b/scroll_to_top.module
    @@ -67,4 +27,46 @@ function scroll_to_top_permission() {
    +		$path = drupal_get_path('module', 'scroll_to_top');
    +		$page['#attached']['css'][$path . '/scroll_to_top.css'] = array('every_page' => TRUE);
    +		$page['#attached']['js'][$path . '/scroll_to_top.js'] = array('every_page' => TRUE);
    +		_drupal_add_js(array('scroll_to_top' => array('label' => t($config->get('scroll_to_top_label', 'Back to top')))), 'setting');
    +		$position = "";
    

    Since _drupal_add_js is deprectaed use hook_library_info() and #attached.

  2. +++ b/scroll_to_top.module
    @@ -67,4 +27,46 @@ function scroll_to_top_permission() {
    +		_drupal_add_css($css, 'inline');
    

    use #attached instead

tarekdj’s picture

Issue marked for Tunisian local sprint next week!

tarekdj’s picture

Issue tags: +Novice
mykolay’s picture

Status: Needs work » Needs review
Issue tags: -drupalsprint, -TUNIS_2014_FEBRUARY, -Novice
FileSize
18.95 KB
10.84 KB

We have seen that work on fixing the patch stopped so we decided to help.

Here is patch that porting the module to Drupal 8 with fixes conversion of which were listed in the comments #5, #6.

We want to continue development of version for Drupal 8. Can you please add me (@InternetDevels team) as a (co-) maintainers?

tarekdj’s picture

Hi id_matvey,
I appreciate your involvement and your interest. But I consider this little module as an opportunity for novices especially for my local community to learn drupal. I don't think for now that I need a co-maintainer. Thank you again.

mykolay’s picture

Drupal 8 is changing rapidly and so we can keep the branch fast updated we need maintainers accsess.

shkiper’s picture

Hi, I made a version of this module that works with Drupal 8 beta
Here is my patch

gvso’s picture

Hi!, Here is patch that porting the module to Drupal 8. This works with the current Drupal 8 beta 3.

naveenvalecha’s picture

Status: Needs review » Needs work

Thanks! Awesome patch. Needs minor modifications. :)

  1. +++ b/css/scroll_to_top.css
    @@ -0,0 +1,65 @@
    +#back-top {
    +	position: fixed;
    +	bottom: 10px;
    +	margin-left: 20px;
    +	z-index:499;
    +	/*IE6 hack */
    +		 _position: absolute;
    +		 _top:expression(documentElement.scrollTop+body.scrollTop);
    +		 _margin-top: 500px;
    

    White space issues.
    Also at lot of places in the file.
    No need to do IE6 hack becuase drupal 8 does not provide supports of IE6.

  2. +++ b/js/scroll_to_top.js
    @@ -0,0 +1,47 @@
    +(function($){
    +/**
    

    Need to use window object as well.
    (function ($, window) {
    and use the window instead of $(window)
    I guess it should be like that I have specified.

  3. +++ b/js/scroll_to_top.js
    @@ -0,0 +1,47 @@
    +	// append  back to top link top body if it is not
    +	var exist= jQuery('#back-top').length; // exist = 0 if element doesn't exist
    +	if(exist == 0){ // this test is for fixing the ajax bug
    +		$("body").append("<p id='back-top'><a href='#top'><span id='button'></span><span id='link'>" + settings.scroll_to_top.label + "</span></a></p>");
    +	}
    +	// Preview function
    +	$("input").change(function () {
    +		// building the style for preview
    +		var style="<style>#scroll-to-top-prev-container #back-top-prev span#button-prev{ background-color:"+$("#edit-scroll-to-top-bg-color-out").val()+";} #scroll-to-top-prev-container #back-top-prev span#button-prev:hover{ background-color:"+$("#edit-scroll-to-top-bg-color-hover").val()+" }</style>"
    +		// building the html content of preview
    +		var html="<p id='back-top-prev' style='position:relative;'><a href='#top'><span id='button-prev'></span><span id='link'>";
    +		// if label enabled display it
    +		if($("#edit-scroll-to-top-display-text").attr('checked')){
    +		html+=$("#edit-scroll-to-top-label").val();
    +		}
    +		html+="</span></a></p>";
    +		// update the preview
    +		$("#scroll-to-top-prev-container").html(style+html);
    +	});
    

    Lot of white space issues in the whole file.

  4. +++ b/scroll_to_top.libraries.yml
    @@ -0,0 +1,7 @@
    +scroll_to_top:
    +  version: 1.x
    +  js:
    +    js/scroll_to_top.js: {}
    +  css:
    +    theme:
    +      css/scroll_to_top.css: {}
    

    Add the dependencies here.under js path.
    dependencies:
    - core/jquery

  5. +++ b/scroll_to_top.module
    @@ -6,65 +6,51 @@
    +    _drupal_add_css($css, 'inline');
    +    _drupal_add_js( array('scroll_to_top' => array( 'label' => t($config->get( 'scroll_to_top_label')))), 'setting');
    

    We should use #attached instead of these deprecated functions.

  6. +++ b/src/Form/ScrollToTopForm.php
    @@ -0,0 +1,100 @@
    +    $config->set( 'scroll_to_top_label', $form_state->getValue('scroll_to_top_label'))
    +      ->set('scroll_to_top_position', $form_state->getValue('scroll_to_top_position'))
    +      ->set('scroll_to_top_bg_color_hover', $form_state->getValue('scroll_to_top_bg_color_hover'))
    +      ->set('scroll_to_top_bg_color_out', $form_state->getValue('scroll_to_top_bg_color_out'))
    +      ->set('scroll_to_top_display_text', $form_state->getValue('scroll_to_top_display_text'))
    +      ->set('scroll_to_top_enable_admin_theme', $form_state->getValue('scroll_to_top_enable_admin_theme'))
    

    Its not a issue but I prefer this one. Get the form state values using $form_state->getValues in a variable and then set them in configuration.

For interdiff : https://docs.google.com/presentation/d/1EcsQ88tlNwi3lGh2u-5SYz06_3i9fcc5...

naveenvalecha’s picture

+++ b/css/scroll_to_top.css
@@ -0,0 +1,65 @@
diff --git a/css/up-arrow.png b/css/up-arrow.png

diff --git a/css/up-arrow.png b/css/up-arrow.png
new file mode 100755

Better to keep the background image inside the images directory in module.

gvso’s picture

Here is my revision. The (function ( $, window) { and just window instead $(window) make the module not work...

gvso’s picture

Status: Needs work » Needs review
naveenvalecha’s picture

Status: Needs review » Needs work

Seems half patch. new patch missed the .settings.yml,.libraries.yml,

gvso’s picture

Status: Needs work » Needs review
FileSize
19.99 KB
1.19 KB

I realized that you gave me suggestions minutes before I submitted my last patch. Here is going again. I hope this is ok.

gvso’s picture

In this patch I solve the white spaces issues. The interdiff doesn't show differences and give me an empty file, so I just submit the patch. Sorry, I am learning how to do these stuff, but now I am understanding how it works :)

tarekdj’s picture

Status: Needs review » Needs work

The patch doesn't apply correctly due to binary file issue in arrow.png. Good work basically with fiew changes:

  1. +++ b/js/scroll_to_top.js
    @@ -0,0 +1,49 @@
    +(function ($) {
    

    This becomes:

    (function ($, Drupal, drupalSettings) {
    

    see: https://www.drupal.org/node/1793334

  2. +++ b/js/scroll_to_top.js
    @@ -0,0 +1,49 @@
    +      $("body").append("<p id='back-top'><a href='#top'><span id='button'></span><span id='link'>" + settings.scroll_to_top.label + "</span></a></p>");
    

    use:
    $("body").append("<p id='back-top'><a href='#top'><span id='button'></span><span id='link'>" + drupalSettings.label + "</span></a></p>");

  3. +++ b/scroll_to_top.module
    @@ -6,65 +6,51 @@
    +function scroll_to_top_page_build() {
    

    Change by:

    function scroll_to_top_preprocess_page(&$variables) {
    
  4. +++ b/scroll_to_top.module
    @@ -6,65 +6,51 @@
    +    _drupal_add_library( 'scroll_to_top/scroll_to_top' );
    

    change by :

    $variables['#attached']['library'][] = 'scroll_to_top/scroll_to_top';
    
  5. +++ b/scroll_to_top.module
    @@ -6,65 +6,51 @@
    +    _drupal_add_css($css, 'inline');
    

    use:

    $variables['#attached']['css'][] = array( 'data' => $css, 'type' => 'inline');
    
  6. +++ b/scroll_to_top.module
    @@ -6,65 +6,51 @@
    +    _drupal_add_js( array('scroll_to_top' => array( 'label' => t($config->get( 'scroll_to_top_label')))), 'setting');
    

    use:

    $variables['#attached']['js'][] = array('type' => 'setting', 'data' => array('label' => t($config->get( 'scroll_to_top_label'))));
    

I also noticed that there is a problem with color forms in scroll to top settings (needs confirmation)

gvso’s picture

Status: Needs work » Needs review
FileSize
20.09 KB
4.52 KB

Thank you very much for reviewing. Here is my patch again. I noticed that without the ready handle the button isn't appended in the body, also I changed all $(element).handle(function(){}); by $(element).on('handle', function(){});. Furthermore, with that the correct way for the preview is $('scroll-to-top').on('change', 'input', function(){});.

tarekdj’s picture

Status: Needs review » Needs work

Almost there :-)!
It's Ok for using .on() but you have to keep Drupal.behaviors. You can see some example in core module js files that would help you.
A last little thing: see https://www.drupal.org/node/1955232 ;-)
Good job

gvso’s picture

Status: Needs work » Needs review
FileSize
20.18 KB
4.02 KB

I've done what you told me. Thanks again. Here is the patch

naveenvalecha’s picture

Awesome Job!
Patch seems Ready to go!
+1 for RTBC

tarekdj’s picture

Status: Needs review » Reviewed & tested by the community

Great work! Patch will be committed to new branch tomorrow.

gvso’s picture

I'm so glad for this. Thank you very much for the help!

naveenvalecha’s picture

@tarekdj,
A minor change.Would you please apply it while commmitting.

+++ b/scroll_to_top.info.yml
@@ -0,0 +1,5 @@
+package: Other

Remove this package key because the package is already other if we not specify.
Also Add the configure key.
configure: scroll_to_top.form

@gvso,
Nice contribution!
If you wanna write up your experiance for other students then It would be very good if you write your experiance how did you port this module to Drupal 8.
I have just prepared a single slide for you to just show you the sample example.See the presentation below
https://docs.google.com/presentation/d/1FkFJqkg4M3g3TBUHQRxUzeJB8hEPzkEZ...

  • tarekdj committed dce2912 on 8.x-0.x authored by gvso
    Issue #2147973 by gvso, id_matvey, Gordogost, andrii zahura,...
tarekdj’s picture

Version: 7.x-2.x-dev » 8.x-0.x-dev
Status: Reviewed & tested by the community » Closed (fixed)

Thank you all for the awesome work!

naveenvalecha’s picture

Status: Closed (fixed) » Fixed

Cool :) Thanks @tarekdj!
Closing the issue with right status.

gvso’s picture

@naveenvalecha I'm gonna do it. I am also going to do a video explaining how to port this module from scratch :)

naveenvalecha’s picture

Cool :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

gvso’s picture

I absolutely forgot to copy the link. Here is the series where I explain how to port a module using this as an example https://conocimientoplus.wordpress.com/2014/12/10/porting-a-drupal-7-mod...

naveenvalecha’s picture

Awesome!