Commit ef303b5f authored by Thorsten Wißmann's avatar Thorsten Wißmann 🐧
Browse files

Build a custom box for showing smv code

parent ff0d2da2
.overlayBox {
overflow: hidden;
display: none;
position: fixed;
top: 10%;
left: 10%;
bottom: 10%;
right: 10%;
z-index: 1;
background-color: rgba(0,0,0, 0.9);
color: white;
white-space: pre;
border-radius: 8px;
}
.overlayBox.overlayBoxVisible {
height: 80%;
width: 80%;
display: -webkit-box; /* OLD - iOS 6-, Safari 3.1-6 */
display: -moz-box; /* OLD - Firefox 19- (buggy but mostly works) */
display: -ms-flexbox; /* TWEENER - IE 10 */
display: -webkit-flex; /* NEW - Chrome */
display: flex; /* NEW, Spec - Opera 12.1, Firefox 20+ */
-ms-flex-direction: column;
-moz-flex-direction: column;
-webkit-flex-direction: column;
flex-direction: column;
padding: 5px;
}
.overlayBox .overlayHeader {
height: 2em;
padding-left: 0.3em;
padding-top: 0.1em;
padding-bottom: 0.3em;
padding-right: 0em;
font-weight: bold;
}
.overlayBox .overlayHeader > * {
height: 89%;
background: rgba(10, 10, 10, 0.9);
font-weight: bold;
float: right;
color: white;
border: none;
}
.overlayBox .overlayContent {
/* border: 1px solid red; */
border: none;
font-family: monospace;
flex: 1;
overflow-y: scroll;
overflow-x: auto;
}
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
<link rel="stylesheet" type="text/css" href="carcolors.css"> <link rel="stylesheet" type="text/css" href="carcolors.css">
<link rel="stylesheet" type="text/css" href="main.css"> <link rel="stylesheet" type="text/css" href="main.css">
<link rel="stylesheet" type="text/css" href="multilang.css"> <link rel="stylesheet" type="text/css" href="multilang.css">
<link rel="stylesheet" type="text/css" href="overlay.css">
</head> </head>
<body> <body>
<script type="text/javascript"> <script type="text/javascript">
...@@ -30,11 +31,13 @@ ...@@ -30,11 +31,13 @@
} }
}); });
app.ports.stringInNewTab.subscribe( app.ports.stringInNewTab.subscribe(
function(text) { function(params) {
/* from http://stackoverflow.com/a/20194533/4400896 */ /* from http://stackoverflow.com/a/20194533/4400896 */
var a = window.document.createElement('a'); // var a = window.document.createElement('a');
var base64 = btoa(unescape(encodeURIComponent(text))); // var text = params.content;
window.open("data:text/plain;charset=UTF-8;base64,"+base64,"UTF-8 Text"); // var base64 = btoa(unescape(encodeURIComponent(text)));
// window.open("data:text/plain;charset=UTF-8;base64,"+base64,"UTF-8 Text");
app.ports.showOverlayMessage.send(params);
}); });
app.ports.downloadPlainText.subscribe( app.ports.downloadPlainText.subscribe(
function(params) { function(params) {
......
...@@ -27,6 +27,7 @@ import ListUtils ...@@ -27,6 +27,7 @@ import ListUtils
import Shunt import Shunt
import RailPuzzle.History as RPHist import RailPuzzle.History as RPHist
import MultiLang import MultiLang
import Overlay
type alias Flags = type alias Flags =
{ clickableHeader : Bool { clickableHeader : Bool
...@@ -40,6 +41,7 @@ type alias Model = ...@@ -40,6 +41,7 @@ type alias Model =
, queries : Array (List Int) -- queries to solve for the current puzzle , queries : Array (List Int) -- queries to solve for the current puzzle
, smv : NuSmvInput.Model , smv : NuSmvInput.Model
, languageSwitcher : MultiLang.Model , languageSwitcher : MultiLang.Model
, overlay : Overlay.Model
, flags : Flags , flags : Flags
} }
...@@ -49,6 +51,7 @@ type Msg ...@@ -49,6 +51,7 @@ type Msg
| SwitchQuery String | SwitchQuery String
| ForSmv NuSmvInput.Msg | ForSmv NuSmvInput.Msg
| ForMultiLang MultiLang.Msg | ForMultiLang MultiLang.Msg
| ForOverlay Overlay.Msg
| NextPuzzle | NextPuzzle
main = main =
...@@ -88,13 +91,18 @@ init flags = ...@@ -88,13 +91,18 @@ init flags =
, queries = Array.fromList ex.queries , queries = Array.fromList ex.queries
, query_index = 0 , query_index = 0
, languageSwitcher = MultiLang.init , languageSwitcher = MultiLang.init
, overlay = Overlay.init
, flags = flags , flags = flags
} }
, Cmd.none , Cmd.none
) )
subscriptions : Model -> Sub Msg subscriptions : Model -> Sub Msg
subscriptions model = Sub.map ForRails <| RailPuzzle.subscriptions model.rails subscriptions model =
Sub.batch
[ Sub.map ForRails <| RailPuzzle.subscriptions model.rails
, Sub.map ForOverlay <| Overlay.subscriptions model.overlay
]
update : Msg -> Model -> (Model, Cmd Msg) update : Msg -> Model -> (Model, Cmd Msg)
update msg model = update msg model =
...@@ -125,6 +133,11 @@ update msg model = ...@@ -125,6 +133,11 @@ update msg model =
in in
({ model | smv = smv, rails = rails }, cmds) ({ model | smv = smv, rails = rails }, cmds)
ForOverlay msg ->
({ model
| overlay = Overlay.update msg model.overlay
}, Cmd.none)
NextPuzzle -> NextPuzzle ->
if ((model.query_index + 1) < Array.length model.queries) if ((model.query_index + 1) < Array.length model.queries)
then update (SwitchQuery <| toString <| model.query_index + 1) model then update (SwitchQuery <| toString <| model.query_index + 1) model
...@@ -334,6 +347,7 @@ view model = ...@@ -334,6 +347,7 @@ view model =
[ Html.map ForRails <| RailPuzzle.view model.rails ] [ Html.map ForRails <| RailPuzzle.view model.rails ]
, Html.map ForSmv <| Html.lazy NuSmvInput.viewSmvOptions model.smv , Html.map ForSmv <| Html.lazy NuSmvInput.viewSmvOptions model.smv
] ]
, Html.map ForOverlay <| Html.lazy Overlay.view model.overlay
, Html.lazy NuSmvInput.viewPlaceholder model.smv , Html.lazy NuSmvInput.viewPlaceholder model.smv
] ]
......
...@@ -95,7 +95,7 @@ update msg model = ...@@ -95,7 +95,7 @@ update msg model =
ShowSmvFile -> ShowSmvFile ->
re () re ()
|> Maybe.map (\x -> |> Maybe.map (\x ->
Ports.stringInNewTab x.content Ports.stringInNewTab x
) )
DownloadSmvFile -> DownloadSmvFile ->
re () re ()
......
module Overlay exposing (..)
import Html exposing (Html, div, button)
import Html as Html
import Html.Attributes as HA
import Html.Events as HE
import Platform.Sub
import Ports
{-|
A module for showing a kind of big message box with
fixed font content
-}
type alias Model =
{ filename : String
, content : String
, visible : Bool
}
type Msg
= Show { filename : String, content : String }
| Hide
init : Model
init =
{ filename = ""
, content = ""
, visible = False
}
subscriptions : Model -> Sub Msg
subscriptions _ = Ports.showOverlayMessage Show
update : Msg -> Model -> Model
update msg model =
case msg of
Show str ->
{ filename = str.filename
, content = str.content
, visible = True
}
Hide ->
{ filename = ""
, content = ""
, visible = False
}
view : Model -> Html Msg
view model =
div
[ HA.classList
[ ("overlayBox", True)
, ("overlayBoxVisible", model.visible)
]
]
[ div
[ HA.class "overlayHeader" ]
[ Html.text model.filename
, Html.button [ HE.onClick Hide ] [Html.text "X"]
]
, div
[ HA.class "overlayContent" ]
[ Html.text model.content ]
]
-- vim: ft=elm et ts=2 sw=2
...@@ -15,7 +15,7 @@ port scrollIntoView : String -> Cmd msg ...@@ -15,7 +15,7 @@ port scrollIntoView : String -> Cmd msg
-} -}
port svgScreenshot : String -> Cmd msg port svgScreenshot : String -> Cmd msg
port stringInNewTab : String -> Cmd msg port stringInNewTab : { filename : String, content : String } -> Cmd msg
{-| {-|
Trigger a text/plain file download Trigger a text/plain file download
...@@ -24,4 +24,11 @@ port stringInNewTab : String -> Cmd msg ...@@ -24,4 +24,11 @@ port stringInNewTab : String -> Cmd msg
-} -}
port downloadPlainText : { filename : String, content : String } -> Cmd msg port downloadPlainText : { filename : String, content : String } -> Cmd msg
{-|
this subscription is fired if some sourcefile has to be
shown in some kind of message box
-}
port showOverlayMessage : ({ filename : String, content : String } -> msg) -> Sub msg
-- vim: ft=elm et ts=2 sw=2 -- vim: ft=elm et ts=2 sw=2
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment