Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scrollup
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
scrollup
Commits
6ff48c92
Commit
6ff48c92
authored
May 22, 2024
by
Vladimir Roudakov
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3325272
by VladimirAus, vknikolov, jannakha: Rewrite scrollup to use Vanila JS
parent
d84419fb
No related branches found
No related tags found
1 merge request
!7
Resolve #3325272 "Rewrite scrollup to"
Pipeline
#178781
passed with warnings
May 22, 2024
Stage: build
Stage: validate
Changes
3
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
css/scrollup_top.css
+7
-6
7 additions, 6 deletions
css/scrollup_top.css
js/scrollup_top.js
+52
-49
52 additions, 49 deletions
js/scrollup_top.js
scrollup.libraries.yml
+1
-2
1 addition, 2 deletions
scrollup.libraries.yml
with
60 additions
and
57 deletions
css/scrollup_top.css
+
7
−
6
View file @
6ff48c92
.scrollup
{
width
:
5
0px
;
height
:
5
0px
;
width
:
8
0px
;
height
:
10
0px
;
position
:
fixed
;
bottom
:
50px
;
text-indent
:
-9999px
;
background
:
url
(
'../images/arrow.png'
)
center
no-repeat
;
border-radius
:
50%
;
background
:
url
(..
/
images
/
arrow
.
png
)
50%
20%
no-repeat
;
display
:
none
;
}
.scroll-title
{
text-indent
:
0
;
min-width
:
100px
;
position
:
relative
;
top
:
31px
;
top
:
15px
;
text-align
:
center
;
color
:
#fff
;
}
a
.scrollup
{
border-bottom-style
:
none
;
border-bottom
:
0
;
z-index
:
10
;
}
.scrollup
:hover
{
...
...
This diff is collapsed.
Click to expand it.
js/scrollup_top.js
+
52
−
49
View file @
6ff48c92
/**
* @file
* ScrollUp javascript file.
*/
(
function
(
$
,
Drupal
,
drupalSettings
,
once
)
{
(
function
(
Drupal
,
drupalSettings
,
once
)
{
Drupal
.
behaviors
.
scrollup
=
{
attach
:
function
(
context
,
settings
)
{
$
(
document
).
ready
(
function
()
{
if
(
drupalSettings
.
scrollup_title
==
''
||
drupalSettings
.
scrollup_title
==
null
)
{
var
scroll_title
=
''
;
attach
:
function
()
{
let
linkTitle
=
'
Scroll to the top of the page.
'
;
let
linkContent
=
''
;
if
(
drupalSettings
.
scrollup_title
!==
''
&&
drupalSettings
.
scrollup_title
!==
null
)
{
linkTitle
=
drupalSettings
.
scrollup_title
;
linkContent
=
drupalSettings
.
scrollup_title
;
}
else
{
var
scroll_title
=
drupalSettings
.
scrollup_title
;
const
bodyContainer
=
once
(
'
scrollup
'
,
document
.
querySelector
(
'
body
'
));
if
(
bodyContainer
.
length
===
0
)
{
return
;
}
once
(
'
scrollToTop
'
,
'
body
'
).
forEach
(
function
(
element
)
{
$
(
element
).
append
(
'
<a href="#" title="
'
+
scroll_title
+
'
" class="scrollup">Scroll<div class="scroll-title">
'
+
scroll_title
+
'
</div></a>
'
);
});
var
position
=
drupalSettings
.
scrollup_position
;
var
button_bg_color
=
drupalSettings
.
scrollup_button_bg_color
;
var
hover_button_bg_color
=
drupalSettings
.
scrollup_button_hover_bg_color
;
var
scroll_window_position
=
parseInt
(
drupalSettings
.
scrollup_window_position
);
var
scroll_speed
=
parseInt
(
drupalSettings
.
scrollup_speed
);
const
[
body
]
=
bodyContainer
;
body
.
insertAdjacentHTML
(
"
beforeend
"
,
`<a href="#" title="
${
linkTitle
}
" class="scrollup">Scroll<span class="scroll-title">
${
linkContent
}
</span></a>`
);
const
scrollUpButton
=
document
.
querySelector
(
'
.scrollup
'
);
const
position
=
drupalSettings
.
scrollup_position
;
const
button_bg_color
=
drupalSettings
.
scrollup_button_bg_color
;
const
hover_button_bg_color
=
drupalSettings
.
scrollup_button_hover_bg_color
;
const
scroll_window_position
=
parseInt
(
drupalSettings
.
scrollup_window_position
);
const
scroll_speed
=
parseInt
(
drupalSettings
.
scrollup_speed
);
if
(
position
==
1
)
{
$
(
'
.scrollup
'
).
css
({
"
right
"
:
"
100px
"
,
"
background-color
"
:
button_bg_color
});
document
.
dir
===
'
ltr
'
?
scrollUpButton
.
style
.
right
=
'
0px
'
:
scrollUpButton
.
style
.
left
=
'
0px
'
;
}
else
{
$
(
'
.scrollup
'
).
css
({
"
left
"
:
"
100px
"
,
"
background-color
"
:
button_bg_color
});
scrollUpButton
.
style
.
left
=
'
0px
'
;
}
scrollUpButton
.
style
.
backgroundColor
=
`
${
button_bg_color
}
`
;
$
(
"
.scrollup
"
).
hover
(
function
()
{
$
(
this
).
css
(
"
background-color
"
,
hover_button_bg_color
);
},
function
()
{
$
(
this
).
css
(
"
background-color
"
,
button_bg_color
);
scrollUpButton
.
addEventListener
(
"
mouseover
"
,
function
(
event
)
{
event
.
preventDefault
();
scrollUpButton
.
style
.
backgroundColor
=
`
${
hover_button_bg_color
}
`
;
});
$
(
window
).
scroll
(
function
()
{
if
(
$
(
this
).
scrollTop
()
>
scroll_window_position
)
{
$
(
'
.scrollup
'
).
fadeIn
();
}
else
{
$
(
'
.scrollup
'
).
fadeOut
();
}
scrollUpButton
.
addEventListener
(
"
mouseleave
"
,
function
(
event
)
{
event
.
preventDefault
();
scrollUpButton
.
style
.
backgroundColor
=
`
${
button_bg_color
}
`
;
});
$
(
"
.scrollup
"
).
click
(
function
()
{
$
(
"
html, body
"
).
animate
({
scrollTop
:
0
},
scroll_speed
);
return
false
;
window
.
addEventListener
(
'
scroll
'
,
function
(
event
)
{
event
.
preventDefault
();
scrollUpButton
.
style
.
display
=
(
window
.
pageYOffset
>
scroll_window_position
)
?
'
block
'
:
'
none
'
;
});
scrollUpButton
.
addEventListener
(
'
click
'
,
function
(
event
)
{
event
.
preventDefault
();
document
.
querySelectorAll
(
'
html, body
'
).
forEach
(
node
=>
node
.
scrollTo
({
top
:
0
,
behavior
:
"
smooth
"
,
duration
:
scroll_speed
}))
});
}
};
})(
jQuery
,
Drupal
,
drupalSettings
,
once
);
})(
Drupal
,
drupalSettings
,
once
);
This diff is collapsed.
Click to expand it.
scrollup.libraries.yml
+
1
−
2
View file @
6ff48c92
scrollup
:
version
:
1
.x
version
:
3
.x
css
:
theme
:
css/scrollup_top.css
:
{}
js
:
js/scrollup_top.js
:
{}
dependencies
:
-
core/jquery
-
core/drupalSettings
-
core/drupal
-
core/once
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment