Skip to content

Commit 0e629dc

Browse files
committed
feat/embed: open link in newtab in embed view mode
1 parent 6678c56 commit 0e629dc

File tree

6 files changed

+52
-16
lines changed

6 files changed

+52
-16
lines changed

Diff for: assets/js/ports.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,9 @@ export const actions = {
552552
'LOG': (app, session, message) => {
553553
console.log(`From Elm:`, message);
554554
},
555+
'LOGERR': (app, session, message) => {
556+
console.warn(`Error from Elm:`, message);
557+
},
555558
'SHOW': (app, session, id) => {
556559
var $e = document.getElementById(id);
557560
if (!$e) { return }
@@ -564,8 +567,8 @@ export const actions = {
564567
$e.style.display = "none";
565568
//$e.style.visibility = "hidden";
566569
},
567-
'LOGERR': (app, session, message) => {
568-
console.warn(`Error from Elm:`, message);
570+
'OPENINNEWTAB': (app, session, url) => {
571+
window.open(url, '_blank');
569572
},
570573
'CLICK': (app, session, target) => {
571574
if (target == "") {

Diff for: assets/sass/fractal6.scss

+13-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,20 @@
55
*
66
*/
77

8-
#app.embed .is-hidden-embed {
9-
display: none;
8+
#app.embed {
9+
.is-hidden-embed {
10+
display: none !important;
11+
}
12+
13+
.columns {
14+
}
15+
.orgPane > .column, .orgPane > * > .column, .orgPane > * > * > .column {
16+
padding: 0 !important;
17+
width: 100% !important;
18+
}
1019
}
1120

21+
1222
/*
1323
*
1424
* Bulma Fixes
@@ -1205,7 +1215,7 @@ figcaption {
12051215
position: relative;
12061216
//position: absolute;
12071217
box-shadow: 0 0 1px 0 var(--is-highlight);
1208-
margin-top: 3rem;
1218+
margin-top: 4rem;
12091219
padding: 1rem 1rem 1rem;
12101220
}
12111221

Diff for: src/Extra/Url.elm

+12-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
-}
2020

2121

22-
module Extra.Url exposing (queryBuilder, queryFullBuilder, queryParser, toAnchor)
22+
module Extra.Url exposing (getUrlQueryParam, queryBuilder, queryFullBuilder, queryParser, toAnchor)
2323

2424
import Dict exposing (Dict)
25+
import List.Extra as LE
26+
import Maybe exposing (withDefault)
2527
import Url exposing (Url)
2628

2729

@@ -105,3 +107,12 @@ toAnchor x =
105107
|> String.replace " " "-"
106108
|> String.toLower
107109
|> String.append "#"
110+
111+
112+
getUrlQueryParam : String -> Url -> Maybe String
113+
getUrlQueryParam key url =
114+
url.query
115+
|> Maybe.map (String.split "&")
116+
|> Maybe.andThen (LE.find (String.startsWith (key ++ "=")))
117+
|> Maybe.map (String.split "=")
118+
|> Maybe.andThen LE.last

Diff for: src/Main.elm

+6-2
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ module Main exposing (main)
2323

2424
import Browser exposing (Document)
2525
import Browser.Navigation as Nav exposing (Key)
26-
import Extra.Url exposing (queryParser)
26+
import Extra.Url exposing (getUrlQueryParam, queryParser)
2727
import Generated.Pages as Pages
2828
import Generated.Route as Route exposing (Route(..))
2929
import Global exposing (Msg(..))
3030
import Html
3131
import Ports
3232
import Session exposing (encodeViewMode)
3333
import Url exposing (Url)
34+
import Url.Parser.Query
3435

3536

3637
main : Program Flags Model Msg
@@ -94,7 +95,10 @@ update : Msg -> Model -> ( Model, Cmd Msg )
9495
update msg model =
9596
case msg of
9697
LinkClicked (Browser.Internal url) ->
97-
if Route.fromUrl url == Just Route.Logout then
98+
if getUrlQueryParam "view" model.url == Just "embed" then
99+
( model, Ports.openInNewTab (Url.toString url) )
100+
101+
else if Route.fromUrl url == Just Route.Logout then
98102
( model, Nav.replaceUrl model.key (Url.toString url) )
99103

100104
else

Diff for: src/Org/Project.elm

+1-1
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ view_ : Global.Model -> Model -> Html Msg
690690
view_ global model =
691691
div [ class "columns is-centered" ]
692692
[ div [ class "column is-12 is-11-desktop is-10-fullhd pb-0" ]
693-
[ div [ class "columns is-centered mb-0" ]
693+
[ div [ class "columns is-centered mb-0 is-hidden-embed" ]
694694
[ div [ class "column is-tree-quarter pb-1" ]
695695
[ case model.project_data of
696696
Success p ->

Diff for: src/Ports.elm

+15-7
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,14 @@ log message =
591591
}
592592

593593

594+
logErr : String -> Cmd msg
595+
logErr message =
596+
outgoing
597+
{ action = "LOGERR"
598+
, data = JE.string message
599+
}
600+
601+
594602
show : String -> Cmd msg
595603
show message =
596604
outgoing
@@ -607,18 +615,18 @@ hide message =
607615
}
608616

609617

610-
fitHeight : String -> Cmd msg
611-
fitHeight message =
618+
openInNewTab : String -> Cmd msg
619+
openInNewTab url =
612620
outgoing
613-
{ action = "FIT_HEIGHT"
614-
, data = JE.string message
621+
{ action = "OPENINNEWTAB"
622+
, data = JE.string url
615623
}
616624

617625

618-
logErr : String -> Cmd msg
619-
logErr message =
626+
fitHeight : String -> Cmd msg
627+
fitHeight message =
620628
outgoing
621-
{ action = "LOGERR"
629+
{ action = "FIT_HEIGHT"
622630
, data = JE.string message
623631
}
624632

0 commit comments

Comments
 (0)