Skip to content
Permalink
Browse files

Added support to History.set to allow setting the target

  • Loading branch information...
darkfrog26 committed Aug 5, 2019
1 parent 1acf571 commit 30fac501b8964499cde9502914d8be44093de2a6
@@ -46,8 +46,8 @@ object History {
})
}

def set(url: URL): Unit = {
document.location.href = url.toString
def set(url: URL, target: String = "_self"): Unit = {
window.open(url.toString, target)
stateChange := HistoryStateChange(url, StateType.Set, null)
}

@@ -2,13 +2,15 @@ package io.youi.example.screen

import io.youi.app.screen.UIScreen
import io.youi.example.ui.component.Header
import io.youi.net.URL
import io.youi.ui

import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global

trait UIExampleScreen extends UIScreen {
protected def header: Header = UIExampleScreen.header
def url: URL = URL(s"https://github.com/outr/youi/tree/master/example/js/src/main/scala/io/youi/example/ui/${getClass.getSimpleName}.scala")

override protected def init(): Future[Unit] = super.init().map { _ =>
container.position.top := header.position.bottom
@@ -4,10 +4,13 @@ import io.youi.component.{Container, HTMLTextView, ImageView}
import io.youi.example.ClientExampleApplication
import io.youi._
import io.youi.app.screen.ScreenManager
import io.youi.example.screen.UIExampleScreen
import io.youi.example.ui.UIExamples
import io.youi.font.GoogleFont
import io.youi.image.Image
import io.youi.paint.Paint
import io.youi.style.{Position, WhiteSpace}
import io.youi.style.{Display, Position, WhiteSpace}
import reactify._

import scala.concurrent.ExecutionContext.Implicits.global

@@ -45,6 +48,28 @@ class Header extends Container { self =>
position.top := 15.0
}

children += logo
children += title
val link: HTMLTextView = new HTMLTextView {
GoogleFont.`Open Sans`.`600`.load().foreach { fnt =>
font := fnt
}
font.size := 14.pt
color := application.colors.blue.dark
value := "View Source"
cursor := Cursor.Pointer
ScreenManager().active.attachAndFire {
case _: UIExampleScreen => display := Display.Block
case _ => display := Display.None
}
event.click.on {
ScreenManager().active() match {
case screen: UIExampleScreen => History.set(screen.url, "_blank")
case _ =>
}
}
whiteSpace := WhiteSpace.NoWrap
position.right := ui.size.width - 25.0
position.top := title.position.bottom - 5.0
}

children ++= List(logo, title, link)
}

0 comments on commit 30fac50

Please sign in to comment.
You can’t perform that action at this time.