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 @@
<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="multilang.css">
<link rel="stylesheet" type="text/css" href="overlay.css">
</head>
<body>
<script type="text/javascript">
......@@ -30,11 +31,13 @@
}
});
app.ports.stringInNewTab.subscribe(
function(text) {
function(params) {
/* from http://stackoverflow.com/a/20194533/4400896 */
var a = window.document.createElement('a');
var base64 = btoa(unescape(encodeURIComponent(text)));
window.open("data:text/plain;charset=UTF-8;base64,"+base64,"UTF-8 Text");
// var a = window.document.createElement('a');
// var text = params.content;
// 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(
function(params) {
......
......@@ -27,6 +27,7 @@ import ListUtils
import Shunt
import RailPuzzle.History as RPHist
import MultiLang
import Overlay
type alias Flags =
{ clickableHeader : Bool
......@@ -40,6 +41,7 @@ type alias Model =
, queries : Array (List Int) -- queries to solve for the current puzzle
, smv : NuSmvInput.Model
, languageSwitcher : MultiLang.Model
, overlay : Overlay.Model
, flags : Flags
}
......@@ -49,6 +51,7 @@ type Msg
| SwitchQuery String
| ForSmv NuSmvInput.Msg
| ForMultiLang MultiLang.Msg
| ForOverlay Overlay.Msg
| NextPuzzle
main =
......@@ -88,13 +91,18 @@ init flags =
, queries = Array.fromList ex.queries
, query_index = 0
, languageSwitcher = MultiLang.init
, overlay = Overlay.init
, flags = flags
}
, Cmd.none
)
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 =
......@@ -125,6 +133,11 @@ update msg model =
in
({ model | smv = smv, rails = rails }, cmds)
ForOverlay msg ->
({ model
| overlay = Overlay.update msg model.overlay
}, Cmd.none)
NextPuzzle ->
if ((model.query_index + 1) < Array.length model.queries)
then update (SwitchQuery <| toString <| model.query_index + 1) model
......@@ -334,6 +347,7 @@ view model =
[ Html.map ForRails <| RailPuzzle.view model.rails ]
, Html.map ForSmv <| Html.lazy NuSmvInput.viewSmvOptions model.smv
]
, Html.map ForOverlay <| Html.lazy Overlay.view model.overlay
, Html.lazy NuSmvInput.viewPlaceholder model.smv
]
......
......@@ -95,7 +95,7 @@ update msg model =
ShowSmvFile ->
re ()
|> Maybe.map (\x ->
Ports.stringInNewTab x.content
Ports.stringInNewTab x
)
DownloadSmvFile ->
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
-}
port svgScreenshot : String -> Cmd msg
port stringInNewTab : String -> Cmd msg
port stringInNewTab : { filename : String, content : String } -> Cmd msg
{-|
Trigger a text/plain file download
......@@ -24,4 +24,11 @@ port stringInNewTab : 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
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