Skip to content

Commit 37add41

Browse files
committed
Fix homepage scrolling error. Remove svg4everybody
1 parent 6c4ebaf commit 37add41

File tree

3 files changed

+28
-41
lines changed

3 files changed

+28
-41
lines changed

guide/homepage/.js/src/main/scala/io/udash/web/homepage/components/Header.scala

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,19 @@ import io.udash.web.commons.config.ExternalUrls
55
import io.udash.web.commons.styles.GlobalStyles
66
import io.udash.web.commons.styles.attributes.Attributes
77
import io.udash.web.commons.styles.components.{HeaderButtonsStyles, HeaderNavStyles, MobileMenuStyles}
8-
import io.udash.web.homepage.Context._
9-
import io.udash.web.homepage.{HelloState, IndexState}
8+
import io.udash.web.homepage.Context.*
9+
import io.udash.web.homepage.HelloState
1010
import io.udash.web.homepage.styles.partials.{HeaderStyles, HomepageStyles}
11-
import io.udash.wrappers.jquery.{JQueryEvent, _}
12-
import org.scalajs.dom.Element
13-
import scalatags.JsDom.all._
11+
import io.udash.wrappers.jquery.*
12+
import org.scalajs.dom.{Element, document}
13+
import scalatags.JsDom.all.*
1414

1515
object Header extends HeaderButtons with HeaderNav {
16-
import io.udash.css.CssView._
16+
import io.udash.css.CssView.*
1717

1818
override val buttonStyles: HeaderButtonsStyles = HeaderStyles
1919
override val navStyles: HeaderNavStyles = HeaderStyles
2020

21-
private val window = jQ(org.scalajs.dom.window)
22-
window.on("scroll", onScroll)
23-
2421
private lazy val btnMobileMenu = a(href := "#", MobileMenuStyles.btnMobile, HeaderStyles.btnMobile)(
2522
div(MobileMenuStyles.btnMobileLines)(
2623
span(MobileMenuStyles.btnMobileLineTop),
@@ -46,35 +43,34 @@ object Header extends HeaderButtons with HeaderNav {
4643
)
4744
).render
4845

49-
private lazy val jqNav = jQ(navElement)
50-
private lazy val jqMobileButton = jQ(btnMobileMenu)
46+
locally {
47+
jQ(org.scalajs.dom.window).on("scroll", onScroll)
5148

52-
jqMobileButton.on(EventName.click, (_: Element, jqEvent: JQueryEvent) => {
53-
jqEvent.preventDefault()
54-
toggleBooleanAttribute(jqNav, Attributes.data(Attributes.Active))
55-
toggleBooleanAttribute(jqMobileButton, Attributes.data(Attributes.Active))
56-
})
49+
jQ(btnMobileMenu).on(EventName.click, (_: Element, jqEvent: JQueryEvent) => {
50+
jqEvent.preventDefault()
51+
toggleBooleanAttribute(navElement, Attributes.data(Attributes.Active))
52+
toggleBooleanAttribute(btnMobileMenu, Attributes.data(Attributes.Active))
53+
})
54+
}
5755

5856
private def onScroll(el: Element, ev: JQueryEvent): Unit = {
5957
val pinnedAttr: String = Attributes.data(Attributes.Pinned)
6058

61-
val pin = jQ(template).attr(pinnedAttr).getOrElse("false").toBoolean
62-
val scrollTop = jQ(org.scalajs.dom.window).scrollTop()
63-
val introHeight = jQ(s".${HomepageStyles.sectionIntro.className}").height()
64-
59+
val pin = template.attributes.get(pinnedAttr).exists(_.value == "true")
60+
val scrollTop = org.scalajs.dom.window.scrollY
61+
val introHeight = document.querySelector(s".${HomepageStyles.sectionIntro.className}").getBoundingClientRect().height
6562
if (scrollTop >= introHeight && !pin) {
66-
jQ(template).attr(pinnedAttr, "true")
63+
template.setAttribute(pinnedAttr, "true")
6764
} else if (scrollTop < introHeight && pin) {
68-
jQ(template).attr(pinnedAttr, "false")
65+
template.setAttribute(pinnedAttr, "false")
6966
}
7067
}
7168

7269
def getTemplate: Modifier = template
7370

74-
private def toggleBooleanAttribute(jqElement: JQuery, attribute: String): Unit = {
75-
val activeOption = jqElement.attr(attribute)
76-
val newValue = if (activeOption.isEmpty || !activeOption.get.toBoolean) true else false
77-
78-
jqElement.attr(Attributes.data(Attributes.Active), newValue.toString)
71+
private def toggleBooleanAttribute(element: Element, attribute: String): Unit = {
72+
val activeOption = element.attributes.get(attribute).map(_.value)
73+
val newValue = activeOption.isEmpty || !activeOption.get.toBoolean
74+
element.setAttribute(attribute, newValue.toString)
7975
}
8076
}
Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
package io.udash.web.homepage.views
22

3-
import com.avsystem.commons._
4-
import io.udash._
3+
import com.avsystem.commons.*
4+
import io.udash.*
55
import io.udash.css.CssView
66
import io.udash.web.commons.components.Footer
77
import io.udash.web.commons.styles.GlobalStyles
88
import io.udash.web.homepage.RootState
99
import io.udash.web.homepage.components.Header
1010
import io.udash.web.homepage.styles.partials.HomepageStyles
11-
import scalatags.JsDom.tags2._
12-
13-
import scala.scalajs.js
11+
import scalatags.JsDom.tags2.*
1412

1513
object RootViewFactory extends StaticViewFactory[RootState.type](() => new RootView)
1614

1715
class RootView extends ContainerView with CssView {
18-
import scalatags.JsDom.all._
16+
import scalatags.JsDom.all.*
1917

2018
private val content = div(
2119
Header.getTemplate,
@@ -26,9 +24,4 @@ class RootView extends ContainerView with CssView {
2624
)
2725

2826
override def getTemplate: Modifier = content
29-
30-
override def renderChild(view: Option[View]): Unit = {
31-
super.renderChild(view)
32-
js.Dynamic.global.svg4everybody()
33-
}
3427
}

project/Dependencies.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import sbt.*
55
import sbt.Keys.scalaVersion
66

77
object Dependencies {
8-
val versionOfScala = "2.13.18" //update .github/workflows/ci.yml as well
8+
val versionOfScala = "2.13.18" //run githubWorkflowGenerate
99

1010
val jqueryWrapperVersion = "3.3.0"
1111

@@ -30,7 +30,6 @@ object Dependencies {
3030
val flexmarkVersion = "0.64.8"
3131
val logbackVersion = "1.3.16"
3232
val fontAwesomeVersion = "5.10.1"
33-
val svg4everybodyVersion = "2.1.9"
3433

3534
val scalatestVersion = "3.2.19"
3635
val mockitoScalaVersion = "2.0.0"
@@ -165,7 +164,6 @@ object Dependencies {
165164
))
166165

167166
val homepageJsDeps = Def.setting(Seq[JSModuleID](
168-
"org.webjars.npm" % "svg4everybody" % svg4everybodyVersion / s"$svg4everybodyVersion/dist/svg4everybody.js",
169167
ProvidedJS / "prism.js",
170168
))
171169

0 commit comments

Comments
 (0)